Make ApiValidator to work with jsonschema>=4.0.0

As of Zed jsonschema version has been bumped to 4.14.0 in
upper-constraints, which means project should support running with
this version. This patch aims to fix ApiValidator that is not compatible
with new jsonschema.

Other deprecations, like FormatChecker.cls_checks decorator are left
intact and must be covered with follow-up patches.

We also move zuul queues to project scope as otherwise jobs do not
run due to config error.

We also replace iteritems with six method as iteritems have been dropped
from Python 3.

Change-Id: Ia8b69587aa9b3d04ffcdea7c6b97a8ae65f67534
(cherry picked from commit ebc6d74bf8)
This commit is contained in:
Dmitriy Rabotyagov 2022-11-16 13:58:35 +01:00 committed by Dmitriy Rabotyagov
parent c943f4a510
commit aab24afe34
4 changed files with 56 additions and 71 deletions

View File

@ -1,4 +1,5 @@
- project:
queue: sahara
templates:
- openstack-python3-zed-jobs
- periodic-stable-jobs
@ -22,7 +23,6 @@
- openstack-ansible-deploy-aio_sahara_metal-ubuntu-focal:
voting: false
gate:
queue: sahara
jobs:
- sahara-tests-scenario:
voting: false

View File

@ -259,7 +259,7 @@ class ApiValidatorTest(testtools.TestCase):
def test_validate_hostname(self):
schema = {
"type": "string",
"format": "hostname",
"format": "idn-hostname",
}
self._validate_success(schema, "abcd")

View File

@ -97,8 +97,7 @@ def validate_posix_path(entry):
return res is not None
class ConfigTypeMeta(type):
def __instancecheck__(cls, instance):
def is_config(cls, instance):
# configs should be dict
if not isinstance(instance, dict):
return False
@ -127,8 +126,7 @@ class ConfigTypeMeta(type):
return True
class SimpleConfigTypeMeta(type):
def __instancecheck__(cls, instance):
def is_simple_config(cls, instance):
# configs should be dict
if not isinstance(instance, dict):
return False
@ -144,18 +142,7 @@ class SimpleConfigTypeMeta(type):
return True
@six.add_metaclass(ConfigTypeMeta)
class ConfigsType(dict):
pass
@six.add_metaclass(SimpleConfigTypeMeta)
class SimpleConfigsType(dict):
pass
class FlavorTypeMeta(type):
def __instancecheck__(cls, instance):
def is_flavor_type(cls, instance):
try:
int(instance)
except (ValueError, TypeError):
@ -165,17 +152,15 @@ class FlavorTypeMeta(type):
and type(instance) != bool)
@six.add_metaclass(FlavorTypeMeta)
class FlavorType(object):
pass
class ApiValidator(jsonschema.Draft4Validator):
def __init__(self, schema):
format_checker = jsonschema.FormatChecker()
super(ApiValidator, self).__init__(
schema, format_checker=format_checker, types={
"configs": ConfigsType,
"flavor": FlavorType,
"simple_config": SimpleConfigsType,
TYPE_CHECKER = jsonschema.Draft4Validator.TYPE_CHECKER.redefine_many({
"configs": is_config,
"flavor": is_flavor_type,
"simple_config": is_simple_config,
})
def __init__(self, schema, resolver=None,
format_checker=jsonschema.FormatChecker()):
super(ApiValidator, self).__init__(
schema, format_checker=format_checker)

View File

@ -50,7 +50,7 @@ def wrap_entity(func):
def _get_all_tags(image_props):
tags = []
for key, value in image_props.iteritems():
for key, value in six.iteritems(image_props):
if key.startswith(PROP_TAG) and value:
tags.append(key)
return tags
@ -69,7 +69,7 @@ def _parse_tags(image_props):
def _serialize_metadata(image):
data = {}
for key, value in image.iteritems():
for key, value in six.iteritems(image):
if key.startswith('_sahara') and value:
data[key] = value
return data