Add functional confirm_migration_error test

This test checks if allocations have been
successfully cleaned up upon the driver failing
during "confirm_migration".

Change-Id: I9d6478f492351b58aa87b8f56e907ee633d6d1c6
Related-bug: #1821594
(cherry picked from commit 873ac499c5)
This commit is contained in:
Rodrigo Barbieri 2019-05-08 16:01:25 -03:00 committed by Matt Riedemann
parent 91282f879c
commit d7d7f11543
1 changed files with 53 additions and 0 deletions

View File

@ -2495,6 +2495,59 @@ class ServerMovingTests(integrated_helpers.ProviderUsageBaseTestCase):
new_flavor=new_flavor, source_rp_uuid=source_rp_uuid,
dest_rp_uuid=dest_rp_uuid)
def test_migration_confirm_resize_error(self):
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)
self._move_and_check_allocations(
server, request={'migrate': None}, old_flavor=self.flavor1,
new_flavor=self.flavor1, source_rp_uuid=source_rp_uuid,
dest_rp_uuid=dest_rp_uuid)
# Mock failure
def fake_confirm_migration(context, migration, instance, network_info):
raise exception.MigrationPreCheckError(
reason='test_migration_confirm_resize_error')
with mock.patch('nova.virt.fake.FakeDriver.'
'confirm_migration',
side_effect=fake_confirm_migration):
# Confirm the migration/resize and check the usages
post = {'confirmResize': None}
self.api.post_server_action(
server['id'], post, check_response_status=[204])
server = self._wait_for_state_change(self.api, server, 'ERROR')
# After confirming and error, we should have an allocation only on the
# destination host
self.assertFlavorMatchesUsage(dest_rp_uuid, self.flavor1)
self.assertRequestMatchesUsage({'VCPU': 0,
'MEMORY_MB': 0,
'DISK_GB': 0}, source_rp_uuid)
self.assertFlavorMatchesAllocation(self.flavor1, server['id'],
dest_rp_uuid)
self._run_periodics()
# Check we're still accurate after running the periodics
self.assertFlavorMatchesUsage(dest_rp_uuid, self.flavor1)
self.assertRequestMatchesUsage({'VCPU': 0,
'MEMORY_MB': 0,
'DISK_GB': 0}, source_rp_uuid)
self.assertFlavorMatchesAllocation(self.flavor1, server['id'],
dest_rp_uuid)
self._delete_and_check_allocations(server)
def _test_resize_revert(self, dest_hostname):
source_hostname = self._other_hostname(dest_hostname)
source_rp_uuid = self._get_provider_uuid_by_host(source_hostname)