Skip to content

Commit

Permalink
Propagate default values for parameters from the master seed
Browse files Browse the repository at this point in the history
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
  • Loading branch information
marios authored and Jay Dobies committed Jun 10, 2015
1 parent 2f0f31d commit c404125
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
5 changes: 5 additions & 0 deletions tuskar/manager/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)

Expand Down
41 changes: 39 additions & 2 deletions tuskar/templates/template_seed.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

0 comments on commit c404125

Please sign in to comment.