Add notifier events to cinder volume rename, reset-state

Implements: notifiers for cinder volume rename, reset-state
Fixes: bug #1271692
Change-Id: Ie82a4c062904a4f86c9f6364649b8c2b9f71ea6e
This commit is contained in:
jenny-shieh 2014-01-22 12:20:07 -08:00
parent d540eb6f7c
commit adbb272398
7 changed files with 59 additions and 0 deletions

View 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')

View 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)}

View 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)

View 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'],

View 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 = {}

View 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)

View 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 = {}