- 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 os.path
import platform
import distro
import re
import jsonschema
@ -450,22 +451,42 @@ def _extend_with_default_and_alias(validator_class, offline=False):
def is_string_type(checker, instance):
return isinstance(instance, six.string_types)
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,
},
)
validator.DEFAULT_TYPES.update({
"array": (list, tuple),
"regex": six.string_types,
"url": 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_class,
{
"properties": properties_validator,
"deprecated": error_on_deprecated,
"type": validate_regex_type,
"required": _validate_required,
"additionalProperties": _validate_additional_properties,
"anyOf": _validate_any_of,
},
)
validator.DEFAULT_TYPES.update({
"array": (list, tuple),
"regex": 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