Sync template processing

tripleo-heat-templates and tripleo-common now both have their own code
for template processing as of Ie664c9c5f455b7320a58a26f35bc403355408d9b.

As the above commit mentions, this duplication should be refactored in
the future so these 2 processes can share the same code. In the short
term however, we need to keep these 2 in sync. This patch adds handling
of the disable_constraints logic to the tripleo-common code so that the
2 are in sync.

Partially-implements: blueprint split-stack-software-configuration
Change-Id: Id318d0bc3a6358749b7b83b16640012611f15c4f
This commit is contained in:
James Slagle 2016-12-22 10:31:35 -05:00
parent 8d5d00191c
commit 75a58a3556
2 changed files with 64 additions and 0 deletions

View File

@ -134,6 +134,9 @@ class ProcessTemplatesAction(base.TripleOAction):
raise Exception(error_msg)
role_names = [r.get('name') for r in role_data]
r_map = {}
for r in role_data:
r_map[r.get('name')] = r
excl_templates = j2_excl_data.get('name')
for f in [f.get('name') for f in container_files[1]]:
@ -150,6 +153,8 @@ class ProcessTemplatesAction(base.TripleOAction):
for role in role_names:
j2_data = {'role': role}
LOG.info("jinja2 rendering role %s" % role)
if r_map[role].get('disable_constraints', False):
j2_data['disable_constraints'] = True
out_f = "-".join(
[role.lower(),
os.path.basename(f).replace('.role.j2.yaml',

View File

@ -71,6 +71,27 @@ name:
J2_EXCLUDES_EMPTY_FILE = """
"""
ROLE_DATA_DISABLE_CONSTRAINTS_YAML = """
- name: RoleWithDisableConstraints
disable_constraints: True
"""
JINJA_SNIPPET_DISABLE_CONSTRAINTS = """
{{role}}Image:
type: string
default: overcloud-full
{% if disable_constraints is not defined %}
constraints:
- custom_constraint: glance.image
{% endif %}
"""
EXPECTED_JINJA_RESULT_DISABLE_CONSTRAINTS = """
RoleWithDisableConstraintsImage:
type: string
default: overcloud-full
"""
class UploadTemplatesActionTest(base.TestCase):
@ -190,6 +211,44 @@ class ProcessTemplatesActionTest(base.TestCase):
swift.put_object.assert_has_calls(
put_object_mock_calls, any_order=True)
@mock.patch('tripleo_common.actions.base.TripleOAction.get_object_client')
@mock.patch('mistral.context.ctx')
def test_process_custom_roles_disable_constraints(
self, ctx_mock, get_obj_client_mock):
def return_multiple_files(*args):
if args[1] == constants.OVERCLOUD_J2_NAME:
return ['', JINJA_SNIPPET_DISABLE_CONSTRAINTS]
if args[1] == 'disable-constraints.role.j2.yaml':
return ['', JINJA_SNIPPET_DISABLE_CONSTRAINTS]
if args[1] == constants.OVERCLOUD_J2_EXCLUDES:
return ['', J2_EXCLUDES]
elif args[1] == constants.OVERCLOUD_J2_ROLES_NAME:
return ['', ROLE_DATA_DISABLE_CONSTRAINTS_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}])
# setup swift
swift = mock.MagicMock()
swift.get_object = mock.MagicMock(side_effect=return_multiple_files)
swift.get_container = mock.MagicMock(
side_effect=return_container_files)
get_obj_client_mock.return_value = swift
# Test
action = templates.ProcessTemplatesAction()
action._process_custom_roles()
put_object_mock_call = mock.call(
constants.DEFAULT_CONTAINER_NAME,
"rolewithdisableconstraints-disable-constraints.yaml",
EXPECTED_JINJA_RESULT_DISABLE_CONSTRAINTS)
self.assertEqual(swift.put_object.call_args_list[1],
put_object_mock_call)
@mock.patch('tripleo_common.actions.base.TripleOAction.get_object_client')
@mock.patch('mistral.context.ctx')
def test_j2_render_and_put(self, ctx_mock, get_obj_client_mock):