from cinder.api import xmlutil
from cinder import db
from cinder import exception
+from cinder.openstack.common.notifier import api as notifier_api
from cinder.volume import volume_types
-
authorize = extensions.extension_authorizer('volume', 'types_extra_specs')
db.volume_type_extra_specs_update_or_create(context,
type_id,
specs)
+ notifier_info = dict(type_id=type_id, specs=specs)
+ notifier_api.notify(context, 'volumeTypeExtraSpecs',
+ 'volume_type_extra_specs.create',
+ notifier_api.INFO, notifier_info)
return body
@wsgi.serializers(xml=VolumeTypeExtraSpecTemplate)
db.volume_type_extra_specs_update_or_create(context,
type_id,
body)
+ notifier_info = dict(type_id=type_id, id=id)
+ notifier_api.notify(context, 'volumeTypeExtraSpecs',
+ 'volume_type_extra_specs.update',
+ notifier_api.INFO, notifier_info)
return body
@wsgi.serializers(xml=VolumeTypeExtraSpecTemplate)
self._check_type(context, type_id)
authorize(context)
db.volume_type_extra_specs_delete(context, type_id, id)
+ notifier_info = dict(type_id=type_id, id=id)
+ notifier_api.notify(context, 'volumeTypeExtraSpecs',
+ 'volume_type_extra_specs.delete',
+ notifier_api.INFO, notifier_info)
return webob.Response(status_int=202)
from cinder.api.v1 import types
from cinder.api.views import types as views_types
from cinder import exception
+from cinder.openstack.common.notifier import api as notifier_api
from cinder.volume import volume_types
_view_builder_class = views_types.ViewBuilder
+ def _notify_voloume_type_error(self, context, method, payload):
+ notifier_api.notify(context,
+ 'volumeType',
+ method,
+ notifier_api.ERROR,
+ payload)
+
@wsgi.action("create")
@wsgi.serializers(xml=types.VolumeTypeTemplate)
def _create(self, req, body):
try:
volume_types.create(context, name, specs)
vol_type = volume_types.get_volume_type_by_name(context, name)
+ notifier_info = dict(volume_types=vol_type)
+ notifier_api.notify(context, 'volumeType',
+ 'volume_type.create',
+ notifier_api.INFO, notifier_info)
+
except exception.VolumeTypeExists as err:
+ notifier_err = dict(volume_types=vol_type, error_message=str(err))
+ self._notify_voloume_type_error(context,
+ 'volume_type.create',
+ notifier_err)
+
raise webob.exc.HTTPConflict(explanation=str(err))
- except exception.NotFound:
+ except exception.NotFound as err:
+ notifier_err = dict(volume_types=vol_type, error_message=str(err))
+ self._notify_voloume_type_error(context,
+ 'volume_type.create',
+ notifier_err)
raise webob.exc.HTTPNotFound()
return self._view_builder.show(req, vol_type)
try:
vol_type = volume_types.get_volume_type(context, id)
volume_types.destroy(context, vol_type['id'])
- except exception.NotFound:
+ notifier_info = dict(volume_types=vol_type)
+ notifier_api.notify(context, 'volumeType',
+ 'volume_type.delete',
+ notifier_api.INFO, notifier_info)
+ except exception.NotFound as err:
+ notifier_err = dict(id=id, error_message=str(err))
+ self._notify_voloume_type_error(context,
+ 'volume_type.delete',
+ notifier_err)
+
raise webob.exc.HTTPNotFound()
return webob.Response(status_int=202)
import webob
from cinder.api.contrib import types_extra_specs
+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
import cinder.wsgi
def setUp(self):
super(VolumeTypesExtraSpecsTest, self).setUp()
+ self.flags(connection_type='fake',
+ host='fake',
+ notification_driver=[test_notifier.__name__])
self.stubs.Set(cinder.db, 'volume_type_get', volume_type_get)
self.api_path = '/v2/fake/os-volume-types/1/extra_specs'
self.controller = types_extra_specs.VolumeTypeExtraSpecsController()
+ """to reset notifier drivers left over from other api/contrib tests"""
+ notifier_api._reset_drivers()
+ test_notifier.NOTIFICATIONS = []
+
+ def tearDown(self):
+ notifier_api._reset_drivers()
+ super(VolumeTypesExtraSpecsTest, self).tearDown()
def test_index(self):
self.stubs.Set(cinder.db, 'volume_type_extra_specs_get',
self.stubs.Set(cinder.db, 'volume_type_extra_specs_delete',
delete_volume_type_extra_specs)
+ self.assertEquals(len(test_notifier.NOTIFICATIONS), 0)
req = fakes.HTTPRequest.blank(self.api_path + '/key5')
self.controller.delete(req, 1, 'key5')
+ self.assertEquals(len(test_notifier.NOTIFICATIONS), 1)
def test_create(self):
self.stubs.Set(cinder.db,
return_create_volume_type_extra_specs)
body = {"extra_specs": {"key1": "value1"}}
+ self.assertEquals(len(test_notifier.NOTIFICATIONS), 0)
req = fakes.HTTPRequest.blank(self.api_path)
res_dict = self.controller.create(req, 1, body)
+ self.assertEquals(len(test_notifier.NOTIFICATIONS), 1)
self.assertEqual('value1', res_dict['extra_specs']['key1'])
return_create_volume_type_extra_specs)
body = {"key1": "value1"}
+ self.assertEquals(len(test_notifier.NOTIFICATIONS), 0)
req = fakes.HTTPRequest.blank(self.api_path + '/key1')
res_dict = self.controller.update(req, 1, 'key1', body)
+ self.assertEquals(len(test_notifier.NOTIFICATIONS), 1)
self.assertEqual('value1', res_dict['key1'])
from cinder.api.contrib import types_manage
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.volume import volume_types
class VolumeTypesManageApiTest(test.TestCase):
def setUp(self):
super(VolumeTypesManageApiTest, self).setUp()
+ self.flags(connection_type='fake',
+ host='fake',
+ notification_driver=[test_notifier.__name__])
self.controller = types_manage.VolumeTypesManageController()
+ """to reset notifier drivers left over from other api/contrib tests"""
+ notifier_api._reset_drivers()
+ test_notifier.NOTIFICATIONS = []
+
+ def tearDown(self):
+ notifier_api._reset_drivers()
+ super(VolumeTypesManageApiTest, self).tearDown()
def test_volume_types_delete(self):
self.stubs.Set(volume_types, 'get_volume_type',
return_volume_types_destroy)
req = fakes.HTTPRequest.blank('/v2/fake/types/1')
+ self.assertEquals(len(test_notifier.NOTIFICATIONS), 0)
self.controller._delete(req, 1)
+ self.assertEquals(len(test_notifier.NOTIFICATIONS), 1)
def test_volume_types_delete_not_found(self):
self.stubs.Set(volume_types, 'get_volume_type',
self.stubs.Set(volume_types, 'destroy',
return_volume_types_destroy)
+ self.assertEquals(len(test_notifier.NOTIFICATIONS), 0)
req = fakes.HTTPRequest.blank('/v2/fake/types/777')
self.assertRaises(webob.exc.HTTPNotFound, self.controller._delete,
req, '777')
+ self.assertEquals(len(test_notifier.NOTIFICATIONS), 1)
def test_create(self):
self.stubs.Set(volume_types, 'create',
body = {"volume_type": {"name": "vol_type_1",
"extra_specs": {"key1": "value1"}}}
req = fakes.HTTPRequest.blank('/v2/fake/types')
+
+ self.assertEquals(len(test_notifier.NOTIFICATIONS), 0)
res_dict = self.controller._create(req, body)
+ self.assertEquals(len(test_notifier.NOTIFICATIONS), 1)
self.assertEqual(1, len(res_dict))
self.assertEqual('vol_type_1', res_dict['volume_type']['name'])