diff --git a/.zuul.yaml b/.zuul.yaml index 369087cba7..b06e5ac96f 100644 --- a/.zuul.yaml +++ b/.zuul.yaml @@ -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 diff --git a/sahara/tests/unit/utils/test_api_validator.py b/sahara/tests/unit/utils/test_api_validator.py index 1ea21e65fb..23828647cf 100644 --- a/sahara/tests/unit/utils/test_api_validator.py +++ b/sahara/tests/unit/utils/test_api_validator.py @@ -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") diff --git a/sahara/utils/api_validator.py b/sahara/utils/api_validator.py index ec3174f94a..558110d483 100644 --- a/sahara/utils/api_validator.py +++ b/sahara/utils/api_validator.py @@ -97,85 +97,70 @@ def validate_posix_path(entry): return res is not None -class ConfigTypeMeta(type): - def __instancecheck__(cls, instance): - # configs should be dict - if not isinstance(instance, dict): +def is_config(cls, instance): + # configs should be dict + if not isinstance(instance, dict): + return False + + # check dict content + for applicable_target, configs in six.iteritems(instance): + # upper-level dict keys (applicable targets) should be strings + if not isinstance(applicable_target, six.string_types): return False - # check dict content - for applicable_target, configs in six.iteritems(instance): - # upper-level dict keys (applicable targets) should be strings - if not isinstance(applicable_target, six.string_types): - return False - - # upper-level dict values should be dicts - if not isinstance(configs, dict): - return False - - # check internal dict content - for config_name, config_value in six.iteritems(configs): - # internal dict keys should be strings - if not isinstance(config_name, six.string_types): - return False - - # internal dict values should be strings or integers or bools - if not isinstance(config_value, - (six.string_types, six.integer_types)): - return False - - return True - - -class SimpleConfigTypeMeta(type): - def __instancecheck__(cls, instance): - # configs should be dict - if not isinstance(instance, dict): + # upper-level dict values should be dicts + if not isinstance(configs, dict): return False - # check dict content - for conf_name, conf_value in six.iteritems(instance): - # keys should be strings, values should be int, string or bool - if not isinstance(conf_name, six.string_types): + # check internal dict content + for config_name, config_value in six.iteritems(configs): + # internal dict keys should be strings + if not isinstance(config_name, six.string_types): return False - if not isinstance(conf_value, + + # internal dict values should be strings or integers or bools + if not isinstance(config_value, (six.string_types, six.integer_types)): return False - return True + + return True -@six.add_metaclass(ConfigTypeMeta) -class ConfigsType(dict): - pass +def is_simple_config(cls, instance): + # configs should be dict + if not isinstance(instance, dict): + return False + + # check dict content + for conf_name, conf_value in six.iteritems(instance): + # keys should be strings, values should be int, string or bool + if not isinstance(conf_name, six.string_types): + return False + if not isinstance(conf_value, + (six.string_types, six.integer_types)): + return False + return True -@six.add_metaclass(SimpleConfigTypeMeta) -class SimpleConfigsType(dict): - pass - - -class FlavorTypeMeta(type): - def __instancecheck__(cls, instance): - try: - int(instance) - except (ValueError, TypeError): - return (isinstance(instance, six.string_types) - and uuidutils.is_uuid_like(instance)) - return (isinstance(instance, six.integer_types + six.string_types) - and type(instance) != bool) - - -@six.add_metaclass(FlavorTypeMeta) -class FlavorType(object): - pass +def is_flavor_type(cls, instance): + try: + int(instance) + except (ValueError, TypeError): + return (isinstance(instance, six.string_types) + and uuidutils.is_uuid_like(instance)) + return (isinstance(instance, six.integer_types + six.string_types) + and type(instance) != bool) class ApiValidator(jsonschema.Draft4Validator): - def __init__(self, schema): - format_checker = jsonschema.FormatChecker() + + 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, types={ - "configs": ConfigsType, - "flavor": FlavorType, - "simple_config": SimpleConfigsType, - }) + schema, format_checker=format_checker) diff --git a/sahara/utils/openstack/images.py b/sahara/utils/openstack/images.py index efa162b0a9..e5267261e5 100644 --- a/sahara/utils/openstack/images.py +++ b/sahara/utils/openstack/images.py @@ -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