Merge "Add helper method for waiting migrations in functional tests"

This commit is contained in:
Jenkins 2017-07-26 23:43:23 +00:00 committed by Gerrit Code Review
commit 592d120de9
2 changed files with 24 additions and 0 deletions

View File

@ -429,3 +429,7 @@ class TestOpenStackClient(object):
def post_keypair(self, keypair): def post_keypair(self, keypair):
return self.api_post('/os-keypairs', keypair).body['keypair'] return self.api_post('/os-keypairs', keypair).body['keypair']
def get_active_migrations(self, server_id):
return self.api_get('/servers/%s/migrations' %
server_id).body['migrations']

View File

@ -255,3 +255,23 @@ class NotificationSampleTestBase(test.TestCase,
self.api.post_server_volume( self.api.post_server_volume(
server['id'], {"volumeAttachment": {"volumeId": volume_id}}) server['id'], {"volumeAttachment": {"volumeId": volume_id}})
self._wait_for_notification('instance.volume_attach.end') self._wait_for_notification('instance.volume_attach.end')
def _wait_and_get_migrations(self, server, max_retries=20):
"""Simple method to wait for the migrations
Here we wait for the moment where active migration is in progress so
we can get them and use them in the migration-related tests.
:param server: server we'd like to use
:param max_retries: maximum number of retries
:returns: the migrations
"""
retries = 0
while retries < max_retries:
retries += 1
migrations = self.admin_api.get_active_migrations(server['id'])
if (len(migrations) > 0 and
migrations[0]['status'] != 'preparing'):
return migrations
if retries == max_retries:
self.fail('The migration table left empty.')