Merge "check task_state in the live_migrate_instance"

This commit is contained in:
Zuul 2017-11-08 01:50:38 +00:00 committed by Gerrit Code Review
commit 4179cfd036
2 changed files with 24 additions and 0 deletions

View File

@ -478,6 +478,9 @@ class NovaHelper(object):
'OS-EXT-SRV-ATTR:host') != dest_hostname \
and retry:
instance = self.nova.servers.get(instance.id)
if not getattr(instance, 'OS-EXT-STS:task_state'):
LOG.debug("Instance task state: %s is null" % instance_id)
break
LOG.debug(
'Waiting the migration of {0} to {1}'.format(
instance,

View File

@ -165,6 +165,27 @@ class TestNovaHelper(base.TestCase):
)
self.assertFalse(is_success)
@mock.patch.object(time, 'sleep', mock.Mock())
def test_live_migrate_instance_with_task_state(
self, mock_glance, mock_cinder, mock_neutron, mock_nova):
nova_util = nova_helper.NovaHelper()
server = self.fake_server(self.instance_uuid)
setattr(server, 'OS-EXT-SRV-ATTR:host',
self.source_node)
setattr(server, 'OS-EXT-STS:task_state', '')
self.fake_nova_find_list(nova_util, find=server, list=None)
nova_util.live_migrate_instance(
self.instance_uuid, self.destination_node
)
time.sleep.assert_not_called()
setattr(server, 'OS-EXT-STS:task_state', 'migrating')
self.fake_nova_find_list(nova_util, find=server, list=server)
nova_util.live_migrate_instance(
self.instance_uuid, self.destination_node
)
time.sleep.assert_called_with(1)
@mock.patch.object(time, 'sleep', mock.Mock())
def test_live_migrate_instance_no_destination_node(
self, mock_glance, mock_cinder, mock_neutron, mock_nova):