From 2e32ed122b415009722456716c47d8374e9d449c Mon Sep 17 00:00:00 2001 From: Matt Riedemann Date: Wed, 23 Nov 2016 16:18:18 -0500 Subject: [PATCH] Fix race in test_volume_swap_server_with_error This functional test is waiting for a flag to be set in the CinderFixture which is called when swap_volume calls volume_api.unreserve_volume after the swap_volume error occurs. That happens after the two swap-volume notifications are sent (for start and error). The test was asserting a 5th notification for the generic instance fault, which happens, but might not happen before the CinderFixture flag is set and the test checks for 5 notifications. This test really only cares that there are the two swap-volume notifications, so to avoid a race this change just makes the test assert that there are at least 4 versioned notifications by the time the swap-volume error occurs, which is all it was checking after that anyway. Change-Id: I8fd44b083f109c034958a305a4e41f9d810c4389 Closes-Bug: #1639894 --- .../notification_sample_tests/test_instance.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/nova/tests/functional/notification_sample_tests/test_instance.py b/nova/tests/functional/notification_sample_tests/test_instance.py index f1f295e2e9..cc432e0082 100644 --- a/nova/tests/functional/notification_sample_tests/test_instance.py +++ b/nova/tests/functional/notification_sample_tests/test_instance.py @@ -561,13 +561,20 @@ class TestInstanceNotificationSample( self.cinder.SWAP_ERR_NEW_VOL) self._wait_until_swap_volume_error() - # Five versioned notifications are generated. + # Five versioned notifications are generated. We only rely on the + # first four because _wait_until_swap_volume_error will return True + # after volume_api.unreserve is called on the cinder fixture, and that + # happens before the instance fault is handled in the compute manager + # which generates the 5th notification (compute.exception). # 0. instance-create-start # 1. instance-create-start # 2. instance-volume_swap-start # 3. instance-volume_swap-error # 4. compute.exception - self.assertEqual(5, len(fake_notifier.VERSIONED_NOTIFICATIONS)) + self.assertTrue(len(fake_notifier.VERSIONED_NOTIFICATIONS) >= 4, + 'Unexpected number of versioned notifications. ' + 'Expected at least 4, got: %s' % + len(fake_notifier.VERSIONED_NOTIFICATIONS)) self._verify_notification( 'instance-volume_swap-start', replacements={