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:
lg.yue 2016-08-01 11:08:17 +08:00
parent c7130f4cfe
commit a940f1748a
2 changed files with 16 additions and 0 deletions

View File

@ -135,6 +135,9 @@ class VolumeManageController(wsgi.Controller):
kwargs['metadata'] = volume.get('metadata', None)
kwargs['availability_zone'] = volume.get('availability_zone', None)
kwargs['bootable'] = utils.get_bool_param('bootable', volume)
utils.check_metadata_properties(kwargs['metadata'])
# Not found exception will be handled at wsgi level
new_volume = self.volume_api.manage_existing(context,
volume['host'],

View File

@ -13,6 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import ddt
import mock
from oslo_config import cfg
from oslo_serialization import jsonutils
@ -126,6 +127,7 @@ def api_get_manageable_volumes(*args, **kwargs):
return vols
@ddt.ddt
@mock.patch('cinder.objects.service.Service.get_by_host_and_topic',
service_get_by_host_and_topic)
@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,
marker=None, offset=0, sort_dirs=['desc'],
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)