]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Tests: Harden fake_notifier asserts
authorEric Harney <eharney@redhat.com>
Tue, 10 Mar 2015 20:34:16 +0000 (16:34 -0400)
committerEric Harney <eharney@redhat.com>
Wed, 11 Mar 2015 14:19:09 +0000 (14:19 +0000)
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

index 3837900187ac4a1d9f7c83ea38855188a0c41193..1cd47b14e2a1252f6fa1ca673118a5a380d58d8c 100644 (file)
@@ -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)