Skip to content

Commit

Permalink
test(jinja): add state files for testing known Jinja issues
Browse files Browse the repository at this point in the history
Check for problems associated with this bug:

* saltstack/salt#60188
  - Affects use of `grains`, `opts`, `pillar` & `salt` in Jinja.

Fix was first available in `3004`:

* saltstack/salt#60811

Use tests to apply the Jinja2 downgrade only where necessary
(and to ensure that it is actually working).
  • Loading branch information
myii committed Apr 3, 2022
1 parent bd8b022 commit e83078c
Show file tree
Hide file tree
Showing 15 changed files with 51 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ commitlint:
| tee -a ${PKGS_VERSIONS_FILE}'
- 'docker exec "${TESTINFRA_CONTAINER}" ${CMD_SALT_CALL_PIP_LIST}
| tee -a ${PKGS_VERSIONS_FILE}'
# Prepare the `test_jinja` state files
- 'docker exec "${TESTINFRA_CONTAINER}" mkdir -p /srv/salt/'
- 'docker cp test/test_jinja/ ${TESTINFRA_CONTAINER}:/srv/salt/test_jinja/'
# Run the integration tests
# Not using `${SVB}` instead of `${SV}` here since the test file itself handles
# the any version number issues (e.g. the extra `.0` in the version number).
Expand Down
4 changes: 2 additions & 2 deletions .yamllint
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
extends: 'default'

# Files to ignore completely
# 1. All YAML files under directory `node_modules/`, introduced during the Travis run
# 1. All YAML files under directory `node_modules/`, introduced during the CI run
# 2. Any SLS files under directory `test/`, which are actually state files
# 3. Any YAML files under directory `.kitchen/`, introduced during local testing
ignore: |
node_modules/
test/test_jinja/
.kitchen/
.travis.yml
yaml-files:
# Default settings
Expand Down
18 changes: 18 additions & 0 deletions test/integration/test_jinja.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
def test_jinja_grains(host):
cmd = host.run("salt-call --local state.sls test_jinja.grains")
assert cmd.rc == 0


def test_jinja_opts(host):
cmd = host.run("salt-call --local state.sls test_jinja.opts")
assert cmd.rc == 0


def test_jinja_pillar(host):
cmd = host.run("salt-call --local state.sls test_jinja.pillar")
assert cmd.rc == 0


def test_jinja_salt(host):
cmd = host.run("salt-call --local state.sls test_jinja.salt")
assert cmd.rc == 0
1 change: 1 addition & 0 deletions test/test_jinja/grains.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{%- import_yaml "./grains.yaml" as grains %}
5 changes: 5 additions & 0 deletions test/test_jinja/grains.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{%- from "test_jinja/grains.jinja" import grains with context %}
test_jinja/grains/cmd.run:
cmd.run:
- name: pwd
1 change: 1 addition & 0 deletions test/test_jinja/grains.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{%- set grains = grains.get('os', '') %}
1 change: 1 addition & 0 deletions test/test_jinja/opts.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{%- import_yaml "./opts.yaml" as opts %}
5 changes: 5 additions & 0 deletions test/test_jinja/opts.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{%- from "test_jinja/opts.jinja" import opts with context %}
test_jinja/opts/cmd.run:
cmd.run:
- name: pwd
1 change: 1 addition & 0 deletions test/test_jinja/opts.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{%- set opts = opts.get('__cli', '') %}
1 change: 1 addition & 0 deletions test/test_jinja/pillar.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{%- import_yaml "./pillar.yaml" as pillar %}
5 changes: 5 additions & 0 deletions test/test_jinja/pillar.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{%- from "test_jinja/pillar.jinja" import pillar with context %}
test_jinja/pillar/cmd.run:
cmd.run:
- name: pwd
1 change: 1 addition & 0 deletions test/test_jinja/pillar.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{%- set pillar = pillar.get('pillar', '') %}
1 change: 1 addition & 0 deletions test/test_jinja/salt.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{%- import_yaml "./salt.yaml" as salt %}
5 changes: 5 additions & 0 deletions test/test_jinja/salt.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{%- from "test_jinja/salt.jinja" import salt with context %}
test_jinja/salt/cmd.run:
cmd.run:
- name: pwd
1 change: 1 addition & 0 deletions test/test_jinja/salt.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{%- set salt = salt['pillar.get']('salt', '') %}

0 comments on commit e83078c

Please sign in to comment.