]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Make test_create_delete_snapshot more robust
authorEric Harney <eharney@redhat.com>
Mon, 19 Jan 2015 19:01:45 +0000 (14:01 -0500)
committerEric Harney <eharney@redhat.com>
Mon, 19 Jan 2015 19:11:55 +0000 (14:11 -0500)
This patch does two things to improve this test, and
help debug issues with it failing.

- Add additional checks for contents of the first two
  expected notifications.
- Assert the length of the notifications list after checking
  its contents so that if it contains unexpected items, we can
  see what they are.  This should help with the current gate
  failures.

Change-Id: Ib92247389fb3be6d65a658880fd47e634f1da8d1
Related-Bug: #1412513

cinder/tests/test_volume.py

index 61b8830dea437708c1cc7365e8d784a117e3329e..ad32e6803fea77f2eec9370dbbec828a2435026d 100644 (file)
@@ -1760,13 +1760,24 @@ class VolumeTestCase(BaseVolumeTestCase):
             **self.volume_params)
         self.assertEqual(len(fake_notifier.NOTIFICATIONS), 0)
         self.volume.create_volume(self.context, volume['id'])
+        msg = fake_notifier.NOTIFICATIONS[0]
+        self.assertEqual(msg['event_type'], 'volume.create.start')
+        self.assertEqual(msg['payload']['status'], 'creating')
+        self.assertEqual(msg['priority'], 'INFO')
+        msg = fake_notifier.NOTIFICATIONS[1]
+        self.assertEqual(msg['event_type'], 'volume.create.end')
+        self.assertEqual(msg['payload']['status'], 'available')
+        self.assertEqual(msg['priority'], 'INFO')
+        if len(fake_notifier.NOTIFICATIONS) > 2:
+            # Cause an assert to print the unexpected item
+            self.assertFalse(fake_notifier.NOTIFICATIONS[2])
         self.assertEqual(len(fake_notifier.NOTIFICATIONS), 2)
+
         snapshot_id = self._create_snapshot(volume['id'])['id']
         self.volume.create_snapshot(self.context, volume['id'], snapshot_id)
         self.assertEqual(snapshot_id,
                          db.snapshot_get(context.get_admin_context(),
                                          snapshot_id).id)
-        self.assertEqual(len(fake_notifier.NOTIFICATIONS), 4)
         msg = fake_notifier.NOTIFICATIONS[2]
         self.assertEqual(msg['event_type'], 'snapshot.create.start')
         expected = {
@@ -1787,8 +1798,13 @@ class VolumeTestCase(BaseVolumeTestCase):
         expected['status'] = 'available'
         self.assertDictMatch(msg['payload'], expected)
 
+        if len(fake_notifier.NOTIFICATIONS) > 4:
+            # Cause an assert to print the unexpected item
+            self.assertFalse(fake_notifier.NOTIFICATIONS[4])
+
+        self.assertEqual(len(fake_notifier.NOTIFICATIONS), 4)
+
         self.volume.delete_snapshot(self.context, snapshot_id)
-        self.assertEqual(len(fake_notifier.NOTIFICATIONS), 6)
         msg = fake_notifier.NOTIFICATIONS[4]
         self.assertEqual(msg['event_type'], 'snapshot.delete.start')
         expected['status'] = 'available'
@@ -1797,6 +1813,12 @@ class VolumeTestCase(BaseVolumeTestCase):
         self.assertEqual(msg['event_type'], 'snapshot.delete.end')
         self.assertDictMatch(msg['payload'], expected)
 
+        if len(fake_notifier.NOTIFICATIONS) > 6:
+            # Cause an assert to print the unexpected item
+            self.assertFalse(fake_notifier.NOTIFICATIONS[6])
+
+        self.assertEqual(len(fake_notifier.NOTIFICATIONS), 6)
+
         snap = db.snapshot_get(context.get_admin_context(read_deleted='yes'),
                                snapshot_id)
         self.assertEqual(snap['status'], 'deleted')