Skip to content

Commit

Permalink
Merge pull request #46 from myii/feat/prepare-for-splitting-suites-fo…
Browse files Browse the repository at this point in the history
…r-vault-formula

feat(vault): prepare for splitting suites for `vault-formula`
  • Loading branch information
myii authored Sep 27, 2019
2 parents 76ea081 + e093ea3 commit b41c5a9
Show file tree
Hide file tree
Showing 7 changed files with 378 additions and 364 deletions.
83 changes: 44 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 @@ -103,30 +106,32 @@ prepare-git-branch-for-{{ formula }}:
old_ci_files: {{ context.old_ci_files }}
platforms: {{ context.platforms | yaml }}
platforms_matrix: {{ context.platforms_matrix | yaml }}
platforms_matrix_commented_includes: {{ context.platforms_matrix_commented_includes | yaml }}
script_kitchen: {{ context.script_kitchen | yaml }}
suite: {{ suite | yaml }}
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
23 changes: 14 additions & 9 deletions ssf/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ ssf_node_anchors:
# only `includes` will be considered, mimicking `kitchen list`
# Note: This applies automatically via. `kitchen.yml`
# but is applied manually in the matrix (Travis/Cirrus)
# TODO: Use `kitchen list -b` output to define the matrix or too slow?
# Note: Cannot rely on `kitchen list` since there could end up being
# far too many entries (e.g. `vault-formula` & `iptables-formula`)
# Hence, the inclusion of `platforms_matrix_commented_includes`
# yamllint disable-line rule:line-length
# Ref: https://github.com/test-kitchen/test-kitchen/blob/7ce894e74f828f9e36531cf2d74588dd74fbf240/lib/kitchen/config.rb#L183-L193
excludes: []
Expand Down Expand Up @@ -112,14 +114,17 @@ ssf_node_anchors:
- [arch-base , latest, 2017.7, 2]
platforms_matrix:
# Comments in `platforms` apply here, too
# [os , os_ver, salt_ver, py_ver, inspec_suite]
- [debian , 10 , develop, 3, default]
- [ubuntu , 18.04, 2019.2, 3, default]
- [amazonlinux , 2 , 2019.2, 2, default]
- [arch-base , latest, 2019.2, 2, default]
- [fedora , 29 , 2018.3, 2, default]
- [opensuse/leap, 15 , 2018.3, 2, default]
- [centos , 6 , 2017.7, 2, default]
# [os , os_ver, salt_ver, py_ver, inspec_suite]
- [debian , 10 , develop, 3, default]
- [ubuntu , 18.04, 2019.2, 3, default]
- [amazonlinux , 2 , 2019.2, 2, default]
- [arch-base , latest, 2019.2, 2, default]
- [fedora , 29 , 2018.3, 2, default]
- [opensuse/leap, 15 , 2018.3, 2, default]
- [centos , 6 , 2017.7, 2, default]
# To deal with excessive instances when mimicking `kitchen list -b`
# If values are set, only use these as commented entries in the matrix
platforms_matrix_commented_includes: []
script_kitchen:
bin: bin/kitchen
cmd: verify
Expand Down
2 changes: 1 addition & 1 deletion ssf/files/default/.cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ docker_builder:
name: Test ${INSTANCE}
env:
matrix:
{{- format_ci_matrix(platforms, inspec_suites_kitchen, inspec_suites_matrix, platforms_matrix, semrel_formula, old_ci_files, width=6) }}
{{- format_ci_matrix(platforms, inspec_suites_kitchen, inspec_suites_matrix, platforms_matrix, platforms_matrix_commented_includes, semrel_formula, old_ci_files, width=6) }}
bundle_install_script: bundle install
verify_script:
{%- for pre_cmd in script_kitchen.pre %}
Expand Down
2 changes: 1 addition & 1 deletion ssf/files/default/.travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ env:
# However, the groupings needed to be maintained in some semblance of order
# so this is a best-effort matrix, in the circumstances
{%- endif %}
{{- format_ci_matrix(platforms, inspec_suites_kitchen, inspec_suites_matrix, platforms_matrix, semrel_formula, old_ci_files) }}
{{- format_ci_matrix(platforms, inspec_suites_kitchen, inspec_suites_matrix, platforms_matrix, platforms_matrix_commented_includes, semrel_formula, old_ci_files) }}

script:
{%- for pre_cmd in script_kitchen.pre %}
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
Loading

0 comments on commit b41c5a9

Please sign in to comment.