From bf713ac7e1a761d031cfb49c5b6e888f788ad7ff Mon Sep 17 00:00:00 2001
From: licanwei
Date: Sun, 15 Oct 2017 20:22:13 -0700
Subject: [PATCH] Optimize live_migrate_instance
https://github.com/openstack/python-novaclient/blob/
master/novaclient/v2/servers.py#L468
From nova api version 2.25(Mitaka release), the default value of
block_migration is None which is mapped to 'auto'.
So we can remove 'block_migration' from live_migrate_instance.
Change-Id: I75a581d3146824b1146e2acf5a7fbe4f8368a4e8
---
watcher/applier/actions/migration.py | 15 ++--------
watcher/common/nova_helper.py | 9 +++---
.../tests/applier/actions/test_migration.py | 28 -------------------
3 files changed, 7 insertions(+), 45 deletions(-)
diff --git a/watcher/applier/actions/migration.py b/watcher/applier/actions/migration.py
index 07eb83a3a..d0b6dcf3d 100644
--- a/watcher/applier/actions/migration.py
+++ b/watcher/applier/actions/migration.py
@@ -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 "
diff --git a/watcher/common/nova_helper.py b/watcher/common/nova_helper.py
index 8bc08a59b..55a1aff94 100644
--- a/watcher/common/nova_helper.py
+++ b/watcher/common/nova_helper.py
@@ -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)
diff --git a/watcher/tests/applier/actions/test_migration.py b/watcher/tests/applier/actions/test_migration.py
index 7d85a0064..d7078320b 100644
--- a/watcher/tests/applier/actions/test_migration.py
+++ b/watcher/tests/applier/actions/test_migration.py
@@ -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"