From 8a862715bfb17f70b480258c263b5d99d058d3e3 Mon Sep 17 00:00:00 2001 From: Matt Riedemann Date: Wed, 13 Aug 2014 14:27:22 -0700 Subject: [PATCH] Remove _instance_update usage in _build_instance The _build_instance method has an instance object so just call instance.save() rather than _instance_update which does a separate call to conductor to update the instance updates the resource tracker, which is unnecessary in this case. Compare to the _build_resources method. Part of blueprint compute-manager-objects-juno Change-Id: Ic350a424f83638e8129d55dda168913798ebc31a --- nova/compute/manager.py | 7 +++---- nova/tests/compute/test_compute_mgr.py | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 1e647708eb5c..f8abdd00121e 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -1340,10 +1340,9 @@ class ComputeManager(manager.Manager): instance, requested_networks, macs, security_groups, dhcp_options) - self._instance_update( - context, instance.uuid, - vm_state=vm_states.BUILDING, - task_state=task_states.BLOCK_DEVICE_MAPPING) + instance.vm_state = vm_states.BUILDING + instance.task_state = task_states.BLOCK_DEVICE_MAPPING + instance.save() # Verify that all the BDMs have a device_name set and assign a # default to the ones missing it with the help of the driver. diff --git a/nova/tests/compute/test_compute_mgr.py b/nova/tests/compute/test_compute_mgr.py index 201600d40ac8..5459432cc723 100644 --- a/nova/tests/compute/test_compute_mgr.py +++ b/nova/tests/compute/test_compute_mgr.py @@ -107,7 +107,6 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase): self.mox.StubOutWithMock(self.compute, '_get_resource_tracker') self.mox.StubOutWithMock(self.compute, '_allocate_network') - self.mox.StubOutWithMock(self.compute, '_instance_update') self.mox.StubOutWithMock(objects.BlockDeviceMappingList, 'get_by_instance_uuid') @@ -134,17 +133,17 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase): self.compute._allocate_network(mox.IgnoreArg(), instance, mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg()).WithSideEffects(fake_allocate) - self.compute._instance_update(self.context, instance.uuid, - system_metadata={'network_allocated': 'True'}) self.mox.ReplayAll() - self.compute._build_instance(self.context, {}, {}, + instance, nw_info = self.compute._build_instance(self.context, {}, {}, None, None, None, True, node, instance, {}, False) self.assertFalse(self.admin_context, "_allocate_network called with admin context") + self.assertEqual(vm_states.BUILDING, instance.vm_state) + self.assertEqual(task_states.BLOCK_DEVICE_MAPPING, instance.task_state) def test_allocate_network_fails(self): self.flags(network_allocate_retries=0)