Add metadata length check to volume-manage
api os-volume-manage allows user to create volume with metadata, but it does not do metadata length limit. This patch does length check in advance Change-Id: I09b0d2b692af8fade5ffff16c1cc61655fb700e5 Closes-Bug: 1602086 Partial-Bug: 1593588
This commit is contained in:
parent
c7130f4cfe
commit
a940f1748a
@ -135,6 +135,9 @@ class VolumeManageController(wsgi.Controller):
|
|||||||
kwargs['metadata'] = volume.get('metadata', None)
|
kwargs['metadata'] = volume.get('metadata', None)
|
||||||
kwargs['availability_zone'] = volume.get('availability_zone', None)
|
kwargs['availability_zone'] = volume.get('availability_zone', None)
|
||||||
kwargs['bootable'] = utils.get_bool_param('bootable', volume)
|
kwargs['bootable'] = utils.get_bool_param('bootable', volume)
|
||||||
|
|
||||||
|
utils.check_metadata_properties(kwargs['metadata'])
|
||||||
|
|
||||||
# Not found exception will be handled at wsgi level
|
# Not found exception will be handled at wsgi level
|
||||||
new_volume = self.volume_api.manage_existing(context,
|
new_volume = self.volume_api.manage_existing(context,
|
||||||
volume['host'],
|
volume['host'],
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import ddt
|
||||||
import mock
|
import mock
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
@ -126,6 +127,7 @@ def api_get_manageable_volumes(*args, **kwargs):
|
|||||||
return vols
|
return vols
|
||||||
|
|
||||||
|
|
||||||
|
@ddt.ddt
|
||||||
@mock.patch('cinder.objects.service.Service.get_by_host_and_topic',
|
@mock.patch('cinder.objects.service.Service.get_by_host_and_topic',
|
||||||
service_get_by_host_and_topic)
|
service_get_by_host_and_topic)
|
||||||
@mock.patch('cinder.volume.volume_types.get_volume_type_by_name',
|
@mock.patch('cinder.volume.volume_types.get_volume_type_by_name',
|
||||||
@ -322,3 +324,14 @@ class VolumeManageTest(test.TestCase):
|
|||||||
self._admin_ctxt, 'fakehost', limit=CONF.osapi_max_limit,
|
self._admin_ctxt, 'fakehost', limit=CONF.osapi_max_limit,
|
||||||
marker=None, offset=0, sort_dirs=['desc'],
|
marker=None, offset=0, sort_dirs=['desc'],
|
||||||
sort_keys=['reference'])
|
sort_keys=['reference'])
|
||||||
|
|
||||||
|
@ddt.data({'a' * 256: 'a'},
|
||||||
|
{'a': 'a' * 256},
|
||||||
|
{'': 'a'},
|
||||||
|
)
|
||||||
|
def test_manage_volume_with_invalid_metadata(self, value):
|
||||||
|
body = {'volume': {'host': 'host_ok',
|
||||||
|
'ref': 'fake_ref',
|
||||||
|
"metadata": value}}
|
||||||
|
res = self._get_resp_post(body)
|
||||||
|
self.assertEqual(400, res.status_int)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user