From d8902ee6219a5e435935379132a51903daac57de Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Tue, 8 Oct 2024 11:59:29 +0100 Subject: [PATCH] tests: Actually raise on invalid schemas We added schema checks in Ie085fbe965894a1cd5e78ba8d652ced50c77f3de but forgot the final check. We also fix the issues that have been introduced since. Signed-off-by: Stephen Finucane Change-Id: I5efcb967b8cf677207a3ba812d8ddb4bcd7ab0b9 --- manila/api/schemas/resource_locks.py | 17 ++++++++++------- manila/tests/api/test_schemas.py | 10 ++++++++++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/manila/api/schemas/resource_locks.py b/manila/api/schemas/resource_locks.py index 74cc375abb..8981f1fd7d 100644 --- a/manila/api/schemas/resource_locks.py +++ b/manila/api/schemas/resource_locks.py @@ -42,7 +42,8 @@ create_request_body = { }, 'resource_type': { 'type': ['string', 'null'], - 'enum': constants.RESOURCE_LOCK_RESOURCE_TYPES + (None,), + 'enum': list(constants.RESOURCE_LOCK_RESOURCE_TYPES) + + [None], 'default': constants.SHARE_RESOURCE_TYPE, 'description': helpers.description( 'resource_lock_resource_type' @@ -50,7 +51,8 @@ create_request_body = { }, 'resource_action': { 'type': ['string', 'null'], - 'enum': constants.RESOURCE_LOCK_RESOURCE_ACTIONS + (None,), + 'enum': list(constants.RESOURCE_LOCK_RESOURCE_ACTIONS) + + [None], 'default': constants.RESOURCE_ACTION_DELETE, 'description': helpers.description( 'resource_lock_resource_action_create_optional' @@ -74,7 +76,8 @@ update_request_body = { 'properties': { 'resource_action': { 'type': ['string', 'null'], - 'enum': constants.RESOURCE_LOCK_RESOURCE_ACTIONS + (None,), + 'enum': list(constants.RESOURCE_LOCK_RESOURCE_ACTIONS) + + [None], 'description': helpers.description( 'resource_lock_resource_action_optional' ), @@ -158,14 +161,14 @@ index_request_query = { }), 'resource_action': parameter_types.multi_params({ 'type': ['string', 'null'], - 'enum': constants.RESOURCE_LOCK_RESOURCE_ACTIONS + (None,), + 'enum': list(constants.RESOURCE_LOCK_RESOURCE_ACTIONS) + [None], 'description': helpers.description( 'resource_lock_resource_action_query' ), }), 'resource_type': parameter_types.multi_params({ 'type': ['string', 'null'], - 'enum': constants.RESOURCE_LOCK_RESOURCE_TYPES + (None,), + 'enum': list(constants.RESOURCE_LOCK_RESOURCE_TYPES) + [None], 'description': helpers.description( 'resource_lock_resource_type_query' ), @@ -228,7 +231,7 @@ _resource_lock_response = { }, 'resource_type': { 'type': 'string', - 'enum': constants.RESOURCE_LOCK_RESOURCE_TYPES, + 'enum': list(constants.RESOURCE_LOCK_RESOURCE_TYPES), 'description': helpers.description('resource_lock_resource_type'), }, 'resource_id': { @@ -238,7 +241,7 @@ _resource_lock_response = { }, 'resource_action': { 'type': 'string', - 'enum': constants.RESOURCE_LOCK_RESOURCE_ACTIONS, + 'enum': list(constants.RESOURCE_LOCK_RESOURCE_ACTIONS), 'description': helpers.description( 'resource_lock_resource_action' ), diff --git a/manila/tests/api/test_schemas.py b/manila/tests/api/test_schemas.py index bec7745401..578e5464a2 100644 --- a/manila/tests/api/test_schemas.py +++ b/manila/tests/api/test_schemas.py @@ -11,11 +11,14 @@ # under the License. import jsonschema.exceptions +from oslo_log import log from manila.api.v2 import router from manila.api.validation import validators from manila import test +LOG = log.getLogger(__name__) + class SchemaTest(test.TestCase): @@ -34,6 +37,7 @@ class SchemaTest(test.TestCase): try: self.meta_schema.check_schema(schema) except jsonschema.exceptions.SchemaError: + LOG.exception('schema validation failed') invalid_schemas.add(func.__qualname__) def _validate_func(func, method): @@ -152,3 +156,9 @@ class SchemaTest(test.TestCase): f"Found API resources without response body schemas: " f"{sorted(missing_response_schemas)}" ) + + if invalid_schemas: + raise self.failureException( + f"Found API resources with invalid schemas: " + f"{sorted(invalid_schemas)}" + )