Browse Source

Merge "Add functional test to delete a server while in VERIFY_RESIZE"

tags/19.0.0.0rc1
Zuul 2 months ago
parent
commit
5ca858eaa7

+ 3
- 1
nova/compute/api.py View File

@@ -2134,7 +2134,9 @@ class API(base.Base):
2134 2134
 
2135 2135
     def _confirm_resize_on_deleting(self, context, instance):
2136 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 2140
         migration = None
2139 2141
         for status in ('finished', 'confirming'):
2140 2142
             try:

+ 23
- 0
nova/tests/functional/integrated_helpers.py View File

@@ -40,6 +40,7 @@ from nova.tests.unit import cast_as_call
40 40
 from nova.tests.unit import fake_notifier
41 41
 import nova.tests.unit.image.fake
42 42
 from nova.tests.unit import policy_fixture
43
+from nova import utils
43 44
 from nova.virt import fake
44 45
 
45 46
 
@@ -714,9 +715,26 @@ class ProviderUsageBaseTestCase(test.TestCase, InstanceHelperMixin):
714 715
     def _delete_and_check_allocations(self, server):
715 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 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 738
         self.api.delete_server(server['id'])
721 739
         self._wait_until_deleted(server)
722 740
         # NOTE(gibi): The resource allocation is deleted after the instance is
@@ -737,6 +755,11 @@ class ProviderUsageBaseTestCase(test.TestCase, InstanceHelperMixin):
737 755
         allocations = self._get_allocations_by_server_uuid(server['id'])
738 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 763
     def _run_periodics(self):
741 764
         """Run the update_available_resource task on every compute manager
742 765
 

+ 22
- 0
nova/tests/functional/test_servers.py View File

@@ -2688,6 +2688,28 @@ class ServerMovingTests(integrated_helpers.ProviderUsageBaseTestCase):
2688 2688
 
2689 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 2713
     def _wait_for_notification_event_type(self, event_type, max_retries=50):
2692 2714
         retry_counter = 0
2693 2715
         while True:

Loading…
Cancel
Save