test(roles): run molecule's check step before and after converge #395
No files matched your search
+10
-10
@@ -95,16 +95,16 @@ names a check that does not exist yet and its backlog issue.
|
||||
- **Negative tests.** Every validation has one in `verify.yml` (or a file it includes):
|
||||
block/rescue/assert matching the expected error message, run last or failing before any
|
||||
change. *Why:* a bare "it failed" passes for the wrong error. *Held:* review.
|
||||
- **Check mode.** Every scenario runs `check` before and after converge. The only guards are
|
||||
`check_mode: false` on read-only probes and `when: not ansible_check_mode`, alone or as
|
||||
`not ansible_check_mode or <condition>` where the condition shows the task can run, such as a
|
||||
registered result that is not changed; `--check` is the supported preview, and the README says
|
||||
a play-level `check_mode: true` is not supported. A role whose `--check` needs its package
|
||||
installed says so in README Notes and keeps the step; a role that cannot support check mode at
|
||||
all says why there and drops the step, with an exception in the test below. *Why:* check-mode
|
||||
breakage is a frequent fix, and one guard pattern is reviewable. *Held:* Molecule for the run
|
||||
passing, `tests/scripts/test_run_molecule_scenarios.py` for the steps being there; review for
|
||||
the guards.
|
||||
- **Check mode.** Every scenario runs `check` before and after converge. Guards:
|
||||
`check_mode: false` on read-only probes, and `when: not ansible_check_mode`, alone or as
|
||||
`not ansible_check_mode or <condition>` where the condition shows the task can run (such as a
|
||||
registered result that is not changed). README: `--check` is the supported preview and a
|
||||
play-level `check_mode: true` is not supported; a role whose `--check` needs its package
|
||||
installed says so in Notes and keeps the step; a role that cannot support check mode at all
|
||||
says why in Notes and drops the step, which also needs an exception in the test named below.
|
||||
*Why:* check-mode breakage is a frequent fix, and one guard pattern is reviewable. *Held:*
|
||||
Molecule for the run passing, `tests/scripts/test_run_molecule_scenarios.py` for the steps
|
||||
being there; review for the guards.
|
||||
|
||||
## Roles calling roles
|
||||
|
||||
|
||||
@@ -12,6 +12,12 @@
|
||||
docker_molecule_repo: /srv/docker-stub-repo
|
||||
docker_molecule_work: /var/tmp/docker-stub-work
|
||||
tasks:
|
||||
# The image ships without apt lists, and --check does not refresh them, so the fresh-host
|
||||
# check finds the packages the role installs.
|
||||
- name: Refresh the apt cache
|
||||
ansible.builtin.apt:
|
||||
update_cache: true
|
||||
|
||||
- name: Copy the repository builder
|
||||
ansible.builtin.copy:
|
||||
src: build-stub-repo.sh
|
||||
|
||||
@@ -14,6 +14,12 @@
|
||||
hosts: all
|
||||
gather_facts: false
|
||||
tasks:
|
||||
# The image ships without apt lists, and --check does not refresh them, so the fresh-host
|
||||
# check finds the packages the role installs.
|
||||
- name: Refresh the apt cache
|
||||
ansible.builtin.apt:
|
||||
update_cache: true
|
||||
|
||||
- name: Create the unit drop-in directory
|
||||
ansible.builtin.file:
|
||||
path: /etc/systemd/system/traefik.service.d
|
||||
|
||||
@@ -14,11 +14,11 @@
|
||||
- item.state | default('present') == 'present'
|
||||
- not item.system | default(false)
|
||||
|
||||
# Under --check a user the role would create does not exist yet, and authorized_key fails on a missing user.
|
||||
- name: Read the existing users for the check-mode preview
|
||||
ansible.builtin.getent:
|
||||
database: passwd
|
||||
|
||||
# Under --check a user the role would create does not exist yet, and authorized_key fails on a missing user.
|
||||
- name: Enforce authorized_keys authoritatively
|
||||
become: true
|
||||
ansible.posix.authorized_key:
|
||||
|
||||
@@ -395,25 +395,6 @@ class ScenarioPlatformsTest(unittest.TestCase):
|
||||
seen[name] = where
|
||||
self.assertNotIn("destroy", data["scenario"]["test_sequence"], path)
|
||||
|
||||
|
||||
class ScenarioSequenceTest(unittest.TestCase):
|
||||
"""A role scenario previews the fresh host and the configured host with molecule's check step."""
|
||||
|
||||
def test_role_scenarios_run_check_before_and_after_converge(self):
|
||||
# A check-only scenario has no converge to surround, so it is not held to this.
|
||||
files = sorted(REPO.glob("roles/*/molecule/*/molecule.yml"))
|
||||
self.assertTrue(files)
|
||||
for path in files:
|
||||
sequence = yaml.safe_load(path.read_text())["scenario"]["test_sequence"]
|
||||
if "converge" not in sequence:
|
||||
continue
|
||||
at = sequence.index("converge")
|
||||
self.assertEqual(
|
||||
sequence[at - 1 : at + 3],
|
||||
["check", "converge", "check", "idempotence"],
|
||||
path.relative_to(REPO),
|
||||
)
|
||||
|
||||
def test_the_workflow_finds_the_containers_by_the_run_label(self):
|
||||
# the sweep of earlier runs filters by the key, the cleanup of this run by key and value
|
||||
self.assertEqual(
|
||||
@@ -435,5 +416,24 @@ class ScenarioSequenceTest(unittest.TestCase):
|
||||
)
|
||||
|
||||
|
||||
class ScenarioSequenceTest(unittest.TestCase):
|
||||
"""A role scenario previews the fresh host and the configured host with molecule's check step."""
|
||||
|
||||
def test_role_scenarios_run_check_before_and_after_converge(self):
|
||||
# A check-only scenario has no converge to surround, so it is not held to this.
|
||||
files = sorted(REPO.glob("roles/*/molecule/*/molecule.yml"))
|
||||
self.assertTrue(files)
|
||||
for path in files:
|
||||
sequence = yaml.safe_load(path.read_text())["scenario"]["test_sequence"]
|
||||
if "converge" not in sequence:
|
||||
continue
|
||||
at = sequence.index("converge")
|
||||
self.assertEqual(
|
||||
sequence[at - 1 : at + 3],
|
||||
["check", "converge", "check", "idempotence"],
|
||||
path.relative_to(REPO),
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user