diff --git a/karbor/api/schemas/checkpoints.py b/karbor/api/schemas/checkpoints.py new file mode 100644 index 00000000..9e1fb8c2 --- /dev/null +++ b/karbor/api/schemas/checkpoints.py @@ -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, +} diff --git a/karbor/api/v1/providers.py b/karbor/api/v1/providers.py index da652e57..4a89b6e5 100644 --- a/karbor/api/v1/providers.py +++ b/karbor/api/v1/providers.py @@ -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'): diff --git a/karbor/tests/unit/api/v1/test_providers.py b/karbor/tests/unit/api/v1/test_providers.py index 5cf02cc7..65cffd3c 100644 --- a/karbor/tests/unit/api/v1/test_providers.py +++ b/karbor/tests/unit/api/v1/test_providers.py @@ -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)