- Unify branch for both RHEL versions

This commit is contained in:
soksanichenko 2022-11-11 16:31:43 +02:00
parent b61e59d676
commit 4e0d2d14c9

View File

@ -39,6 +39,7 @@ from __future__ import print_function
import multiprocessing import multiprocessing
import os.path import os.path
import platform import platform
import distro
import re import re
import jsonschema import jsonschema
@ -450,6 +451,9 @@ def _extend_with_default_and_alias(validator_class, offline=False):
def is_string_type(checker, instance): def is_string_type(checker, instance):
return isinstance(instance, six.string_types) return isinstance(instance, six.string_types)
# RHEL9 has newer version of package jsonschema
# which has another way of working with validators
if float(distro.linux_distribution()[1]) < 9:
validator = jsonschema.validators.extend( validator = jsonschema.validators.extend(
validator_class, validator_class,
{ {
@ -466,6 +470,23 @@ def _extend_with_default_and_alias(validator_class, offline=False):
"regex": six.string_types, "regex": six.string_types,
"url": six.string_types, "url": six.string_types,
}) })
else:
type_checker = validator_class.TYPE_CHECKER.redefine_many(
{"array": is_array, "regex": is_string_type, "url": is_string_type}
)
validator = jsonschema.validators.extend(
validator_class,
{
"properties": properties_validator,
"deprecated": error_on_deprecated,
"type": validate_regex_type,
"required": _validate_required,
"additionalProperties": _validate_additional_properties,
"anyOf": _validate_any_of,
},
type_checker=type_checker,
)
return validator return validator