From da8ee01b65851c15a2a6ec5e50ece2b3a809dbbc Mon Sep 17 00:00:00 2001 From: Ekaterina Fedorova Date: Mon, 9 Jun 2014 16:24:30 +0400 Subject: [PATCH] Make categories optional parameter Change-Id: I5960de1b7e01db491046b89f08fd95324d24551d Closes-Bug: #1311033 --- .../specification/murano-repository.rst | 6 ----- murano/api/v1/catalog.py | 25 ++++++++++--------- murano/api/v1/schemas.py | 4 +-- murano/db/catalog/api.py | 4 --- 4 files changed, 14 insertions(+), 25 deletions(-) diff --git a/doc/source/specification/murano-repository.rst b/doc/source/specification/murano-repository.rst index 050d345fe..f9603c206 100644 --- a/doc/source/specification/murano-repository.rst +++ b/doc/source/specification/murano-repository.rst @@ -249,8 +249,6 @@ Allowed operations: { "op": "replace", "path": "/name", "value": "New name" } ] -Note, that replacing categories with empty list is not allowed as well as the removing last category. - **Request 200 (application/murano-packages-json-patch)** :: @@ -292,10 +290,6 @@ Note, that replacing categories with empty list is not allowed as well as the re * An attempt to perform operation that is not allowed on the specified path * An attempt to update non-public package by user whose tenant is not an owner of this package -**Response 400** - -* An attempt to replace categories with empty list or remove last category - **Response 404** * An attempt to update package that doesn't exist diff --git a/murano/api/v1/catalog.py b/murano/api/v1/catalog.py index b10667f61..e3fe0570f 100644 --- a/murano/api/v1/catalog.py +++ b/murano/api/v1/catalog.py @@ -91,12 +91,13 @@ def _validate_body(body): raise exc.HTTPBadRequest('Uploading file is too large.' ' The limit is {0} Mb'.format(mb_limit)) - if len(body.keys()) != 2: + if len(body.keys()) > 2: msg = _("'multipart/form-data' request body should contain " - "2 parts: json string and zip archive. Current body consist " - "of {0} part(s)").format(len(body.keys())) + "1 or 2 parts: json string and zip archive. Current body " + "consists of {0} part(s)").format(len(body.keys())) LOG.error(msg) raise exc.HTTPBadRequest(msg) + file_obj = None package_meta = None for part in body.values(): @@ -110,10 +111,6 @@ def _validate_body(body): msg = _('There is no file package with application description') LOG.error(msg) raise exc.HTTPBadRequest(msg) - if package_meta is None: - msg = _('There is no json with meta information about package') - LOG.error(msg) - raise exc.HTTPBadRequest(msg) return file_obj, package_meta @@ -128,6 +125,7 @@ class Controller(object): { "op": "add", "path": "/tags", "value": [ "foo", "bar" ] } { "op": "add", "path": "/categories", "value": [ "foo", "bar" ] } { "op": "remove", "path": "/tags" } + { "op": "remove", "path": "/categories" } { "op": "replace", "path": "/tags", "value": ["foo", "bar"] } { "op": "replace", "path": "/is_public", "value": true } { "op": "replace", "path": "/description", @@ -185,11 +183,14 @@ class Controller(object): """ _check_content_type(req, 'multipart/form-data') file_obj, package_meta = _validate_body(body) - try: - jsonschema.validate(package_meta, schemas.PKG_UPLOAD_SCHEMA) - except jsonschema.ValidationError as e: - LOG.exception(e) - raise exc.HTTPBadRequest(explanation=e.message) + if package_meta: + try: + jsonschema.validate(package_meta, schemas.PKG_UPLOAD_SCHEMA) + except jsonschema.ValidationError as e: + LOG.exception(e) + raise exc.HTTPBadRequest(explanation=e.message) + else: + package_meta = {} with tempfile.NamedTemporaryFile(delete=False) as tempf: LOG.debug("Storing package archive in a temporary file") diff --git a/murano/api/v1/schemas.py b/murano/api/v1/schemas.py index 50c9b2f3d..e574a8417 100644 --- a/murano/api/v1/schemas.py +++ b/murano/api/v1/schemas.py @@ -37,7 +37,7 @@ PKG_UPLOAD_SCHEMA = { }, "categories": { "type": "array", - "minItems": 1, + "minItems": 0, "items": {"type": "string"}, "uniqueItems": True }, @@ -46,7 +46,6 @@ PKG_UPLOAD_SCHEMA = { "is_public": {"type": "boolean"}, "enabled": {"type": "boolean"} }, - "required": ["categories"], "additionalProperties": False } @@ -62,7 +61,6 @@ PKG_UPDATE_SCHEMA = { }, "categories": { "type": "array", - "minItems": 1, "items": {"type": "string"}, "uniqueItems": True }, diff --git a/murano/db/catalog/api.py b/murano/db/catalog/api.py index 289b6e683..e4a2e64e8 100644 --- a/murano/db/catalog/api.py +++ b/murano/db/catalog/api.py @@ -197,10 +197,6 @@ def _do_remove(package, change): "does not exist.").format(value, path) LOG.error(msg) raise exc.HTTPNotFound(msg) - if path == 'categories' and len(current_values) == 1: - msg = _("At least one category should be assigned to the package") - LOG.error(msg) - raise exc.HTTPBadRequest(msg) item_to_remove = find(current_values, lambda i: i.name == value) current_values.remove(item_to_remove) return package