Merge "placement: validate member_of values are uuids"

This commit is contained in:
Jenkins 2017-01-18 04:28:31 +00:00 committed by Gerrit Code Review
commit d0802bf90d
2 changed files with 13 additions and 2 deletions

View File

@ -67,8 +67,6 @@ GET_RPS_SCHEMA_1_0 = {
# Placement API microversion 1.3 adds support for a member_of attribute
GET_RPS_SCHEMA_1_3 = copy.deepcopy(GET_RPS_SCHEMA_1_0)
GET_RPS_SCHEMA_1_3['properties']['member_of'] = {
# TODO(mriedem): At some point we need to do jsonschema and/or uuid
# validation of the value(s) here.
"type": "string"
}
@ -291,6 +289,13 @@ def list_resource_providers(req):
value = value[3:].split(',')
else:
value = [value]
# Make sure the values are actually UUIDs.
for aggr_uuid in value:
if not uuidutils.is_uuid_like(aggr_uuid):
raise webob.exc.HTTPBadRequest(
_('Invalid uuid value: %(uuid)s') %
{'uuid': aggr_uuid},
json_formatter=util.json_error_formatter)
filters[attr] = value
if 'resources' in req.GET:
resources = _normalize_resources_qs_param(req.GET['resources'])

View File

@ -47,6 +47,12 @@ tests:
response_json_paths:
$.resource_providers[0].uuid: 893337e9-1e55-49f0-bcfe-6a2f16fbf2f7
- name: get by aggregates no result not a uuid
GET: '/resource_providers?member_of=not+a+uuid'
status: 400
response_strings:
- 'Invalid uuid value: not a uuid'
- name: associate an aggregate with rp2
PUT: /resource_providers/5202c48f-c960-4eec-bde3-89c4f22a17b9/aggregates
data: