Merge "Optimize live_migrate_instance"
This commit is contained in:
@@ -112,18 +112,9 @@ class Migrate(base.BaseAction):
|
||||
result = nova.live_migrate_instance(instance_id=self.instance_uuid,
|
||||
dest_hostname=destination)
|
||||
except nova_helper.nvexceptions.ClientException as e:
|
||||
if e.code == 400:
|
||||
LOG.debug("Live migration of instance %s failed. "
|
||||
"Trying to live migrate using block migration."
|
||||
% self.instance_uuid)
|
||||
result = nova.live_migrate_instance(
|
||||
instance_id=self.instance_uuid,
|
||||
dest_hostname=destination,
|
||||
block_migration=True)
|
||||
else:
|
||||
LOG.debug("Nova client exception occurred while live "
|
||||
"migrating instance %s.Exception: %s" %
|
||||
(self.instance_uuid, e))
|
||||
LOG.debug("Nova client exception occurred while live "
|
||||
"migrating instance %s.Exception: %s" %
|
||||
(self.instance_uuid, e))
|
||||
except Exception as e:
|
||||
LOG.exception(e)
|
||||
LOG.critical("Unexpected error occurred. Migration failed for "
|
||||
|
||||
@@ -422,8 +422,7 @@ class NovaHelper(object):
|
||||
|
||||
return True
|
||||
|
||||
def live_migrate_instance(self, instance_id, dest_hostname,
|
||||
block_migration=False, retry=120):
|
||||
def live_migrate_instance(self, instance_id, dest_hostname, retry=120):
|
||||
"""This method does a live migration of a given instance
|
||||
|
||||
This method uses the Nova built-in live_migrate()
|
||||
@@ -436,7 +435,6 @@ class NovaHelper(object):
|
||||
:param dest_hostname: the name of the destination compute node, if
|
||||
destination_node is None, nova scheduler choose
|
||||
the destination host
|
||||
:param block_migration: No shared storage is required.
|
||||
"""
|
||||
LOG.debug("Trying to live migrate instance %s " % (instance_id))
|
||||
|
||||
@@ -450,8 +448,9 @@ class NovaHelper(object):
|
||||
LOG.debug(
|
||||
"Instance %s found on host '%s'." % (instance_id, host_name))
|
||||
|
||||
instance.live_migrate(host=dest_hostname,
|
||||
block_migration=block_migration)
|
||||
# From nova api version 2.25(Mitaka release), the default value of
|
||||
# block_migration is None which is mapped to 'auto'.
|
||||
instance.live_migrate(host=dest_hostname)
|
||||
|
||||
instance = self.nova.servers.get(instance_id)
|
||||
|
||||
|
||||
@@ -210,34 +210,6 @@ class TestMigration(base.TestCase):
|
||||
dest_hostname="compute1-hostname"
|
||||
)
|
||||
|
||||
def test_live_migrate_non_shared_storage_instance(self):
|
||||
self.m_helper.find_instance.return_value = self.INSTANCE_UUID
|
||||
|
||||
self.m_helper.live_migrate_instance.side_effect = [
|
||||
nova_helper.nvexceptions.ClientException(400, "BadRequest"), True]
|
||||
|
||||
try:
|
||||
self.action.execute()
|
||||
except Exception as exc:
|
||||
self.fail(exc)
|
||||
|
||||
self.m_helper.live_migrate_instance.assert_has_calls([
|
||||
mock.call(instance_id=self.INSTANCE_UUID,
|
||||
dest_hostname="compute2-hostname"),
|
||||
mock.call(instance_id=self.INSTANCE_UUID,
|
||||
dest_hostname="compute2-hostname",
|
||||
block_migration=True)
|
||||
])
|
||||
|
||||
expected = [mock.call.first(instance_id=self.INSTANCE_UUID,
|
||||
dest_hostname="compute2-hostname"),
|
||||
mock.call.second(instance_id=self.INSTANCE_UUID,
|
||||
dest_hostname="compute2-hostname",
|
||||
block_migration=True)
|
||||
]
|
||||
self.m_helper.live_migrate_instance.mock_calls == expected
|
||||
self.assertEqual(2, self.m_helper.live_migrate_instance.call_count)
|
||||
|
||||
def test_abort_live_migrate(self):
|
||||
migration = mock.MagicMock()
|
||||
migration.id = "2"
|
||||
|
||||
Reference in New Issue
Block a user