From 1a4c2e82f168634d1574abf7b29d6185bc7a3f30 Mon Sep 17 00:00:00 2001
From: Lena Novokshonova <enovokshonova@mirantis.com>
Date: Mon, 26 Jan 2015 12:51:02 +0400
Subject: [PATCH] Add notifications about snapshot.update.*

Now we have notifications about volume.update.*, but don't have
notifications about snapshot.update.*
In this patchset added this notifications.

Change-Id: Idc17516436b06871421c17cde0e2128f81613716
---
 cinder/api/v2/snapshots.py                 | 5 +++++
 cinder/tests/unit/api/v2/test_snapshots.py | 8 ++++++--
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/cinder/api/v2/snapshots.py b/cinder/api/v2/snapshots.py
index d3976629d..45c7ac471 100644
--- a/cinder/api/v2/snapshots.py
+++ b/cinder/api/v2/snapshots.py
@@ -27,6 +27,7 @@ from cinder import exception
 from cinder.i18n import _, _LI
 from cinder import utils
 from cinder import volume
+from cinder.volume import utils as volume_utils
 
 
 LOG = logging.getLogger(__name__)
@@ -261,6 +262,8 @@ class SnapshotsController(wsgi.Controller):
 
         try:
             snapshot = self.volume_api.get_snapshot(context, id)
+            volume_utils.notify_about_snapshot_usage(context, snapshot,
+                                                     'update.start')
             self.volume_api.update_snapshot(context, snapshot, update_dict)
         except exception.NotFound:
             msg = _("Snapshot could not be found")
@@ -268,6 +271,8 @@ class SnapshotsController(wsgi.Controller):
 
         snapshot.update(update_dict)
         req.cache_db_snapshot(snapshot)
+        volume_utils.notify_about_snapshot_usage(context, snapshot,
+                                                 'update.end')
 
         return {'snapshot': _translate_snapshot_detail_view(context, snapshot)}
 
diff --git a/cinder/tests/unit/api/v2/test_snapshots.py b/cinder/tests/unit/api/v2/test_snapshots.py
index 1a7e4f8d3..882b957a5 100644
--- a/cinder/tests/unit/api/v2/test_snapshots.py
+++ b/cinder/tests/unit/api/v2/test_snapshots.py
@@ -45,8 +45,12 @@ def _get_default_snapshot_param():
         'status': 'available',
         'volume_size': 100,
         'created_at': None,
+        'user_id': 'bcb7746c7a41472d88a1ffac89ba6a9b',
+        'project_id': '7ffe17a15c724e2aa79fc839540aec15',
         'display_name': 'Default name',
         'display_description': 'Default description',
+        'deleted': None,
+        'volume': {'availability_zone': 'test_zone'}
     }
 
 
@@ -201,6 +205,7 @@ class SnapshotApiTest(test.TestCase):
             }
         }
         self.assertEqual(expected, res_dict)
+        self.assertEqual(2, len(self.notifier.notifications))
 
     def test_snapshot_update_missing_body(self):
         body = {}
@@ -277,7 +282,6 @@ class SnapshotApiTest(test.TestCase):
         fake_volume_obj = fake_volume.fake_volume_obj(ctx)
         snapshot_get_by_id.return_value = snapshot_obj
         volume_get_by_id.return_value = fake_volume_obj
-
         req = fakes.HTTPRequest.blank('/v2/snapshots/%s' % UUID)
         resp_dict = self.controller.show(req, UUID)
 
@@ -359,7 +363,7 @@ class SnapshotApiTest(test.TestCase):
 
         # admin case
         list_snapshots_with_limit_and_offset(is_admin=True)
-        # non_admin case
+        # non-admin case
         list_snapshots_with_limit_and_offset(is_admin=False)
 
     @mock.patch('cinder.db.snapshot_metadata_get', return_value=dict())
-- 
2.45.2