Fix race fail in test_resize_with_reschedule_then_live_migrate

The assertion in the test that the migration status is 'completed'
is flawed in that it assumes when the instance status is 'ACTIVE'
the migration is completed, which isn't True, since the instance
status gets changed before the migration is completed, but they are
very close in time so there is a race, which is how this test slipped
by. This fixes the issue by polling the migration status until it
is actually completed or we timeout.

Change-Id: I61f745667f4c003d7e3ca6f2f9a99194930ac892
Closes-Bug: #1762876
This commit is contained in:
Matt Riedemann 2018-04-11 10:43:34 -04:00
parent fe976dcc55
commit 4afa8c2b97
1 changed files with 6 additions and 5 deletions

View File

@ -143,11 +143,12 @@ class TestRequestSpecRetryReschedule(test.TestCase,
self.admin_api.post_server_action(server['id'], data)
server = self._wait_for_state_change(self.admin_api, server, 'ACTIVE')
self.assertEqual('host2', server['OS-EXT-SRV-ATTR:host'])
migrations = self.admin_api.api_get(
'os-migrations?instance_uuid=%s&migration_type=live-migration' %
server['id']).body['migrations']
self.assertEqual(1, len(migrations))
self.assertEqual('completed', migrations[0]['status'])
# NOTE(mriedem): The instance status effectively goes to ACTIVE before
# the migration status is changed to "completed" since
# post_live_migration_at_destination changes the instance status
# and _post_live_migration changes the migration status later. So we
# need to poll the migration record until it's complete or we timeout.
self._wait_for_migration_status(server, ['completed'])
reqspec = objects.RequestSpec.get_by_instance_uuid(
nova_context.get_admin_context(), server['id'])
self.assertIsNone(reqspec.retry)