From c4041256f3e81c69a8d02b41078ce0b33098f28a Mon Sep 17 00:00:00 2001 From: marios Date: Wed, 10 Jun 2015 17:26:27 +0300 Subject: [PATCH] Propagate default values for parameters from the master seed Some parameters like ServiceNetMap are defaulted in the master_seed template. If there is no default set for this parameter in any of the role templates where it is used, propagate the default value from the master_seed to that role (overcloud-without-mergepy.yaml). The default value is also included in the environment file Change-Id: I1ff97ccabf6be6afba03fc08f817c0d98f554ed2 --- tuskar/manager/plan.py | 5 ++++ tuskar/templates/template_seed.py | 41 +++++++++++++++++++++++++++++-- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/tuskar/manager/plan.py b/tuskar/manager/plan.py index d20672f..e835864 100644 --- a/tuskar/manager/plan.py +++ b/tuskar/manager/plan.py @@ -176,6 +176,8 @@ def _find_role_type(registry): master_seed, deployment_plan.master_template) template_seed.add_top_level_outputs( master_seed, deployment_plan.master_template) + template_seed.preserve_defaults( + master_seed, deployment_plan.master_template) if role_type is None: LOG.error( @@ -214,6 +216,9 @@ def _find_role_type(registry): additem = RegistryEntry(entry.alias, entry.filename) environment.add_registry_entry(additem, unique=True) + # similarly defaults from master_seed to to environment parameters + template_seed.preserve_defaults(master_seed, environment) + # Save the updated plan. updated = self._save_updated_plan(plan_uuid, deployment_plan) diff --git a/tuskar/templates/template_seed.py b/tuskar/templates/template_seed.py index 3d9109f..13a5b85 100644 --- a/tuskar/templates/template_seed.py +++ b/tuskar/templates/template_seed.py @@ -34,6 +34,7 @@ import copy import logging +from tuskar.templates.heat import Environment from tuskar.templates.heat import EnvironmentParameter from tuskar.templates.heat import Resource from tuskar.templates import namespace as ns_utils @@ -101,6 +102,32 @@ def add_top_level_parameters(source, destination, environment): environment.add_parameter(ep) +def preserve_defaults(source, destination): + """Preserve default values from the master_seed. + + For example ServiceNetMap has a default value specified in + overcloud-without-merge.py but is specified as {} in the role + templates. If the master default is not empty and the destination + value is empty, then propagate it. This is also applied to the + Environment file (hence, dp.default, vs dp.value) + """ + def _update_value(exists, dp): + if isinstance(destination, Environment): + if exists and exists.default and not dp.value: + dp.value = exists.default + else: + if exists and exists.default and not dp.default: + dp.default = exists.default + + for dp in destination.parameters: + try: + exists = source.find_parameter_by_name( + ns_utils.remove_template_namespace(dp.name)) + except ValueError: # non namespaced attributes + exists = source.find_parameter_by_name(dp.name) + _update_value(exists, dp) + + def add_top_level_outputs(source, destination): """Adds all top-level outputs from the source template into the given template. If the output is already in the destination, it will not be @@ -307,12 +334,22 @@ def _top_level_property_keys(keys, check_me): :type keys: list """ + # this is borked. consider the example: + # keystone_admin_api_vip: + # {get_attr: [VipMap, net_ip_map, { + # get_param: [ServiceNetMap, KeystoneAdminApiNetwork]}]} if isinstance(check_me, (dict, list)): - for pr in check_me: + if isinstance(check_me, list): + values = check_me + else: + values = check_me.values() + for pr in values: if isinstance(pr, dict): for k, v in pr.items(): - if k == 'get_param': + if k == 'get_param' and isinstance(v, str): keys.append(v) + elif k == 'get_param' and isinstance(v, list): + keys.append(v[0]) else: # It could be a nested dictionary, so recurse further _top_level_property_keys(keys, v)