From 2709e30956b53be1dca91eec801220f0efbaed93 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Thu, 14 Jul 2022 15:43:40 +0100 Subject: [PATCH] Fix compatibility with jsonschema 4.x This changed one of the error messages we depend on [1]. [1] https://github.com/python-jsonschema/jsonschema/commit/641e9b8c Change-Id: I643ec568ee2eb2ec1a555f813fd2f1acff915afa Signed-off-by: Stephen Finucane --- .../v1/validation_error_test_data.yaml | 4 ++-- nova/tests/unit/compute/test_provider_config.py | 14 +++++++++++++- requirements.txt | 1 + 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/nova/tests/unit/compute/provider_config_data/v1/validation_error_test_data.yaml b/nova/tests/unit/compute/provider_config_data/v1/validation_error_test_data.yaml index 278b77cae684..ac0b61a2074b 100644 --- a/nova/tests/unit/compute/provider_config_data/v1/validation_error_test_data.yaml +++ b/nova/tests/unit/compute/provider_config_data/v1/validation_error_test_data.yaml @@ -31,7 +31,7 @@ property__source_file_present_value: schema_version: '1.0' __source_file: "present" expected_messages: - - "{} is not allowed for" + - "should not be valid under {}" - "validating 'not' in schema['properties']['__source_file']" property__source_file_present_null: config: @@ -39,7 +39,7 @@ property__source_file_present_null: schema_version: '1.0' __source_file: null expected_messages: - - "{} is not allowed for" + - "should not be valid under {}" - "validating 'not' in schema['properties']['__source_file']" provider_invalid_uuid: config: diff --git a/nova/tests/unit/compute/test_provider_config.py b/nova/tests/unit/compute/test_provider_config.py index b9070bd21808..384d4650542b 100644 --- a/nova/tests/unit/compute/test_provider_config.py +++ b/nova/tests/unit/compute/test_provider_config.py @@ -13,13 +13,14 @@ import copy import ddt import fixtures +import importlib.metadata import microversion_parse import os - from unittest import mock from oslo_utils.fixture import uuidsentinel from oslotest import base +from packaging import version from nova.compute import provider_config from nova import exception as nova_exc @@ -118,6 +119,17 @@ class SchemaValidationTestCasesV1(SchemaValidationMixin): @ddt.unpack @ddt.file_data('provider_config_data/v1/validation_error_test_data.yaml') def test_validation_errors(self, config, expected_messages): + # TODO(stephenfin): Drop this once we no longer support jsonschema 3.x + jsonschema_version = importlib.metadata.version('jsonschema') + if version.parse(jsonschema_version) < version.parse('4.0.0'): + if expected_messages == [ + "should not be valid under {}", + "validating 'not' in schema['properties']['__source_file']", + ]: + expected_messages = [ + "{} is not allowed for", + "validating 'not' in schema['properties']['__source_file']", # noqa: E501 + ] self.run_test_validation_errors(config, expected_messages) @ddt.unpack diff --git a/requirements.txt b/requirements.txt index 03b86ef1c897..8bac17323e66 100644 --- a/requirements.txt +++ b/requirements.txt @@ -66,3 +66,4 @@ python-dateutil>=2.7.0 # BSD futurist>=1.8.0 # Apache-2.0 openstacksdk>=0.35.0 # Apache-2.0 PyYAML>=5.1 # MIT +packaging>=21.0 # Apache-2.0