]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Add snapshot events to the cinder notification
authorMichael Kerrin <michael.kerrin@hp.com>
Thu, 28 Mar 2013 13:05:01 +0000 (13:05 +0000)
committerMichael Kerrin <michael.kerrin@hp.com>
Thu, 28 Mar 2013 13:30:38 +0000 (13:30 +0000)
Added and tested snapshot.create.start & snapshot.create.end
on creation of a new snapshot

Added and tested snapshot.delete.start & snapshot.delete.end
on the deletion of a snapshot

Change-Id: Ic3c1cc8949109149c59cf106a24b4eb0d8ba5580

cinder/tests/test_volume.py
cinder/volume/manager.py

index 91474f1ce8b5df49503b7650613bb63b9c6c8f35..1661758fd64eb3fa82e8d183fbfc553e32d8792a 100644 (file)
@@ -350,14 +350,75 @@ class VolumeTestCase(test.TestCase):
     def test_create_delete_snapshot(self):
         """Test snapshot can be created and deleted."""
         volume = self._create_volume()
+        self.assertEquals(len(test_notifier.NOTIFICATIONS), 0)
         self.volume.create_volume(self.context, volume['id'])
+        self.assertEquals(len(test_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.assertEquals(len(test_notifier.NOTIFICATIONS), 4)
+        msg = test_notifier.NOTIFICATIONS[2]
+        self.assertEquals(msg['event_type'], 'snapshot.create.start')
+        expected = {
+            'created_at': 'DONTCARE',
+            'deleted': '',
+            'display_name': None,
+            'snapshot_id': snapshot_id,
+            'status': 'creating',
+            'tenant_id': 'fake',
+            'user_id': 'fake',
+            'volume_id': volume['id'],
+            'volume_size': 0
+        }
+        self.assertDictMatch(msg['payload'], expected)
+        msg = test_notifier.NOTIFICATIONS[3]
+        self.assertEquals(msg['event_type'], 'snapshot.create.end')
+        expected = {
+            'created_at': 'DONTCARE',
+            'deleted': '',
+            'display_name': None,
+            'snapshot_id': snapshot_id,
+            'status': 'creating',
+            'tenant_id': 'fake',
+            'user_id': 'fake',
+            'volume_id': volume['id'],
+            'volume_size': 0
+        }
+        self.assertDictMatch(msg['payload'], expected)
 
         self.volume.delete_snapshot(self.context, snapshot_id)
+        self.assertEquals(len(test_notifier.NOTIFICATIONS), 6)
+        msg = test_notifier.NOTIFICATIONS[4]
+        self.assertEquals(msg['event_type'], 'snapshot.delete.start')
+        expected = {
+            'created_at': 'DONTCARE',
+            'deleted': '',
+            'display_name': None,
+            'snapshot_id': snapshot_id,
+            'status': 'available',
+            'tenant_id': 'fake',
+            'user_id': 'fake',
+            'volume_id': volume['id'],
+            'volume_size': 0
+        }
+        self.assertDictMatch(msg['payload'], expected)
+        msg = test_notifier.NOTIFICATIONS[5]
+        self.assertEquals(msg['event_type'], 'snapshot.delete.end')
+        expected = {
+            'created_at': 'DONTCARE',
+            'deleted': '',
+            'display_name': None,
+            'snapshot_id': snapshot_id,
+            'status': 'available',
+            'tenant_id': 'fake',
+            'user_id': 'fake',
+            'volume_id': volume['id'],
+            'volume_size': 0
+        }
+        self.assertDictMatch(msg['payload'], expected)
+
         snap = db.snapshot_get(context.get_admin_context(read_deleted='yes'),
                                snapshot_id)
         self.assertEquals(snap['status'], 'deleted')
index 9c2402d7381b3d69750e9ed4ee03ea43f621f15d..8a90b0c2567900aa02aa2b6e45171076ca312481 100644 (file)
@@ -452,6 +452,8 @@ class VolumeManager(manager.SchedulerDependentManager):
         context = context.elevated()
         snapshot_ref = self.db.snapshot_get(context, snapshot_id)
         LOG.info(_("snapshot %s: creating"), snapshot_ref['name'])
+        self._notify_about_snapshot_usage(
+            context, snapshot_ref, "create.start")
 
         try:
             snap_name = snapshot_ref['name']
@@ -474,6 +476,7 @@ class VolumeManager(manager.SchedulerDependentManager):
                                                         snapshot_ref['id'],
                                                         volume_id)
         LOG.info(_("snapshot %s: created successfully"), snapshot_ref['name'])
+        self._notify_about_snapshot_usage(context, snapshot_ref, "create.end")
         return snapshot_id
 
     def delete_snapshot(self, context, snapshot_id):
@@ -481,6 +484,8 @@ class VolumeManager(manager.SchedulerDependentManager):
         context = context.elevated()
         snapshot_ref = self.db.snapshot_get(context, snapshot_id)
         LOG.info(_("snapshot %s: deleting"), snapshot_ref['name'])
+        self._notify_about_snapshot_usage(
+            context, snapshot_ref, "delete.start")
 
         if context.project_id != snapshot_ref['project_id']:
             project_id = snapshot_ref['project_id']
@@ -520,6 +525,7 @@ class VolumeManager(manager.SchedulerDependentManager):
         self.db.volume_glance_metadata_delete_by_snapshot(context, snapshot_id)
         self.db.snapshot_destroy(context, snapshot_id)
         LOG.info(_("snapshot %s: deleted successfully"), snapshot_ref['name'])
+        self._notify_about_snapshot_usage(context, snapshot_ref, "delete.end")
 
         # Commit the reservations
         if reservations:
@@ -702,3 +708,12 @@ class VolumeManager(manager.SchedulerDependentManager):
         volume_utils.notify_about_volume_usage(
             context, volume, event_suffix,
             extra_usage_info=extra_usage_info, host=self.host)
+
+    def _notify_about_snapshot_usage(self,
+                                     context,
+                                     snapshot,
+                                     event_suffix,
+                                     extra_usage_info=None):
+        volume_utils.notify_about_snapshot_usage(
+            context, snapshot, event_suffix,
+            extra_usage_info=extra_usage_info, host=self.host)