Browse Source

fix unshelve notification test instability

The unshelve notification sample test shelve-offloads an instance, waits for
it state to change to SHELVED_OFFLOADED then unshelve the instance and matches
generated the unshelve notification with the stored sample. This test
intermittently fails as the host paramter of the instance doesn't match
sometimes. The reason is that the compute manager during shelve offloading
first sets the state of the instance then later sets the host of the instance.
So the test can start unshelving the instance before the host is cleaned by
the shelve offload code.

The test is updated to not just wait for the state change but also wait for
the change of the host attribute.

Change-Id: I459332de407187724fd2962effb7f3a34751f505
Closes-Bug: #1704423
tags/16.0.0.0b3
Balazs Gibizer 1 year ago
parent
commit
da57d17e6c

+ 11
- 5
nova/tests/functional/integrated_helpers.py View File

@@ -218,22 +218,28 @@ class _IntegratedTestBase(test.TestCase):
218 218
 
219 219
 
220 220
 class InstanceHelperMixin(object):
221
-    def _wait_for_state_change(self, admin_api, server, expected_status,
222
-                               max_retries=10):
221
+    def _wait_for_server_parameter(self, admin_api, server, expected_params,
222
+                                   max_retries=10):
223 223
         retry_count = 0
224 224
         while True:
225 225
             server = admin_api.get_server(server['id'])
226
-            if server['status'] == expected_status:
226
+            if all([server[attr] == expected_params[attr]
227
+                    for attr in expected_params]):
227 228
                 break
228 229
             retry_count += 1
229 230
             if retry_count == max_retries:
230 231
                 self.fail('Wait for state change failed, '
231
-                          'expected_status=%s, actual_status=%s'
232
-                          % (expected_status, server['status']))
232
+                          'expected_params=%s, server=%s'
233
+                          % (expected_params, server))
233 234
             time.sleep(0.5)
234 235
 
235 236
         return server
236 237
 
238
+    def _wait_for_state_change(self, admin_api, server, expected_status,
239
+                               max_retries=10):
240
+        return self._wait_for_server_parameter(
241
+            admin_api, server, {'status': expected_status}, max_retries)
242
+
237 243
     def _build_minimal_create_server_request(self, api, name, image_uuid=None,
238 244
                                              flavor_id=None, networks=None):
239 245
         server = {}

+ 14
- 4
nova/tests/functional/notification_sample_tests/test_instance.py View File

@@ -456,8 +456,13 @@ class TestInstanceNotificationSample(
456 456
         self._wait_for_state_change(self.api, server,
457 457
                                     expected_status='SHELVED')
458 458
         self.api.post_server_action(server['id'], {'shelveOffload': {}})
459
-        self._wait_for_state_change(self.api, server,
460
-                                    expected_status='SHELVED_OFFLOADED')
459
+        # we need to wait for the instance.host to become None as well before
460
+        # we can unshelve to make sure that the unshelve.start notification
461
+        # payload is stable as the compute manager first sets the instance
462
+        # state then a bit later sets the instance.host to None.
463
+        self._wait_for_server_parameter(self.api, server,
464
+                                        {'status': 'SHELVED_OFFLOADED',
465
+                                         'OS-EXT-SRV-ATTR:host': None})
461 466
 
462 467
         self.assertEqual(4, len(fake_notifier.VERSIONED_NOTIFICATIONS))
463 468
         self._verify_notification(
@@ -493,8 +498,13 @@ class TestInstanceNotificationSample(
493 498
         # instance status to 'SHELVED_OFFLOADED'
494 499
         self.flags(shelved_offload_time = 0)
495 500
         self.api.post_server_action(server['id'], {'shelve': {}})
496
-        self._wait_for_state_change(self.api, server,
497
-                                    expected_status='SHELVED_OFFLOADED')
501
+        # we need to wait for the instance.host to become None as well before
502
+        # we can unshelve to make sure that the unshelve.start notification
503
+        # payload is stable as the compute manager first sets the instance
504
+        # state then a bit later sets the instance.host to None.
505
+        self._wait_for_server_parameter(self.api, server,
506
+                                        {'status': 'SHELVED_OFFLOADED',
507
+                                         'OS-EXT-SRV-ATTR:host': None})
498 508
 
499 509
         post = {'unshelve': None}
500 510
         self.api.post_server_action(server['id'], post)

Loading…
Cancel
Save