Skip to content

Commit

Permalink
feat: allow explicit specification of empty suites (i.e. name: '')
Browse files Browse the repository at this point in the history
* Empty suites are used to run all suites during the Travis run
* Before this, these were handled implicitly when they were set
  - E.g. `vault-formula` had 3 suites defined but all of them running
    for each instance
  • Loading branch information
myii committed Sep 27, 2019
1 parent 585ca2b commit 220eb4a
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 88 deletions.
82 changes: 43 additions & 39 deletions ssf/config/formulas.sls
Original file line number Diff line number Diff line change
Expand Up @@ -46,41 +46,44 @@ prepare-git-branch-for-{{ formula }}:
{%- for index in range(0, inspec_suites_kitchen | length) %}
{%- set suite = inspec_suites_kitchen[index] %}
{%- set dest_file = semrel_file_specs.dest_file | d(semrel_file ) %}
{%- if dest_file.startswith('formula/') %}
{#- Replace 'formula/' with the actual name of the formula #}
{%- set dest_file = '{0}/{1}'.format(semrel_formula, dest_file.split('/')[-1]) %}
{%- elif dest_file.startswith('inspec/') %}
{%- set inspec_tests_path_prefix = suite.verifier.inspec_tests_path_prefix %}
{%- set test_suite = suite.verifier.test_suite %}
{#- The test suite to use may be a different than the suite's name, so need to point to it accordingly #}
{%- if test_suite not in ['.', suite.name] %}
{%- set dest_file = '' %}
{%- else %}
{%- set dest_file = '{0}/{1}/{2}'.format(inspec_tests_path_prefix, suite.name, dest_file.split('/')[-1]) %}
{#- Only manage files for the suite if the `suite.name` is set #}
{#- Or if dealing with CI files (where an empty `suite.name` is actually used) #}
{%- if suite.name or dest_file in ['.cirrus.yml', '.travis.yml'] %}
{%- if dest_file.startswith('formula/') %}
{#- Replace 'formula/' with the actual name of the formula #}
{%- set dest_file = '{0}/{1}'.format(semrel_formula, dest_file.split('/')[-1]) %}
{%- elif dest_file.startswith('inspec/') %}
{%- set inspec_tests_path_prefix = suite.verifier.inspec_tests_path_prefix %}
{%- set test_suite = suite.verifier.test_suite %}
{#- The test suite to use may be a different than the suite's name, so need to point to it accordingly #}
{%- if test_suite not in ['.', suite.name] %}
{%- set dest_file = '' %}
{%- else %}
{%- set dest_file = '{0}/{1}/{2}'.format(inspec_tests_path_prefix, suite.name, dest_file.split('/')[-1]) %}
{%- endif %}
{%- endif %}
{%- endif %}
{%- set dest = '{0}/{1}/{2}'.format(ssf.formulas_path, formula, dest_file) %}
{#- Only run the states for each suite if the same template is being used for each file (in each suite) #}
{#- Furthermore, only continue if the `dest_file` has actually been set #}
{%- if dest_file and dest_file not in dest_file_done %}
{%- do dest_file_done.append(dest_file) %}
{#- Add files by default #}
{%- set add_or_rm = ['add', 'add', 'managed'] %}
{#- Remove files if the file is `.cirrus.yml` and `use_cirrus_ci` is `False` #}
{#- Likewise, if running the state for TOFS files when `use_tofs` is `False` #}
{%- if (semrel_file == '.cirrus.yml' and not use_cirrus_ci) or
(semrel_file in ['docs/TOFS_pattern.rst', 'formula/libtofs.jinja'] and not use_tofs)
{%- set dest = '{0}/{1}/{2}'.format(ssf.formulas_path, formula, dest_file) %}
{#- Only run the states for each suite if the same template is being used for each file (in each suite) #}
{#- Furthermore, only continue if the `dest_file` has actually been set #}
{%- if dest_file and dest_file not in dest_file_done %}
{%- do dest_file_done.append(dest_file) %}
{#- Add files by default #}
{%- set add_or_rm = ['add', 'add', 'managed'] %}
{#- Remove files if the file is `.cirrus.yml` and `use_cirrus_ci` is `False` #}
{#- Likewise, if running the state for TOFS files when `use_tofs` is `False` #}
{%- if (semrel_file == '.cirrus.yml' and not use_cirrus_ci) or
(semrel_file in ['docs/TOFS_pattern.rst', 'formula/libtofs.jinja'] and not use_tofs)
%}
{%- set add_or_rm = ['rm', 'remove', 'absent'] %}
{%- endif %}
{%- set add_or_rm = ['rm', 'remove', 'absent'] %}
{%- endif %}
{#- Stage 2: Add or remove the file as necessary #}
{#- Stage 2: Add or remove the file as necessary #}
{{ add_or_rm[1] }}-{{ formula }}-{{ dest_file }}:
file.{{ add_or_rm[2] }}:
- name: {{ dest }}
{#- The rest of the settings only apply when adding files #}
{%- if add_or_rm[0] == 'add' %}
{#- The rest of the settings only apply when adding files #}
{%- if add_or_rm[0] == 'add' %}
- source: {{ files_switch([semrel_file],
default_files_switch=[formula_tofs_dir]
)
Expand All @@ -90,11 +93,11 @@ prepare-git-branch-for-{{ formula }}:
- group: {{ ssf.group }}
- makedirs: True
- template: {{ template }}
{#- Only send the `context` if a file template is being used #}
{%- if template %}
{#- Only send the `context` if a file template is being used #}
{%- if template %}
- context:
{#- Using `| yaml` since `| json` (and `| tojson`) end up quoting the indexing for `inspec_suites_kitchen` #}
{#- Maintaining the rest for consistency #}
{#- Using `| yaml` since `| json` (and `| tojson`) end up quoting the indexing for `inspec_suites_kitchen` #}
{#- Maintaining the rest for consistency #}
tplroot: {{ tplroot }}
semrel_formula: {{ semrel_file_specs.alt_semrel_formula | d(semrel_formula) }}
formula: {{ formula }}
Expand All @@ -108,25 +111,26 @@ prepare-git-branch-for-{{ formula }}:
travis: {{ context.travis | yaml }}
use_cirrus_ci: {{ use_cirrus_ci }}
yamllint: {{ context.yamllint | yaml }}
{%- endif %}
{%- if ssf.git.states.prepare.active %}
{%- endif %}
{%- if ssf.git.states.prepare.active %}
- require:
- cmd: prepare-git-branch-for-{{ formula }}
{%- endif %}
{%- endif %}
{%- endif %}
{%- if ssf.git.states.add_rm.active %}
{%- if ssf.git.states.add_rm.active %}
cmd.run:
- name: |
git {{ add_or_rm[0] }} {{ dest_file }}
- cwd: {{ ssf.formulas_path }}/{{ formula }}/
- runas: {{ ssf.user }}
- onchanges:
- file: {{ add_or_rm[1] }}-{{ formula }}-{{ dest_file }}
{%- if ssf.git.states.commit_push.active %}
{%- if ssf.git.states.commit_push.active %}
- onchanges_in:
- cmd: commit-and-push-{{ formula }}
{%- endif %}
{%- endif %}
{%- endif %}
{%- endif %}
{%- endif %}
{#- [End] for index in range(0, inspec_suites_kitchen | length) #}
Expand Down
5 changes: 3 additions & 2 deletions ssf/files/default/kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,9 @@ verifier:
suites:
{%- for index in range(0, inspec_suites_kitchen | length) %}
{%- set suite = inspec_suites_kitchen[index] %}
{#- Do not include the suite if `includes: *includes_NONE` has been set #}
{%- if not (suite.includes and not suite.includes[0]) %}
{#- Only include the suite if the `suite.name` is set #}
{#- Furthermore, do not include if `includes: *includes_NONE` has been set #}
{%- if suite.name and not (suite.includes and not suite.includes[0]) %}
- name: {{ suite.name }}
{{- format_includes_excludes(suite, 'excludes') }}
{{- format_includes_excludes(suite, 'includes') }}
Expand Down
91 changes: 44 additions & 47 deletions ssf/libcimatrix.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -13,63 +13,60 @@
{#- Work through each inspec suite defined for the formula, ordered by the suite number #}
{%- for index in range(0, inspec_suites_kitchen | length) %}
{%- set suite = inspec_suites_kitchen[index] %}
{#- Prepare `includes` and `excludes` #}
{%- set suite_name = '' %}
{%- set includes = [] %}
{%- set excludes = [] %}
{#- Only continue if the `suite.name` is present in the given matrix #}
{%- if suite.name in inspec_suites_matrix %}
{%- set suite_name = suite.name %}
{%- set includes = suite.includes %}
{%- set excludes = suite.excludes %}
{%- endif %}
{%- set platform_and_suite_name = platform + [suite_name] %}
{%- set platform_and_suite_name = platform + [suite_name] %}
{#- Prevent using a `platform_and_suite_name` more than once #}
{#- I.e. In case suite_name resolves to `''` multiple times #}
{%- if platform_and_suite_name not in platform_and_suite_names_done %}
{%- do platform_and_suite_names_done.append(platform_and_suite_name) %}
{#- Only continue depending on an appropriate combination of `includes` and `excludes`: #}
{#- |---|-----|-----|--------| #}
{#- | # | inc | exc | result | #}
{#- |---|-----|-----|--------| #}
{#- | 1 | y | [] | TRUE | #}
{#- | 2 | y | n | TRUE | #}
{#- | 3 | y | y | TRUE | #}
{#- | 4 | [] | [] | TRUE | #}
{#- | 5 | [] | n | TRUE | #}
{#- | 6 | [] | y | FALSE | #}
{#- | 7 | n | [] | FALSE | #}
{#- | 8 | n | n | FALSE | #}
{#- | 9 | n | y | FALSE | #}
{#- |---|-----|-----|--------| #}
{%- if (platform in includes) or (not includes and platform not in excludes) %}
{#- Compare combined [platform] and [suite_name] to see if enabled in the matrix #}
{%- if platform_and_suite_name in platforms_matrix %}
{%- set comment = '' %}
{%- else %}
{%- set comment = '# ' %}
{%- endif %}
{#- Only add a prefix if suite_name is given #}
{%- set prefix = '' %}
{%- if suite_name %}
{%- set prefix = suite_name|replace('_', '-') ~ '-' %}
{%- endif %}
{#- This `if` block is temporary and should eventually be removed #}
{%- if old_ci_files and loop.index0 == 0 %}
{%- if semrel_formula == 'postgres' and os == 'ubuntu' and os_ver == 18.04 %}
{%- if platform_and_suite_name not in platform_and_suite_names_done %}
{%- do platform_and_suite_names_done.append(platform_and_suite_name) %}
{#- Only continue depending on an appropriate combination of `includes` and `excludes`: #}
{#- |---|-----|-----|--------| #}
{#- | # | inc | exc | result | #}
{#- |---|-----|-----|--------| #}
{#- | 1 | y | [] | TRUE | #}
{#- | 2 | y | n | TRUE | #}
{#- | 3 | y | y | TRUE | #}
{#- | 4 | [] | [] | TRUE | #}
{#- | 5 | [] | n | TRUE | #}
{#- | 6 | [] | y | FALSE | #}
{#- | 7 | n | [] | FALSE | #}
{#- | 8 | n | n | FALSE | #}
{#- | 9 | n | y | FALSE | #}
{#- |---|-----|-----|--------| #}
{%- if (platform in includes) or (not includes and platform not in excludes) %}
{#- Compare combined [platform] and [suite_name] to see if enabled in the matrix #}
{%- if platform_and_suite_name in platforms_matrix %}
{%- set comment = '' %}
{%- else %}
{%- set comment = '# ' %}
{%- endif %}
{#- Only add a prefix if suite_name is given #}
{%- set prefix = '' %}
{%- if suite_name %}
{%- set prefix = suite_name|replace('_', '-') ~ '-' %}
{%- endif %}
{#- This `if` block is temporary and should eventually be removed #}
{%- if old_ci_files and loop.index0 == 0 %}
{%- if semrel_formula == 'postgres' and os == 'ubuntu' and os_ver == 18.04 %}
# TODO: Re-enable this once the `systemd` service can be restarted reliably
{%- elif semrel_formula == 'openvpn' and os == 'fedora' and os_ver == 29 and salt_ver == 2018.3 and py_ver == 2 %}
{%- elif semrel_formula == 'openvpn' and os == 'fedora' and os_ver == 29 and salt_ver == 2018.3 and py_ver == 2 %}
# Currently fails with "Cipher 'AES-256-GCM' mode not supported"
{%- endif %}
{%- endif %}
{%- endif %}
{#- Concatenate the `INSTANCE` #}
{%- set instance = '{0}{1}-{2}-{3}-py{4}'.format(
prefix,
os | replace('/', '-'),
os_ver | replace('.', ''),
salt_ver | replace('.', '-'),
py_ver,
) %}
{#- Concatenate the `INSTANCE` #}
{%- set instance = '{0}{1}-{2}-{3}-py{4}'.format(
prefix,
os | replace('/', '-'),
os_ver | replace('.', ''),
salt_ver | replace('.', '-'),
py_ver,
) %}
{{ comment }}- INSTANCE: {{ instance }}
{%- endif %}
{%- endif %}
{%- endif %}
{#- [End] for index in range(0, inspec_suites_kitchen | length) #}
Expand Down

0 comments on commit 220eb4a

Please sign in to comment.