From 143fe79c9e4daf9ab0b10402caea444080d3bf1f Mon Sep 17 00:00:00 2001 From: Lajos Katona Date: Mon, 28 Aug 2017 14:10:46 +0200 Subject: [PATCH] Add functional for live migrate delete Related-Bug: #1714237 Change-Id: I3bf0032f8cecf098fd941e5e5b41c9ff3d8336e4 --- nova/tests/functional/api/client.py | 4 ++ nova/tests/functional/test_servers.py | 78 ++++++++++++++++++++++++++- 2 files changed, 80 insertions(+), 2 deletions(-) diff --git a/nova/tests/functional/api/client.py b/nova/tests/functional/api/client.py index d58744cf3b34..f5df234f96c1 100644 --- a/nova/tests/functional/api/client.py +++ b/nova/tests/functional/api/client.py @@ -454,3 +454,7 @@ class TestOpenStackClient(object): return self.api_post( '/servers/%s/migrations/%s/action' % (server_id, migration_id), {'force_complete': None}) + + def delete_migration(self, server_id, migration_id): + return self.api_delete( + '/servers/%s/migrations/%s' % (server_id, migration_id)) diff --git a/nova/tests/functional/test_servers.py b/nova/tests/functional/test_servers.py index 3cd79804b86b..593369edbd69 100644 --- a/nova/tests/functional/test_servers.py +++ b/nova/tests/functional/test_servers.py @@ -2290,15 +2290,24 @@ class ServerMovingTests(ProviderUsageBaseTestCase): def _mock_live_migration(self, context, instance, dest, post_method, recover_method, block_migration=False, migrate_data=None): + self._abort_migration = False + self._migrating = True while self._migrating: time.sleep(0.5) - post_method(context, instance, dest, block_migration, - migrate_data) + if self._abort_migration: + recover_method(context, instance, dest) + else: + post_method(context, instance, dest, block_migration, + migrate_data) def _mock_force_complete(self, instance): self._migrating = False + def _mock_live_migration_abort(self, instance): + self._abort_migration = True + self._migrating = False + @mock.patch('nova.virt.fake.FakeDriver.live_migration') @mock.patch('nova.virt.fake.FakeDriver.live_migration_force_complete') def test_live_migrate_force_complete(self, mock_force_complete, @@ -2351,6 +2360,71 @@ class ServerMovingTests(ProviderUsageBaseTestCase): self._delete_and_check_allocations( server, source_rp_uuid, dest_rp_uuid) + @mock.patch('nova.virt.fake.FakeDriver.live_migration') + @mock.patch('nova.virt.fake.FakeDriver.live_migration_abort') + def test_live_migrate_delete(self, mock_live_migration_abort, + mock_live_migration): + mock_live_migration.side_effect = self._mock_live_migration + mock_live_migration_abort.side_effect = self._mock_live_migration_abort + + source_hostname = self.compute1.host + dest_hostname = self.compute2.host + source_rp_uuid = self._get_provider_uuid_by_host(source_hostname) + dest_rp_uuid = self._get_provider_uuid_by_host(dest_hostname) + + server = self._boot_and_check_allocations( + self.flavor1, source_hostname) + + post = { + 'os-migrateLive': { + 'host': dest_hostname, + 'block_migration': True, + } + } + self.api.post_server_action(server['id'], post) + + migration = self._wait_for_migration_status(server, 'running') + + self.api.delete_migration(server['id'], migration['id']) + self._wait_for_server_parameter(self.api, server, + {'OS-EXT-SRV-ATTR:host': source_hostname, + 'status': 'ACTIVE'}) + + self._run_periodics() + + allocations = self._get_allocations_by_server_uuid(server['id']) + # Note(lajos katona): After solving bug #1714237 there should be + # only 1 allocation: + # self.assertEqual(1, len(allocations)) + self.assertEqual(2, len(allocations)) + + # Note(lajos katona): After solving bug #1714237 the destination + # resource provider should not be among the allocations: + # self.assertNotIn(dest_rp_uuid, allocations) + + source_usages = self._get_provider_usages(source_rp_uuid) + self.assertFlavorMatchesAllocation(self.flavor1, source_usages) + + source_allocation = allocations[source_rp_uuid]['resources'] + self.assertFlavorMatchesAllocation(self.flavor1, source_allocation) + + dest_usages = self._get_provider_usages(dest_rp_uuid) + # Note(lajos katona): After solving bug #1714237 on the destination + # there should be zero usage: + # self.assertFlavorMatchesAllocation( + # {'ram': 0, 'disk': 0, 'vcpus': 0}, dest_usages) + self.assertFlavorMatchesAllocation(self.flavor1, dest_usages) + + dest_allocation = allocations[dest_rp_uuid]['resources'] + # Note(lajos katona): After solving bug #1714237 on the destination + # there should be zero allocation: + # self.assertFlavorMatchesAllocation( + # {'ram': 0, 'disk': 0, 'vcpus': 0}, dest_allocation) + self.assertFlavorMatchesAllocation(self.flavor1, dest_allocation) + + self._delete_and_check_allocations( + server, source_rp_uuid, dest_rp_uuid) + class ServerRescheduleTests(ProviderUsageBaseTestCase): """Tests server create scenarios which trigger a reschedule during