diff options
author | Jenkins <jenkins@review.openstack.org> | 2014-07-13 16:46:15 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2014-07-13 16:46:15 +0000 |
commit | 4915592dc98dae768281f25b814afd19f1448ea4 (patch) | |
tree | c23b49fcec6bd87e7c852e625bc3cfce18cd40a2 /ironic/nova | |
parent | baf332a1e696d5eab76615dae5ffc39d8c60bc53 (diff) | |
parent | 0aec9f0a5305080115e128d0ec8fac9cf103b010 (diff) | |
download | ironic-4915592dc98dae768281f25b814afd19f1448ea4.tar.gz |
Merge "Clean up nova virt driver test code"
Diffstat (limited to 'ironic/nova')
-rw-r--r-- | ironic/nova/tests/virt/ironic/test_driver.py | 87 |
1 files changed, 41 insertions, 46 deletions
diff --git a/ironic/nova/tests/virt/ironic/test_driver.py b/ironic/nova/tests/virt/ironic/test_driver.py index 9f5d8013f..ec5921b66 100644 --- a/ironic/nova/tests/virt/ironic/test_driver.py +++ b/ironic/nova/tests/virt/ironic/test_driver.py @@ -33,6 +33,7 @@ from nova import context as nova_context from nova import exception from nova.objects import flavor as flavor_obj from nova.objects import instance as instance_obj +from nova.openstack.common import jsonutils from nova.openstack.common import loopingcall from nova.openstack.common import uuidutils from nova import test @@ -65,6 +66,20 @@ class FakeLoopingCall(object): self.start.return_value = self +def _get_properties(): + return {'cpus': 2, + 'memory_mb': 512, + 'local_gb': 10, + 'cpu_arch': 'x86_64'} + + +def _get_stats(): + return {'cpu_arch': 'x86_64', + 'ironic_driver': + 'ironic.nova.virt.ironic.driver.IronicDriver', + 'test_spec': 'test_value'} + + FAKE_CLIENT_WRAPPER = FakeClientWrapper() @@ -117,70 +132,53 @@ class IronicDriverTestCase(test.NoDBTestCase): icli, instance) def test__node_resource(self): - node_uuid = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee' - cpus = 2 - mem = 512 - disk = 10 - arch = 'x86_64' - properties = {'cpus': cpus, 'memory_mb': mem, - 'local_gb': disk, 'cpu_arch': arch} + node_uuid = uuidutils.generate_uuid() + instance_uuid = uuidutils.generate_uuid() + props = _get_properties() + stats = _get_stats() node = ironic_utils.get_test_node(uuid=node_uuid, - instance_uuid=uuidutils.generate_uuid(), - properties=properties) + instance_uuid=instance_uuid, + properties=props) result = self.driver._node_resource(node) - self.assertEqual(cpus, result['vcpus']) - self.assertEqual(cpus, result['vcpus_used']) - self.assertEqual(mem, result['memory_mb']) - self.assertEqual(mem, result['memory_mb_used']) - self.assertEqual(disk, result['local_gb']) - self.assertEqual(disk, result['local_gb_used']) + self.assertEqual(props['cpus'], result['vcpus']) + self.assertEqual(props['cpus'], result['vcpus_used']) + self.assertEqual(props['memory_mb'], result['memory_mb']) + self.assertEqual(props['memory_mb'], result['memory_mb_used']) + self.assertEqual(props['local_gb'], result['local_gb']) + self.assertEqual(props['local_gb'], result['local_gb_used']) self.assertEqual(node_uuid, result['hypervisor_hostname']) - self.assertEqual('{"cpu_arch": "x86_64", "ironic_driver": "' - 'ironic.nova.virt.ironic.driver.IronicDriver", ' - '"test_spec": "test_value"}', - result['stats']) + self.assertEqual(stats, jsonutils.loads(result['stats'])) def test__node_resource_no_instance_uuid(self): - node_uuid = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee' - cpus = 2 - mem = 512 - disk = 10 - arch = 'x86_64' - properties = {'cpus': cpus, 'memory_mb': mem, - 'local_gb': disk, 'cpu_arch': arch} + node_uuid = uuidutils.generate_uuid() + props = _get_properties() + stats = _get_stats() node = ironic_utils.get_test_node(uuid=node_uuid, instance_uuid=None, power_state=ironic_states.POWER_OFF, - properties=properties) + properties=props) result = self.driver._node_resource(node) - self.assertEqual(cpus, result['vcpus']) + self.assertEqual(props['cpus'], result['vcpus']) self.assertEqual(0, result['vcpus_used']) - self.assertEqual(mem, result['memory_mb']) + self.assertEqual(props['memory_mb'], result['memory_mb']) self.assertEqual(0, result['memory_mb_used']) - self.assertEqual(disk, result['local_gb']) + self.assertEqual(props['local_gb'], result['local_gb']) self.assertEqual(0, result['local_gb_used']) self.assertEqual(node_uuid, result['hypervisor_hostname']) - self.assertEqual('{"cpu_arch": "x86_64", "ironic_driver": "' - 'ironic.nova.virt.ironic.driver.IronicDriver", ' - '"test_spec": "test_value"}', - result['stats']) + self.assertEqual(stats, jsonutils.loads(result['stats'])) @mock.patch.object(ironic_driver.IronicDriver, '_node_resources_unavailable') def test__node_resource_unavailable_node_res(self, mock_res_unavail): mock_res_unavail.return_value = True - node_uuid = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee' - cpus = 2 - mem = 512 - disk = 10 - arch = 'x86_64' - properties = {'cpus': cpus, 'memory_mb': mem, - 'local_gb': disk, 'cpu_arch': arch} + node_uuid = uuidutils.generate_uuid() + props = _get_properties() + stats = _get_stats() node = ironic_utils.get_test_node(uuid=node_uuid, instance_uuid=None, - properties=properties) + properties=props) result = self.driver._node_resource(node) self.assertEqual(0, result['vcpus']) @@ -190,10 +188,7 @@ class IronicDriverTestCase(test.NoDBTestCase): self.assertEqual(0, result['local_gb']) self.assertEqual(0, result['local_gb_used']) self.assertEqual(node_uuid, result['hypervisor_hostname']) - self.assertEqual('{"cpu_arch": "x86_64", "ironic_driver": "' - 'ironic.nova.virt.ironic.driver.IronicDriver", ' - '"test_spec": "test_value"}', - result['stats']) + self.assertEqual(stats, jsonutils.loads(result['stats'])) @mock.patch.object(firewall.NoopFirewallDriver, 'prepare_instance_filter', create=True) |