fix(roles): refresh apt in the docker and traefik scenarios and apply review round 2
The molecule images ship without apt lists, and --check does not refresh them, so the fresh-host check of docker and traefik could not find curl and wget. Their prepare now refreshes the cache, as pihole's and system_baseline's already do by installing fixtures. The sequence test gets its own class after the platform tests, the check-mode rule is split into guards and README, and the user_management comment sits on the task it explains. Assisted-by: Claude Code
This commit is contained in:
1 parent
3afff00b9b
commit
9ce0fbd433
5 files changed
+42
-30
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):
|
- **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
|
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.
|
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.** 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
|
`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
|
`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
|
registered result that is not changed). README: `--check` is the supported preview and a
|
||||||
a play-level `check_mode: true` is not supported. A role whose `--check` needs its package
|
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
|
installed says so in Notes and keeps the step; a role that cannot support check mode at all
|
||||||
all says why there and drops the step, with an exception in the test below. *Why:* check-mode
|
says why in Notes and drops the step, which also needs an exception in the test named below.
|
||||||
breakage is a frequent fix, and one guard pattern is reviewable. *Held:* Molecule for the run
|
*Why:* check-mode breakage is a frequent fix, and one guard pattern is reviewable. *Held:*
|
||||||
passing, `tests/scripts/test_run_molecule_scenarios.py` for the steps being there; review for
|
Molecule for the run passing, `tests/scripts/test_run_molecule_scenarios.py` for the steps
|
||||||
the guards.
|
being there; review for the guards.
|
||||||
|
|
||||||
## Roles calling roles
|
## Roles calling roles
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,12 @@
|
|||||||
docker_molecule_repo: /srv/docker-stub-repo
|
docker_molecule_repo: /srv/docker-stub-repo
|
||||||
docker_molecule_work: /var/tmp/docker-stub-work
|
docker_molecule_work: /var/tmp/docker-stub-work
|
||||||
tasks:
|
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
|
- name: Copy the repository builder
|
||||||
ansible.builtin.copy:
|
ansible.builtin.copy:
|
||||||
src: build-stub-repo.sh
|
src: build-stub-repo.sh
|
||||||
|
|||||||
@@ -14,6 +14,12 @@
|
|||||||
hosts: all
|
hosts: all
|
||||||
gather_facts: false
|
gather_facts: false
|
||||||
tasks:
|
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
|
- name: Create the unit drop-in directory
|
||||||
ansible.builtin.file:
|
ansible.builtin.file:
|
||||||
path: /etc/systemd/system/traefik.service.d
|
path: /etc/systemd/system/traefik.service.d
|
||||||
|
|||||||
@@ -14,11 +14,11 @@
|
|||||||
- item.state | default('present') == 'present'
|
- item.state | default('present') == 'present'
|
||||||
- not item.system | default(false)
|
- 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
|
- name: Read the existing users for the check-mode preview
|
||||||
ansible.builtin.getent:
|
ansible.builtin.getent:
|
||||||
database: passwd
|
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
|
- name: Enforce authorized_keys authoritatively
|
||||||
become: true
|
become: true
|
||||||
ansible.posix.authorized_key:
|
ansible.posix.authorized_key:
|
||||||
|
|||||||
@@ -395,25 +395,6 @@ class ScenarioPlatformsTest(unittest.TestCase):
|
|||||||
seen[name] = where
|
seen[name] = where
|
||||||
self.assertNotIn("destroy", data["scenario"]["test_sequence"], path)
|
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):
|
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
|
# the sweep of earlier runs filters by the key, the cleanup of this run by key and value
|
||||||
self.assertEqual(
|
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__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
Reference in new issue
Block a user