]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Display NOTIFICATIONS on assert failure
authorGorka Eguileor <geguileo@redhat.com>
Tue, 26 May 2015 14:39:28 +0000 (16:39 +0200)
committerGorka Eguileor <geguileo@redhat.com>
Tue, 26 May 2015 14:48:30 +0000 (16:48 +0200)
From time to time we have itermitent errors regarding the
fake_notifier.NOTIFICATIONS count.

This patch does two things to try to find out which notifications are
being fired unexpectedly:
- Make sure that fake_notifier is reset in cleanup regardless of
  exception raised by shutil.rmtree
- Display fake_notifier.NOTIFICATIONS whenever count assertion fails.

Related-Bug: #1412513
Change-Id: I07370636d8b30098dcb2a70ef1985c2f5aee81be

cinder/tests/unit/test_volume.py

index 14080e75537a984268fc8c9dc15e65fbf5e284c1..93a4ba151ead0857355483954c4304998437cd8a 100644 (file)
@@ -134,11 +134,11 @@ class BaseVolumeTestCase(test.TestCase):
         self.called = []
 
     def _cleanup(self):
+        fake_notifier.reset()
         try:
             shutil.rmtree(CONF.volumes_dir)
         except OSError:
             pass
-        fake_notifier.reset()
 
     def fake_get_target(obj, iqn):
         return 1
@@ -392,7 +392,8 @@ class VolumeTestCase(BaseVolumeTestCase):
 
         volume_id = volume['id']
         self.assertIsNone(volume['encryption_key_id'])
-        self.assertEqual(0, len(fake_notifier.NOTIFICATIONS))
+        self.assertEqual(0, len(fake_notifier.NOTIFICATIONS),
+                         fake_notifier.NOTIFICATIONS)
         self.assertRaises(exception.DriverNotInitialized,
                           self.volume.create_volume,
                           self.context, volume_id)
@@ -469,7 +470,8 @@ class VolumeTestCase(BaseVolumeTestCase):
 
         volume_id = volume['id']
         self.assertIsNone(volume['encryption_key_id'])
-        self.assertEqual(0, len(fake_notifier.NOTIFICATIONS))
+        self.assertEqual(0, len(fake_notifier.NOTIFICATIONS),
+                         fake_notifier.NOTIFICATIONS)
         self.assertRaises(exception.DriverNotInitialized,
                           self.volume.delete_volume,
                           self.context, volume_id)
@@ -500,9 +502,11 @@ class VolumeTestCase(BaseVolumeTestCase):
             **self.volume_params)
         volume_id = volume['id']
         self.assertIsNone(volume['encryption_key_id'])
-        self.assertEqual(0, len(fake_notifier.NOTIFICATIONS))
+        self.assertEqual(0, len(fake_notifier.NOTIFICATIONS),
+                         fake_notifier.NOTIFICATIONS)
         self.volume.create_volume(self.context, volume_id)
-        self.assertEqual(2, len(fake_notifier.NOTIFICATIONS))
+        self.assertEqual(2, len(fake_notifier.NOTIFICATIONS),
+                         fake_notifier.NOTIFICATIONS)
         msg = fake_notifier.NOTIFICATIONS[0]
         self.assertEqual('volume.create.start', msg['event_type'])
         expected = {
@@ -534,7 +538,8 @@ class VolumeTestCase(BaseVolumeTestCase):
         vol = db.volume_get(context.get_admin_context(read_deleted='yes'),
                             volume_id)
         self.assertEqual('deleted', vol['status'])
-        self.assertEqual(4, len(fake_notifier.NOTIFICATIONS))
+        self.assertEqual(4, len(fake_notifier.NOTIFICATIONS),
+                         fake_notifier.NOTIFICATIONS)
         msg = fake_notifier.NOTIFICATIONS[2]
         self.assertEqual('volume.delete.start', msg['event_type'])
         self.assertDictMatch(expected, msg['payload'])
@@ -2782,7 +2787,8 @@ class VolumeTestCase(BaseVolumeTestCase):
             self.context,
             availability_zone=CONF.storage_availability_zone,
             **self.volume_params)
-        self.assertEqual(0, len(fake_notifier.NOTIFICATIONS))
+        self.assertEqual(0, len(fake_notifier.NOTIFICATIONS),
+                         fake_notifier.NOTIFICATIONS)
         self.volume.create_volume(self.context, volume['id'])
         msg = fake_notifier.NOTIFICATIONS[0]
         self.assertEqual('volume.create.start', msg['event_type'])
@@ -2795,7 +2801,8 @@ class VolumeTestCase(BaseVolumeTestCase):
         if len(fake_notifier.NOTIFICATIONS) > 2:
             # Cause an assert to print the unexpected item
             self.assertFalse(fake_notifier.NOTIFICATIONS[2])
-        self.assertEqual(2, len(fake_notifier.NOTIFICATIONS))
+        self.assertEqual(2, len(fake_notifier.NOTIFICATIONS),
+                         fake_notifier.NOTIFICATIONS)
 
         snapshot_id = self._create_snapshot(volume['id'],
                                             size=volume['size'])['id']
@@ -2828,7 +2835,8 @@ class VolumeTestCase(BaseVolumeTestCase):
             # Cause an assert to print the unexpected item
             self.assertFalse(fake_notifier.NOTIFICATIONS[4])
 
-        self.assertEqual(4, len(fake_notifier.NOTIFICATIONS))
+        self.assertEqual(4, len(fake_notifier.NOTIFICATIONS),
+                         fake_notifier.NOTIFICATIONS)
 
         self.volume.delete_snapshot(self.context, snapshot_obj)
         msg = fake_notifier.NOTIFICATIONS[4]
@@ -2843,7 +2851,8 @@ class VolumeTestCase(BaseVolumeTestCase):
             # Cause an assert to print the unexpected item
             self.assertFalse(fake_notifier.NOTIFICATIONS[6])
 
-        self.assertEqual(6, len(fake_notifier.NOTIFICATIONS))
+        self.assertEqual(6, len(fake_notifier.NOTIFICATIONS),
+                         fake_notifier.NOTIFICATIONS)
 
         snap = db.snapshot_get(context.get_admin_context(read_deleted='yes'),
                                snapshot_id)
@@ -4493,9 +4502,11 @@ class VolumeTestCase(BaseVolumeTestCase):
             availability_zone=CONF.storage_availability_zone,
             volume_type='type1,type2')
         group_id = group['id']
-        self.assertEqual(0, len(fake_notifier.NOTIFICATIONS))
+        self.assertEqual(0, len(fake_notifier.NOTIFICATIONS),
+                         fake_notifier.NOTIFICATIONS)
         self.volume.create_consistencygroup(self.context, group_id)
-        self.assertEqual(2, len(fake_notifier.NOTIFICATIONS))
+        self.assertEqual(2, len(fake_notifier.NOTIFICATIONS),
+                         fake_notifier.NOTIFICATIONS)
         msg = fake_notifier.NOTIFICATIONS[0]
         self.assertEqual('consistencygroup.create.start', msg['event_type'])
         expected = {
@@ -4522,7 +4533,8 @@ class VolumeTestCase(BaseVolumeTestCase):
             context.get_admin_context(read_deleted='yes'),
             group_id)
         self.assertEqual('deleted', cg['status'])
-        self.assertEqual(4, len(fake_notifier.NOTIFICATIONS))
+        self.assertEqual(4, len(fake_notifier.NOTIFICATIONS),
+                         fake_notifier.NOTIFICATIONS)
         msg = fake_notifier.NOTIFICATIONS[2]
         self.assertEqual('consistencygroup.delete.start', msg['event_type'])
         self.assertDictMatch(expected, msg['payload'])
@@ -4589,7 +4601,8 @@ class VolumeTestCase(BaseVolumeTestCase):
             'consistencygroup_id': group_id
         }
         self.assertEqual('available', cg['status'])
-        self.assertEqual(10, len(fake_notifier.NOTIFICATIONS))
+        self.assertEqual(10, len(fake_notifier.NOTIFICATIONS),
+                         fake_notifier.NOTIFICATIONS)
         msg = fake_notifier.NOTIFICATIONS[6]
         self.assertEqual('consistencygroup.update.start', msg['event_type'])
         self.assertDictMatch(expected, msg['payload'])
@@ -4697,13 +4710,15 @@ class VolumeTestCase(BaseVolumeTestCase):
 
         if len(fake_notifier.NOTIFICATIONS) > 6:
             self.assertFalse(fake_notifier.NOTIFICATIONS[6])
-        self.assertEqual(6, len(fake_notifier.NOTIFICATIONS))
+        self.assertEqual(6, len(fake_notifier.NOTIFICATIONS),
+                         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(10, len(fake_notifier.NOTIFICATIONS))
+        self.assertEqual(10, len(fake_notifier.NOTIFICATIONS),
+                         fake_notifier.NOTIFICATIONS)
 
         msg = fake_notifier.NOTIFICATIONS[6]
         self.assertEqual('consistencygroup.delete.start', msg['event_type'])
@@ -4829,7 +4844,8 @@ class VolumeTestCase(BaseVolumeTestCase):
 
         if len(fake_notifier.NOTIFICATIONS) > 2:
             self.assertFalse(fake_notifier.NOTIFICATIONS[2])
-        self.assertEqual(2, len(fake_notifier.NOTIFICATIONS))
+        self.assertEqual(2, len(fake_notifier.NOTIFICATIONS),
+                         fake_notifier.NOTIFICATIONS)
 
         cgsnapshot_returns = self._create_cgsnapshot(group_id, volume_id)
         cgsnapshot_id = cgsnapshot_returns[0]['id']
@@ -4861,7 +4877,8 @@ class VolumeTestCase(BaseVolumeTestCase):
         msg = fake_notifier.NOTIFICATIONS[5]
         self.assertEqual('snapshot.create.end', msg['event_type'])
 
-        self.assertEqual(6, len(fake_notifier.NOTIFICATIONS))
+        self.assertEqual(6, len(fake_notifier.NOTIFICATIONS),
+                         fake_notifier.NOTIFICATIONS)
 
         self.volume.delete_cgsnapshot(self.context, cgsnapshot_id)
 
@@ -4876,7 +4893,8 @@ class VolumeTestCase(BaseVolumeTestCase):
         self.assertEqual('cgsnapshot.delete.end', msg['event_type'])
         self.assertDictMatch(expected, msg['payload'])
 
-        self.assertEqual(10, len(fake_notifier.NOTIFICATIONS))
+        self.assertEqual(10, len(fake_notifier.NOTIFICATIONS),
+                         fake_notifier.NOTIFICATIONS)
 
         cgsnap = db.cgsnapshot_get(
             context.get_admin_context(read_deleted='yes'),