Browse Source

Merge "Fix the race in confirm resize func test"

changes/38/676138/17
Zuul 1 week ago
parent
commit
696476f4ac
2 changed files with 37 additions and 40 deletions
  1. 29
    14
      nova/tests/functional/integrated_helpers.py
  2. 8
    26
      nova/tests/functional/test_servers.py

+ 29
- 14
nova/tests/functional/integrated_helpers.py View File

@@ -27,6 +27,7 @@ import os_traits
27 27
 from oslo_log import log as logging
28 28
 from oslo_utils.fixture import uuidsentinel as uuids
29 29
 
30
+from nova.compute import instance_actions
30 31
 from nova.compute import utils as compute_utils
31 32
 import nova.conf
32 33
 from nova import context
@@ -309,12 +310,21 @@ class InstanceHelperMixin(object):
309 310
         """
310 311
         if api is None:
311 312
             api = self.api
312
-        completion_event = None
313
+        return self._wait_for_instance_action_event(
314
+            api, server, expected_action, event_name, event_result='error')
315
+
316
+    def _wait_for_instance_action_event(
317
+            self, api, server, action_name, event_name, event_result):
318
+        """Polls the instance action events for the given instance, action,
319
+        event, and event result until it finds the event.
320
+        """
321
+        actions = []
322
+        events = []
313 323
         for attempt in range(10):
314 324
             actions = api.get_instance_actions(server['id'])
315
-            # Look for the migrate action.
325
+            # The API returns the newest event first
316 326
             for action in actions:
317
-                if action['action'] == expected_action:
327
+                if action['action'] == action_name:
318 328
                     events = (
319 329
                         api.api_get(
320 330
                             '/servers/%s/os-instance-actions/%s' %
@@ -322,21 +332,18 @@ class InstanceHelperMixin(object):
322 332
                         ).body['instanceAction']['events'])
323 333
                     # Look for the action event being in error state.
324 334
                     for event in events:
335
+                        result = event['result']
325 336
                         if (event['event'] == event_name and
326
-                                event['result'] is not None and
327
-                                event['result'].lower() == 'error'):
328
-                            completion_event = event
329
-                            # Break out of the events loop.
330
-                            break
331
-                    if completion_event:
332
-                        # Break out of the actions loop.
333
-                        break
337
+                                result is not None and
338
+                                result.lower() == event_result.lower()):
339
+                            return event
334 340
             # We didn't find the completion event yet, so wait a bit.
335 341
             time.sleep(0.5)
336 342
 
337
-        if completion_event is None:
338
-            self.fail('Timed out waiting for %s failure event. Current '
339
-                      'instance actions: %s' % (event_name, actions))
343
+        self.fail(
344
+            'Timed out waiting for %s instance action event. Current instance '
345
+            'actions: %s. Events in the last matching action: %s'
346
+            % (event_name, actions, events))
340 347
 
341 348
     def _wait_for_migration_status(self, server, expected_statuses):
342 349
         """Waits for a migration record with the given statuses to be found
@@ -912,3 +919,11 @@ class ProviderUsageBaseTestCase(test.TestCase, InstanceHelperMixin):
912 919
         # Account for reserved_host_cpus.
913 920
         expected_vcpu_usage = CONF.reserved_host_cpus + flavor['vcpus']
914 921
         self.assertEqual(expected_vcpu_usage, hypervisor['vcpus_used'])
922
+
923
+    def _confirm_resize(self, server):
924
+        self.api.post_server_action(server['id'], {'confirmResize': None})
925
+        server = self._wait_for_state_change(self.api, server, 'ACTIVE')
926
+        self._wait_for_instance_action_event(
927
+            self.api, server, instance_actions.CONFIRM_RESIZE,
928
+            'compute_confirm_resize', 'success')
929
+        return server

+ 8
- 26
nova/tests/functional/test_servers.py View File

@@ -1811,10 +1811,7 @@ class ServerMovingTests(integrated_helpers.ProviderUsageBaseTestCase):
1811 1811
             source_rp_uuid, dest_rp_uuid)
1812 1812
 
1813 1813
         # Confirm the resize and check the usages
1814
-        post = {'confirmResize': None}
1815
-        self.api.post_server_action(
1816
-            server['id'], post, check_response_status=[204])
1817
-        self._wait_for_state_change(self.api, server, 'ACTIVE')
1814
+        self._confirm_resize(server)
1818 1815
 
1819 1816
         # After confirming, we should have an allocation only on the
1820 1817
         # destination host
@@ -1889,10 +1886,7 @@ class ServerMovingTests(integrated_helpers.ProviderUsageBaseTestCase):
1889 1886
             server, self.flavor2, self.flavor3, rp_uuid)
1890 1887
 
1891 1888
         # Confirm the resize and check the usages
1892
-        post = {'confirmResize': None}
1893
-        self.api.post_server_action(
1894
-            server['id'], post, check_response_status=[204])
1895
-        self._wait_for_state_change(self.api, server, 'ACTIVE')
1889
+        self._confirm_resize(server)
1896 1890
 
1897 1891
         self._run_periodics()
1898 1892
 
@@ -2020,8 +2014,7 @@ class ServerMovingTests(integrated_helpers.ProviderUsageBaseTestCase):
2020 2014
             dest_rp_uuid, self.flavor2, volume_backed=False)
2021 2015
 
2022 2016
         # Now confirm the resize and check hypervisor usage again.
2023
-        self.api.post_server_action(server['id'], {'confirmResize': None})
2024
-        self._wait_for_state_change(self.api, server, 'ACTIVE')
2017
+        self._confirm_resize(server)
2025 2018
 
2026 2019
         # There should no resource usage for flavor1 on the source host.
2027 2020
         self.assert_hypervisor_usage(
@@ -3125,11 +3118,7 @@ class ServerMovingTests(integrated_helpers.ProviderUsageBaseTestCase):
3125 3118
         self._wait_for_state_change(self.api, created_server, 'VERIFY_RESIZE')
3126 3119
 
3127 3120
         # Confirm the resize
3128
-        post = {'confirmResize': None}
3129
-        self.api.post_server_action(
3130
-            created_server['id'], post, check_response_status=[204])
3131
-        new_server = self._wait_for_state_change(self.api, created_server,
3132
-                                                 'ACTIVE')
3121
+        new_server = self._confirm_resize(created_server)
3133 3122
         inst_dest_host = new_server["OS-EXT-SRV-ATTR:host"]
3134 3123
 
3135 3124
         self.assertEqual(dest_hostname, inst_dest_host)
@@ -3300,10 +3289,7 @@ class ServerMovingTests(integrated_helpers.ProviderUsageBaseTestCase):
3300 3289
             server, self.flavor1, source_rp_uuid, dest_rp_uuid)
3301 3290
 
3302 3291
         # Confirm the move and check the usages
3303
-        post = {'confirmResize': None}
3304
-        self.api.post_server_action(
3305
-            server['id'], post, check_response_status=[204])
3306
-        self._wait_for_state_change(self.api, server, 'ACTIVE')
3292
+        self._confirm_resize(server)
3307 3293
 
3308 3294
         def _check_allocation():
3309 3295
             # the target host usage should be according to the flavor
@@ -3951,8 +3937,7 @@ class VolumeBackedServerTest(integrated_helpers.ProviderUsageBaseTestCase):
3951 3937
             self.admin_api, server, 'VERIFY_RESIZE')
3952 3938
         self.assertEqual('host2', server['OS-EXT-SRV-ATTR:host'])
3953 3939
         # Confirm the cold migration and check usage and the request spec.
3954
-        self.api.post_server_action(server['id'], {'confirmResize': None})
3955
-        self._wait_for_state_change(self.api, server, 'ACTIVE')
3940
+        self._confirm_resize(server)
3956 3941
         reqspec = objects.RequestSpec.get_by_instance_uuid(ctxt, server['id'])
3957 3942
         # Make sure it's set.
3958 3943
         self.assertTrue(reqspec.is_bfv)
@@ -6552,9 +6537,7 @@ class ServerMoveWithPortResourceRequestTest(
6552 6537
             server, compute3_rp_uuid, non_qos_port, qos_port,
6553 6538
             migration_uuid, source_compute_rp_uuid=self.compute1_rp_uuid)
6554 6539
 
6555
-        self.api.post_server_action(server['id'], {'confirmResize': None})
6556
-        self._wait_for_migration_status(server, ['confirmed'])
6557
-
6540
+        self._confirm_resize(server)
6558 6541
         # check that allocation is still OK
6559 6542
         self._check_allocation(
6560 6543
             server, compute3_rp_uuid, non_qos_port, qos_port)
@@ -6585,8 +6568,7 @@ class ServerMoveWithPortResourceRequestTest(
6585 6568
             server, self.compute2_rp_uuid, non_qos_port, qos_port,
6586 6569
             migration_uuid, source_compute_rp_uuid=self.compute1_rp_uuid)
6587 6570
 
6588
-        self.api.post_server_action(server['id'], {'confirmResize': None})
6589
-        self._wait_for_migration_status(server, ['confirmed'])
6571
+        self._confirm_resize(server)
6590 6572
 
6591 6573
         # check that allocation is still OK
6592 6574
         self._check_allocation(

Loading…
Cancel
Save