X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ice_validator%2Ftests%2Ftest_initial_configuration.py;h=13cc2c7f5f20ee2c4044f14b6753a7c0fa50fdef;hb=d8ffed96caada0308ac2ee3f4daf90b7aacb5137;hp=f911ce9879e3fef3d0aa2ef46cd1227c0914a6e7;hpb=533930e4f25494316ea7bc06bcc84b452b2fa529;p=vvp%2Fvalidation-scripts.git diff --git a/ice_validator/tests/test_initial_configuration.py b/ice_validator/tests/test_initial_configuration.py index f911ce9..13cc2c7 100644 --- a/ice_validator/tests/test_initial_configuration.py +++ b/ice_validator/tests/test_initial_configuration.py @@ -65,24 +65,26 @@ def test_00_valid_yaml(filename): ).format(str(e).replace("\n", " ")) +def check_duplicate_keys(yaml_path): + import yaml as normal_yaml + + try: + with open(yaml_path) as fh: + normal_yaml.load(fh, yaml_custom_utils.UniqueKeyLoader) # nosec + except ConstructorError as e: + pytest.fail("{} {}".format(e.problem, e.problem_mark)) + + @pytest.mark.base @validates("R-92635") def test_02_no_duplicate_keys_in_file(yaml_file): - """ - Checks that no duplicate keys exist in a given YAML file. - """ - import yaml as normal_yaml # we can't use the caching version in this test + check_duplicate_keys(yaml_file) - normal_yaml.add_constructor( - yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG, - yaml_custom_utils.raise_duplicates_keys, - ) - try: - with open(yaml_file) as fh: - normal_yaml.load(fh) - except ConstructorError as e: - pytest.fail("{} {}".format(e.problem, e.problem_mark)) +@pytest.mark.base +@validates("R-92635") +def test_02a_no_duplicate_keys_in_env(env_file): + check_duplicate_keys(env_file) @pytest.mark.base @@ -93,7 +95,7 @@ def test_03_all_referenced_resources_exists(yaml_file): actually exists in all yaml files """ with open(yaml_file) as fh: - yml = yaml.load(fh) + yml = yaml.safe_load(fh) # skip if resources are not defined if "resources" not in yml: @@ -174,20 +176,10 @@ def test_05_all_get_param_have_defined_parameter(yaml_file): @validates("R-90152") @pytest.mark.base -def test_06_heat_template_resource_section_has_resources(heat_template): - - found_resource = False - - with open(heat_template) as fh: - yml = yaml.load(fh) - - resources = yml.get("resources") - if resources: - for k1, v1 in yml["resources"].items(): - if not isinstance(v1, dict): - continue - - found_resource = True - break - - assert found_resource, "Heat templates must contain at least one resource" +def test_06_heat_template_resource_section_has_resources(yaml_file): + template = load_yaml(yaml_file) + if "resources" not in template: + pytest.skip("No resources section") + assert ( + len(template["resources"]) > 0 + ), "If resources section present, then there must be at least 1 resource defined."