From c07471da124a6445bf0fd0377606b9a937109e79 Mon Sep 17 00:00:00 2001 From: Imran Iqbal Date: Tue, 6 Aug 2019 09:52:57 +0100 Subject: [PATCH] fix(libtofs): avoid using subpath by default * Only the `systemd-formula` uses these, so avoid for all other formulas --- docs/TOFS_pattern.rst | 3 ++- template/libtofs.jinja | 7 +++++-- template/subcomponent/config/file.sls | 3 ++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/docs/TOFS_pattern.rst b/docs/TOFS_pattern.rst index 1e9098ac..4fea5dda 100644 --- a/docs/TOFS_pattern.rst +++ b/docs/TOFS_pattern.rst @@ -493,7 +493,8 @@ For example, the following ``formula.component.config`` SLS: - mode: 644 - template: jinja - source: {{ files_switch(['formula.conf'], - lookup='formula' + lookup='formula', + use_subpath=True ) }} diff --git a/template/libtofs.jinja b/template/libtofs.jinja index 05fe09ab..3fad8b44 100644 --- a/template/libtofs.jinja +++ b/template/libtofs.jinja @@ -2,7 +2,8 @@ lookup=None, default_files_switch=['id', 'os_family'], indent_width=6, - v1_path_prefix='') %} + v1_path_prefix='', + use_subpath=False) %} {#- Returns a valid value for the "source" parameter of a "file.managed" state function. This makes easier the usage of the Template Override and @@ -19,6 +20,8 @@ * indent_witdh: indentation of the result value to conform to YAML * v1_path_prefix: (deprecated) only used for injecting a path prefix into the source, to support older TOFS configs + * use_subpath: defaults to `False` but if set, lookup the source file + recursively from the current state directory up to `tplroot` Example (based on a `tplroot` of `xxx`): @@ -66,7 +69,7 @@ {%- set path_prefix_exts = [''] %} {%- if v1_path_prefix != '' %} {%- do path_prefix_exts.append(v1_path_prefix) %} - {%- elif tplroot != tpldir %} + {%- elif use_subpath and tplroot != tpldir %} {#- Walk directory tree to find {{ files_dir }} #} {%- set subpath_parts = tpldir.lstrip(tplroot).lstrip('/').split('/') %} {%- for path in subpath_parts %} diff --git a/template/subcomponent/config/file.sls b/template/subcomponent/config/file.sls index 6aa532b9..8f845493 100644 --- a/template/subcomponent/config/file.sls +++ b/template/subcomponent/config/file.sls @@ -14,7 +14,8 @@ template-subcomponent-config-file-file-managed: file.managed: - name: {{ template.subcomponent.config }} - source: {{ files_switch(['subcomponent-example.tmpl'], - lookup='template-subcomponent-config-file-file-managed' + lookup='template-subcomponent-config-file-file-managed', + use_subpath=True ) }} - mode: 644