Add support for network_data.yaml to process templates action
To enable rendering a list of networks we need to include an optional network_data.yaml file. We may make this mandatory in a future revision but since t-h-t doesn't yet contain this file we tolerate it being missing with a warning. Change-Id: I9f818912bd8e2a3220e41c8ccbbab3d9063b4d72 Partial-Bug: #1633090
This commit is contained in:
parent
a191504835
commit
d9b56b35db
|
@ -161,6 +161,16 @@ class ProcessTemplatesAction(base.TripleOAction):
|
|||
% constants.OVERCLOUD_J2_ROLES_NAME)
|
||||
return
|
||||
|
||||
try:
|
||||
j2_network_file = swift.get_object(
|
||||
self.container, constants.OVERCLOUD_J2_NETWORKS_NAME)[1]
|
||||
network_data = yaml.safe_load(j2_network_file)
|
||||
except swiftexceptions.ClientException:
|
||||
# Until t-h-t contains network_data.yaml we tolerate a missing file
|
||||
LOG.warning("No %s file found, ignoring"
|
||||
% constants.OVERCLOUD_J2_ROLES_NAME)
|
||||
network_data = []
|
||||
|
||||
j2_excl_data = self._get_j2_excludes_file()
|
||||
|
||||
try:
|
||||
|
@ -211,7 +221,7 @@ class ProcessTemplatesAction(base.TripleOAction):
|
|||
elif f.endswith('.j2.yaml'):
|
||||
LOG.info("jinja2 rendering %s" % f)
|
||||
j2_template = swift.get_object(self.container, f)[1]
|
||||
j2_data = {'roles': role_data}
|
||||
j2_data = {'roles': role_data, 'networks': network_data}
|
||||
out_f = f.replace('.j2.yaml', '.yaml')
|
||||
self._j2_render_and_put(j2_template, j2_data, out_f)
|
||||
|
||||
|
|
|
@ -23,6 +23,9 @@ OVERCLOUD_J2_NAME = "overcloud.j2.yaml"
|
|||
#: The name of custom roles data file used when rendering the jinja template.
|
||||
OVERCLOUD_J2_ROLES_NAME = "roles_data.yaml"
|
||||
|
||||
#: The name of custom roles network data file used when rendering j2 templates.
|
||||
OVERCLOUD_J2_NETWORKS_NAME = "network_data.yaml"
|
||||
|
||||
#: The name of custom roles excl file used when rendering the jinja template.
|
||||
OVERCLOUD_J2_EXCLUDES = "j2_excludes.yaml"
|
||||
|
||||
|
|
|
@ -40,6 +40,11 @@ ROLE_DATA_YAML = r"""
|
|||
name: CustomRole
|
||||
"""
|
||||
|
||||
NETWORK_DATA_YAML = r"""
|
||||
-
|
||||
name: anetwork
|
||||
"""
|
||||
|
||||
EXPECTED_JINJA_RESULT = r"""
|
||||
# Jinja loop for Role in role_data.yaml
|
||||
|
||||
|
@ -239,11 +244,15 @@ class ProcessTemplatesActionTest(base.TestCase):
|
|||
return ['', J2_EXCLUDES]
|
||||
elif args[1] == constants.OVERCLOUD_J2_ROLES_NAME:
|
||||
return ['', ROLE_DATA_YAML]
|
||||
elif args[1] == constants.OVERCLOUD_J2_NETWORKS_NAME:
|
||||
return ['', NETWORK_DATA_YAML]
|
||||
|
||||
def return_container_files(*args):
|
||||
return ('headers', [{'name': constants.OVERCLOUD_J2_NAME},
|
||||
return ('headers', [
|
||||
{'name': constants.OVERCLOUD_J2_NAME},
|
||||
{'name': 'foo.j2.yaml'},
|
||||
{'name': constants.OVERCLOUD_J2_ROLES_NAME}])
|
||||
{'name': constants.OVERCLOUD_J2_ROLES_NAME},
|
||||
{'name': constants.OVERCLOUD_J2_NETWORKS_NAME}])
|
||||
|
||||
# setup swift
|
||||
swift = mock.MagicMock()
|
||||
|
@ -289,11 +298,15 @@ class ProcessTemplatesActionTest(base.TestCase):
|
|||
return ['', J2_EXCLUDES]
|
||||
elif args[1] == constants.OVERCLOUD_J2_ROLES_NAME:
|
||||
return ['', ROLE_DATA_DISABLE_CONSTRAINTS_YAML]
|
||||
elif args[1] == constants.OVERCLOUD_J2_NETWORKS_NAME:
|
||||
return ['', NETWORK_DATA_YAML]
|
||||
|
||||
def return_container_files(*args):
|
||||
return ('headers', [{'name': constants.OVERCLOUD_J2_NAME},
|
||||
return ('headers', [
|
||||
{'name': constants.OVERCLOUD_J2_NAME},
|
||||
{'name': 'disable-constraints.role.j2.yaml'},
|
||||
{'name': constants.OVERCLOUD_J2_ROLES_NAME}])
|
||||
{'name': constants.OVERCLOUD_J2_ROLES_NAME},
|
||||
{'name': constants.OVERCLOUD_J2_NETWORKS_NAME}])
|
||||
|
||||
# setup swift
|
||||
swift = mock.MagicMock()
|
||||
|
|
Loading…
Reference in New Issue