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".

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

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

@@ -2495,6 +2495,59 @@ class ServerMovingTests(integrated_helpers.ProviderUsageBaseTestCase):
2495 2495
             new_flavor=new_flavor, source_rp_uuid=source_rp_uuid,
2496 2496
             dest_rp_uuid=dest_rp_uuid)
2497 2497
 
2498
+    def test_migration_confirm_resize_error(self):
2499
+        source_hostname = self.compute1.host
2500
+        dest_hostname = self.compute2.host
2501
+
2502
+        source_rp_uuid = self._get_provider_uuid_by_host(source_hostname)
2503
+        dest_rp_uuid = self._get_provider_uuid_by_host(dest_hostname)
2504
+
2505
+        server = self._boot_and_check_allocations(self.flavor1,
2506
+                                                  source_hostname)
2507
+
2508
+        self._move_and_check_allocations(
2509
+            server, request={'migrate': None}, old_flavor=self.flavor1,
2510
+            new_flavor=self.flavor1, source_rp_uuid=source_rp_uuid,
2511
+            dest_rp_uuid=dest_rp_uuid)
2512
+
2513
+        # Mock failure
2514
+        def fake_confirm_migration(context, migration, instance, network_info):
2515
+            raise exception.MigrationPreCheckError(
2516
+                reason='test_migration_confirm_resize_error')
2517
+
2518
+        with mock.patch('nova.virt.fake.FakeDriver.'
2519
+                        'confirm_migration',
2520
+                        side_effect=fake_confirm_migration):
2521
+
2522
+            # Confirm the migration/resize and check the usages
2523
+            post = {'confirmResize': None}
2524
+            self.api.post_server_action(
2525
+                server['id'], post, check_response_status=[204])
2526
+            server = self._wait_for_state_change(self.api, server, 'ERROR')
2527
+
2528
+        # After confirming and error, we should have an allocation only on the
2529
+        # destination host
2530
+
2531
+        self.assertFlavorMatchesUsage(dest_rp_uuid, self.flavor1)
2532
+        self.assertRequestMatchesUsage({'VCPU': 0,
2533
+                                        'MEMORY_MB': 0,
2534
+                                        'DISK_GB': 0}, source_rp_uuid)
2535
+        self.assertFlavorMatchesAllocation(self.flavor1, server['id'],
2536
+                                           dest_rp_uuid)
2537
+
2538
+        self._run_periodics()
2539
+
2540
+        # Check we're still accurate after running the periodics
2541
+
2542
+        self.assertFlavorMatchesUsage(dest_rp_uuid, self.flavor1)
2543
+        self.assertRequestMatchesUsage({'VCPU': 0,
2544
+                                        'MEMORY_MB': 0,
2545
+                                        'DISK_GB': 0}, source_rp_uuid)
2546
+        self.assertFlavorMatchesAllocation(self.flavor1, server['id'],
2547
+                                           dest_rp_uuid)
2548
+
2549
+        self._delete_and_check_allocations(server)
2550
+
2498 2551
     def _test_resize_revert(self, dest_hostname):
2499 2552
         source_hostname = self._other_hostname(dest_hostname)
2500 2553
         source_rp_uuid = self._get_provider_uuid_by_host(source_hostname)

Loading…
Cancel
Save