From 47469ac8683e914d4dcc26ae38bcea1e4a22587a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Antal?= Date: Mon, 24 Jul 2017 11:19:32 +0200 Subject: [PATCH] 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 Implements: bp versioned-notification-transformation-pike --- nova/tests/functional/api/client.py | 4 ++++ .../notification_sample_base.py | 20 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/nova/tests/functional/api/client.py b/nova/tests/functional/api/client.py index 7fde21465349..4b85ddd059b9 100644 --- a/nova/tests/functional/api/client.py +++ b/nova/tests/functional/api/client.py @@ -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'] diff --git a/nova/tests/functional/notification_sample_tests/notification_sample_base.py b/nova/tests/functional/notification_sample_tests/notification_sample_base.py index 70488e41e729..6114a6949862 100644 --- a/nova/tests/functional/notification_sample_tests/notification_sample_base.py +++ b/nova/tests/functional/notification_sample_tests/notification_sample_base.py @@ -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.')