diff options
author | 2019-07-30 08:50:48 -0700 | |
---|---|---|
committer | 2019-08-16 16:42:09 -0500 | |
commit | 940ae7b0283191d590de40b71a9136bebc80e83c (patch) | |
tree | 8924052bded9411f87212969e1e51ee388e2be20 /ice_validator/tests/structures.py | |
parent | 14c5243cbbb0652ee9ad99519d7d456f5a6c88f4 (diff) |
[VVP] Adding preload generation functionality
preload.py discovers and loads implementations of
AbstractPreloadGenerator from any module on sys.path prefixed with
preload_*
Initial support is provided for VNF-API and GR-API. The templates
will provide a guide for users to provide their values.
Known limitations:
- No support for Contrail. Preload will be created, but contrail
parameters will be skipped. This will be addressed in the future.
Issue-ID: VVP-227
Signed-off-by: stark, steven <steven.stark@att.com>
Change-Id: I081d50ac379062fbf1bffebd687e920220d32571
Signed-off-by: Lovett, Trevor <trevor.lovett@att.com>
Signed-off-by: Lovett, Trevor (tl2972) <tl2972@att.com>
Diffstat (limited to 'ice_validator/tests/structures.py')
-rw-r--r-- | ice_validator/tests/structures.py | 40 |
1 files changed, 33 insertions, 7 deletions
diff --git a/ice_validator/tests/structures.py b/ice_validator/tests/structures.py index 5e81587..12bfc63 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" @@ -606,19 +606,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 +637,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 +775,22 @@ 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): """ |