Merge "Add importing modules instead of classes"
This commit is contained in:
@@ -17,17 +17,16 @@
|
||||
import mock
|
||||
|
||||
from watcher.common import utils
|
||||
from watcher.decision_engine.audit.default import DefaultAuditHandler
|
||||
from watcher.decision_engine.messaging.audit_endpoint import AuditEndpoint
|
||||
from watcher.metrics_engine.cluster_model_collector.manager import \
|
||||
CollectorManager
|
||||
from watcher.tests.db.base import DbTestCase
|
||||
from watcher.tests.decision_engine.strategy.strategies.faker_cluster_state \
|
||||
import FakerModelCollector
|
||||
from watcher.decision_engine.audit import default
|
||||
from watcher.decision_engine.messaging import audit_endpoint
|
||||
from watcher.metrics_engine.cluster_model_collector import manager
|
||||
from watcher.tests.db import base
|
||||
from watcher.tests.decision_engine.strategy.strategies \
|
||||
import faker_cluster_state
|
||||
from watcher.tests.objects import utils as obj_utils
|
||||
|
||||
|
||||
class TestAuditEndpoint(DbTestCase):
|
||||
class TestAuditEndpoint(base.DbTestCase):
|
||||
def setUp(self):
|
||||
super(TestAuditEndpoint, self).setUp()
|
||||
self.audit_template = obj_utils.create_test_audit_template(
|
||||
@@ -36,28 +35,29 @@ class TestAuditEndpoint(DbTestCase):
|
||||
self.context,
|
||||
audit_template_id=self.audit_template.id)
|
||||
|
||||
@mock.patch.object(CollectorManager, "get_cluster_model_collector")
|
||||
@mock.patch.object(manager.CollectorManager, "get_cluster_model_collector")
|
||||
def test_do_trigger_audit(self, mock_collector):
|
||||
mock_collector.return_value = FakerModelCollector()
|
||||
mock_collector.return_value = faker_cluster_state.FakerModelCollector()
|
||||
audit_uuid = utils.generate_uuid()
|
||||
|
||||
audit_handler = DefaultAuditHandler(mock.MagicMock())
|
||||
endpoint = AuditEndpoint(audit_handler)
|
||||
audit_handler = default.DefaultAuditHandler(mock.MagicMock())
|
||||
endpoint = audit_endpoint.AuditEndpoint(audit_handler)
|
||||
|
||||
with mock.patch.object(DefaultAuditHandler, 'execute') as mock_call:
|
||||
with mock.patch.object(default.DefaultAuditHandler,
|
||||
'execute') as mock_call:
|
||||
mock_call.return_value = 0
|
||||
endpoint.do_trigger_audit(audit_handler, audit_uuid)
|
||||
|
||||
mock_call.assert_called_once_with(audit_uuid, audit_handler)
|
||||
|
||||
@mock.patch.object(CollectorManager, "get_cluster_model_collector")
|
||||
@mock.patch.object(manager.CollectorManager, "get_cluster_model_collector")
|
||||
def test_trigger_audit(self, mock_collector):
|
||||
mock_collector.return_value = FakerModelCollector()
|
||||
mock_collector.return_value = faker_cluster_state.FakerModelCollector()
|
||||
audit_uuid = utils.generate_uuid()
|
||||
audit_handler = DefaultAuditHandler(mock.MagicMock())
|
||||
endpoint = AuditEndpoint(audit_handler)
|
||||
audit_handler = default.DefaultAuditHandler(mock.MagicMock())
|
||||
endpoint = audit_endpoint.AuditEndpoint(audit_handler)
|
||||
|
||||
with mock.patch.object(DefaultAuditHandler, 'execute') \
|
||||
with mock.patch.object(default.DefaultAuditHandler, 'execute') \
|
||||
as mock_call:
|
||||
mock_call.return_value = 0
|
||||
endpoint.trigger_audit(audit_handler, audit_uuid)
|
||||
|
||||
@@ -17,13 +17,13 @@
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
from watcher.decision_engine.model.disk_info import DiskInfo
|
||||
from watcher.decision_engine.model import disk_info
|
||||
from watcher.tests import base
|
||||
|
||||
|
||||
class TestDiskInfo(base.BaseTestCase):
|
||||
def test_all(self):
|
||||
disk_information = DiskInfo()
|
||||
disk_information = disk_info.DiskInfo()
|
||||
disk_information.set_size(1024)
|
||||
self.assertEqual(1024, disk_information.get_size())
|
||||
|
||||
|
||||
@@ -19,18 +19,17 @@
|
||||
import uuid
|
||||
|
||||
from watcher.common import exception
|
||||
from watcher.common.exception import IllegalArgumentException
|
||||
from watcher.decision_engine.model.hypervisor import Hypervisor
|
||||
from watcher.decision_engine.model.hypervisor_state import HypervisorState
|
||||
from watcher.decision_engine.model.model_root import ModelRoot
|
||||
from watcher.decision_engine.model import hypervisor as hypervisor_model
|
||||
from watcher.decision_engine.model import hypervisor_state
|
||||
from watcher.decision_engine.model import model_root
|
||||
from watcher.tests import base
|
||||
from watcher.tests.decision_engine.strategy.strategies.faker_cluster_state import \
|
||||
FakerModelCollector
|
||||
from watcher.tests.decision_engine.strategy.strategies \
|
||||
import faker_cluster_state
|
||||
|
||||
|
||||
class TestModel(base.BaseTestCase):
|
||||
def test_model(self):
|
||||
fake_cluster = FakerModelCollector()
|
||||
fake_cluster = faker_cluster_state.FakerModelCollector()
|
||||
model = fake_cluster.generate_scenario_1()
|
||||
|
||||
self.assertEqual(5, len(model._hypervisors))
|
||||
@@ -38,17 +37,17 @@ class TestModel(base.BaseTestCase):
|
||||
self.assertEqual(5, len(model.get_mapping().get_mapping()))
|
||||
|
||||
def test_add_hypervisor(self):
|
||||
model = ModelRoot()
|
||||
model = model_root.ModelRoot()
|
||||
id = "{0}".format(uuid.uuid4())
|
||||
hypervisor = Hypervisor()
|
||||
hypervisor = hypervisor_model.Hypervisor()
|
||||
hypervisor.uuid = id
|
||||
model.add_hypervisor(hypervisor)
|
||||
self.assertEqual(hypervisor, model.get_hypervisor_from_id(id))
|
||||
|
||||
def test_delete_hypervisor(self):
|
||||
model = ModelRoot()
|
||||
model = model_root.ModelRoot()
|
||||
id = "{0}".format(uuid.uuid4())
|
||||
hypervisor = Hypervisor()
|
||||
hypervisor = hypervisor_model.Hypervisor()
|
||||
hypervisor.uuid = id
|
||||
model.add_hypervisor(hypervisor)
|
||||
self.assertEqual(hypervisor, model.get_hypervisor_from_id(id))
|
||||
@@ -57,10 +56,10 @@ class TestModel(base.BaseTestCase):
|
||||
model.get_hypervisor_from_id, id)
|
||||
|
||||
def test_get_all_hypervisors(self):
|
||||
model = ModelRoot()
|
||||
model = model_root.ModelRoot()
|
||||
for i in range(10):
|
||||
id = "{0}".format(uuid.uuid4())
|
||||
hypervisor = Hypervisor()
|
||||
hypervisor = hypervisor_model.Hypervisor()
|
||||
hypervisor.uuid = id
|
||||
model.add_hypervisor(hypervisor)
|
||||
all_hypervisors = model.get_all_hypervisors()
|
||||
@@ -69,17 +68,18 @@ class TestModel(base.BaseTestCase):
|
||||
model.assert_hypervisor(hyp)
|
||||
|
||||
def test_set_get_state_hypervisors(self):
|
||||
model = ModelRoot()
|
||||
model = model_root.ModelRoot()
|
||||
id = "{0}".format(uuid.uuid4())
|
||||
hypervisor = Hypervisor()
|
||||
hypervisor = hypervisor_model.Hypervisor()
|
||||
hypervisor.uuid = id
|
||||
model.add_hypervisor(hypervisor)
|
||||
|
||||
self.assertIsInstance(hypervisor.state, HypervisorState)
|
||||
self.assertIsInstance(hypervisor.state,
|
||||
hypervisor_state.HypervisorState)
|
||||
|
||||
hyp = model.get_hypervisor_from_id(id)
|
||||
hyp.state = HypervisorState.OFFLINE
|
||||
self.assertIsInstance(hyp.state, HypervisorState)
|
||||
hyp.state = hypervisor_state.HypervisorState.OFFLINE
|
||||
self.assertIsInstance(hyp.state, hypervisor_state.HypervisorState)
|
||||
|
||||
# /watcher/decision_engine/framework/model/hypervisor.py
|
||||
# set_state accept any char chain.
|
||||
@@ -93,9 +93,9 @@ class TestModel(base.BaseTestCase):
|
||||
# vms = model.get_all_vms()
|
||||
# self.assert(len(model._vms))
|
||||
def test_hypervisor_from_id_raise(self):
|
||||
model = ModelRoot()
|
||||
model = model_root.ModelRoot()
|
||||
id = "{0}".format(uuid.uuid4())
|
||||
hypervisor = Hypervisor()
|
||||
hypervisor = hypervisor_model.Hypervisor()
|
||||
hypervisor.uuid = id
|
||||
model.add_hypervisor(hypervisor)
|
||||
|
||||
@@ -104,35 +104,35 @@ class TestModel(base.BaseTestCase):
|
||||
model.get_hypervisor_from_id, id2)
|
||||
|
||||
def test_remove_hypervisor_raise(self):
|
||||
model = ModelRoot()
|
||||
model = model_root.ModelRoot()
|
||||
id = "{0}".format(uuid.uuid4())
|
||||
hypervisor = Hypervisor()
|
||||
hypervisor = hypervisor_model.Hypervisor()
|
||||
hypervisor.uuid = id
|
||||
model.add_hypervisor(hypervisor)
|
||||
|
||||
id2 = "{0}".format(uuid.uuid4())
|
||||
hypervisor2 = Hypervisor()
|
||||
hypervisor2 = hypervisor_model.Hypervisor()
|
||||
hypervisor2.uuid = id2
|
||||
|
||||
self.assertRaises(exception.HypervisorNotFound,
|
||||
model.remove_hypervisor, hypervisor2)
|
||||
|
||||
def test_assert_hypervisor_raise(self):
|
||||
model = ModelRoot()
|
||||
model = model_root.ModelRoot()
|
||||
id = "{0}".format(uuid.uuid4())
|
||||
hypervisor = Hypervisor()
|
||||
hypervisor = hypervisor_model.Hypervisor()
|
||||
hypervisor.uuid = id
|
||||
model.add_hypervisor(hypervisor)
|
||||
self.assertRaises(IllegalArgumentException,
|
||||
self.assertRaises(exception.IllegalArgumentException,
|
||||
model.assert_hypervisor, "objet_qcq")
|
||||
|
||||
def test_vm_from_id_raise(self):
|
||||
fake_cluster = FakerModelCollector()
|
||||
fake_cluster = faker_cluster_state.FakerModelCollector()
|
||||
model = fake_cluster.generate_scenario_1()
|
||||
self.assertRaises(exception.InstanceNotFound,
|
||||
model.get_vm_from_id, "valeur_qcq")
|
||||
|
||||
def test_assert_vm_raise(self):
|
||||
model = ModelRoot()
|
||||
self.assertRaises(IllegalArgumentException,
|
||||
model = model_root.ModelRoot()
|
||||
self.assertRaises(exception.IllegalArgumentException,
|
||||
model.assert_vm, "valeur_qcq")
|
||||
|
||||
@@ -16,17 +16,17 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
from watcher.decision_engine.model.compute_resource import ComputeResource
|
||||
from watcher.decision_engine.model import compute_resource
|
||||
from watcher.tests import base
|
||||
|
||||
|
||||
class TestNamedElement(base.BaseTestCase):
|
||||
def test_namedelement(self):
|
||||
id = ComputeResource()
|
||||
id = compute_resource.ComputeResource()
|
||||
id.uuid = "BLABLABLA"
|
||||
self.assertEqual("BLABLABLA", id.uuid)
|
||||
|
||||
def test_set_get_human_id(self):
|
||||
id = ComputeResource()
|
||||
id = compute_resource.ComputeResource()
|
||||
id.human_id = "BLABLABLA"
|
||||
self.assertEqual("BLABLABLA", id.human_id)
|
||||
|
||||
@@ -16,15 +16,15 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
from watcher.decision_engine.model.vm import VM
|
||||
from watcher.decision_engine.model.vm_state import VMState
|
||||
from watcher.decision_engine.model import vm as vm_model
|
||||
from watcher.decision_engine.model import vm_state
|
||||
from watcher.tests import base
|
||||
|
||||
|
||||
class TestVm(base.BaseTestCase):
|
||||
def test_namedelement(self):
|
||||
vm = VM()
|
||||
vm.state = VMState.ACTIVE
|
||||
self.assertEqual(VMState.ACTIVE, vm.state)
|
||||
vm = vm_model.VM()
|
||||
vm.state = vm_state.VMState.ACTIVE
|
||||
self.assertEqual(vm_state.VMState.ACTIVE, vm.state)
|
||||
vm.human_id = "human_05"
|
||||
self.assertEqual("human_05", vm.human_id)
|
||||
|
||||
@@ -18,7 +18,7 @@ import mock
|
||||
import oslo_messaging as om
|
||||
from watcher.common import exception
|
||||
from watcher.common import utils
|
||||
from watcher.decision_engine.rpcapi import DecisionEngineAPI
|
||||
from watcher.decision_engine import rpcapi
|
||||
from watcher.tests import base
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ class TestDecisionEngineAPI(base.TestCase):
|
||||
def setUp(self):
|
||||
super(TestDecisionEngineAPI, self).setUp()
|
||||
|
||||
api = DecisionEngineAPI()
|
||||
api = rpcapi.DecisionEngineAPI()
|
||||
|
||||
def test_get_version(self):
|
||||
expected_version = self.api.API_VERSION
|
||||
@@ -40,7 +40,7 @@ class TestDecisionEngineAPI(base.TestCase):
|
||||
mock_call.assert_called_once_with(
|
||||
expected_context.to_dict(),
|
||||
'check_api_version',
|
||||
api_version=DecisionEngineAPI().api_version)
|
||||
api_version=rpcapi.DecisionEngineAPI().api_version)
|
||||
|
||||
def test_execute_audit_throw_exception(self):
|
||||
audit_uuid = "uuid"
|
||||
|
||||
Reference in New Issue
Block a user