X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ice_validator%2Ftests%2Fstructures.py;h=887917c240a1ae3182884c92fedfe53fdf2d7536;hb=00c64458942602efe5a3b712540b98ac94fb60f4;hp=8abe87b9b6dac20950b3cc9f350015ce4d3b8d0f;hpb=503041fb7ec395fe57e418d584c4a5d06f4c9877;p=vvp%2Fvalidation-scripts.git diff --git a/ice_validator/tests/structures.py b/ice_validator/tests/structures.py index 8abe87b..887917c 100644 --- a/ice_validator/tests/structures.py +++ b/ice_validator/tests/structures.py @@ -45,7 +45,7 @@ import re import sys from tests import cached_yaml as yaml -from tests.helpers import load_yaml +from tests.helpers import load_yaml, get_param from .utils import nested_dict VERSION = "4.2.0" @@ -252,15 +252,19 @@ class ContrailV2NetworkFlavorBaseProcessor(HeatProcessor): network_flavor = cls.network_flavor_internal else: p = param.get("get_param") - if isinstance(p, str): - if "_int_" in p or p.startswith("int_"): - network_flavor = cls.network_flavor_internal - elif "_subint_" in p: - network_flavor = cls.network_flavor_subint - else: - network_flavor = cls.network_flavor_external + network_flavor = cls.get_network_format(p) return network_flavor + @classmethod + def get_network_format(cls, param): + if isinstance(param, str): + if "_int_" in param or param.startswith("int_"): + return cls.network_flavor_internal + elif "_subint_" in param: + return cls.network_flavor_subint + else: + return cls.network_flavor_external + class ContrailV2InstanceIpProcessor(ContrailV2NetworkFlavorBaseProcessor): """ ContrailV2 InstanceIp @@ -494,11 +498,14 @@ class NeutronPortProcessor(HeatProcessor): """Returns True/False as `resource` is/not An OS::Nova:Port with the property binding:vnic_type """ - return nested_dict.get( - resource, "type" - ) == cls.resource_type and "binding:vnic_type" in nested_dict.get( - resource, "properties", default={} - ) + resource_properties = nested_dict.get(resource, "properties", default={}) + if ( + nested_dict.get(resource, "type") == cls.resource_type + and resource_properties.get("binding:vnic_type", "") == "direct" + ): + return True + + return False class NovaServerProcessor(HeatProcessor): @@ -598,6 +605,10 @@ class Heat(object): self.load_env(envpath) self.heat_processors = self.get_heat_processors() + @property + def is_heat(self): + return "heat_template_version" in self.yml + @property def contrail_resources(self): """This attribute is a dict of Contrail resources. @@ -606,19 +617,28 @@ class Heat(object): resource_type=ContrailV2VirtualMachineInterfaceProcessor.resource_type ) - def get_all_resources(self, base_dir): + def get_all_resources(self, base_dir=None, count=1): """ - Like ``resources``, - but this returns all the resources definitions + Like ``resources``, but this returns all the resources definitions defined in the template, resource groups, and nested YAML files. + + A special variable will be added to all resource properties (__count__). + This will normally be 1, but if the resource is generated by a + ResourceGroup **and** an env file is present, then the count will be + the value from the env file (assuming this follows standard VNF Heat + Guidelines) """ + base_dir = base_dir or self.dirname resources = {} for r_id, r_data in self.resources.items(): + r_data["__count__"] = count resources[r_id] = r_data resource = Resource(r_id, r_data) if resource.is_nested(): + nested_count = resource.get_count(self.env) nested = Heat(os.path.join(base_dir, resource.get_nested_filename())) - resources.update(nested.get_all_resources(base_dir)) + nested_resources = nested.get_all_resources(count=nested_count) + resources.update(nested_resources) return resources @staticmethod @@ -628,13 +648,14 @@ class Heat(object): """ return _HEAT_PROCESSORS - def get_resource_by_type(self, resource_type): + def get_resource_by_type(self, resource_type, all_resources=False): """Return dict of resources whose type is `resource_type`. key is resource_id, value is resource. """ + resources = self.get_all_resources() if all_resources else self.resources return { rid: resource - for rid, resource in self.resources.items() + for rid, resource in resources.items() if self.nested_get(resource, "type") == resource_type } @@ -765,6 +786,24 @@ class Resource(object): else: return self.properties + def get_count(self, env): + if self.resource_type == "OS::Heat::ResourceGroup": + if not env: + return 1 + env_params = env.parameters + count_param = get_param(self.properties["count"]) + count_value = env_params.get(count_param) if count_param else 1 + try: + return int(count_value) + except (ValueError, TypeError): + print( + ( + "WARNING: Invalid value for count parameter {}. Expected " + "an integer, but got {}. Defaulting to 1" + ).format(count_param, count_value) + ) + return 1 + @property def depends_on(self): """