test(roles): run molecule's check step before and after converge
Every role scenario with a converge now runs check right before it (a fresh host) and right after it (a configured host), and a script test fails a scenario without both. pihole and pve_lxc move their second check from after idempotence to after converge to match. The roles that failed under --check on a fresh host get the two allowed guards: cloudflared, docker, gitea, gitea_runner, traefik and user_management. ufw and fail2ban preview only a host where their package is installed, as their READMEs now say. Closes #134 Assisted-by: Claude Code
This commit is contained in:
1 parent
51b38211e7
commit
cf2286b7a7
56 files changed
+202
-35
No files matched your search
@@ -89,7 +89,7 @@ Change the registration scope of a registered runner: set `gitea_runner_registra
|
||||
|
||||
## Tests
|
||||
|
||||
The `default` molecule scenario runs in CI only, on two platforms: `${MOLECULE_IMAGE}` (Ubuntu 24.04) and `${MOLECULE_IMAGE_2604}` (Ubuntu 26.04). It runs without a Gitea server and without Docker: a stub `docker.service`, a stub runner binary and a seeded `.runner` stand in for them, and the downloads come from local `file://` URLs. It covers the converge with the prune timer and an update through `_binary_update` (and its idempotence), the rendered `config.yaml` and unit, the prune gate script, the count prune and the disk check against a stub `docker` CLI, turning the pressure prune off, a failed checksum that leaves the runner running, the input asserts, the CI refusal of a forced re-registration and the mint-before-drop order, and the remove path. Registration, the Docker install and the host packages of the host-executor label are not covered.
|
||||
The `default` molecule scenario runs in CI only, on two platforms: `${MOLECULE_IMAGE}` (Ubuntu 24.04) and `${MOLECULE_IMAGE_2604}` (Ubuntu 26.04). It runs without a Gitea server and without Docker: a stub `docker.service`, a stub runner binary and a seeded `.runner` stand in for them, and the downloads come from local `file://` URLs. It covers the converge with the prune timer and an update through `_binary_update` (and its idempotence), the rendered `config.yaml` and unit, the prune gate script, the count prune and the disk check against a stub `docker` CLI, turning the pressure prune off, a failed checksum that leaves the runner running, the input asserts, the CI refusal of a forced re-registration and the mint-before-drop order, and the remove path. Registration, the Docker install and the host packages of the host-executor label are not covered. It runs `check` before the converge (a fresh host) and after it (a configured host).
|
||||
|
||||
## Notes
|
||||
|
||||
@@ -101,4 +101,5 @@ The `default` molecule scenario runs in CI only, on two platforms: `${MOLECULE_I
|
||||
- The Docker prune units (`gitea-runner-docker-prune.{service,timer}`) are written only while `gitea_runner_docker_prune_enabled` is true. Setting it back to false leaves them in place: run `systemctl disable --now gitea-runner-docker-prune.timer` by hand. `gitea_runner_remove` deletes them, the pressure units and the prune scripts. A run skipped because a job was running is not retried until the next timer elapse: shorten `gitea_runner_docker_prune_schedule` (e.g. `*-*-* 04:30:00`) if that happens.
|
||||
- The pressure prune (`gitea-runner-docker-prune-pressure.{service,timer}`) runs once per check while usage is above the threshold; it has no low watermark, so usage that stays high needs a smaller count or a larger disk. A threshold set back to `0` stops its timer and removes its units and the disk check script. The age prunes and the count prune both apply: an image either one removes is gone.
|
||||
- The play fails when `gitea-runner` is not `active` after start.
|
||||
- Check mode: `--check` is the supported preview; a play-level `check_mode: true` is not supported. Under `--check`, the work directory ownership task is skipped when the runner group or user is new, and starting Docker when `docker.io` is not installed yet. When the systemd unit is new or would change, the start, the running check, the `Restart Gitea Runner` handler and the update swap are skipped.
|
||||
- `no_log` covers the token mint, the token fact and the registration command.
|
||||
@@ -4,3 +4,5 @@
|
||||
ansible.builtin.systemd:
|
||||
name: gitea-runner
|
||||
state: restarted
|
||||
# Under --check a new unit is only simulated, so systemd would not find it.
|
||||
when: not ansible_check_mode or __gitea_runner_unit_file | default({}) is not changed
|
||||
@@ -66,13 +66,16 @@ verifier:
|
||||
scenario:
|
||||
# molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the
|
||||
# container as soon as this scenario ends. After a local run, run `molecule destroy` yourself.
|
||||
# A check runs before the converge (fresh host) and after it (configured host).
|
||||
test_sequence:
|
||||
- dependency
|
||||
- cleanup
|
||||
- syntax
|
||||
- create
|
||||
- prepare
|
||||
- check
|
||||
- converge
|
||||
- check
|
||||
- idempotence
|
||||
- side_effect
|
||||
- verify
|
||||
|
||||
@@ -17,6 +17,10 @@
|
||||
owner: "{{ gitea_runner_user }}"
|
||||
group: "{{ gitea_runner_group }}"
|
||||
recurse: true
|
||||
# Under --check a new account is only simulated, so an existing directory cannot be chowned to it.
|
||||
when: >-
|
||||
not ansible_check_mode or
|
||||
(__gitea_runner_group_account | default({}) is not changed and __gitea_runner_user_account | default({}) is not changed)
|
||||
tags: [gitea_runner, configure]
|
||||
|
||||
- name: Check current runner registration file state
|
||||
@@ -62,6 +66,7 @@
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
register: __gitea_runner_unit_file
|
||||
tags: [gitea_runner, configure]
|
||||
|
||||
- name: Reload systemd
|
||||
@@ -76,6 +81,8 @@
|
||||
name: gitea-runner
|
||||
enabled: true
|
||||
state: started
|
||||
# Under --check a new unit is only simulated, so systemd would not find it.
|
||||
when: not ansible_check_mode or __gitea_runner_unit_file is not changed
|
||||
tags: [gitea_runner, configure]
|
||||
|
||||
- name: Check runner service status
|
||||
@@ -88,5 +95,8 @@
|
||||
- name: Fail if runner service is not running
|
||||
ansible.builtin.fail:
|
||||
msg: "Gitea runner service is not running"
|
||||
when: gitea_runner_service_status.status.ActiveState != "active"
|
||||
when:
|
||||
- gitea_runner_service_status.status.ActiveState != "active"
|
||||
# The start above is skipped under --check for a new unit.
|
||||
- not ansible_check_mode or __gitea_runner_unit_file | default({}) is not changed
|
||||
tags: [gitea_runner, configure, health]
|
||||
@@ -17,6 +17,7 @@
|
||||
name:
|
||||
- docker.io
|
||||
state: present
|
||||
register: __gitea_runner_docker_package
|
||||
tags: [gitea_runner, docker, install]
|
||||
|
||||
- name: Enable and start Docker
|
||||
@@ -25,6 +26,8 @@
|
||||
name: docker
|
||||
enabled: true
|
||||
state: started
|
||||
# Under --check a new package is only simulated, so there is no docker unit yet.
|
||||
when: not ansible_check_mode or __gitea_runner_docker_package is not changed
|
||||
tags: [gitea_runner, docker, install]
|
||||
|
||||
- name: Add the runner user to the docker group
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
ansible.builtin.group:
|
||||
name: "{{ gitea_runner_group }}"
|
||||
system: true
|
||||
register: __gitea_runner_group_account
|
||||
tags: [gitea_runner, prereqs, always]
|
||||
|
||||
- name: Ensure runner user exists
|
||||
@@ -16,6 +17,7 @@
|
||||
home: "{{ gitea_runner_home }}"
|
||||
create_home: true
|
||||
system: true
|
||||
register: __gitea_runner_user_account
|
||||
tags: [gitea_runner, prereqs, always]
|
||||
|
||||
- name: Check if runner is installed
|
||||
|
||||
@@ -54,7 +54,8 @@
|
||||
The runner was not stopped and still runs {{ gitea_runner_installed_version }}.
|
||||
tags: [gitea_runner, update]
|
||||
|
||||
# An include does not pass its tags on to the included tasks, hence apply.
|
||||
# An include does not pass its tags on to the included tasks, hence apply. Under --check a
|
||||
# new unit is only simulated, so the stop and start of the swap would not find it.
|
||||
- name: Swap in the staged runner binary
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino._binary_update
|
||||
@@ -66,6 +67,7 @@
|
||||
_binary_update_staged_path: "{{ gitea_runner_staged_binary }}"
|
||||
_binary_update_version_command: ["{{ gitea_runner_install_dir }}/gitea-runner", --version]
|
||||
_binary_update_expected_version: "{{ gitea_runner_version }}"
|
||||
when: not ansible_check_mode or __gitea_runner_unit_file | default({}) is not changed
|
||||
tags: [gitea_runner, update]
|
||||
|
||||
always:
|
||||
|
||||
Reference in new issue
Block a user