From d1b03bf268303d05f1067239fd3f7e87498fe091 Mon Sep 17 00:00:00 2001 From: Eric Harney Date: Tue, 10 Mar 2015 16:34:16 -0400 Subject: [PATCH] Tests: Harden fake_notifier asserts This is a continuation of 8740e063 - Make test_create_delete_snapshot more robust The same issue cropped up for me in test_create_consistencygroup_from_src(). Add some more specific asserts to try to reveal what is going wrong here. The idea is to assert more specific things (examining individual notifications) before more general asserts (count of notifications) when possible, to fail the test on the check that will provide the most information back. Related-Bug: #1412513 Change-Id: I267bd5933247f69f220a7be871a63e4db9eb9a80 --- cinder/tests/test_volume.py | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/cinder/tests/test_volume.py b/cinder/tests/test_volume.py index 383790018..1cd47b14e 100644 --- a/cinder/tests/test_volume.py +++ b/cinder/tests/test_volume.py @@ -3804,7 +3804,7 @@ class VolumeTestCase(BaseVolumeTestCase): 'consistencygroup_id': group2_id } self.assertEqual('available', cg2['status']) - self.assertEqual(6, len(fake_notifier.NOTIFICATIONS)) + msg = fake_notifier.NOTIFICATIONS[2] self.assertEqual('consistencygroup.create.start', msg['event_type']) self.assertDictMatch(expected, msg['payload']) @@ -3812,8 +3812,16 @@ class VolumeTestCase(BaseVolumeTestCase): self.assertEqual('consistencygroup.create.end', msg['event_type']) self.assertDictMatch(expected, msg['payload']) + if len(fake_notifier.NOTIFICATIONS) > 6: + self.assertFalse(fake_notifier.NOTIFICATIONS[6]) + self.assertEqual(6, len(fake_notifier.NOTIFICATIONS)) + self.volume.delete_consistencygroup(self.context, group2_id) + + if len(fake_notifier.NOTIFICATIONS) > 10: + self.assertFalse(fake_notifier.NOTIFICATIONS[10]) self.assertEqual(len(fake_notifier.NOTIFICATIONS), 10) + msg = fake_notifier.NOTIFICATIONS[6] self.assertEqual(msg['event_type'], 'consistencygroup.delete.start') expected['status'] = 'available' @@ -3890,14 +3898,21 @@ class VolumeTestCase(BaseVolumeTestCase): self.context, consistencygroup_id=group_id) cgsnapshot_id = cgsnapshot['id'] + + if len(fake_notifier.NOTIFICATIONS) > 2: + self.assertFalse(fake_notifier.NOTIFICATIONS[2]) self.assertEqual(len(fake_notifier.NOTIFICATIONS), 2) + cgsnapshot_returns = self._create_cgsnapshot(group_id, volume_id) cgsnapshot_id = cgsnapshot_returns[0]['id'] self.volume.create_cgsnapshot(self.context, group_id, cgsnapshot_id) self.assertEqual(cgsnapshot_id, db.cgsnapshot_get(context.get_admin_context(), cgsnapshot_id).id) - self.assertEqual(len(fake_notifier.NOTIFICATIONS), 6) + + if len(fake_notifier.NOTIFICATIONS) > 6: + self.assertFalse(fake_notifier.NOTIFICATIONS[6]) + msg = fake_notifier.NOTIFICATIONS[2] self.assertEqual(msg['event_type'], 'cgsnapshot.create.start') expected = { @@ -3918,8 +3933,13 @@ class VolumeTestCase(BaseVolumeTestCase): msg = fake_notifier.NOTIFICATIONS[5] self.assertEqual(msg['event_type'], 'snapshot.create.end') + self.assertEqual(len(fake_notifier.NOTIFICATIONS), 6) + self.volume.delete_cgsnapshot(self.context, cgsnapshot_id) - self.assertEqual(len(fake_notifier.NOTIFICATIONS), 10) + + if len(fake_notifier.NOTIFICATIONS) > 10: + self.assertFalse(fake_notifier.NOTIFICATIONS[10]) + msg = fake_notifier.NOTIFICATIONS[6] self.assertEqual(msg['event_type'], 'cgsnapshot.delete.start') expected['status'] = 'available' @@ -3928,6 +3948,8 @@ class VolumeTestCase(BaseVolumeTestCase): self.assertEqual(msg['event_type'], 'cgsnapshot.delete.end') self.assertDictMatch(msg['payload'], expected) + self.assertEqual(len(fake_notifier.NOTIFICATIONS), 10) + cgsnap = db.cgsnapshot_get( context.get_admin_context(read_deleted='yes'), cgsnapshot_id) -- 2.45.2