Browse Source

Add functional confirm_migration_error test

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

This backport is not clean due to change
If6aa37d9b6b48791e070799ab026c816fda4441c, which
refactored the testing framework. Within the refactor,
new assertion methods were added and method
"assertFlavorMatchesAllocation" was modified.
This backport needed to be adapted in order to
be compatible with the testing framework prior to
If6aa37d9b6b48791e070799ab026c816fda4441c.

Change-Id: I9d6478f492351b58aa87b8f56e907ee633d6d1c6
Related-bug: #1821594
(cherry picked from commit 873ac499c5)
(cherry picked from commit d7d7f11543)
tags/18.2.1
Rodrigo Barbieri 4 months ago
parent
commit
01bfb7863c
1 changed files with 72 additions and 0 deletions
  1. 72
    0
      nova/tests/functional/test_servers.py

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

@@ -1838,6 +1838,78 @@ class ServerMovingTests(integrated_helpers.ProviderUsageBaseTestCase):
1838 1838
             new_flavor=new_flavor, source_rp_uuid=source_rp_uuid,
1839 1839
             dest_rp_uuid=dest_rp_uuid)
1840 1840
 
1841
+    def test_migration_confirm_resize_error(self):
1842
+        source_hostname = self.compute1.host
1843
+        dest_hostname = self.compute2.host
1844
+
1845
+        source_rp_uuid = self._get_provider_uuid_by_host(source_hostname)
1846
+        dest_rp_uuid = self._get_provider_uuid_by_host(dest_hostname)
1847
+
1848
+        server = self._boot_and_check_allocations(self.flavor1,
1849
+                                                  source_hostname)
1850
+
1851
+        self._move_and_check_allocations(
1852
+            server, request={'migrate': None}, old_flavor=self.flavor1,
1853
+            new_flavor=self.flavor1, source_rp_uuid=source_rp_uuid,
1854
+            dest_rp_uuid=dest_rp_uuid)
1855
+
1856
+        # Mock failure
1857
+        def fake_confirm_migration(context, migration, instance, network_info):
1858
+            raise exception.MigrationPreCheckError(
1859
+                reason='test_migration_confirm_resize_error')
1860
+
1861
+        with mock.patch('nova.virt.fake.FakeDriver.'
1862
+                        'confirm_migration',
1863
+                        side_effect=fake_confirm_migration):
1864
+
1865
+            # Confirm the migration/resize and check the usages
1866
+            post = {'confirmResize': None}
1867
+            self.api.post_server_action(
1868
+                server['id'], post, check_response_status=[204])
1869
+            server = self._wait_for_state_change(self.api, server, 'ERROR')
1870
+
1871
+        # After confirming and error, we should have an allocation only on the
1872
+        # destination host
1873
+        source_usages = self._get_provider_usages(source_rp_uuid)
1874
+        self.assertEqual({'VCPU': 0,
1875
+                          'MEMORY_MB': 0,
1876
+                          'DISK_GB': 0}, source_usages,
1877
+                          'Source host %s still has usage after the failed '
1878
+                          'migration_confirm' % source_hostname)
1879
+
1880
+        # Check that the server only allocates resource from the original host
1881
+        allocations = self._get_allocations_by_server_uuid(server['id'])
1882
+        self.assertEqual(1, len(allocations))
1883
+
1884
+        dest_allocation = allocations[dest_rp_uuid]['resources']
1885
+        self.assertFlavorMatchesAllocation(self.flavor1, dest_allocation)
1886
+
1887
+        dest_usages = self._get_provider_usages(dest_rp_uuid)
1888
+        self.assertFlavorMatchesAllocation(self.flavor1, dest_usages)
1889
+
1890
+        self._run_periodics()
1891
+
1892
+        # After confirming and error, we should have an allocation only on the
1893
+        # destination host
1894
+        source_usages = self._get_provider_usages(source_rp_uuid)
1895
+        self.assertEqual({'VCPU': 0,
1896
+                          'MEMORY_MB': 0,
1897
+                          'DISK_GB': 0}, source_usages,
1898
+                          'Source host %s still has usage after the failed '
1899
+                          'migration_confirm' % source_hostname)
1900
+
1901
+        # Check that the server only allocates resource from the original host
1902
+        allocations = self._get_allocations_by_server_uuid(server['id'])
1903
+        self.assertEqual(1, len(allocations))
1904
+
1905
+        dest_allocation = allocations[dest_rp_uuid]['resources']
1906
+        self.assertFlavorMatchesAllocation(self.flavor1, dest_allocation)
1907
+
1908
+        dest_usages = self._get_provider_usages(dest_rp_uuid)
1909
+        self.assertFlavorMatchesAllocation(self.flavor1, dest_usages)
1910
+
1911
+        self._delete_and_check_allocations(server)
1912
+
1841 1913
     def _test_resize_revert(self, dest_hostname):
1842 1914
         source_hostname = self._other_hostname(dest_hostname)
1843 1915
         source_rp_uuid = self._get_provider_uuid_by_host(source_hostname)

Loading…
Cancel
Save