From 8740e0630938a88cd03c514ffe873613801f04b9 Mon Sep 17 00:00:00 2001 From: Eric Harney Date: Mon, 19 Jan 2015 14:01:45 -0500 Subject: [PATCH] Make test_create_delete_snapshot more robust 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 | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/cinder/tests/test_volume.py b/cinder/tests/test_volume.py index 61b8830de..ad32e6803 100644 --- a/cinder/tests/test_volume.py +++ b/cinder/tests/test_volume.py @@ -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') -- 2.45.2