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
changes/70/657870/3
Rodrigo Barbieri 4 months ago
parent
commit
873ac499c5
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

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

Loading…
Cancel
Save