X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ice_validator%2Ftests%2Ftest_environment_file_parameters.py;h=84c5c34491052738e4907a1835e772341feb8e40;hb=ded5c74ea07eb1541587de1042444fa6b590ddde;hp=100e4a1bab12af75cfbf9b327fc3e4b3f40daa0b;hpb=2b57f73aad5c0a6755a7dfddc7e79937a74de00f;p=vvp%2Fvalidation-scripts.git diff --git a/ice_validator/tests/test_environment_file_parameters.py b/ice_validator/tests/test_environment_file_parameters.py index 100e4a1..84c5c34 100644 --- a/ice_validator/tests/test_environment_file_parameters.py +++ b/ice_validator/tests/test_environment_file_parameters.py @@ -90,13 +90,13 @@ ENV_PARAMETER_SPEC = { }, {"property": ("fixed_ips", "subnet"), "persistent": False, "kwargs": {}}, { - "property": ("fixed_ips", "allowed_address_pairs"), + "property": ("allowed_address_pairs", "ip_address"), "persistent": False, "network_type": "external", "kwargs": {"exclude_parameter": re.compile(r"^(.+?)_int_(.+?)$")}, }, { - "property": ("fixed_ips", "allowed_address_pairs"), + "property": ("allowed_address_pairs", "ip_address"), "persistent": True, "network_type": "internal", "kwargs": {"exclude_parameter": re.compile(r"^((?!_int_).)*$")}, @@ -218,30 +218,49 @@ def run_test_parameter(yaml_file, resource_type, *prop, **kwargs): assert not invalid_parameters, "\n".join(invalid_parameters) -def get_preload_excluded_parameters(yaml_file): +def get_preload_excluded_parameters(yaml_file, persistent_only=False, env_spec=None): """ Returns set of all parameters that should not be included in the preload's vnf parameters/tag-values section. + + if persistent_only only parameters that are marked as persistent will + be excluded """ + env_spec = env_spec or ENV_PARAMETER_SPEC results = [] - for resource_type, specs in ENV_PARAMETER_SPEC.items(): + for resource_type, specs in env_spec.items(): # apply to all resources if not in the format of an OpenStack resource all_resources = "::" not in resource_type for spec in specs: - results.extend(get_template_parameters(yaml_file, resource_type, - spec, all_resources)) - return {item["param"] for item in results} - - -def get_template_parameters(yaml_file, resource_type, spec, all_resources=False): + if persistent_only and not spec.get("persistent"): + continue + results.extend( + get_template_parameters( + yaml_file, resource_type, spec, all_resources, nested_resources=True + ) + ) + results = {item["param"] for item in results} + for param in Heat(yaml_file).parameters: + # AZs often are manipulated and passed into nested templates making + # them difficult to detect by looking for the assignment. We'll + # just extract them from the parameters if they are there to be safe + if re.match(r"availability_zone_\d+", param): + results.add(param) + return results + + +def get_template_parameters( + yaml_file, resource_type, spec, all_resources=False, nested_resources=False +): parameters = [] heat = Heat(yaml_file) if all_resources: - resources = heat.resources + resources = heat.resources if not nested_resources else heat.get_all_resources() else: - resources = heat.get_resource_by_type(resource_type) - + resources = heat.get_resource_by_type( + resource_type, all_resources=nested_resources + ) for rid, resource_props in resources.items(): for param in prop_iterator(resource_props, *spec.get("property")): if param and get_param(param) and param_helper(spec, get_param(param), rid): @@ -249,7 +268,6 @@ def get_template_parameters(yaml_file, resource_type, spec, all_resources=False) # then checking if its actually using get_param # then checking a custom helper function (mostly for internal vs external networks) parameters.append({"resource": rid, "param": get_param(param)}) - return parameters @@ -268,10 +286,11 @@ def env_violation(yaml_file, parameter, persistent): env_yaml = environment_pair.get("eyml") parameters = env_yaml.get("parameters", {}) in_env = False - for param, value in parameters.items(): - if re.match(parameter, parameter): - in_env = True - break + if parameters: # env file can be just parameters: + for param, value in parameters.items(): + if re.match(parameter, param): + in_env = True + break # confusing return. This function is looking for a violation. return not persistent == in_env