Merge "check the validity of metadata when update volume"
This commit is contained in:
commit
4e3d2efdd9
@ -341,6 +341,10 @@ class VolumeController(wsgi.Controller):
|
|||||||
self.volume_api.update(context, volume, update_dict)
|
self.volume_api.update(context, volume, update_dict)
|
||||||
except exception.VolumeNotFound as error:
|
except exception.VolumeNotFound as error:
|
||||||
raise exc.HTTPNotFound(explanation=error.msg)
|
raise exc.HTTPNotFound(explanation=error.msg)
|
||||||
|
except exception.InvalidVolumeMetadata as error:
|
||||||
|
raise webob.exc.HTTPBadRequest(explanation=error.msg)
|
||||||
|
except exception.InvalidVolumeMetadataSize as error:
|
||||||
|
raise webob.exc.HTTPRequestEntityTooLarge(explanation=error.msg)
|
||||||
|
|
||||||
volume.update(update_dict)
|
volume.update(update_dict)
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ import six
|
|||||||
from six.moves import range
|
from six.moves import range
|
||||||
from six.moves import urllib
|
from six.moves import urllib
|
||||||
import webob
|
import webob
|
||||||
|
from webob import exc
|
||||||
|
|
||||||
from cinder.api import common
|
from cinder.api import common
|
||||||
from cinder.api import extensions
|
from cinder.api import extensions
|
||||||
@ -659,6 +660,48 @@ class VolumeApiTest(test.TestCase):
|
|||||||
self.assertEqual(2, len(self.notifier.notifications))
|
self.assertEqual(2, len(self.notifier.notifications))
|
||||||
self.assertTrue(mock_validate.called)
|
self.assertTrue(mock_validate.called)
|
||||||
|
|
||||||
|
@mock.patch(
|
||||||
|
'cinder.api.openstack.wsgi.Controller.validate_name_and_description')
|
||||||
|
def test_volume_update_metadata_value_too_long(self, mock_validate):
|
||||||
|
self.stubs.Set(volume_api.API, 'get', stubs.stub_volume_api_get)
|
||||||
|
|
||||||
|
updates = {
|
||||||
|
"metadata": {"key1": ("a" * 260)}
|
||||||
|
}
|
||||||
|
body = {"volume": updates}
|
||||||
|
req = fakes.HTTPRequest.blank('/v2/volumes/%s' % fake.VOLUME_ID)
|
||||||
|
self.assertEqual(0, len(self.notifier.notifications))
|
||||||
|
self.assertRaises(exc.HTTPRequestEntityTooLarge,
|
||||||
|
self.controller.update, req, fake.VOLUME_ID, body)
|
||||||
|
|
||||||
|
@mock.patch(
|
||||||
|
'cinder.api.openstack.wsgi.Controller.validate_name_and_description')
|
||||||
|
def test_volume_update_metadata_key_too_long(self, mock_validate):
|
||||||
|
self.stubs.Set(volume_api.API, 'get', stubs.stub_volume_api_get)
|
||||||
|
|
||||||
|
updates = {
|
||||||
|
"metadata": {("a" * 260): "value1"}
|
||||||
|
}
|
||||||
|
body = {"volume": updates}
|
||||||
|
req = fakes.HTTPRequest.blank('/v2/volumes/%s' % fake.VOLUME_ID)
|
||||||
|
self.assertEqual(0, len(self.notifier.notifications))
|
||||||
|
self.assertRaises(exc.HTTPRequestEntityTooLarge,
|
||||||
|
self.controller.update, req, fake.VOLUME_ID, body)
|
||||||
|
|
||||||
|
@mock.patch(
|
||||||
|
'cinder.api.openstack.wsgi.Controller.validate_name_and_description')
|
||||||
|
def test_volume_update_metadata_empty_key(self, mock_validate):
|
||||||
|
self.stubs.Set(volume_api.API, 'get', stubs.stub_volume_api_get)
|
||||||
|
|
||||||
|
updates = {
|
||||||
|
"metadata": {"": "value1"}
|
||||||
|
}
|
||||||
|
body = {"volume": updates}
|
||||||
|
req = fakes.HTTPRequest.blank('/v2/volumes/%s' % fake.VOLUME_ID)
|
||||||
|
self.assertEqual(0, len(self.notifier.notifications))
|
||||||
|
self.assertRaises(exc.HTTPBadRequest,
|
||||||
|
self.controller.update, req, fake.VOLUME_ID, body)
|
||||||
|
|
||||||
@mock.patch(
|
@mock.patch(
|
||||||
'cinder.api.openstack.wsgi.Controller.validate_name_and_description')
|
'cinder.api.openstack.wsgi.Controller.validate_name_and_description')
|
||||||
def test_volume_update_with_admin_metadata(self, mock_validate):
|
def test_volume_update_with_admin_metadata(self, mock_validate):
|
||||||
|
@ -449,6 +449,8 @@ class API(base.Base):
|
|||||||
msg = _("The volume cannot be updated during maintenance.")
|
msg = _("The volume cannot be updated during maintenance.")
|
||||||
raise exception.InvalidVolume(reason=msg)
|
raise exception.InvalidVolume(reason=msg)
|
||||||
|
|
||||||
|
utils.check_metadata_properties(fields.get('metadata', None))
|
||||||
|
|
||||||
volume.update(fields)
|
volume.update(fields)
|
||||||
volume.save()
|
volume.save()
|
||||||
LOG.info(_LI("Volume updated successfully."), resource=volume)
|
LOG.info(_LI("Volume updated successfully."), resource=volume)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user