summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Riedemann <mriedem@us.ibm.com>2013-05-29 21:12:04 -0700
committerMatt Riedemann <mriedem@us.ibm.com>2013-05-30 07:52:33 -0700
commit1690a1ae8f2fdddebfb8ae50a8492aedf466b8e3 (patch)
tree968f7fe649af0c936595a581c9d346a989f80ced
parent783b0e836d9ba0630d4745a6457144fac6dfa9f0 (diff)
downloadnova-1690a1ae8f2fdddebfb8ae50a8492aedf466b8e3.tar.gz
nova-1690a1ae8f2fdddebfb8ae50a8492aedf466b8e3.tar.xz
nova-1690a1ae8f2fdddebfb8ae50a8492aedf466b8e3.zip
Add power_on flag to virt driver finish/revert migration methods
This patch adds a boolean power_on flag to the virt driver finish_migration and finish_revert_migration methods to indicate whether or not to power on the instance as part of the resize/migrate operation. The default is to power on the instance. Related to bug 1177811 Change-Id: I76c7d6912eda2c333554855a8956bd0fbb1e8b6d
-rw-r--r--nova/tests/virt/hyperv/test_hypervapi.py31
-rw-r--r--nova/tests/virt/libvirt/test_libvirt.py45
-rw-r--r--nova/tests/virt/powervm/test_powervm.py32
-rw-r--r--nova/tests/virt/vmwareapi/test_vmwareapi.py100
-rw-r--r--nova/tests/virt/xenapi/test_xenapi.py29
-rwxr-xr-xnova/virt/driver.py26
-rwxr-xr-xnova/virt/fake.py4
-rwxr-xr-xnova/virt/hyperv/driver.py8
-rw-r--r--nova/virt/hyperv/migrationops.py10
-rwxr-xr-xnova/virt/libvirt/driver.py33
-rwxr-xr-xnova/virt/powervm/driver.py13
-rw-r--r--nova/virt/powervm/operator.py11
-rwxr-xr-xnova/virt/vmwareapi/driver.py9
-rw-r--r--nova/virt/vmwareapi/vmops.py13
-rwxr-xr-xnova/virt/xenapi/driver.py11
-rw-r--r--nova/virt/xenapi/vmops.py17
16 files changed, 302 insertions, 90 deletions
diff --git a/nova/tests/virt/hyperv/test_hypervapi.py b/nova/tests/virt/hyperv/test_hypervapi.py
index b6df2ea31..cfc79c388 100644
--- a/nova/tests/virt/hyperv/test_hypervapi.py
+++ b/nova/tests/virt/hyperv/test_hypervapi.py
@@ -1159,7 +1159,7 @@ class HyperVAPITestCase(test.TestCase):
instance_type, network_info)
self._mox.VerifyAll()
- def test_finish_migration(self):
+ def _test_finish_migration(self, power_on):
self._instance_data = self._get_instance_data()
instance = db.instance_create(self._context, self._instance_data)
instance['system_metadata'] = {}
@@ -1198,14 +1198,21 @@ class HyperVAPITestCase(test.TestCase):
self._set_vm_name(instance['name'])
self._setup_create_instance_mocks(None, False)
- vmutils.VMUtils.set_vm_state(mox.Func(self._check_instance_name),
- constants.HYPERV_VM_STATE_ENABLED)
+ if power_on:
+ vmutils.VMUtils.set_vm_state(mox.Func(self._check_instance_name),
+ constants.HYPERV_VM_STATE_ENABLED)
self._mox.ReplayAll()
self._conn.finish_migration(self._context, None, instance, "",
- network_info, None, False, None)
+ network_info, None, False, None, power_on)
self._mox.VerifyAll()
+ def test_finish_migration_power_on(self):
+ self._test_finish_migration(True)
+
+ def test_finish_migration_power_off(self):
+ self._test_finish_migration(False)
+
def test_confirm_migration(self):
self._instance_data = self._get_instance_data()
instance = db.instance_create(self._context, self._instance_data)
@@ -1218,7 +1225,7 @@ class HyperVAPITestCase(test.TestCase):
self._conn.confirm_migration(None, instance, network_info)
self._mox.VerifyAll()
- def test_finish_revert_migration(self):
+ def _test_finish_revert_migration(self, power_on):
self._instance_data = self._get_instance_data()
instance = db.instance_create(self._context, self._instance_data)
network_info = fake_network.fake_get_instance_nw_info(
@@ -1246,9 +1253,17 @@ class HyperVAPITestCase(test.TestCase):
self._set_vm_name(instance['name'])
self._setup_create_instance_mocks(None, False)
- vmutils.VMUtils.set_vm_state(mox.Func(self._check_instance_name),
- constants.HYPERV_VM_STATE_ENABLED)
+ if power_on:
+ vmutils.VMUtils.set_vm_state(mox.Func(self._check_instance_name),
+ constants.HYPERV_VM_STATE_ENABLED)
self._mox.ReplayAll()
- self._conn.finish_revert_migration(instance, network_info, None)
+ self._conn.finish_revert_migration(instance, network_info, None,
+ power_on)
self._mox.VerifyAll()
+
+ def test_finish_revert_migration_power_on(self):
+ self._test_finish_revert_migration(True)
+
+ def test_finish_revert_migration_power_off(self):
+ self._test_finish_revert_migration(False)
diff --git a/nova/tests/virt/libvirt/test_libvirt.py b/nova/tests/virt/libvirt/test_libvirt.py
index f72c37cd1..6b70fe1c6 100644
--- a/nova/tests/virt/libvirt/test_libvirt.py
+++ b/nova/tests/virt/libvirt/test_libvirt.py
@@ -4951,7 +4951,7 @@ class LibvirtDriverTestCase(test.TestCase):
self.libvirtconnection._wait_for_running({'name': 'else',
'uuid': 'other_uuid'})
- def test_finish_migration(self):
+ def _test_finish_migration(self, power_on):
"""Test for nova.virt.libvirt.libvirt_driver.LivirtConnection
.finish_migration. """
@@ -4960,6 +4960,8 @@ class LibvirtDriverTestCase(test.TestCase):
{'type': 'raw', 'path': '/test/disk.local',
'local_gb': 10, 'backing_file': '/base/disk.local'}]
disk_info_text = jsonutils.dumps(disk_info)
+ powered_on = power_on
+ self.fake_create_domain_called = False
def fake_can_resize_fs(path, size, use_cow=False):
return False
@@ -4981,7 +4983,9 @@ class LibvirtDriverTestCase(test.TestCase):
block_device_info=None):
pass
- def fake_create_domain(xml, instance=None):
+ def fake_create_domain(xml, instance=None, power_on=True):
+ self.fake_create_domain_called = True
+ self.assertEqual(powered_on, power_on)
return None
def fake_enable_hairpin(instance):
@@ -4991,7 +4995,10 @@ class LibvirtDriverTestCase(test.TestCase):
pass
def fake_get_info(instance):
- return {'state': power_state.RUNNING}
+ if powered_on:
+ return {'state': power_state.RUNNING}
+ else:
+ return {'state': power_state.SHUTDOWN}
self.flags(use_cow_images=True)
self.stubs.Set(libvirt_driver.disk, 'extend', fake_extend)
@@ -5015,11 +5022,20 @@ class LibvirtDriverTestCase(test.TestCase):
self.libvirtconnection.finish_migration(
context.get_admin_context(), None, ins_ref,
- disk_info_text, None, None, None)
+ disk_info_text, None, None, None, None, power_on)
+ self.assertTrue(self.fake_create_domain_called)
+
+ def test_finish_migration_power_on(self):
+ self._test_finish_migration(True)
+
+ def test_finish_migration_power_off(self):
+ self._test_finish_migration(False)
- def test_finish_revert_migration(self):
+ def _test_finish_revert_migration(self, power_on):
"""Test for nova.virt.libvirt.libvirt_driver.LivirtConnection
.finish_revert_migration. """
+ powered_on = power_on
+ self.fake_create_domain_called = False
def fake_execute(*args, **kwargs):
pass
@@ -5027,14 +5043,19 @@ class LibvirtDriverTestCase(test.TestCase):
def fake_plug_vifs(instance, network_info):
pass
- def fake_create_domain(xml, instance=None):
+ def fake_create_domain(xml, instance=None, power_on=True):
+ self.fake_create_domain_called = True
+ self.assertEqual(powered_on, power_on)
return None
def fake_enable_hairpin(instance):
pass
def fake_get_info(instance):
- return {'state': power_state.RUNNING}
+ if powered_on:
+ return {'state': power_state.RUNNING}
+ else:
+ return {'state': power_state.SHUTDOWN}
def fake_to_xml(instance, network_info, disk_info,
image_meta=None, rescue=None,
@@ -5063,7 +5084,15 @@ class LibvirtDriverTestCase(test.TestCase):
f = open(libvirt_xml_path, 'w')
f.close()
- self.libvirtconnection.finish_revert_migration(ins_ref, None)
+ self.libvirtconnection.finish_revert_migration(ins_ref, None,
+ None, power_on)
+ self.assertTrue(self.fake_create_domain_called)
+
+ def test_finish_revert_migration_power_on(self):
+ self._test_finish_revert_migration(True)
+
+ def test_finish_revert_migration_power_off(self):
+ self._test_finish_revert_migration(False)
def _test_finish_revert_migration_after_crash(self, backup_made, new_made):
class FakeLoopingCall:
diff --git a/nova/tests/virt/powervm/test_powervm.py b/nova/tests/virt/powervm/test_powervm.py
index a923d52ff..3781c6738 100644
--- a/nova/tests/virt/powervm/test_powervm.py
+++ b/nova/tests/virt/powervm/test_powervm.py
@@ -380,7 +380,9 @@ class PowerVMDriverTestCase(test.TestCase):
expected_path = '/some/file/path/filename'
self.assertEqual(joined_path, expected_path)
- def _test_finish_revert_migration_after_crash(self, backup_made, new_made):
+ def _test_finish_revert_migration_after_crash(self, backup_made,
+ new_made,
+ power_on):
inst = {'name': 'foo'}
network_info = []
network_info.append({'address': 'fa:89:f0:8b:9b:39'})
@@ -404,21 +406,24 @@ class PowerVMDriverTestCase(test.TestCase):
'foo')
self.powervm_connection._powervm._operator.set_lpar_mac_base_value(
'foo', 'fa:89:f0:8b:9b:39')
- self.powervm_connection._powervm.power_on('foo')
+ if power_on:
+ self.powervm_connection._powervm.power_on('foo')
self.mox.ReplayAll()
self.powervm_connection.finish_revert_migration(inst, network_info,
- block_device_info=None)
+ 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)
+ self._test_finish_revert_migration_after_crash(True, True, True)
def test_finish_revert_migration_after_crash_before_new(self):
- self._test_finish_revert_migration_after_crash(True, False)
+ self._test_finish_revert_migration_after_crash(True, False, True)
def test_finish_revert_migration_after_crash_before_backup(self):
- self._test_finish_revert_migration_after_crash(False, False)
+ # NOTE(mriedem): tests the power_on=False case also
+ self._test_finish_revert_migration_after_crash(False, False, False)
def test_migrate_volume_use_instance_name(self):
inst_name = 'instance-00000000'
@@ -457,7 +462,7 @@ class PowerVMDriverTestCase(test.TestCase):
expected_path = 'some/image/path/logical-vol-name_rsz.gz'
self.assertEqual(file_path, expected_path)
- def test_deploy_from_migrated_file(self):
+ def _test_deploy_from_migrated_file(self, power_on):
instance = self.instance
context = 'fake_context'
network_info = []
@@ -469,9 +474,10 @@ class PowerVMDriverTestCase(test.TestCase):
self.flags(powervm_mgr=dest)
fake_op = self.powervm_connection._powervm
self.deploy_from_vios_file_called = False
+ self.power_on = power_on
def fake_deploy_from_vios_file(lpar, file_path, size,
- decompress):
+ decompress, power_on):
exp_file_path = 'some/file/path.gz'
exp_size = 40 * 1024 ** 3
exp_decompress = True
@@ -479,15 +485,23 @@ class PowerVMDriverTestCase(test.TestCase):
self.assertEqual(exp_file_path, file_path)
self.assertEqual(exp_size, size)
self.assertEqual(exp_decompress, decompress)
+ self.assertEqual(self.power_on, power_on)
self.stubs.Set(fake_op, '_deploy_from_vios_file',
fake_deploy_from_vios_file)
self.powervm_connection.finish_migration(context, None,
instance, disk_info, network_info,
None, resize_instance=True,
- block_device_info=None)
+ block_device_info=None,
+ power_on=power_on)
self.assertEqual(self.deploy_from_vios_file_called, True)
+ def test_deploy_from_migrated_file_power_on(self):
+ self._test_deploy_from_migrated_file(True)
+
+ def test_deploy_from_migrated_file_power_off(self):
+ self._test_deploy_from_migrated_file(False)
+
def test_set_lpar_mac_base_value(self):
instance = self.instance
context = 'fake_context'
diff --git a/nova/tests/virt/vmwareapi/test_vmwareapi.py b/nova/tests/virt/vmwareapi/test_vmwareapi.py
index 9508a5805..2691857fe 100644
--- a/nova/tests/virt/vmwareapi/test_vmwareapi.py
+++ b/nova/tests/virt/vmwareapi/test_vmwareapi.py
@@ -35,10 +35,12 @@ from nova.tests import matchers
from nova.tests import utils
from nova.tests.virt.vmwareapi import db_fakes
from nova.tests.virt.vmwareapi import stubs
+from nova.virt import fake
from nova.virt.vmwareapi import driver
from nova.virt.vmwareapi import fake as vmwareapi_fake
from nova.virt.vmwareapi import vim
from nova.virt.vmwareapi import vm_util
+from nova.virt.vmwareapi import vmops
class fake_vm_ref(object):
@@ -113,7 +115,7 @@ class VMwareAPIVMTestCase(test.TestCase):
vmwareapi_fake.reset()
db_fakes.stub_out_db_instance_api(self.stubs)
stubs.set_stubs(self.stubs)
- self.conn = driver.VMwareESXDriver(None, False)
+ self.conn = driver.VMwareVCDriver(fake.FakeVirtAPI)
# NOTE(vish): none of the network plugging code is actually
# being tested
self.network_info = utils.get_test_network_info(legacy_model=False)
@@ -381,6 +383,102 @@ class VMwareAPIVMTestCase(test.TestCase):
self.mox.ReplayAll()
self.conn.get_console_output(self.instance)
+ def _test_finish_migration(self, power_on):
+ """
+ Tests the finish_migration method on vmops via the
+ VMwareVCDriver. Results are checked against whether or not
+ the underlying instance should have been powered on.
+ """
+
+ self.power_on_called = False
+
+ def fake_power_on(instance):
+ self.assertEquals(self.instance, instance)
+ self.power_on_called = True
+
+ def fake_vmops_update_instance_progress(context, instance, step,
+ total_steps):
+ self.assertEquals(self.context, context)
+ self.assertEquals(self.instance, instance)
+ self.assertEquals(4, step)
+ self.assertEqual(vmops.RESIZE_TOTAL_STEPS, total_steps)
+
+ self.stubs.Set(self.conn._vmops, "power_on", fake_power_on)
+ self.stubs.Set(self.conn._vmops, "_update_instance_progress",
+ fake_vmops_update_instance_progress)
+
+ # setup the test instance in the database
+ self._create_vm()
+ # perform the migration on our stubbed methods
+ self.conn.finish_migration(context=self.context,
+ migration=None,
+ instance=self.instance,
+ disk_info=None,
+ network_info=None,
+ image_meta=None,
+ power_on=power_on)
+ # verify the results
+ self.assertEquals(power_on, self.power_on_called)
+
+ def test_finish_migration_power_on(self):
+ self._test_finish_migration(power_on=True)
+
+ def test_finish_migration_power_off(self):
+ self._test_finish_migration(power_on=False)
+
+ def _test_finish_revert_migration(self, power_on):
+ """
+ Tests the finish_revert_migration method on vmops via the
+ VMwareVCDriver. Results are checked against whether or not
+ the underlying instance should have been powered on.
+ """
+
+ # setup the test instance in the database
+ self._create_vm()
+
+ self.power_on_called = False
+ self.vm_name = str(self.instance['name']) + '-orig'
+
+ def fake_power_on(instance):
+ self.assertEquals(self.instance, instance)
+ self.power_on_called = True
+
+ def fake_get_orig_vm_name_label(instance):
+ self.assertEquals(self.instance, instance)
+ return self.vm_name
+
+ def fake_get_vm_ref_from_name(session, vm_name):
+ self.assertEquals(self.vm_name, vm_name)
+ return vmwareapi_fake._get_objects("VirtualMachine")[0]
+
+ def fake_call_method(*args, **kwargs):
+ pass
+
+ def fake_wait_for_task(*args, **kwargs):
+ pass
+
+ self.stubs.Set(self.conn._vmops, "power_on", fake_power_on)
+ self.stubs.Set(self.conn._vmops, "_get_orig_vm_name_label",
+ fake_get_orig_vm_name_label)
+ self.stubs.Set(vm_util, "get_vm_ref_from_name",
+ fake_get_vm_ref_from_name)
+ self.stubs.Set(self.conn._session, "_call_method", fake_call_method)
+ self.stubs.Set(self.conn._session, "_wait_for_task",
+ fake_wait_for_task)
+
+ # perform the revert on our stubbed methods
+ self.conn.finish_revert_migration(instance=self.instance,
+ network_info=None,
+ power_on=power_on)
+ # verify the results
+ self.assertEquals(power_on, self.power_on_called)
+
+ def test_finish_revert_migration_power_on(self):
+ self._test_finish_revert_migration(power_on=True)
+
+ def test_finish_revert_migration_power_off(self):
+ self._test_finish_revert_migration(power_on=False)
+
class VMwareAPIHostTestCase(test.TestCase):
"""Unit tests for Vmware API host calls."""
diff --git a/nova/tests/virt/xenapi/test_xenapi.py b/nova/tests/virt/xenapi/test_xenapi.py
index 538752cf2..4fbaa2ace 100644
--- a/nova/tests/virt/xenapi/test_xenapi.py
+++ b/nova/tests/virt/xenapi/test_xenapi.py
@@ -1069,7 +1069,8 @@ 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, instance, block_info,
+ power_on):
self.finish_revert_migration_called = True
conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False)
@@ -1391,7 +1392,7 @@ class XenAPIMigrateInstance(stubs.XenAPITestBase):
self.context, instance,
'127.0.0.1', instance_type, None)
- def test_revert_migrate(self):
+ def _test_revert_migrate(self, power_on):
instance = create_instance_with_system_metadata(self.context,
self.instance_values)
self.called = False
@@ -1426,14 +1427,21 @@ class XenAPIMigrateInstance(stubs.XenAPITestBase):
cow_uuid = xenapi_fake.get_record('VDI', cow)['uuid']
conn.finish_migration(self.context, self.migration, instance,
dict(base_copy=base_uuid, cow=cow_uuid),
- network_info, image_meta, resize_instance=True)
+ network_info, image_meta, resize_instance=True,
+ block_device_info=None, power_on=power_on)
self.assertEqual(self.called, True)
- self.assertEqual(self.fake_vm_start_called, True)
+ self.assertEqual(self.fake_vm_start_called, power_on)
conn.finish_revert_migration(instance, network_info)
self.assertEqual(self.fake_finish_revert_migration_called, True)
- def test_finish_migrate(self):
+ def test_revert_migrate_power_on(self):
+ self._test_revert_migrate(True)
+
+ def test_revert_migrate_power_off(self):
+ self._test_revert_migrate(False)
+
+ def _test_finish_migrate(self, power_on):
instance = create_instance_with_system_metadata(self.context,
self.instance_values)
self.called = False
@@ -1458,9 +1466,16 @@ class XenAPIMigrateInstance(stubs.XenAPITestBase):
image_meta = {'id': instance['image_ref'], 'disk_format': 'vhd'}
conn.finish_migration(self.context, self.migration, instance,
dict(base_copy='hurr', cow='durr'),
- network_info, image_meta, resize_instance=True)
+ network_info, image_meta, resize_instance=True,
+ block_device_info=None, power_on=power_on)
self.assertEqual(self.called, True)
- self.assertEqual(self.fake_vm_start_called, True)
+ self.assertEqual(self.fake_vm_start_called, power_on)
+
+ def test_finish_migrate_power_on(self):
+ self._test_finish_migrate(True)
+
+ def test_finish_migrate_power_off(self):
+ self._test_finish_migrate(False)
def test_finish_migrate_no_local_storage(self):
tiny_type = flavors.get_instance_type_by_name('m1.tiny')
diff --git a/nova/virt/driver.py b/nova/virt/driver.py
index 93bff1ff4..6f79de048 100755
--- a/nova/virt/driver.py
+++ b/nova/virt/driver.py
@@ -343,14 +343,23 @@ class ComputeDriver(object):
def finish_migration(self, context, migration, instance, disk_info,
network_info, image_meta, resize_instance,
- block_device_info=None):
- """Completes a resize, turning on the migrated instance
+ block_device_info=None, power_on=True):
+ """Completes a resize.
+ :param context: the context for the migration/resize
+ :param migration: the migrate/resize information
+ :param instance: the instance being migrated/resized
+ :param disk_info: the newly transferred disk information
:param network_info:
:py:meth:`~nova.network.manager.NetworkManager.get_instance_nw_info`
:param image_meta: image object returned by nova.image.glance that
defines the image from which this instance
was created
+ :param resize_instance: True if the instance is being resized,
+ False otherwise
+ :param block_device_info: instance volume block device info
+ :param power_on: True if the instance should be powered on, False
+ otherwise
"""
raise NotImplementedError()
@@ -360,8 +369,17 @@ class ComputeDriver(object):
raise NotImplementedError()
def finish_revert_migration(self, instance, network_info,
- block_device_info=None):
- """Finish reverting a resize, powering back on the instance."""
+ block_device_info=None, power_on=True):
+ """
+ Finish reverting a resize.
+
+ :param instance: the instance being migrated/resized
+ :param network_info:
+ :py:meth:`~nova.network.manager.NetworkManager.get_instance_nw_info`
+ :param block_device_info: instance volume block device info
+ :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()
diff --git a/nova/virt/fake.py b/nova/virt/fake.py
index c38dc9ed6..1b65571a5 100755
--- a/nova/virt/fake.py
+++ b/nova/virt/fake.py
@@ -170,7 +170,7 @@ class FakeDriver(driver.ComputeDriver):
pass
def finish_revert_migration(self, instance, network_info,
- block_device_info=None):
+ block_device_info=None, power_on=True):
pass
def post_live_migration_at_destination(self, context, instance,
@@ -368,7 +368,7 @@ class FakeDriver(driver.ComputeDriver):
def finish_migration(self, context, migration, instance, disk_info,
network_info, image_meta, resize_instance,
- block_device_info=None):
+ block_device_info=None, power_on=True):
return
def confirm_migration(self, migration, instance, network_info):
diff --git a/nova/virt/hyperv/driver.py b/nova/virt/hyperv/driver.py
index 477f8fa2a..675f36f54 100755
--- a/nova/virt/hyperv/driver.py
+++ b/nova/virt/hyperv/driver.py
@@ -172,17 +172,17 @@ class HyperVDriver(driver.ComputeDriver):
self._migrationops.confirm_migration(migration, instance, network_info)
def finish_revert_migration(self, instance, network_info,
- block_device_info=None):
+ block_device_info=None, power_on=True):
self._migrationops.finish_revert_migration(instance, network_info,
- block_device_info)
+ block_device_info, power_on)
def finish_migration(self, context, migration, instance, disk_info,
network_info, image_meta, resize_instance=False,
- block_device_info=None):
+ block_device_info=None, power_on=True):
self._migrationops.finish_migration(context, migration, instance,
disk_info, network_info,
image_meta, resize_instance,
- block_device_info)
+ block_device_info, power_on)
def get_host_ip_addr(self):
return self._hostops.get_host_ip_addr()
diff --git a/nova/virt/hyperv/migrationops.py b/nova/virt/hyperv/migrationops.py
index ff8651efe..5ce092bf3 100644
--- a/nova/virt/hyperv/migrationops.py
+++ b/nova/virt/hyperv/migrationops.py
@@ -144,7 +144,7 @@ class MigrationOps(object):
self._pathutils.rename(revert_path, instance_path)
def finish_revert_migration(self, instance, network_info,
- block_device_info=None):
+ block_device_info=None, power_on=True):
LOG.debug(_("finish_revert_migration called"), instance=instance)
instance_name = instance['name']
@@ -157,7 +157,8 @@ class MigrationOps(object):
self._vmops.create_instance(instance, network_info, block_device_info,
root_vhd_path)
- self._vmops.power_on(instance)
+ if power_on:
+ self._vmops.power_on(instance)
def _merge_base_vhd(self, diff_vhd_path, base_vhd_path):
base_vhd_copy_path = os.path.join(os.path.dirname(diff_vhd_path),
@@ -209,7 +210,7 @@ class MigrationOps(object):
def finish_migration(self, context, migration, instance, disk_info,
network_info, image_meta, resize_instance=False,
- block_device_info=None):
+ block_device_info=None, power_on=True):
LOG.debug(_("finish_migration called"), instance=instance)
instance_name = instance['name']
@@ -239,4 +240,5 @@ class MigrationOps(object):
self._vmops.create_instance(instance, network_info, block_device_info,
root_vhd_path)
- self._vmops.power_on(instance)
+ if power_on:
+ self._vmops.power_on(instance)
diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py
index 7af7e4e2a..becc132de 100755
--- a/nova/virt/libvirt/driver.py
+++ b/nova/virt/libvirt/driver.py
@@ -2386,7 +2386,7 @@ class LibvirtDriver(driver.ComputeDriver):
'id': virt_dom.ID()}
def _create_domain(self, xml=None, domain=None,
- instance=None, launch_flags=0):
+ instance=None, launch_flags=0, power_on=True):
"""Create a domain.
Either domain or xml must be passed in. If both are passed, then
@@ -2409,7 +2409,8 @@ class LibvirtDriver(driver.ComputeDriver):
if xml:
domain = self._conn.defineXML(xml)
- domain.createWithFlags(launch_flags)
+ if power_on:
+ domain.createWithFlags(launch_flags)
self._enable_hairpin(domain.XMLDesc(0))
# NOTE(uni): Now the container is running with its own private mount
@@ -2426,7 +2427,7 @@ class LibvirtDriver(driver.ComputeDriver):
return domain
def _create_domain_and_network(self, xml, instance, network_info,
- block_device_info=None):
+ block_device_info=None, power_on=True):
"""Do required network setup and create domain."""
block_device_mapping = driver.block_device_info_get_mapping(
@@ -2448,7 +2449,7 @@ class LibvirtDriver(driver.ComputeDriver):
self.plug_vifs(instance, network_info)
self.firewall_driver.setup_basic_filtering(instance, network_info)
self.firewall_driver.prepare_instance_filter(instance, network_info)
- domain = self._create_domain(xml, instance=instance)
+ domain = self._create_domain(xml, instance=instance, power_on=power_on)
self.firewall_driver.apply_instance_filter(instance, network_info)
return domain
@@ -3626,7 +3627,7 @@ class LibvirtDriver(driver.ComputeDriver):
def finish_migration(self, context, migration, instance, disk_info,
network_info, image_meta, resize_instance,
- block_device_info=None):
+ block_device_info=None, power_on=True):
LOG.debug(_("Starting finish_migration"), instance=instance)
# resize disks. only "disk" and "disk.local" are necessary.
@@ -3677,10 +3678,12 @@ 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)
- timer = loopingcall.FixedIntervalLoopingCall(self._wait_for_running,
- instance)
- timer.start(interval=0.5).wait()
+ block_device_info, power_on)
+ if power_on:
+ timer = loopingcall.FixedIntervalLoopingCall(
+ self._wait_for_running,
+ instance)
+ timer.start(interval=0.5).wait()
def _cleanup_failed_migration(self, inst_base):
"""Make sure that a failed migrate doesn't prevent us from rolling
@@ -3688,7 +3691,7 @@ class LibvirtDriver(driver.ComputeDriver):
shutil.rmtree(inst_base)
def finish_revert_migration(self, instance, network_info,
- block_device_info=None):
+ block_device_info=None, power_on=True):
LOG.debug(_("Starting finish_revert_migration"),
instance=instance)
@@ -3710,11 +3713,13 @@ class LibvirtDriver(driver.ComputeDriver):
xml = self.to_xml(instance, network_info, disk_info,
block_device_info=block_device_info)
self._create_domain_and_network(xml, instance, network_info,
- block_device_info)
+ block_device_info, power_on)
- timer = loopingcall.FixedIntervalLoopingCall(self._wait_for_running,
- instance)
- timer.start(interval=0.5).wait()
+ if power_on:
+ timer = loopingcall.FixedIntervalLoopingCall(
+ self._wait_for_running,
+ instance)
+ timer.start(interval=0.5).wait()
def confirm_migration(self, migration, instance, network_info):
"""Confirms a resize, destroying the source VM."""
diff --git a/nova/virt/powervm/driver.py b/nova/virt/powervm/driver.py
index 199b10704..5117bdf72 100755
--- a/nova/virt/powervm/driver.py
+++ b/nova/virt/powervm/driver.py
@@ -279,7 +279,7 @@ class PowerVMDriver(driver.ComputeDriver):
def finish_migration(self, context, migration, instance, disk_info,
network_info, image_meta, resize_instance,
- block_device_info=None):
+ block_device_info=None, power_on=True):
"""Completes a resize, turning on the migrated instance
:param network_info:
@@ -297,7 +297,8 @@ class PowerVMDriver(driver.ComputeDriver):
disk_size = max(int(new_lv_size), int(old_lv_size))
disk_size_bytes = disk_size * 1024 * 1024 * 1024
self._powervm.deploy_from_migrated_file(
- lpar_obj, disk_info['root_disk_file'], disk_size_bytes)
+ lpar_obj, disk_info['root_disk_file'], disk_size_bytes,
+ power_on)
else:
# this shouldn't get hit unless someone forgot to handle
# a certain migration type
@@ -312,8 +313,8 @@ class PowerVMDriver(driver.ComputeDriver):
self._powervm.destroy(new_name)
def finish_revert_migration(self, instance, network_info,
- block_device_info=None):
- """Finish reverting a resize, powering back on the instance."""
+ block_device_info=None, power_on=True):
+ """Finish reverting a resize."""
new_name = self._get_resize_name(instance['name'])
@@ -332,4 +333,6 @@ class PowerVMDriver(driver.ComputeDriver):
self._powervm.destroy(instance['name'])
# undo instance rename and start
self._powervm._operator.rename_lpar(new_name, instance['name'])
- self._powervm.power_on(instance['name'])
+
+ if power_on:
+ self._powervm.power_on(instance['name'])
diff --git a/nova/virt/powervm/operator.py b/nova/virt/powervm/operator.py
index f78aeb475..18cba0ba2 100644
--- a/nova/virt/powervm/operator.py
+++ b/nova/virt/powervm/operator.py
@@ -414,7 +414,8 @@ class PowerVMOperator(object):
disk_info['root_disk_file'] = dest_file_path
return disk_info
- def deploy_from_migrated_file(self, lpar, file_path, size):
+ def deploy_from_migrated_file(self, lpar, file_path, size,
+ power_on=True):
"""Deploy the logical volume and attach to new lpar.
:param lpar: lar instance
@@ -426,13 +427,14 @@ class PowerVMOperator(object):
try:
# deploy lpar from file
self._deploy_from_vios_file(lpar, file_path, size,
- decompress=need_decompress)
+ decompress=need_decompress,
+ power_on=power_on)
finally:
# cleanup migrated file
self._operator._remove_file(file_path)
def _deploy_from_vios_file(self, lpar, file_path, size,
- decompress=True):
+ decompress=True, power_on=True):
self._operator.create_lpar(lpar)
lpar = self._operator.get_lpar(lpar['name'])
instance_id = lpar['lpar_id']
@@ -447,7 +449,8 @@ class PowerVMOperator(object):
self._disk_adapter._copy_file_to_device(file_path, diskName,
decompress)
- self._operator.start_lpar(lpar['name'])
+ if power_on:
+ self._operator.start_lpar(lpar['name'])
class BaseOperator(object):
diff --git a/nova/virt/vmwareapi/driver.py b/nova/virt/vmwareapi/driver.py
index 4fa1614e0..916913187 100755
--- a/nova/virt/vmwareapi/driver.py
+++ b/nova/virt/vmwareapi/driver.py
@@ -383,16 +383,17 @@ class VMwareVCDriver(VMwareESXDriver):
self._vmops.confirm_migration(migration, instance, network_info)
def finish_revert_migration(self, instance, network_info,
- block_device_info=None):
+ block_device_info=None, power_on=True):
"""Finish reverting a resize, powering back on the instance."""
- self._vmops.finish_revert_migration(instance)
+ self._vmops.finish_revert_migration(instance, power_on)
def finish_migration(self, context, migration, instance, disk_info,
network_info, image_meta, resize_instance=False,
- block_device_info=None):
+ block_device_info=None, power_on=True):
"""Completes a resize, turning on the migrated instance."""
self._vmops.finish_migration(context, migration, instance, disk_info,
- network_info, image_meta, resize_instance)
+ network_info, image_meta, resize_instance,
+ power_on)
def live_migration(self, context, instance_ref, dest,
post_method, recover_method, block_migration=False,
diff --git a/nova/virt/vmwareapi/vmops.py b/nova/virt/vmwareapi/vmops.py
index cda2ce8e3..538b498b6 100644
--- a/nova/virt/vmwareapi/vmops.py
+++ b/nova/virt/vmwareapi/vmops.py
@@ -978,8 +978,8 @@ class VMwareVMOps(object):
if network_info:
self.unplug_vifs(instance, network_info)
- def finish_revert_migration(self, instance):
- """Finish reverting a resize, powering back on the instance."""
+ def finish_revert_migration(self, instance, power_on=True):
+ """Finish reverting a resize."""
# The original vm was suffixed with '-orig'; find it using
# the old suffix, remove the suffix, then power it back on.
name_label = self._get_orig_vm_name_label(instance)
@@ -995,13 +995,16 @@ class VMwareVMOps(object):
self._session._wait_for_task(instance['uuid'], rename_task)
LOG.debug(_("Renamed the VM from %s") % name_label,
instance=instance)
- self.power_on(instance)
+ if power_on:
+ self.power_on(instance)
def finish_migration(self, context, migration, instance, disk_info,
- network_info, image_meta, resize_instance=False):
+ network_info, image_meta, resize_instance=False,
+ power_on=True):
"""Completes a resize, turning on the migrated instance."""
# 4. Start VM
- self.power_on(instance)
+ if power_on:
+ self.power_on(instance)
self._update_instance_progress(context, instance,
step=4,
total_steps=RESIZE_TOTAL_STEPS)
diff --git a/nova/virt/xenapi/driver.py b/nova/virt/xenapi/driver.py
index 5bc1a3049..cd892bceb 100755
--- a/nova/virt/xenapi/driver.py
+++ b/nova/virt/xenapi/driver.py
@@ -182,18 +182,19 @@ class XenAPIDriver(driver.ComputeDriver):
self._vmops.confirm_migration(migration, instance, network_info)
def finish_revert_migration(self, instance, network_info,
- block_device_info=None):
- """Finish reverting a resize, powering back on the instance."""
+ 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(instance, block_device_info,
+ power_on)
def finish_migration(self, context, migration, instance, disk_info,
network_info, image_meta, resize_instance=False,
- block_device_info=None):
+ block_device_info=None, power_on=True):
"""Completes a resize, turning on the migrated instance."""
self._vmops.finish_migration(context, migration, instance, disk_info,
network_info, image_meta, resize_instance,
- block_device_info)
+ block_device_info, power_on)
def snapshot(self, context, instance, image_id, update_task_state):
"""Create snapshot from a running VM instance."""
diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py
index 29e075655..332f3b88c 100644
--- a/nova/virt/xenapi/vmops.py
+++ b/nova/virt/xenapi/vmops.py
@@ -231,10 +231,13 @@ class VMOps(object):
mount_device,
hotplug=False)
- def finish_revert_migration(self, instance, block_device_info=None):
- self._restore_orig_vm_and_cleanup_orphan(instance, block_device_info)
+ def finish_revert_migration(self, instance, block_device_info=None,
+ power_on=True):
+ self._restore_orig_vm_and_cleanup_orphan(instance, block_device_info,
+ power_on)
- def _restore_orig_vm_and_cleanup_orphan(self, instance, block_device_info):
+ def _restore_orig_vm_and_cleanup_orphan(self, instance,
+ block_device_info, power_on=True):
# NOTE(sirp): the original vm was suffixed with '-orig'; find it using
# the old suffix, remove the suffix, then power it back on.
name_label = self._get_orig_vm_name_label(instance)
@@ -257,11 +260,12 @@ class VMOps(object):
# We crashed before the -orig backup was made
vm_ref = new_ref
- self._start(instance, vm_ref)
+ if power_on:
+ self._start(instance, vm_ref)
def finish_migration(self, context, migration, instance, disk_info,
network_info, image_meta, resize_instance,
- block_device_info=None):
+ block_device_info=None, power_on=True):
root_vdi = vm_utils.move_disks(self._session, instance, disk_info)
if resize_instance:
@@ -292,7 +296,8 @@ class VMOps(object):
self._attach_mapped_block_devices(instance, block_device_info)
# 5. Start VM
- self._start(instance, vm_ref=vm_ref)
+ if power_on:
+ self._start(instance, vm_ref=vm_ref)
self._update_instance_progress(context, instance,
step=5,
total_steps=RESIZE_TOTAL_STEPS)