]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Add notifications about snapshot.update.*
authorLena Novokshonova <enovokshonova@mirantis.com>
Mon, 26 Jan 2015 08:51:02 +0000 (12:51 +0400)
committerSean McGinnis <sean.mcginnis@gmail.com>
Sat, 27 Jun 2015 14:22:55 +0000 (09:22 -0500)
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
cinder/tests/unit/api/v2/test_snapshots.py

index d3976629d72299a9ee5b741096edc71e2d977143..45c7ac471ff975623aabbf12fef510947fd6e7c4 100644 (file)
@@ -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)}
 
index 1a7e4f8d38c21118cec9efbdf64a45b04b1be663..882b957a585b4699d232a092ba6519edae0f5440 100644 (file)
@@ -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())