Add jsonschema validation for checkpoint API

Change-Id: Ia8b2e015ca7e9edd9987b980e06960099a88ce53
Partial-Implements: bp karbor-json-schema-validation
This commit is contained in:
chenying 2017-12-13 17:31:18 +08:00
parent c5ae53d58c
commit f4b59d9bf2
3 changed files with 41 additions and 1 deletions

View File

@ -0,0 +1,37 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""
Schema for Karbor V1 Checkpoints API.
"""
from karbor.api.validation import parameter_types
create = {
'type': 'object',
'properties': {
'type': 'object',
'checkpoint': {
'type': 'object',
'properties': {
'plan_id': parameter_types.uuid,
'extra-info': parameter_types.metadata,
},
'required': ['plan_id'],
'additionalProperties': False,
},
},
'required': ['checkpoint'],
'additionalProperties': False,
}

View File

@ -21,6 +21,8 @@ from webob import exc
from karbor.api import common
from karbor.api.openstack import wsgi
from karbor.api.schemas import checkpoints as checkpoint_schema
from karbor.api import validation
from karbor.common import constants
from karbor import exception
from karbor.i18n import _
@ -333,6 +335,7 @@ class ProvidersController(wsgi.Controller):
LOG.info("Get all checkpoints completed successfully.")
return checkpoints
@validation.schema(checkpoint_schema.create)
def checkpoints_create(self, req, provider_id, body):
"""Creates a new checkpoint."""
if not self.is_valid_body(body, 'checkpoint'):

View File

@ -135,6 +135,6 @@ class ProvidersApiTest(base.TestCase):
self.controller.checkpoints_create(
req,
'2220f8b1-975d-4621-a872-fa9afb43cb6c',
body)
body=body)
self.assertTrue(mock_plan_create.called)
self.assertTrue(mock_protect.called)