diff --git a/tripleo_common/actions/templates.py b/tripleo_common/actions/templates.py index 3ea15c0ff..2d850a583 100644 --- a/tripleo_common/actions/templates.py +++ b/tripleo_common/actions/templates.py @@ -102,6 +102,14 @@ class ProcessTemplatesAction(base.TripleOAction): LOG.info("No %s file found, skipping jinja templating" % constants.OVERCLOUD_J2_ROLES_NAME) return + # FIXME: Check the default list of excluded template roles + # this list should be created using the content of + # j2_excludes.yaml + j2_excl_data = {"name": ["puppet/controller-role.yaml", + "puppet/compute-role.yaml", + "puppet/blockstorage-role.yaml", + "puppet/objectstorage-role.yaml", + "puppet/cephstorage-role.yaml"]} try: # Iterate over all files in the plan container @@ -114,6 +122,8 @@ class ProcessTemplatesAction(base.TripleOAction): raise Exception(error_msg) role_names = [r.get('name') for r in role_data] + excl_templates = j2_excl_data.get('name') + for f in [f.get('name') for f in container_files[1]]: # We do two templating passes here: # 1. *.role.j2.yaml - we template just the role name @@ -123,7 +133,8 @@ class ProcessTemplatesAction(base.TripleOAction): if f.endswith('.role.j2.yaml'): LOG.info("jinja2 rendering role template %s" % f) j2_template = swift.get_object(self.container, f)[1] - LOG.info("jinja2 rendering roles %s" % ",".join(role_names)) + LOG.info("jinja2 rendering roles %s" % "," + .join(role_names)) for role in role_names: j2_data = {'role': role} LOG.info("jinja2 rendering role %s" % role) @@ -132,7 +143,14 @@ class ProcessTemplatesAction(base.TripleOAction): os.path.basename(f).replace('.role.j2.yaml', '.yaml')]) out_f_path = os.path.join(os.path.dirname(f), out_f) - self._j2_render_and_put(j2_template, j2_data, out_f_path) + if not (out_f_path in excl_templates): + self._j2_render_and_put(j2_template, + j2_data, + out_f_path) + else: + LOG.info("Skipping rendering of %s, defined in %s" % + (out_f_path, j2_excl_data)) + elif f.endswith('.j2.yaml'): LOG.info("jinja2 rendering %s" % f) j2_template = swift.get_object(self.container, f)[1] diff --git a/tripleo_common/constants.py b/tripleo_common/constants.py index 9dfd9ae31..724c805c6 100644 --- a/tripleo_common/constants.py +++ b/tripleo_common/constants.py @@ -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 excl file used when rendering the jinja template. +OVERCLOUD_J2_EXCLUDES = "j2_excludes.yaml" + #: The name of the type for resource groups. RESOURCE_GROUP_TYPE = 'OS::Heat::ResourceGroup' diff --git a/tripleo_common/tests/actions/test_templates.py b/tripleo_common/tests/actions/test_templates.py index 5b07b7857..69bf6ea02 100644 --- a/tripleo_common/tests/actions/test_templates.py +++ b/tripleo_common/tests/actions/test_templates.py @@ -36,18 +36,18 @@ JINJA_SNIPPET = """ ROLE_DATA_YAML = """ - - name: Controller + name: CustomRole """ EXPECTED_JINJA_RESULT = """ # Jinja loop for Role in role_data.yaml - # Resources generated for Controller Role - ControllerServiceChain: + # Resources generated for CustomRole Role + CustomRoleServiceChain: type: OS::TripleO::Services properties: Services: - get_param: ControllerServices + get_param: CustomRoleServices ServiceNetMap: {get_attr: [ServiceNetMap, service_net_map]} EndpointMap: {get_attr: [EndpointMap, endpoint_map]} DefaultPasswords: {get_attr: [DefaultPasswords, passwords]} @@ -59,6 +59,15 @@ outputs: description: The software config which runs puppet on the {{role}} role value: {get_resource: {{role}}PuppetConfigImpl}""" +J2_EXCLUDES = """ +name: + - puppet/controller-role.yaml + - puppet/compute-role.yaml + - puppet/blockstorage-role.yaml + - puppet/objectstorage-role.yaml + - puppet/cephstorage-role.yaml +""" + class UploadTemplatesActionTest(base.TestCase): @@ -138,6 +147,8 @@ class ProcessTemplatesActionTest(base.TestCase): return ['', JINJA_SNIPPET] if args[1] == 'foo.j2.yaml': return ['', JINJA_SNIPPET] + if args[1] == constants.OVERCLOUD_J2_EXCLUDES: + return ['', J2_EXCLUDES] elif args[1] == constants.OVERCLOUD_J2_ROLES_NAME: return ['', ROLE_DATA_YAML] @@ -189,9 +200,9 @@ class ProcessTemplatesActionTest(base.TestCase): # Test action = templates.ProcessTemplatesAction() action._j2_render_and_put(JINJA_SNIPPET_CONFIG, - {'role': 'Controller'}, - 'controller-config.yaml') + {'role': 'CustomRole'}, + 'customrole-config.yaml') action_result = swift.put_object._mock_mock_calls[0] - self.assertTrue("Controller" in str(action_result)) + self.assertTrue("CustomRole" in str(action_result))