Add helper method for waiting migrations in functional tests

In functional tests, this method will be used in some places. This
method waits for the migrations and if there is at least one  active
migration in progress, the method return with the migrations.

Change-Id: Ia068de2dac34f2399025fb28fec9af75c1442d63
Co-Authored-By: Alex Szarka <szarka@inf.u-szeged.hu>
Implements: bp versioned-notification-transformation-pike
This commit is contained in:
Gábor Antal 2017-07-24 11:19:32 +02:00
parent e62d931025
commit 47469ac868
2 changed files with 24 additions and 0 deletions

View File

@ -422,3 +422,7 @@ class TestOpenStackClient(object):
def post_keypair(self, 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(
server['id'], {"volumeAttachment": {"volumeId": volume_id}})
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.')