diff options
author | Jay Lau <liugya@cn.ibm.com> | 2013-11-22 23:32:38 +0800 |
---|---|---|
committer | wingwj <wingwj@gmail.com> | 2014-04-20 14:50:21 +0800 |
commit | 6a1def686449675a4524cbbb98689e9f66bdf1e4 (patch) | |
tree | b44add6c505c1e3710f1046b7ffc2dd9250afe2e | |
parent | 0a4146d6822f36c87656d8caa60ae4037b0e8ee4 (diff) | |
download | nova-6a1def686449675a4524cbbb98689e9f66bdf1e4.tar.gz |
Add context as parameter for two libvirt APIs
When finish_revert_migration is called, the caller of
finish_revert_migration already includes context as a parameter,
but finish_revert_migration did not reuse this parameter and still
re-generate the context inside finish_revert_migration, we should
add context as a new parameter for finish_revert_migration so that
the functions inside of it can reuse context when needed.
For the function _create_domain_and_network in libvirt/driver.py,
it set context as an optional parameter, but context isn't really
an optional parameter for this method. We should always pass a
context down because it might be needed somewhere inside
_create_domain_and_network().
The patch includes two parts:
1) Add context as a new parameter for finish_revert_migration
2) Set context as a required parameter for _create_domain_and_network
Closes-Bug: #1251261
(cherry picked from commit 81fc3967bca0f154d72d5de7875b646e1b6c47c8)
Conflicts:
nova/tests/compute/test_compute_mgr.py
nova/virt/vmwareapi/vmops.py
Change-Id: I72d131fc8dce903400e3080d51ba0fc0a1320751
-rw-r--r-- | nova/compute/manager.py | 4 | ||||
-rw-r--r-- | nova/tests/compute/test_compute.py | 2 | ||||
-rw-r--r-- | nova/tests/compute/test_compute_mgr.py | 3 | ||||
-rwxr-xr-x | nova/tests/virt/hyperv/test_hypervapi.py | 3 | ||||
-rw-r--r-- | nova/tests/virt/libvirt/test_libvirt.py | 20 | ||||
-rw-r--r-- | nova/tests/virt/powervm/test_powervm.py | 8 | ||||
-rwxr-xr-x | nova/tests/virt/vmwareapi/test_vmwareapi.py | 3 | ||||
-rw-r--r-- | nova/tests/virt/xenapi/test_vmops.py | 3 | ||||
-rw-r--r-- | nova/tests/virt/xenapi/test_xenapi.py | 7 | ||||
-rw-r--r-- | nova/virt/driver.py | 4 | ||||
-rw-r--r-- | nova/virt/fake.py | 2 | ||||
-rw-r--r-- | nova/virt/hyperv/driver.py | 5 | ||||
-rw-r--r-- | nova/virt/hyperv/migrationops.py | 2 | ||||
-rw-r--r-- | nova/virt/libvirt/driver.py | 29 | ||||
-rw-r--r-- | nova/virt/powervm/driver.py | 2 | ||||
-rw-r--r-- | nova/virt/vmwareapi/driver.py | 4 | ||||
-rwxr-xr-x | nova/virt/vmwareapi/vmops.py | 2 | ||||
-rw-r--r-- | nova/virt/xenapi/driver.py | 5 | ||||
-rw-r--r-- | nova/virt/xenapi/vmops.py | 3 |
19 files changed, 60 insertions, 51 deletions
diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 8651df5f32..95f52e7193 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -684,7 +684,7 @@ class ComputeManager(manager.SchedulerDependentManager): block_dev_info = self._get_instance_volume_block_device_info( context, instance) - self.driver.finish_revert_migration( + self.driver.finish_revert_migration(context, instance, net_info, block_dev_info, power_on) except Exception as e: @@ -2839,7 +2839,7 @@ class ComputeManager(manager.SchedulerDependentManager): context, instance, refresh_conn_info=True) power_on = old_vm_state != vm_states.STOPPED - self.driver.finish_revert_migration(instance, + self.driver.finish_revert_migration(context, instance, network_info, block_device_info, power_on) diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py index d6b4e37c0c..c0f0c9f712 100644 --- a/nova/tests/compute/test_compute.py +++ b/nova/tests/compute/test_compute.py @@ -4186,7 +4186,7 @@ class ComputeTestCase(BaseTestCase): def fake_finish_revert_migration_driver(*args, **kwargs): # Confirm the instance uses the old type in finish_revert_resize - inst = args[0] + inst = args[1] sys_meta = inst.system_metadata self.assertEqual(sys_meta['instance_type_flavorid'], '1') diff --git a/nova/tests/compute/test_compute_mgr.py b/nova/tests/compute/test_compute_mgr.py index b00b588497..2269be8275 100644 --- a/nova/tests/compute/test_compute_mgr.py +++ b/nova/tests/compute/test_compute_mgr.py @@ -311,7 +311,8 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase): utils.instance_sys_meta(instance).AndReturn(sys_meta) self.compute._get_instance_volume_block_device_info( self.context, instance).AndReturn([]) - self.compute.driver.finish_revert_migration(instance, [], [], power_on) + self.compute.driver.finish_revert_migration(self.context, instance, + [], [], power_on) self.compute._instance_update(self.context, instance['uuid'], task_state=None).AndReturn(fixed) self.compute.driver.get_info(fixed).AndReturn( diff --git a/nova/tests/virt/hyperv/test_hypervapi.py b/nova/tests/virt/hyperv/test_hypervapi.py index 0f456e069c..dfac09a75f 100755 --- a/nova/tests/virt/hyperv/test_hypervapi.py +++ b/nova/tests/virt/hyperv/test_hypervapi.py @@ -1597,7 +1597,8 @@ class HyperVAPITestCase(test.NoDBTestCase): constants.HYPERV_VM_STATE_ENABLED) self._mox.ReplayAll() - self._conn.finish_revert_migration(instance, network_info, None, + self._conn.finish_revert_migration(self._context, instance, + network_info, None, power_on) self._mox.VerifyAll() diff --git a/nova/tests/virt/libvirt/test_libvirt.py b/nova/tests/virt/libvirt/test_libvirt.py index db6f9d7321..18fc5098ac 100644 --- a/nova/tests/virt/libvirt/test_libvirt.py +++ b/nova/tests/virt/libvirt/test_libvirt.py @@ -4290,9 +4290,9 @@ class LibvirtConnTestCase(test.TestCase): conn._create_images_and_backing(self.context, instance, libvirt_utils.get_instance_path(instance), disk_info_json) - conn._create_domain_and_network(dummyxml, instance, + conn._create_domain_and_network(self.context, dummyxml, instance, network_info, block_device_info, - context=self.context, reboot=True) + reboot=True) self.mox.ReplayAll() conn._hard_reboot(self.context, instance, network_info, @@ -4326,10 +4326,10 @@ class LibvirtConnTestCase(test.TestCase): block_device_info) _get_existing_domain_xml.assert_has_calls([mock.call(instance, network_info, block_device_info)]) - _create_domain_and_network.assert_has_calls([mock.call(dummyxml, - instance, network_info, - block_device_info=block_device_info, - context=self.context)]) + _create_domain_and_network.assert_has_calls([mock.call( + self.context, dummyxml, + instance, network_info, + block_device_info=block_device_info)]) _attach_pci_devices.assert_has_calls([mock.call('fake_dom', 'fake_pci_devs')]) @@ -7003,8 +7003,9 @@ class LibvirtDriverTestCase(test.TestCase): f = open(libvirt_xml_path, 'w') f.close() - self.libvirtconnection.finish_revert_migration(ins_ref, None, - None, power_on) + self.libvirtconnection.finish_revert_migration( + context.get_admin_context(), ins_ref, + None, None, power_on) self.assertTrue(self.fake_create_domain_called) def test_finish_revert_migration_power_on(self): @@ -7021,6 +7022,7 @@ class LibvirtDriverTestCase(test.TestCase): def wait(self): return None + context = 'fake_context' self.mox.StubOutWithMock(libvirt_utils, 'get_instance_path') self.mox.StubOutWithMock(os.path, 'exists') @@ -7046,7 +7048,7 @@ class LibvirtDriverTestCase(test.TestCase): self.mox.ReplayAll() - self.libvirtconnection.finish_revert_migration({}, []) + self.libvirtconnection.finish_revert_migration(context, {}, []) def test_finish_revert_migration_after_crash(self): self._test_finish_revert_migration_after_crash(backup_made=True) diff --git a/nova/tests/virt/powervm/test_powervm.py b/nova/tests/virt/powervm/test_powervm.py index 14fe28ffca..16a5595850 100644 --- a/nova/tests/virt/powervm/test_powervm.py +++ b/nova/tests/virt/powervm/test_powervm.py @@ -439,9 +439,11 @@ class PowerVMDriverTestCase(test.TestCase): self.mox.ReplayAll() - self.powervm_connection.finish_revert_migration(inst, network_info, - block_device_info=None, - power_on=power_on) + self.powervm_connection.finish_revert_migration( + context.get_admin_context(), + inst, network_info, + block_device_info=None, + power_on=power_on) def test_finish_revert_migration_after_crash(self): self._test_finish_revert_migration_after_crash(True, True, True) diff --git a/nova/tests/virt/vmwareapi/test_vmwareapi.py b/nova/tests/virt/vmwareapi/test_vmwareapi.py index 35f12dd6a2..e0d3d0242d 100755 --- a/nova/tests/virt/vmwareapi/test_vmwareapi.py +++ b/nova/tests/virt/vmwareapi/test_vmwareapi.py @@ -965,7 +965,8 @@ class VMwareAPIVMTestCase(test.NoDBTestCase): fake_wait_for_task) # perform the revert on our stubbed methods - self.conn.finish_revert_migration(instance=self.instance, + self.conn.finish_revert_migration(self.context, + instance=self.instance, network_info=None, power_on=power_on) diff --git a/nova/tests/virt/xenapi/test_vmops.py b/nova/tests/virt/xenapi/test_vmops.py index 3222094ba6..188e6eb395 100644 --- a/nova/tests/virt/xenapi/test_vmops.py +++ b/nova/tests/virt/xenapi/test_vmops.py @@ -80,6 +80,7 @@ class VMOpsTestCase(test.NoDBTestCase): def _test_finish_revert_migration_after_crash(self, backup_made, new_made): instance = {'name': 'foo', 'task_state': task_states.RESIZE_MIGRATING} + context = 'fake_context' self.mox.StubOutWithMock(vm_utils, 'lookup') self.mox.StubOutWithMock(self._vmops, '_destroy') @@ -100,7 +101,7 @@ class VMOpsTestCase(test.NoDBTestCase): self.mox.ReplayAll() - self._vmops.finish_revert_migration(instance, []) + self._vmops.finish_revert_migration(context, instance, []) def test_finish_revert_migration_after_crash(self): self._test_finish_revert_migration_after_crash(True, True) diff --git a/nova/tests/virt/xenapi/test_xenapi.py b/nova/tests/virt/xenapi/test_xenapi.py index 9a45bf0a43..0020d7d712 100644 --- a/nova/tests/virt/xenapi/test_xenapi.py +++ b/nova/tests/virt/xenapi/test_xenapi.py @@ -1309,13 +1309,13 @@ class XenAPIVMTestCase(stubs.XenAPITestBase): def __init__(self): self.finish_revert_migration_called = False - def finish_revert_migration(self, instance, block_info, + def finish_revert_migration(self, context, instance, block_info, power_on): self.finish_revert_migration_called = True conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False) conn._vmops = VMOpsMock() - conn.finish_revert_migration(instance, None) + conn.finish_revert_migration(self.context, instance, None) self.assertTrue(conn._vmops.finish_revert_migration_called) def test_reboot_hard(self): @@ -1717,6 +1717,7 @@ class XenAPIMigrateInstance(stubs.XenAPITestBase): self.called = False self.fake_vm_start_called = False self.fake_finish_revert_migration_called = False + context = 'fake_context' def fake_vm_start(*args, **kwargs): self.fake_vm_start_called = True @@ -1750,7 +1751,7 @@ class XenAPIMigrateInstance(stubs.XenAPITestBase): self.assertEqual(self.called, True) self.assertEqual(self.fake_vm_start_called, power_on) - conn.finish_revert_migration(instance, network_info) + conn.finish_revert_migration(context, instance, network_info) self.assertEqual(self.fake_finish_revert_migration_called, True) def test_revert_migrate_power_on(self): diff --git a/nova/virt/driver.py b/nova/virt/driver.py index 973b9037f5..75686bc7ed 100644 --- a/nova/virt/driver.py +++ b/nova/virt/driver.py @@ -401,11 +401,12 @@ class ComputeDriver(object): # TODO(Vek): Need to pass context in for access to auth_token raise NotImplementedError() - def finish_revert_migration(self, instance, network_info, + def finish_revert_migration(self, context, instance, network_info, block_device_info=None, power_on=True): """ Finish reverting a resize. + :param context: the context for the finish_revert_migration :param instance: the instance being migrated/resized :param network_info: :py:meth:`~nova.network.manager.NetworkManager.get_instance_nw_info` @@ -413,7 +414,6 @@ class ComputeDriver(object): :param power_on: True if the instance should be powered on, False otherwise """ - # TODO(Vek): Need to pass context in for access to auth_token raise NotImplementedError() def pause(self, instance): diff --git a/nova/virt/fake.py b/nova/virt/fake.py index 41825a94f2..b9f8fb4185 100644 --- a/nova/virt/fake.py +++ b/nova/virt/fake.py @@ -172,7 +172,7 @@ class FakeDriver(driver.ComputeDriver): block_device_info=None): pass - def finish_revert_migration(self, instance, network_info, + def finish_revert_migration(self, context, instance, network_info, block_device_info=None, power_on=True): pass diff --git a/nova/virt/hyperv/driver.py b/nova/virt/hyperv/driver.py index 8b16f1e97e..a914bc75b6 100644 --- a/nova/virt/hyperv/driver.py +++ b/nova/virt/hyperv/driver.py @@ -179,9 +179,10 @@ class HyperVDriver(driver.ComputeDriver): def confirm_migration(self, migration, instance, network_info): self._migrationops.confirm_migration(migration, instance, network_info) - def finish_revert_migration(self, instance, network_info, + def finish_revert_migration(self, context, instance, network_info, block_device_info=None, power_on=True): - self._migrationops.finish_revert_migration(instance, network_info, + self._migrationops.finish_revert_migration(context, instance, + network_info, block_device_info, power_on) def finish_migration(self, context, migration, instance, disk_info, diff --git a/nova/virt/hyperv/migrationops.py b/nova/virt/hyperv/migrationops.py index e2b12d45f7..e041e5effb 100644 --- a/nova/virt/hyperv/migrationops.py +++ b/nova/virt/hyperv/migrationops.py @@ -142,7 +142,7 @@ class MigrationOps(object): instance_name) self._pathutils.rename(revert_path, instance_path) - def finish_revert_migration(self, instance, network_info, + def finish_revert_migration(self, context, instance, network_info, block_device_info=None, power_on=True): LOG.debug(_("finish_revert_migration called"), instance=instance) diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index 92be53cc0e..e6fd8e97aa 100644 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -1928,9 +1928,8 @@ class LibvirtDriver(driver.ComputeDriver): # Initialize all the necessary networking, block devices and # start the instance. - self._create_domain_and_network(xml, instance, network_info, - block_device_info, context=context, - reboot=True) + self._create_domain_and_network(context, xml, instance, network_info, + block_device_info, reboot=True) self._prepare_pci_devices_for_use( pci_manager.get_instance_pci_devs(instance)) @@ -1979,8 +1978,8 @@ class LibvirtDriver(driver.ComputeDriver): """resume the specified instance.""" xml = self._get_existing_domain_xml(instance, network_info, block_device_info) - dom = self._create_domain_and_network(xml, instance, network_info, - block_device_info=block_device_info, context=context) + dom = self._create_domain_and_network(context, xml, instance, + network_info, block_device_info=block_device_info) self._attach_pci_devices(dom, pci_manager.get_instance_pci_devs(instance)) @@ -2087,8 +2086,8 @@ class LibvirtDriver(driver.ComputeDriver): block_device_info=block_device_info, write_to_disk=True) - self._create_domain_and_network(xml, instance, network_info, - block_device_info, context=context) + self._create_domain_and_network(context, xml, instance, network_info, + block_device_info) LOG.debug(_("Instance is running"), instance=instance) def _wait_for_boot(): @@ -3211,9 +3210,9 @@ class LibvirtDriver(driver.ComputeDriver): return domain - def _create_domain_and_network(self, xml, instance, network_info, + def _create_domain_and_network(self, context, xml, instance, network_info, block_device_info=None, power_on=True, - context=None, reboot=False): + reboot=False): """Do required network setup and create domain.""" block_device_mapping = driver.block_device_info_get_mapping( @@ -4606,9 +4605,8 @@ class LibvirtDriver(driver.ComputeDriver): xml = self.to_xml(context, instance, network_info, disk_info, block_device_info=block_device_info, write_to_disk=True) - self._create_domain_and_network(xml, instance, network_info, - block_device_info, power_on, - context=context) + self._create_domain_and_network(context, xml, instance, network_info, + block_device_info, power_on) if power_on: timer = loopingcall.FixedIntervalLoopingCall( self._wait_for_running, @@ -4625,7 +4623,7 @@ class LibvirtDriver(driver.ComputeDriver): if e.errno != errno.ENOENT: raise - def finish_revert_migration(self, instance, network_info, + def finish_revert_migration(self, context, instance, network_info, block_device_info=None, power_on=True): LOG.debug(_("Starting finish_revert_migration"), instance=instance) @@ -4644,10 +4642,9 @@ class LibvirtDriver(driver.ComputeDriver): disk_info = blockinfo.get_disk_info(CONF.libvirt_type, instance, block_device_info) - xml = self.to_xml(nova_context.get_admin_context(), - instance, network_info, disk_info, + xml = self.to_xml(context, instance, network_info, disk_info, block_device_info=block_device_info) - self._create_domain_and_network(xml, instance, network_info, + self._create_domain_and_network(context, xml, instance, network_info, block_device_info, power_on) if power_on: diff --git a/nova/virt/powervm/driver.py b/nova/virt/powervm/driver.py index 82bc5199cd..a63de1d32d 100644 --- a/nova/virt/powervm/driver.py +++ b/nova/virt/powervm/driver.py @@ -310,7 +310,7 @@ class PowerVMDriver(driver.ComputeDriver): new_name = self._get_resize_name(instance['name']) self._powervm.destroy(new_name) - def finish_revert_migration(self, instance, network_info, + def finish_revert_migration(self, context, instance, network_info, block_device_info=None, power_on=True): """Finish reverting a resize.""" diff --git a/nova/virt/vmwareapi/driver.py b/nova/virt/vmwareapi/driver.py index 8504a1e963..a31d1f7b50 100644 --- a/nova/virt/vmwareapi/driver.py +++ b/nova/virt/vmwareapi/driver.py @@ -447,11 +447,11 @@ class VMwareVCDriver(VMwareESXDriver): _vmops = self._get_vmops_for_compute_node(instance['node']) _vmops.confirm_migration(migration, instance, network_info) - def finish_revert_migration(self, instance, network_info, + def finish_revert_migration(self, context, instance, network_info, block_device_info=None, power_on=True): """Finish reverting a resize, powering back on the instance.""" _vmops = self._get_vmops_for_compute_node(instance['node']) - _vmops.finish_revert_migration(instance, network_info, + _vmops.finish_revert_migration(context, instance, network_info, block_device_info, power_on) def finish_migration(self, context, migration, instance, disk_info, diff --git a/nova/virt/vmwareapi/vmops.py b/nova/virt/vmwareapi/vmops.py index 3f4d2a76f3..38cf95d414 100755 --- a/nova/virt/vmwareapi/vmops.py +++ b/nova/virt/vmwareapi/vmops.py @@ -1236,7 +1236,7 @@ class VMwareVMOps(object): LOG.warn(_("In vmwareapi:vmops:confirm_migration, got this " "exception while destroying the VM: %s") % str(excep)) - def finish_revert_migration(self, instance, network_info, + def finish_revert_migration(self, context, instance, network_info, block_device_info, power_on=True): """Finish reverting a resize.""" # The original vm was suffixed with '-orig'; find it using diff --git a/nova/virt/xenapi/driver.py b/nova/virt/xenapi/driver.py index d4bcf3832d..473f10d925 100644 --- a/nova/virt/xenapi/driver.py +++ b/nova/virt/xenapi/driver.py @@ -220,11 +220,12 @@ class XenAPIDriver(driver.ComputeDriver): # TODO(Vek): Need to pass context in for access to auth_token self._vmops.confirm_migration(migration, instance, network_info) - def finish_revert_migration(self, instance, network_info, + def finish_revert_migration(self, context, instance, network_info, block_device_info=None, power_on=True): """Finish reverting a resize.""" # NOTE(vish): Xen currently does not use network info. - self._vmops.finish_revert_migration(instance, block_device_info, + self._vmops.finish_revert_migration(context, instance, + block_device_info, power_on) def finish_migration(self, context, migration, instance, disk_info, diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index 611f3f4e21..75fb6f5479 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -239,7 +239,8 @@ class VMOps(object): mount_device, hotplug=False) - def finish_revert_migration(self, instance, block_device_info=None, + def finish_revert_migration(self, context, instance, + block_device_info=None, power_on=True): self._restore_orig_vm_and_cleanup_orphan(instance, block_device_info, power_on) |