X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ice_validator%2Ftests%2Ftest_unique_name_str_replace_use_req_params.py;h=e1d73b71bc9d413a978398e704d705e4062ff824;hb=refs%2Fchanges%2F52%2F78952%2F1;hp=d89d8d9ab0f84a3a4ab44cfcc768fc72c37f004c;hpb=cc21b8b08b6dbcec577bfb26ff397ac899da8002;p=vvp%2Fvalidation-scripts.git diff --git a/ice_validator/tests/test_unique_name_str_replace_use_req_params.py b/ice_validator/tests/test_unique_name_str_replace_use_req_params.py index d89d8d9..e1d73b7 100644 --- a/ice_validator/tests/test_unique_name_str_replace_use_req_params.py +++ b/ice_validator/tests/test_unique_name_str_replace_use_req_params.py @@ -6,7 +6,7 @@ # =================================================================== # # Unless otherwise specified, all software contained herein is licensed -# under the Apache License, Version 2.0 (the “License”); +# under the Apache License, Version 2.0 (the "License"); # you may not use this software except in compliance with the License. # You may obtain a copy of the License at # @@ -21,7 +21,7 @@ # # # Unless otherwise specified, all documentation contained herein is licensed -# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# under the Creative Commons License, Attribution 4.0 Intl. (the "License"); # you may not use this documentation except in compliance with the License. # You may obtain a copy of the License at # @@ -35,19 +35,21 @@ # # ============LICENSE_END============================================ # -# ECOMP is a trademark and service mark of AT&T Intellectual Property. # -import yaml +from tests import cached_yaml as yaml import pytest +from tests.helpers import validates + +@validates("R-85734") def test_unique_name_str_replace_use_req_params(yaml_file): - ''' + """ Check that all occurences of str_replace uses either vnf_name or vf_module_id to construct the name - ''' - req_params = ['vnf_name', 'vf_module_id'] + """ + req_params = {"vnf_name"} with open(yaml_file) as fh: yml = yaml.load(fh) @@ -56,28 +58,30 @@ def test_unique_name_str_replace_use_req_params(yaml_file): if "resources" not in yml: pytest.skip("No resources specified in the heat template") - has_req_params = [] - for v1 in yml["resources"].values(): + missing_req_params = [] + for r_id, v1 in yml["resources"].items(): if not isinstance(v1, dict): continue if "properties" not in v1: continue - if v1["type"] in ["OS::Nova::Server", "OS::Neutron::Port", - "OS::Heat::ResourceGroup"]: + if v1["type"] in ["OS::Nova::Server"]: continue try: v2 = v1["properties"]["name"] str_replace = v2["str_replace"] - all_params = [] + all_params = set() for v3 in str_replace["params"].values(): - all_params.append(v3["get_param"]) - detected_params = set(all_params) & set(req_params) - has_req_params.append(len(detected_params) > 0) + all_params.add(v3["get_param"]) + if req_params.difference(all_params): + msg = ( + "Resource({}) does not use str_replace " + "and the vnf_name parameter to set " + "the name property" + ).format(r_id) + missing_req_params.append(msg) except (TypeError, KeyError): continue - if not has_req_params: - pytest.skip("No str_replace instances were detected") - assert all(c for c in has_req_params) + assert not missing_req_params, ", ".join(missing_req_params)