aboutsummaryrefslogtreecommitdiffstats
path: root/tripleo_heat_templates
diff options
context:
space:
mode:
authorBen Nemec <bnemec@redhat.com>2017-05-18 15:38:22 -0500
committerBen Nemec <bnemec@redhat.com>2017-06-12 15:02:50 -0500
commit8d086b171099f0a968f1fdd1b39706ec64a52f56 (patch)
tree33206165ab8b6d88f367738daae2da4c17266078 /tripleo_heat_templates
parent7613306b8cb67547cc9f0c56f9ba97a45a9e7f73 (diff)
Add storage sample environments
Starts converting storage-related sample environments to the tool, and adds a few new ones for demonstration purposes. This has required the addition of a new category of parameter overrides in the tool. There are some parameters that are part of the public API of roles that should not normally be included in a sample environment for that role. Examples are EndpointMap and ServiceNetMap. Those are both passed into most (all?) roles, but their template defaults are not useful (both default to {}). Unless we are explicitly creating a sample environment that overrides those defaults we don't want them included. Parameters such as RoleName and RoleParameters are similar. We can't change them because they are part of the composable roles interface and that would break any existing custom roles, but we don't really want them included normally either. It's possible these could be made completely private, but there have been some very preliminary discussions about generating role samples that might actually want to set them. In order to avoid issues with editing the unit test file in editors that strip trailing whitespace, the minor formatting bug where params like EndpointMap had a trailing space after the name has also been fixed. Change-Id: If11f30c734bfbc17d463a9890c736d7477186fb9
Diffstat (limited to 'tripleo_heat_templates')
-rwxr-xr-xtripleo_heat_templates/environment_generator.py40
-rw-r--r--tripleo_heat_templates/tests/test_environment_generator.py39
2 files changed, 66 insertions, 13 deletions
diff --git a/tripleo_heat_templates/environment_generator.py b/tripleo_heat_templates/environment_generator.py
index 659a7d57..b3e327f0 100755
--- a/tripleo_heat_templates/environment_generator.py
+++ b/tripleo_heat_templates/environment_generator.py
@@ -22,7 +22,7 @@ import yaml
_PARAM_FORMAT = u""" # %(description)s
%(mandatory)s# Type: %(type)s
- %(name)s: %(default)s
+ %(name)s:%(default)s
"""
_STATIC_MESSAGE_START = (
' # ******************************************************\n'
@@ -44,7 +44,14 @@ _FILE_HEADER = (
)
# Certain parameter names can't be changed, but shouldn't be shown because
# they are never intended for direct user input.
-_PRIVATE_OVERRIDES = ['server', 'servers', 'NodeIndex']
+_PRIVATE_OVERRIDES = ['server', 'servers', 'NodeIndex', 'DefaultPasswords']
+# Hidden params are not included by default when the 'all' option is used,
+# but can be explicitly included by referencing them in sample_defaults or
+# static. This allows us to generate sample environments using them when
+# necessary, but they won't be improperly included by accident.
+_HIDDEN_PARAMS = ['EndpointMap', 'RoleName', 'RoleParameters',
+ 'ServiceNetMap',
+ ]
def _create_output_dir(target_file):
@@ -64,6 +71,8 @@ def _generate_environment(input_env, parent_env=None):
env.update(input_env)
parameter_defaults = {}
param_names = []
+ sample_values = env.get('sample_values', {})
+ static_names = env.get('static', [])
for template_file, template_data in env['files'].items():
with open(template_file) as f:
f_data = yaml.safe_load(f)
@@ -71,6 +80,10 @@ def _generate_environment(input_env, parent_env=None):
parameter_defaults.update(f_params)
if template_data['parameters'] == 'all':
new_names = [k for k, v in f_params.items()]
+ for hidden in _HIDDEN_PARAMS:
+ if (hidden not in (static_names + sample_values.keys()) and
+ hidden in new_names):
+ new_names.remove(hidden)
else:
new_names = template_data['parameters']
missing_params = [name for name in new_names
@@ -82,7 +95,6 @@ def _generate_environment(input_env, parent_env=None):
env['name']))
param_names += new_names
- static_names = env.get('static', [])
static_defaults = {k: v for k, v in parameter_defaults.items()
if k in param_names and
k in static_names
@@ -93,7 +105,8 @@ def _generate_environment(input_env, parent_env=None):
not k.startswith('_') and
k not in static_names
}
- for k, v in env.get('sample_values', {}).items():
+
+ for k, v in sample_values.items():
if k in parameter_defaults:
parameter_defaults[k]['sample'] = v
if k in static_defaults:
@@ -108,17 +121,18 @@ def _generate_environment(input_env, parent_env=None):
default = '<None>'
if value.get('sample') is not None:
default = value['sample']
+ # We ultimately cast this to str for output anyway
+ default = str(default)
if default == '':
default = "''"
- try:
- # If the default value is something like %index%, yaml won't
- # parse the output correctly unless we wrap it in quotes.
- # However, not all default values can be wrapped so we need to
- # do it conditionally.
- if default.startswith('%'):
- default = "'%s'" % default
- except AttributeError:
- pass
+ # If the default value is something like %index%, yaml won't
+ # parse the output correctly unless we wrap it in quotes.
+ # However, not all default values can be wrapped so we need to
+ # do it conditionally.
+ if default.startswith('%'):
+ default = "'%s'" % default
+ if not default.startswith('\n'):
+ default = ' ' + default
values = {'name': name,
'type': value['type'],
diff --git a/tripleo_heat_templates/tests/test_environment_generator.py b/tripleo_heat_templates/tests/test_environment_generator.py
index d0a622da..f4c4cdbf 100644
--- a/tripleo_heat_templates/tests/test_environment_generator.py
+++ b/tripleo_heat_templates/tests/test_environment_generator.py
@@ -34,6 +34,10 @@ parameters:
default: 42
description: Bar description
type: number
+ EndpointMap:
+ default: {}
+ description: Parameter that should not be included by default
+ type: json
resources:
# None
'''
@@ -307,6 +311,41 @@ resource_registry:
OS::TripleO::FakeResource: fake-filename.yaml
''',
}),
+ ('basic-hidden',
+ {'template': basic_template,
+ 'exception': None,
+ 'input_file': '''environments:
+ -
+ name: basic
+ title: Basic Environment
+ description: Basic description
+ files:
+ foo.yaml:
+ parameters: all
+ sample_values:
+ EndpointMap: |-2
+
+ foo: bar
+''',
+ 'expected_output': '''# title: Basic Environment
+# description: |
+# Basic description
+parameter_defaults:
+ # Bar description
+ # Type: number
+ BarParam: 42
+
+ # Parameter that should not be included by default
+ # Type: json
+ EndpointMap:
+ foo: bar
+
+ # Foo description
+ # Type: string
+ FooParam: foo
+
+''',
+ }),
('missing-param',
{'template': basic_template,
'exception': RuntimeError,