From b32df54c93955df3ee46bf86da1c3f467856c589 Mon Sep 17 00:00:00 2001 From: Gary Kotton Date: Mon, 8 Sep 2014 00:44:01 -0700 Subject: [PATCH] Ironic: Fix direct use of flavor and instance module objects This replaces all uses of nova.objects.flavor_obj.Flavor* with nova.objects.Flavor* and nova.objects.instance_obj.Instance* with nova.objects.Instance* This work was done throughout Nova. An example of this is commit 3c1085f528596089a638ac3bb44a9ed3e201e62f. Change-Id: I8f2dbb408acbdf8124bc141925de03ce6f12bd91 --- nova/tests/virt/ironic/test_driver.py | 37 +++++++++++++-------------- nova/virt/ironic/driver.py | 19 +++++++------- 2 files changed, 27 insertions(+), 29 deletions(-) diff --git a/nova/tests/virt/ironic/test_driver.py b/nova/tests/virt/ironic/test_driver.py index 409e4d603d67..0c53f9bd4d00 100644 --- a/nova/tests/virt/ironic/test_driver.py +++ b/nova/tests/virt/ironic/test_driver.py @@ -23,8 +23,7 @@ from nova.compute import power_state as nova_states from nova.compute import task_states 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 import objects from nova.openstack.common import jsonutils from nova.openstack.common import loopingcall from nova.openstack.common import uuidutils @@ -272,7 +271,7 @@ class IronicDriverTestCase(test.NoDBTestCase, test_driver.DriverAPITestHelper): instance_uuid) @mock.patch.object(cw.IronicClientWrapper, 'call') - @mock.patch.object(instance_obj.Instance, 'get_by_uuid') + @mock.patch.object(objects.Instance, 'get_by_uuid') def test_list_instances(self, mock_inst_by_uuid, mock_call): nodes = [] instances = [] @@ -484,10 +483,10 @@ class IronicDriverTestCase(test.NoDBTestCase, test_driver.DriverAPITestHelper): result = self.driver.macs_for_instance(instance) self.assertIsNone(result) - @mock.patch.object(instance_obj.Instance, 'save') + @mock.patch.object(objects.Instance, 'save') @mock.patch.object(loopingcall, 'FixedIntervalLoopingCall') @mock.patch.object(FAKE_CLIENT, 'node') - @mock.patch.object(flavor_obj.Flavor, 'get_by_id') + @mock.patch.object(objects.Flavor, 'get_by_id') @mock.patch.object(ironic_driver.IronicDriver, '_wait_for_active') @mock.patch.object(ironic_driver.IronicDriver, '_add_driver_fields') @mock.patch.object(ironic_driver.IronicDriver, '_plug_vifs') @@ -532,7 +531,7 @@ class IronicDriverTestCase(test.NoDBTestCase, test_driver.DriverAPITestHelper): @mock.patch.object(loopingcall, 'FixedIntervalLoopingCall') @mock.patch.object(FAKE_CLIENT, 'node') - @mock.patch.object(flavor_obj.Flavor, 'get_by_id') + @mock.patch.object(objects.Flavor, 'get_by_id') @mock.patch.object(ironic_driver.IronicDriver, 'destroy') @mock.patch.object(ironic_driver.IronicDriver, '_wait_for_active') @mock.patch.object(ironic_driver.IronicDriver, '_add_driver_fields') @@ -593,7 +592,7 @@ class IronicDriverTestCase(test.NoDBTestCase, test_driver.DriverAPITestHelper): self.driver._add_driver_fields, node, instance, image_meta, flavor) - @mock.patch.object(flavor_obj.Flavor, 'get_by_id') + @mock.patch.object(objects.Flavor, 'get_by_id') @mock.patch.object(FAKE_CLIENT.node, 'update') def test__cleanup_deploy_good(self, mock_update, mock_flavor): mock_flavor.return_value = ironic_utils.get_test_flavor(extra_specs={}) @@ -605,7 +604,7 @@ class IronicDriverTestCase(test.NoDBTestCase, test_driver.DriverAPITestHelper): expected_patch = [{'path': '/instance_uuid', 'op': 'remove'}] mock_update.assert_called_once_with(node.uuid, expected_patch) - @mock.patch.object(flavor_obj.Flavor, 'get_by_id') + @mock.patch.object(objects.Flavor, 'get_by_id') @mock.patch.object(FAKE_CLIENT.node, 'update') def test__cleanup_deploy_fail(self, mock_update, mock_flavor): mock_flavor.return_value = ironic_utils.get_test_flavor(extra_specs={}) @@ -619,7 +618,7 @@ class IronicDriverTestCase(test.NoDBTestCase, test_driver.DriverAPITestHelper): self.ctx, node, instance, None) @mock.patch.object(FAKE_CLIENT, 'node') - @mock.patch.object(flavor_obj.Flavor, 'get_by_id') + @mock.patch.object(objects.Flavor, 'get_by_id') def test_spawn_node_driver_validation_fail(self, mock_flavor, mock_node): mock_flavor.return_value = ironic_utils.get_test_flavor() node_uuid = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee' @@ -638,7 +637,7 @@ class IronicDriverTestCase(test.NoDBTestCase, test_driver.DriverAPITestHelper): mock_flavor.assert_called_with(mock.ANY, instance['instance_type_id']) @mock.patch.object(FAKE_CLIENT, 'node') - @mock.patch.object(flavor_obj.Flavor, 'get_by_id') + @mock.patch.object(objects.Flavor, 'get_by_id') @mock.patch.object(ironic_driver.IronicDriver, '_start_firewall') @mock.patch.object(ironic_driver.IronicDriver, '_plug_vifs') @mock.patch.object(ironic_driver.IronicDriver, '_cleanup_deploy') @@ -667,7 +666,7 @@ class IronicDriverTestCase(test.NoDBTestCase, test_driver.DriverAPITestHelper): mock_cleanup_deploy.assert_called_with(self.ctx, node, instance, None) @mock.patch.object(FAKE_CLIENT, 'node') - @mock.patch.object(flavor_obj.Flavor, 'get_by_id') + @mock.patch.object(objects.Flavor, 'get_by_id') @mock.patch.object(ironic_driver.IronicDriver, '_start_firewall') @mock.patch.object(ironic_driver.IronicDriver, '_plug_vifs') @mock.patch.object(ironic_driver.IronicDriver, '_cleanup_deploy') @@ -695,7 +694,7 @@ class IronicDriverTestCase(test.NoDBTestCase, test_driver.DriverAPITestHelper): instance, None) @mock.patch.object(FAKE_CLIENT, 'node') - @mock.patch.object(flavor_obj.Flavor, 'get_by_id') + @mock.patch.object(objects.Flavor, 'get_by_id') @mock.patch.object(ironic_driver.IronicDriver, '_start_firewall') @mock.patch.object(ironic_driver.IronicDriver, '_plug_vifs') @mock.patch.object(ironic_driver.IronicDriver, '_cleanup_deploy') @@ -724,7 +723,7 @@ class IronicDriverTestCase(test.NoDBTestCase, test_driver.DriverAPITestHelper): @mock.patch.object(loopingcall, 'FixedIntervalLoopingCall') @mock.patch.object(FAKE_CLIENT, 'node') - @mock.patch.object(flavor_obj.Flavor, 'get_by_id') + @mock.patch.object(objects.Flavor, 'get_by_id') @mock.patch.object(ironic_driver.IronicDriver, '_start_firewall') @mock.patch.object(ironic_driver.IronicDriver, '_plug_vifs') @mock.patch.object(ironic_driver.IronicDriver, 'destroy') @@ -754,9 +753,9 @@ class IronicDriverTestCase(test.NoDBTestCase, test_driver.DriverAPITestHelper): fake_net_info) @mock.patch.object(loopingcall, 'FixedIntervalLoopingCall') - @mock.patch.object(instance_obj.Instance, 'save') + @mock.patch.object(objects.Instance, 'save') @mock.patch.object(FAKE_CLIENT, 'node') - @mock.patch.object(flavor_obj.Flavor, 'get_by_id') + @mock.patch.object(objects.Flavor, 'get_by_id') @mock.patch.object(ironic_driver.IronicDriver, '_wait_for_active') @mock.patch.object(ironic_driver.IronicDriver, '_plug_vifs') @mock.patch.object(ironic_driver.IronicDriver, '_start_firewall') @@ -1072,10 +1071,10 @@ class IronicDriverTestCase(test.NoDBTestCase, test_driver.DriverAPITestHelper): @mock.patch.object(ironic_driver.IronicDriver, '_wait_for_active') @mock.patch.object(loopingcall, 'FixedIntervalLoopingCall') @mock.patch.object(FAKE_CLIENT.node, 'set_provision_state') - @mock.patch.object(flavor_obj.Flavor, 'get_by_id') + @mock.patch.object(objects.Flavor, 'get_by_id') @mock.patch.object(ironic_driver.IronicDriver, '_add_driver_fields') @mock.patch.object(FAKE_CLIENT.node, 'get') - @mock.patch.object(instance_obj.Instance, 'save') + @mock.patch.object(objects.Instance, 'save') def _test_rebuild(self, mock_save, mock_get, mock_driver_fields, mock_fg_bid, mock_set_pstate, mock_looping, mock_wait_active, preserve=False): @@ -1125,10 +1124,10 @@ class IronicDriverTestCase(test.NoDBTestCase, test_driver.DriverAPITestHelper): self._test_rebuild(preserve=False) @mock.patch.object(FAKE_CLIENT.node, 'set_provision_state') - @mock.patch.object(flavor_obj.Flavor, 'get_by_id') + @mock.patch.object(objects.Flavor, 'get_by_id') @mock.patch.object(ironic_driver.IronicDriver, '_add_driver_fields') @mock.patch.object(FAKE_CLIENT.node, 'get') - @mock.patch.object(instance_obj.Instance, 'save') + @mock.patch.object(objects.Instance, 'save') def test_rebuild_failures(self, mock_save, mock_get, mock_driver_fields, mock_fg_bid, mock_set_pstate): node_uuid = uuidutils.generate_uuid() diff --git a/nova/virt/ironic/driver.py b/nova/virt/ironic/driver.py index 369717436875..342a26ef8309 100644 --- a/nova/virt/ironic/driver.py +++ b/nova/virt/ironic/driver.py @@ -34,8 +34,7 @@ from nova import exception from nova.i18n import _ from nova.i18n import _LE from nova.i18n import _LW -from nova.objects import flavor as flavor_obj -from nova.objects import instance as instance_obj +from nova import objects from nova.openstack.common import excutils from nova.openstack.common import importutils from nova.openstack.common import jsonutils @@ -293,8 +292,8 @@ class IronicDriver(virt_driver.ComputeDriver): icli = client_wrapper.IronicClientWrapper() # TODO(mrda): It would be better to use instance.get_flavor() here # but right now that doesn't include extra_specs which are required - flavor = flavor_obj.Flavor.get_by_id(context, - instance['instance_type_id']) + flavor = objects.Flavor.get_by_id(context, + instance['instance_type_id']) patch = patcher.create(node).get_cleanup_patch(instance, network_info, flavor) @@ -379,8 +378,8 @@ class IronicDriver(virt_driver.ComputeDriver): icli = client_wrapper.IronicClientWrapper() node_list = icli.call("node.list", associated=True) context = nova_context.get_admin_context() - return [instance_obj.Instance.get_by_uuid(context, - i.instance_uuid).name + return [objects.Instance.get_by_uuid(context, + i.instance_uuid).name for i in node_list] def list_instance_uuids(self): @@ -583,8 +582,8 @@ class IronicDriver(virt_driver.ComputeDriver): icli = client_wrapper.IronicClientWrapper() node = icli.call("node.get", node_uuid) - flavor = flavor_obj.Flavor.get_by_id(context, - instance['instance_type_id']) + flavor = objects.Flavor.get_by_id(context, + instance['instance_type_id']) self._add_driver_fields(node, instance, image_meta, flavor) @@ -965,8 +964,8 @@ class IronicDriver(virt_driver.ComputeDriver): node_uuid = instance.node icli = client_wrapper.IronicClientWrapper() node = icli.call("node.get", node_uuid) - flavor = flavor_obj.Flavor.get_by_id(context, - instance['instance_type_id']) + flavor = objects.Flavor.get_by_id(context, + instance['instance_type_id']) self._add_driver_fields(node, instance, image_meta, flavor, preserve_ephemeral)