summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2019-03-15 04:13:23 +0000
committerGerrit Code Review <review@openstack.org>2019-03-15 04:13:23 +0000
commit5ca858eaa72acd0513e27a4c9518980b769f5d6e (patch)
treed169c357c53771a733438b389186d0f6255a3a46
parent9b2a7f9e7c9c24ad5b698f78681a1de1593b4a53 (diff)
parent33cab70e1c9584d8253a47e49f057381265f1817 (diff)
Merge "Add functional test to delete a server while in VERIFY_RESIZE"
-rw-r--r--nova/compute/api.py4
-rw-r--r--nova/tests/functional/integrated_helpers.py23
-rw-r--r--nova/tests/functional/test_servers.py22
3 files changed, 48 insertions, 1 deletions
diff --git a/nova/compute/api.py b/nova/compute/api.py
index 9934437..519bf9f 100644
--- a/nova/compute/api.py
+++ b/nova/compute/api.py
@@ -2134,7 +2134,9 @@ class API(base.Base):
2134 2134
2135 def _confirm_resize_on_deleting(self, context, instance): 2135 def _confirm_resize_on_deleting(self, context, instance):
2136 # If in the middle of a resize, use confirm_resize to 2136 # If in the middle of a resize, use confirm_resize to
2137 # ensure the original instance is cleaned up too 2137 # ensure the original instance is cleaned up too along
2138 # with its allocations (and migration-based allocations)
2139 # in placement.
2138 migration = None 2140 migration = None
2139 for status in ('finished', 'confirming'): 2141 for status in ('finished', 'confirming'):
2140 try: 2142 try:
diff --git a/nova/tests/functional/integrated_helpers.py b/nova/tests/functional/integrated_helpers.py
index 5d54a19..a5f1d65 100644
--- a/nova/tests/functional/integrated_helpers.py
+++ b/nova/tests/functional/integrated_helpers.py
@@ -40,6 +40,7 @@ from nova.tests.unit import cast_as_call
40from nova.tests.unit import fake_notifier 40from nova.tests.unit import fake_notifier
41import nova.tests.unit.image.fake 41import nova.tests.unit.image.fake
42from nova.tests.unit import policy_fixture 42from nova.tests.unit import policy_fixture
43from nova import utils
43from nova.virt import fake 44from nova.virt import fake
44 45
45 46
@@ -714,9 +715,26 @@ class ProviderUsageBaseTestCase(test.TestCase, InstanceHelperMixin):
714 def _delete_and_check_allocations(self, server): 715 def _delete_and_check_allocations(self, server):
715 """Delete the instance and asserts that the allocations are cleaned 716 """Delete the instance and asserts that the allocations are cleaned
716 717
718 If the server was moved (resized or live migrated), also checks that
719 migration-based allocations are also cleaned up.
720
717 :param server: The API representation of the instance to be deleted 721 :param server: The API representation of the instance to be deleted
718 """ 722 """
719 723
724 # First check to see if there is a related migration record so we can
725 # assert its allocations (if any) are not leaked.
726 with utils.temporary_mutation(self.admin_api, microversion='2.59'):
727 migrations = self.admin_api.api_get(
728 '/os-migrations?instance_uuid=%s' %
729 server['id']).body['migrations']
730 if migrations:
731 # If there is more than one migration, they are sorted by
732 # created_at in descending order so we'll get the last one
733 # which is probably what we'd always want anyway.
734 migration_uuid = migrations[0]['uuid']
735 else:
736 migration_uuid = None
737
720 self.api.delete_server(server['id']) 738 self.api.delete_server(server['id'])
721 self._wait_until_deleted(server) 739 self._wait_until_deleted(server)
722 # NOTE(gibi): The resource allocation is deleted after the instance is 740 # NOTE(gibi): The resource allocation is deleted after the instance is
@@ -737,6 +755,11 @@ class ProviderUsageBaseTestCase(test.TestCase, InstanceHelperMixin):
737 allocations = self._get_allocations_by_server_uuid(server['id']) 755 allocations = self._get_allocations_by_server_uuid(server['id'])
738 self.assertEqual(0, len(allocations)) 756 self.assertEqual(0, len(allocations))
739 757
758 if migration_uuid:
759 # and no allocations for the delete migration
760 allocations = self._get_allocations_by_server_uuid(migration_uuid)
761 self.assertEqual(0, len(allocations))
762
740 def _run_periodics(self): 763 def _run_periodics(self):
741 """Run the update_available_resource task on every compute manager 764 """Run the update_available_resource task on every compute manager
742 765
diff --git a/nova/tests/functional/test_servers.py b/nova/tests/functional/test_servers.py
index 1a40461..959e2ab 100644
--- a/nova/tests/functional/test_servers.py
+++ b/nova/tests/functional/test_servers.py
@@ -2688,6 +2688,28 @@ class ServerMovingTests(integrated_helpers.ProviderUsageBaseTestCase):
2688 2688
2689 self._delete_and_check_allocations(server) 2689 self._delete_and_check_allocations(server)
2690 2690
2691 def test_resize_delete_while_verify(self):
2692 """Test scenario where the server is deleted while in the
2693 VERIFY_RESIZE state and ensures the allocations are properly
2694 cleaned up from the source and target compute node resource providers.
2695 The _confirm_resize_on_deleting() method in the API is actually
2696 responsible for making sure the migration-based allocations get
2697 cleaned up by confirming the resize on the source host before deleting
2698 the server from the target host.
2699 """
2700 dest_hostname = 'host2'
2701 source_hostname = self._other_hostname(dest_hostname)
2702 source_rp_uuid = self._get_provider_uuid_by_host(source_hostname)
2703 dest_rp_uuid = self._get_provider_uuid_by_host(dest_hostname)
2704
2705 server = self._boot_and_check_allocations(self.flavor1,
2706 source_hostname)
2707
2708 self._resize_and_check_allocations(server, self.flavor1, self.flavor2,
2709 source_rp_uuid, dest_rp_uuid)
2710
2711 self._delete_and_check_allocations(server)
2712
2691 def _wait_for_notification_event_type(self, event_type, max_retries=50): 2713 def _wait_for_notification_event_type(self, event_type, max_retries=50):
2692 retry_counter = 0 2714 retry_counter = 0
2693 while True: 2715 while True: