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
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')
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
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()
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)}
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
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")
self._add_visible_admin_metadata(context, volume)
+ volume_utils.notify_about_volume_usage(context, volume,
+ 'update.end')
+
return self._view_builder.detail(req, volume)
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'],
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
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)
}
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',
'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)
}
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',
'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)
}
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)
'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 = {}
'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)
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
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)
}
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': {
}
}
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)
}
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',
],
}}
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)
}
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)
],
}}
self.assertEqual(res_dict, expected)
+ self.assertEqual(len(test_notifier.NOTIFICATIONS), 2)
def test_update_empty_body(self):
body = {}