Merge "Add support for network_data.yaml to process templates action"

This commit is contained in:
Jenkins 2017-02-23 17:06:30 +00:00 committed by Gerrit Code Review
commit 19ee9b6b8d
3 changed files with 33 additions and 7 deletions

View File

@ -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)

View File

@ -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"

View File

@ -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},
{'name': 'foo.j2.yaml'},
{'name': constants.OVERCLOUD_J2_ROLES_NAME}])
return ('headers', [
{'name': constants.OVERCLOUD_J2_NAME},
{'name': 'foo.j2.yaml'},
{'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},
{'name': 'disable-constraints.role.j2.yaml'},
{'name': constants.OVERCLOUD_J2_ROLES_NAME}])
return ('headers', [
{'name': constants.OVERCLOUD_J2_NAME},
{'name': 'disable-constraints.role.j2.yaml'},
{'name': constants.OVERCLOUD_J2_ROLES_NAME},
{'name': constants.OVERCLOUD_J2_NETWORKS_NAME}])
# setup swift
swift = mock.MagicMock()