Skip to content

Commit 4b2d9e4

Browse files
authored
Merge pull request saltstack-formulas#150 from eole/bugfix/libtofs-crash-on-files_switch-lookup-list
Bugfix/libtofs crash on files switch lookup list
2 parents 57d0b85 + 0979d35 commit 4b2d9e4

File tree

5 files changed

+24
-10
lines changed

5 files changed

+24
-10
lines changed

kitchen.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,10 @@ provisioner:
124124
base:
125125
'*':
126126
- template
127+
- define_roles
127128
pillars_from_files:
128129
template.sls: pillar.example
130+
define_roles.sls: test/salt/pillar/define_roles.sls
129131

130132
verifier:
131133
# https://www.inspec.io/

pillar.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ template:
3333
files_switch:
3434
- any/path/can/be/used/here
3535
- id
36+
- roles
3637
- osfinger
3738
- os
3839
- os_family

template/libtofs.jinja

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,25 @@
8383
{%- for fs in fsl %}
8484
{%- for src_file in src_files %}
8585
{%- if fs %}
86-
{%- set fs_dir = salt['config.get'](fs, fs) %}
86+
{%- set fs_dirs = salt['config.get'](fs, fs) %}
8787
{%- else %}
88-
{%- set fs_dir = salt['config.get'](tplroot ~ ':tofs:dirs:default', 'default') %}
88+
{%- set fs_dirs = salt['config.get'](tplroot ~ ':tofs:dirs:default', 'default') %}
8989
{%- endif %}
90-
{%- set url = [
91-
'- salt:/',
92-
path_prefix_inc_ext.strip('/'),
93-
files_dir.strip('/'),
94-
fs_dir.strip('/'),
95-
src_file.strip('/'),
96-
] | select | join('/') %}
90+
{#- Force the `config.get` lookup result as a list where necessary #}
91+
{#- since we need to also handle grains that are lists #}
92+
{%- if fs_dirs is string %}
93+
{%- set fs_dirs = [fs_dirs] %}
94+
{%- endif %}
95+
{%- for fs_dir in fs_dirs %}
96+
{%- set url = [
97+
'- salt:/',
98+
path_prefix_inc_ext.strip('/'),
99+
files_dir.strip('/'),
100+
fs_dir.strip('/'),
101+
src_file.strip('/'),
102+
] | select | join('/') %}
97103
{{ url | indent(indent_width, true) }}
104+
{%- endfor %}
98105
{%- endfor %}
99106
{%- endfor %}
100107
{%- endfor %}

test/integration/default/controls/config_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
its('content') { should include '"lookup": {"added_in_lookup": "lookup_value",' }
1515
its('content') { should include '"pkg": {"name": "' }
1616
its('content') { should include '"service": {"name": "' }
17-
its('content') { should include '"tofs": {"files_switch": ["any/path/can/be/used/here", "id", "osfinger", "os", "os_family"], "source_files": {"template-config-file-file-managed": ["example.tmpl.jinja"]}' }
17+
its('content') { should include '"tofs": {"files_switch": ["any/path/can/be/used/here", "id", "roles", "osfinger", "os", "os_family"], "source_files": {"template-config-file-file-managed": ["example.tmpl.jinja"]}' }
1818
its('content') { should include '"winner": "pillar"}' }
1919
its('content') { should include 'winner of the merge: pillar' }
2020
end

test/salt/pillar/define_roles.sls

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# libtofs.jinja must work with tofs.files_switch looked up list
2+
roles:
3+
- foo
4+
- bar

0 commit comments

Comments
 (0)