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) % constants.OVERCLOUD_J2_ROLES_NAME)
return 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() j2_excl_data = self._get_j2_excludes_file()
try: try:
@ -211,7 +221,7 @@ class ProcessTemplatesAction(base.TripleOAction):
elif f.endswith('.j2.yaml'): elif f.endswith('.j2.yaml'):
LOG.info("jinja2 rendering %s" % f) LOG.info("jinja2 rendering %s" % f)
j2_template = swift.get_object(self.container, f)[1] 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') out_f = f.replace('.j2.yaml', '.yaml')
self._j2_render_and_put(j2_template, j2_data, out_f) 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. #: The name of custom roles data file used when rendering the jinja template.
OVERCLOUD_J2_ROLES_NAME = "roles_data.yaml" 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. #: The name of custom roles excl file used when rendering the jinja template.
OVERCLOUD_J2_EXCLUDES = "j2_excludes.yaml" OVERCLOUD_J2_EXCLUDES = "j2_excludes.yaml"

View File

@ -40,6 +40,11 @@ ROLE_DATA_YAML = r"""
name: CustomRole name: CustomRole
""" """
NETWORK_DATA_YAML = r"""
-
name: anetwork
"""
EXPECTED_JINJA_RESULT = r""" EXPECTED_JINJA_RESULT = r"""
# Jinja loop for Role in role_data.yaml # Jinja loop for Role in role_data.yaml
@ -239,11 +244,15 @@ class ProcessTemplatesActionTest(base.TestCase):
return ['', J2_EXCLUDES] return ['', J2_EXCLUDES]
elif args[1] == constants.OVERCLOUD_J2_ROLES_NAME: elif args[1] == constants.OVERCLOUD_J2_ROLES_NAME:
return ['', ROLE_DATA_YAML] return ['', ROLE_DATA_YAML]
elif args[1] == constants.OVERCLOUD_J2_NETWORKS_NAME:
return ['', NETWORK_DATA_YAML]
def return_container_files(*args): def return_container_files(*args):
return ('headers', [{'name': constants.OVERCLOUD_J2_NAME}, return ('headers', [
{'name': 'foo.j2.yaml'}, {'name': constants.OVERCLOUD_J2_NAME},
{'name': constants.OVERCLOUD_J2_ROLES_NAME}]) {'name': 'foo.j2.yaml'},
{'name': constants.OVERCLOUD_J2_ROLES_NAME},
{'name': constants.OVERCLOUD_J2_NETWORKS_NAME}])
# setup swift # setup swift
swift = mock.MagicMock() swift = mock.MagicMock()
@ -289,11 +298,15 @@ class ProcessTemplatesActionTest(base.TestCase):
return ['', J2_EXCLUDES] return ['', J2_EXCLUDES]
elif args[1] == constants.OVERCLOUD_J2_ROLES_NAME: elif args[1] == constants.OVERCLOUD_J2_ROLES_NAME:
return ['', ROLE_DATA_DISABLE_CONSTRAINTS_YAML] return ['', ROLE_DATA_DISABLE_CONSTRAINTS_YAML]
elif args[1] == constants.OVERCLOUD_J2_NETWORKS_NAME:
return ['', NETWORK_DATA_YAML]
def return_container_files(*args): def return_container_files(*args):
return ('headers', [{'name': constants.OVERCLOUD_J2_NAME}, return ('headers', [
{'name': 'disable-constraints.role.j2.yaml'}, {'name': constants.OVERCLOUD_J2_NAME},
{'name': constants.OVERCLOUD_J2_ROLES_NAME}]) {'name': 'disable-constraints.role.j2.yaml'},
{'name': constants.OVERCLOUD_J2_ROLES_NAME},
{'name': constants.OVERCLOUD_J2_NETWORKS_NAME}])
# setup swift # setup swift
swift = mock.MagicMock() swift = mock.MagicMock()