]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Add notifier events to cinder volume rename, reset-state
authorjenny-shieh <jenny.shieh@hp.com>
Wed, 22 Jan 2014 20:20:07 +0000 (12:20 -0800)
committerjenny-shieh <jenny.shieh@hp.com>
Thu, 23 Jan 2014 02:57:03 +0000 (18:57 -0800)
Implements: notifiers for cinder volume rename, reset-state
Fixes: bug #1271692
Change-Id: Ie82a4c062904a4f86c9f6364649b8c2b9f71ea6e

cinder/api/contrib/admin_actions.py
cinder/api/v1/volumes.py
cinder/api/v2/volumes.py
cinder/tests/api/contrib/test_scheduler_hints.py
cinder/tests/api/v1/test_volumes.py
cinder/tests/api/v2/stubs.py
cinder/tests/api/v2/test_volumes.py

index 800e7053df33c5074ee3832d163bc3c7a5fba5aa..2a4edc853e55c3dd84b7205f28250d81307e949c 100644 (file)
@@ -20,6 +20,7 @@ from cinder.api.openstack import wsgi
 from cinder import db
 from cinder import exception
 from cinder.openstack.common import log as logging
+from cinder.openstack.common.notifier import api as notifier_api
 from cinder.openstack.common import strutils
 from cinder import volume
 
@@ -81,10 +82,21 @@ class AdminController(wsgi.Controller):
         msg = _("Updating %(resource)s '%(id)s' with '%(update)r'")
         LOG.debug(msg, {'resource': self.resource_name, 'id': id,
                         'update': update})
+
+        notifier_info = dict(id=id, update=update)
+        notifier_api.notify(context, 'volumeStatusUpdate',
+                            self.collection + '.reset_status.start',
+                            notifier_api.INFO, notifier_info)
+
         try:
             self._update(context, id, update)
         except exception.NotFound as e:
             raise exc.HTTPNotFound(e)
+
+        notifier_api.notify(context, 'volumeStatusUpdate',
+                            self.collection + '.reset_status.end',
+                            notifier_api.INFO, notifier_info)
+
         return webob.Response(status_int=202)
 
     @wsgi.action('os-force_delete')
index 8364deb03fcec1c38296d176f0b403d729c60a26..708152196cbd9c418d91fa36d785968a0269c554 100644 (file)
@@ -27,6 +27,7 @@ from cinder.openstack.common import log as logging
 from cinder.openstack.common import uuidutils
 from cinder import utils
 from cinder import volume as cinder_volume
+from cinder.volume import utils as volume_utils
 from cinder.volume import volume_types
 
 
@@ -469,6 +470,8 @@ class VolumeController(wsgi.Controller):
 
         try:
             volume = self.volume_api.get(context, id)
+            volume_utils.notify_about_volume_usage(context, volume,
+                                                   'update.start')
             self.volume_api.update(context, volume, update_dict)
         except exception.NotFound:
             raise exc.HTTPNotFound()
@@ -477,6 +480,9 @@ class VolumeController(wsgi.Controller):
 
         self._add_visible_admin_metadata(context, volume)
 
+        volume_utils.notify_about_volume_usage(context, volume,
+                                               'update.end')
+
         return {'volume': _translate_volume_detail_view(context, volume)}
 
 
index 1267cd0b185ec0b28fec682457df9a4725ccacd3..72325cfc992d92abeae9097e51d9428e17248b6f 100644 (file)
@@ -29,6 +29,7 @@ from cinder.openstack.common import log as logging
 from cinder.openstack.common import uuidutils
 from cinder import utils
 from cinder import volume as cinder_volume
+from cinder.volume import utils as volume_utils
 from cinder.volume import volume_types
 
 
@@ -444,6 +445,8 @@ class VolumeController(wsgi.Controller):
 
         try:
             volume = self.volume_api.get(context, id)
+            volume_utils.notify_about_volume_usage(context, volume,
+                                                   'update.start')
             self.volume_api.update(context, volume, update_dict)
         except exception.NotFound:
             msg = _("Volume could not be found")
@@ -453,6 +456,9 @@ class VolumeController(wsgi.Controller):
 
         self._add_visible_admin_metadata(context, volume)
 
+        volume_utils.notify_about_volume_usage(context, volume,
+                                               'update.end')
+
         return self._view_builder.detail(req, volume)
 
 
index 5f8728ba9fe5680ebe23aeeb07e22ff5bd93b47d..ae5c17abc275a095c95e38b833d6aee4ebc5c5b2 100644 (file)
@@ -32,6 +32,8 @@ class SchedulerHintsTestCase(test.TestCase):
         self.fake_instance = stubs.stub_volume(1, uuid=UUID)
         self.fake_instance['created_at'] =\
             datetime.datetime(2013, 1, 1, 1, 1, 1)
+        self.fake_instance['launched_at'] =\
+            datetime.datetime(2013, 1, 1, 1, 1, 1)
         self.flags(
             osapi_volume_extension=[
                 'cinder.api.contrib.select_extensions'],
index 57c4d82b01b9d7a9c47c6f8a69b047753da98937..2bcf3ee233b7e2c8537be4e7471afae232bf7afd 100644 (file)
@@ -25,6 +25,8 @@ from cinder.api.v1 import volumes
 from cinder import context
 from cinder import db
 from cinder import exception
+from cinder.openstack.common.notifier import api as notifier_api
+from cinder.openstack.common.notifier import test_notifier
 from cinder import test
 from cinder.tests.api import fakes
 from cinder.tests.api.v2 import stubs
@@ -60,11 +62,19 @@ class VolumeApiTest(test.TestCase):
         fake_image.stub_out_image_service(self.stubs)
         self.controller = volumes.VolumeController(self.ext_mgr)
 
+        self.flags(host='fake',
+                   notification_driver=[test_notifier.__name__])
+        test_notifier.NOTIFICATIONS = []
+
         self.stubs.Set(db, 'volume_get_all', stubs.stub_volume_get_all)
         self.stubs.Set(db, 'service_get_all_by_topic',
                        stubs.stub_service_get_all_by_topic)
         self.stubs.Set(volume_api.API, 'delete', stubs.stub_volume_delete)
 
+    def tearDown(self):
+        notifier_api._reset_drivers()
+        super(VolumeApiTest, self).tearDown()
+
     def test_volume_create(self):
         self.stubs.Set(volume_api.API, 'get', stubs.stub_volume_get)
         self.stubs.Set(volume_api.API, "create", stubs.stub_volume_create)
@@ -230,6 +240,7 @@ class VolumeApiTest(test.TestCase):
         }
         body = {"volume": updates}
         req = fakes.HTTPRequest.blank('/v1/volumes/1')
+        self.assertEqual(len(test_notifier.NOTIFICATIONS), 0)
         res_dict = self.controller.update(req, '1', body)
         expected = {'volume': {
             'status': 'fakestatus',
@@ -253,6 +264,7 @@ class VolumeApiTest(test.TestCase):
             'created_at': datetime.datetime(1, 1, 1, 1, 1, 1),
             'size': 1}}
         self.assertEqual(res_dict, expected)
+        self.assertEqual(len(test_notifier.NOTIFICATIONS), 2)
 
     def test_volume_update_metadata(self):
         self.stubs.Set(db, 'volume_get', stubs.stub_volume_get_db)
@@ -263,6 +275,7 @@ class VolumeApiTest(test.TestCase):
         }
         body = {"volume": updates}
         req = fakes.HTTPRequest.blank('/v1/volumes/1')
+        self.assertEqual(len(test_notifier.NOTIFICATIONS), 0)
         res_dict = self.controller.update(req, '1', body)
         expected = {'volume': {
             'status': 'fakestatus',
@@ -288,6 +301,7 @@ class VolumeApiTest(test.TestCase):
             'size': 1
         }}
         self.assertEqual(res_dict, expected)
+        self.assertEqual(len(test_notifier.NOTIFICATIONS), 2)
 
     def test_volume_update_with_admin_metadata(self):
         self.stubs.Set(volume_api.API, "update", stubs.stub_volume_update)
@@ -308,6 +322,7 @@ class VolumeApiTest(test.TestCase):
         }
         body = {"volume": updates}
         req = fakes.HTTPRequest.blank('/v1/volumes/1')
+        self.assertEqual(len(test_notifier.NOTIFICATIONS), 0)
         admin_ctx = context.RequestContext('admin', 'fakeproject', True)
         req.environ['cinder.context'] = admin_ctx
         res_dict = self.controller.update(req, '1', body)
@@ -333,6 +348,7 @@ class VolumeApiTest(test.TestCase):
             'created_at': datetime.datetime(1, 1, 1, 1, 1, 1),
             'size': 1}}
         self.assertEqual(res_dict, expected)
+        self.assertEqual(len(test_notifier.NOTIFICATIONS), 2)
 
     def test_update_empty_body(self):
         body = {}
index a940db19f2e8eefe8e1bdef74662da0fab0f7c97..23384c2863d3acbd6db823ff805c397d397c7a96 100644 (file)
@@ -46,6 +46,7 @@ def stub_volume(id, **kwargs):
         'volume_admin_metadata': [{'key': 'attached_mode', 'value': 'rw'},
                                   {'key': 'readonly', 'value': 'False'}],
         'bootable': False,
+        'launched_at': datetime.datetime(1, 1, 1, 1, 1, 1),
         'volume_type': {'name': 'vol_type_name'}}
 
     volume.update(kwargs)
index da6ba5dc94d5af7f351ec2c89c82b0134b4d9d9f..9fe16c8e72c55f2eba08aa84b8614c864eb4e8b7 100644 (file)
@@ -26,6 +26,8 @@ from cinder.api.v2 import volumes
 from cinder import context
 from cinder import db
 from cinder import exception
+from cinder.openstack.common.notifier import api as notifier_api
+from cinder.openstack.common.notifier import test_notifier
 from cinder import test
 from cinder.tests.api import fakes
 from cinder.tests.api.v2 import stubs
@@ -63,12 +65,20 @@ class VolumeApiTest(test.TestCase):
         fake_image.stub_out_image_service(self.stubs)
         self.controller = volumes.VolumeController(self.ext_mgr)
 
+        self.flags(host='fake',
+                   notification_driver=[test_notifier.__name__])
+        test_notifier.NOTIFICATIONS = []
+
         self.stubs.Set(db, 'volume_get_all', stubs.stub_volume_get_all)
         self.stubs.Set(volume_api.API, 'delete', stubs.stub_volume_delete)
         self.stubs.Set(db, 'service_get_all_by_topic',
                        stubs.stub_service_get_all_by_topic)
         self.maxDiff = None
 
+    def tearDown(self):
+        notifier_api._reset_drivers()
+        super(VolumeApiTest, self).tearDown()
+
     def test_volume_create(self):
         self.stubs.Set(volume_api.API, 'get', stubs.stub_volume_get)
         self.stubs.Set(volume_api.API, "create", stubs.stub_volume_create)
@@ -257,6 +267,7 @@ class VolumeApiTest(test.TestCase):
         }
         body = {"volume": updates}
         req = fakes.HTTPRequest.blank('/v2/volumes/1')
+        self.assertEqual(len(test_notifier.NOTIFICATIONS), 0)
         res_dict = self.controller.update(req, '1', body)
         expected = {
             'volume': {
@@ -295,6 +306,7 @@ class VolumeApiTest(test.TestCase):
             }
         }
         self.assertEqual(res_dict, expected)
+        self.assertEqual(len(test_notifier.NOTIFICATIONS), 2)
 
     def test_volume_update_metadata(self):
         self.stubs.Set(volume_api.API, 'get', stubs.stub_volume_get)
@@ -305,6 +317,7 @@ class VolumeApiTest(test.TestCase):
         }
         body = {"volume": updates}
         req = fakes.HTTPRequest.blank('/v2/volumes/1')
+        self.assertEqual(len(test_notifier.NOTIFICATIONS), 0)
         res_dict = self.controller.update(req, '1', body)
         expected = {'volume': {
             'status': 'fakestatus',
@@ -341,6 +354,7 @@ class VolumeApiTest(test.TestCase):
             ],
         }}
         self.assertEqual(res_dict, expected)
+        self.assertEqual(len(test_notifier.NOTIFICATIONS), 2)
 
     def test_volume_update_with_admin_metadata(self):
         self.stubs.Set(volume_api.API, "update", stubs.stub_volume_update)
@@ -361,6 +375,7 @@ class VolumeApiTest(test.TestCase):
         }
         body = {"volume": updates}
         req = fakes.HTTPRequest.blank('/v2/volumes/1')
+        self.assertEqual(len(test_notifier.NOTIFICATIONS), 0)
         admin_ctx = context.RequestContext('admin', 'fake', True)
         req.environ['cinder.context'] = admin_ctx
         res_dict = self.controller.update(req, '1', body)
@@ -398,6 +413,7 @@ class VolumeApiTest(test.TestCase):
             ],
         }}
         self.assertEqual(res_dict, expected)
+        self.assertEqual(len(test_notifier.NOTIFICATIONS), 2)
 
     def test_update_empty_body(self):
         body = {}