Import module instead of class

Bug #1594434 reported by Vincent Françoise on 2016-06-20
14
This bug affects 2 people
Affects Status Importance Assigned to Milestone
watcher
Low
Alexander Stavitskiy

Bug Description

Via the 'grep -r watcher/ -e "import [A-Z]"' command, we can see that there are many places in the watcher codebase where we are importing classes instead of their parent modules.

The objective would be to tidy up our codebase by refactoring these import statements to import the parent module instead of importing the class directly.

NOTE: sqlalchemy imports shouldn't be fixed as they are an exception to the rule (see http://docs.openstack.org/developer/hacking/#imports)

Here below is the current list of imports to fix:

watcher/db/sqlalchemy/models.py:from sqlalchemy.types import TypeDecorator, TEXT
watcher/common/ceilometer_helper.py:from ceilometerclient.exc import HTTPUnauthorized
watcher/decision_engine/messaging/events.py:from enum import Enum
watcher/decision_engine/model/resource.py:from enum import Enum
watcher/decision_engine/model/power_state.py:from enum import Enum
watcher/decision_engine/model/hypervisor_state.py:from enum import Enum
watcher/decision_engine/model/mapping.py:from threading import Lock
watcher/decision_engine/model/hypervisor.py:from watcher.decision_engine.model.compute_resource import ComputeResource
watcher/decision_engine/model/hypervisor.py:from watcher.decision_engine.model.hypervisor_state import HypervisorState
watcher/decision_engine/model/hypervisor.py:from watcher.decision_engine.model.power_state import PowerState
watcher/decision_engine/model/vm_state.py:from enum import Enum
watcher/decision_engine/model/vm.py:from watcher.decision_engine.model.compute_resource import ComputeResource
watcher/decision_engine/model/vm.py:from watcher.decision_engine.model.vm_state import VMState
watcher/tests/common/loader/test_loader.py:from stevedore.extension import Extension
watcher/tests/common/messaging/test_notification_handler.py:from watcher.common.messaging.notification_handler import NotificationHandler
watcher/tests/common/messaging/test_notification_handler.py:from watcher.common.messaging.utils.observable import Observable
watcher/tests/common/messaging/event/test_event_dispatcher.py:from mock import MagicMock
watcher/tests/common/messaging/event/test_event_dispatcher.py:from watcher.common.messaging.events.event import Event
watcher/tests/common/messaging/event/test_event_dispatcher.py:from watcher.common.messaging.events.event_dispatcher import EventDispatcher
watcher/tests/common/messaging/event/test_event_dispatcher.py:from watcher.decision_engine.messaging.events import Events
watcher/tests/cmd/test_applier.py:from watcher.tests.base import BaseTestCase
watcher/tests/decision_engine/messaging/test_audit_endpoint.py:from watcher.decision_engine.audit.default import DefaultAuditHandler
watcher/tests/decision_engine/messaging/test_audit_endpoint.py:from watcher.decision_engine.messaging.audit_endpoint import AuditEndpoint
watcher/tests/decision_engine/messaging/test_audit_endpoint.py:from watcher.tests.db.base import DbTestCase
watcher/tests/decision_engine/messaging/test_audit_endpoint.py: import FakerModelCollector
watcher/tests/decision_engine/model/test_model.py:from watcher.common.exception import IllegalArgumentException
watcher/tests/decision_engine/model/test_model.py:from watcher.decision_engine.model.hypervisor import Hypervisor
watcher/tests/decision_engine/model/test_model.py:from watcher.decision_engine.model.hypervisor_state import HypervisorState
watcher/tests/decision_engine/model/test_model.py:from watcher.decision_engine.model.model_root import ModelRoot
watcher/tests/decision_engine/model/test_named_element.py:from watcher.decision_engine.model.compute_resource import ComputeResource
watcher/tests/decision_engine/model/test_disk_info.py:from watcher.decision_engine.model.disk_info import DiskInfo
watcher/tests/decision_engine/model/test_vm.py:from watcher.decision_engine.model.vm import VM
watcher/tests/decision_engine/model/test_vm.py:from watcher.decision_engine.model.vm_state import VMState
watcher/tests/decision_engine/test_rpcapi.py:from watcher.decision_engine.rpcapi import DecisionEngineAPI
watcher/tests/applier/test_rpcapi.py:from watcher.applier.rpcapi import ApplierAPI
watcher/tests/objects/test_action_plan.py:from testtools.matchers import HasLength
watcher/tests/objects/test_action.py:from testtools.matchers import HasLength
watcher/tests/objects/test_audit.py:from testtools.matchers import HasLength
watcher/tests/objects/test_efficacy_indicator.py:from testtools.matchers import HasLength

Changed in watcher:
assignee: nobody → Alexander Stavitskiy (alexstav)
milestone: none → newton-2

Fix proposed to branch: master
Review: https://review.openstack.org/332241

Changed in watcher:
status: Triaged → In Progress

Reviewed: https://review.openstack.org/332241
Committed: https://git.openstack.org/cgit/openstack/watcher/commit/?id=cb693e40935a5da8b854f14e3b8f2a1469051957
Submitter: Jenkins
Branch: master

commit cb693e40935a5da8b854f14e3b8f2a1469051957
Author: Alexandr Stavitskiy <email address hidden>
Date: Tue Jun 21 19:37:01 2016 +0300

    Add importing modules instead of classes

    This patch removes import of classes and replaces them with import of modules.

    Change-Id: Id2502cf96ac7227cf1036cd54a74f3d7acd83479
    Closes-Bug: #1594434

Changed in watcher:
status: In Progress → Fix Released

This issue was fixed in the openstack/watcher 0.28.0 release.

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Duplicates of this bug

Other bug subscribers