- 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,22 +451,42 @@ 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)
validator = jsonschema.validators.extend( # RHEL9 has newer version of package jsonschema
validator_class, # which has another way of working with validators
{ if float(distro.linux_distribution()[1]) < 9:
"properties": properties_validator, validator = jsonschema.validators.extend(
"deprecated": error_on_deprecated, validator_class,
"type": validate_regex_type, {
"required": _validate_required, "properties": properties_validator,
"additionalProperties": _validate_additional_properties, "deprecated": error_on_deprecated,
"anyOf": _validate_any_of, "type": validate_regex_type,
}, "required": _validate_required,
) "additionalProperties": _validate_additional_properties,
validator.DEFAULT_TYPES.update({ "anyOf": _validate_any_of,
"array": (list, tuple), },
"regex": six.string_types, )
"url": six.string_types, 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 return validator