Files
Kamino/roles/gitea_runner/molecule/default/verify.yml
T
Defame1297 2e32016c43 ci(molecule): run Molecule from the ci image instead of the runner's venv
Pin molecule and its Docker driver in requirements-dev.txt and bake them,
with the driver's collection, into the ci image. The Molecule job runs
docker run on the pinned ci image with the Docker socket and the checkout
mounted at the same path, as the runner user. A pull request whose pins
differ from the image installs its own pins first, so a core bump runs its
scenarios on the new core. gitea_runner no longer installs the molecule
venv and collections.

Closes #225

Assisted-by: Claude Code
2026-11-24 07:14:19 +00:00

656 lines
28 KiB
YAML

---
- name: Verify the converged runner
hosts: all
gather_facts: false
tasks:
- name: Read config.yaml
ansible.builtin.slurp:
src: /var/lib/gitea-runner/config.yaml
register: gitea_runner_test_config_raw
- name: Parse config.yaml
ansible.builtin.set_fact:
gitea_runner_test_config: "{{ gitea_runner_test_config_raw.content | b64decode | from_yaml }}"
# Only keys gitea-runner reads: an executor, engine, image, workdir or auto_remove key
# would be ignored by the runner and give a false picture.
- name: Config.yaml holds the inputs and nothing else
ansible.builtin.assert:
that:
- gitea_runner_test_config.keys() | sort == ['container', 'log', 'runner']
- "gitea_runner_test_config.log == {'level': 'debug'}"
- gitea_runner_test_config.runner.keys() | sort == ['capacity', 'labels']
- gitea_runner_test_config.runner.capacity == 2
- gitea_runner_test_config.runner.labels == ['molecule-docker:docker://ubuntu:24.04', 'molecule-shell:host']
- gitea_runner_test_config.container.keys() | sort == ['docker_host', 'privileged', 'volumes']
- gitea_runner_test_config.container.privileged is false
- gitea_runner_test_config.container.docker_host == '-'
- gitea_runner_test_config.container.volumes == ['/cache:/cache']
quiet: true
- name: Stat the registration file, the staged binary and the backup
ansible.builtin.stat:
path: "{{ gitea_runner_test_path }}"
loop:
- /var/lib/gitea-runner/.runner
- /usr/local/bin/gitea-runner.new
- /usr/local/bin/gitea-runner.bak
loop_control:
loop_var: gitea_runner_test_path
register: gitea_runner_test_files
- name: The registration is private to the runner user, and the update left nothing behind
ansible.builtin.assert:
that:
- gitea_runner_test_files.results[0].stat.mode == '0600'
- gitea_runner_test_files.results[0].stat.pw_name == 'gitea-runner'
- not gitea_runner_test_files.results[1].stat.exists
- not gitea_runner_test_files.results[2].stat.exists
quiet: true
- name: Ask the installed binary for its version
ansible.builtin.command:
argv: [/usr/local/bin/gitea-runner, --version]
register: gitea_runner_test_version
changed_when: false
- name: Ask systemd about the runner
ansible.builtin.systemd:
name: gitea-runner
register: gitea_runner_test_unit
# /proc/<pid> belongs to the user the process runs as.
- name: Read the owner of the runner's main process
ansible.builtin.stat:
path: "/proc/{{ gitea_runner_test_unit.status.MainPID }}"
register: gitea_runner_test_owner
- name: The update swapped in 6.0.1 and the runner runs it as its own user
ansible.builtin.assert:
that:
- "'v6.0.1' in gitea_runner_test_version.stdout"
- gitea_runner_test_unit.status.ActiveState == 'active'
- gitea_runner_test_unit.status.UnitFileState == 'enabled'
- gitea_runner_test_unit.status.ExecStart is search('/usr/local/bin/gitea-runner daemon --config /var/lib/gitea-runner/config.yaml')
- gitea_runner_test_owner.stat.pw_name == 'gitea-runner'
quiet: true
- name: Ask systemd about the prune timer
ansible.builtin.systemd:
name: gitea-runner-docker-prune.timer
register: gitea_runner_test_timer
- name: Read the prune service
ansible.builtin.slurp:
src: /etc/systemd/system/gitea-runner-docker-prune.service
register: gitea_runner_test_prune_service
- name: The prune timer is armed and the service carries the gate, the ages and the count
vars:
gitea_runner_test_prune_text: "{{ gitea_runner_test_prune_service.content | b64decode }}"
ansible.builtin.assert:
that:
- gitea_runner_test_timer.status.ActiveState == 'active'
- gitea_runner_test_timer.status.UnitFileState == 'enabled'
- "'ExecCondition=/usr/local/sbin/gitea-runner-docker-prune-gate 3600' in gitea_runner_test_prune_text"
- "'container prune --force --filter until=24h' in gitea_runner_test_prune_text"
- "'image prune --all --force --filter until=168h' in gitea_runner_test_prune_text"
- "'ExecStart=-/usr/local/sbin/gitea-runner-docker-prune-keep 2' in gitea_runner_test_prune_text"
quiet: true
- name: Ask systemd about the pressure prune timer
ansible.builtin.systemd:
name: gitea-runner-docker-prune-pressure.timer
register: gitea_runner_test_pressure_timer
- name: Read the pressure prune service
ansible.builtin.slurp:
src: /etc/systemd/system/gitea-runner-docker-prune-pressure.service
register: gitea_runner_test_pressure_service
- name: The pressure timer is armed and its service runs behind the gate and the disk check
vars:
gitea_runner_test_pressure_text: "{{ gitea_runner_test_pressure_service.content | b64decode }}"
ansible.builtin.assert:
that:
- gitea_runner_test_pressure_timer.status.ActiveState == 'active'
- gitea_runner_test_pressure_timer.status.UnitFileState == 'enabled'
- "'ExecCondition=/usr/local/sbin/gitea-runner-docker-prune-gate 3600' in gitea_runner_test_pressure_text"
- "'ExecCondition=/usr/local/sbin/gitea-runner-docker-prune-disk-check 90' in gitea_runner_test_pressure_text"
- "'ExecStart=-/usr/local/sbin/gitea-runner-docker-prune-keep 2' in gitea_runner_test_pressure_text"
- "'ExecStart=-/usr/bin/docker builder prune --force --keep-storage 10GB' in gitea_runner_test_pressure_text"
quiet: true
# The prune gate script against a stub docker CLI: no container, a young one (a job may be
# running), an old one (a leaked job container), and a failing docker ps. The stub answers
# `ps -q` from a file and `inspect` with a start time it computes from the container id.
- name: Verify the prune gate script
hosts: all
gather_facts: false
tasks:
- name: Stat the docker CLI
ansible.builtin.stat:
path: /usr/bin/docker
register: gitea_runner_test_docker_cli
- name: The image has no docker CLI the stub would replace
ansible.builtin.assert:
that: not gitea_runner_test_docker_cli.stat.exists
fail_msg: /usr/bin/docker exists in the test image; this play would overwrite it.
quiet: true
- name: Write the stub docker CLI
ansible.builtin.copy:
dest: /usr/bin/docker
mode: "0755"
content: |
#!/bin/sh
case "$1" in
ps) [ -e /tmp/molecule-docker-fail ] && exit 1; cat /tmp/molecule-docker-ids ;;
inspect)
case "$4" in
young) date -u +%Y-%m-%dT%H:%M:%SZ ;;
old) date -u -d '2 hours ago' +%Y-%m-%dT%H:%M:%SZ ;;
*) exit 1 ;;
esac ;;
*) exit 1 ;;
esac
- name: Run each gate case
ansible.builtin.shell:
cmd: |
rm -f /tmp/molecule-docker-fail
printf '%s' '{{ gitea_runner_test_case.ids }}' > /tmp/molecule-docker-ids
{{ 'touch /tmp/molecule-docker-fail' if gitea_runner_test_case.fail else ':' }}
/usr/local/sbin/gitea-runner-docker-prune-gate 3600
loop:
- {name: none, ids: "", fail: false, rc: 0, out: ""}
- {name: young, ids: "young", fail: false, rc: 1, out: "skipping the prune"}
- {name: old, ids: "old", fail: false, rc: 0, out: "ignoring container old"}
- {name: ps-fails, ids: "", fail: true, rc: 1, out: "docker ps failed"}
loop_control:
loop_var: gitea_runner_test_case
label: "{{ gitea_runner_test_case.name }}"
register: gitea_runner_test_gate
# The rc is the result under test; the next task asserts it.
failed_when: false
changed_when: false
- name: The gate let the prune run only when no young container ran
ansible.builtin.assert:
that:
- item.rc == item.gitea_runner_test_case.rc
- item.gitea_runner_test_case.out in item.stdout
fail_msg: "case {{ item.gitea_runner_test_case.name }}: rc {{ item.rc }}, output {{ item.stdout }}"
quiet: true
loop: "{{ gitea_runner_test_gate.results }}"
loop_control:
label: "{{ item.gitea_runner_test_case.name }}"
- name: Remove the stub docker CLI and its files
ansible.builtin.file:
path: "{{ gitea_runner_test_path }}"
state: absent
loop: [/usr/bin/docker, /tmp/molecule-docker-ids, /tmp/molecule-docker-fail]
loop_control:
loop_var: gitea_runner_test_path
# The count prune and the disk check against a stub docker CLI: it answers from the files below,
# records `rmi` calls, and a fail-<command> file makes that command fail. With N = 2, app keeps
# a1 (two tags: counted twice it would push a2 out), a2 and a4 (used by c1); lib keeps m1 though
# it is third in old; s3 (two tags) goes with --force; d1 goes, d2 (used by c2) stays.
- name: Verify the count prune and the disk check
hosts: all
gather_facts: false
vars:
gitea_runner_test_dir: /tmp/molecule-docker
tasks:
- name: Stat the docker CLI
ansible.builtin.stat:
path: /usr/bin/docker
register: gitea_runner_test_docker_cli
- name: The image has no docker CLI the stub would replace
ansible.builtin.assert:
that: not gitea_runner_test_docker_cli.stat.exists
fail_msg: /usr/bin/docker exists in the test image; this play would overwrite it.
quiet: true
- name: Create the stub's directory
ansible.builtin.file:
path: "{{ gitea_runner_test_dir }}"
state: directory
mode: "0755"
- name: Write the stub docker CLI
ansible.builtin.copy:
dest: /usr/bin/docker
mode: "0755"
content: |
#!/bin/sh
d={{ gitea_runner_test_dir }}
[ -e "$d/fail-$1" ] && exit 1
case "$1" in
image) cat "$d/images" ;;
ps) cat "$d/containers" ;;
container)
shift 4
for c in "$@"; do grep "^$c " "$d/container-images" | cut -d' ' -f2; done ;;
info) cat "$d/root" ;;
rmi) echo "$*" >> "$d/rmi" ;;
*) exit 1 ;;
esac
- name: Write the stub's images and containers
ansible.builtin.copy:
dest: "{{ gitea_runner_test_dir }}/{{ gitea_runner_test_fixture.name }}"
mode: "0644"
content: "{{ gitea_runner_test_fixture.content }}"
loop:
- name: images
content: |
sha256:a1 app 2026-01-05 10:00:00 +0000 UTC
sha256:a1 app 2026-01-05 10:00:00 +0000 UTC
sha256:a2 app 2026-01-04 10:00:00 +0000 UTC
sha256:a3 app 2026-01-03 10:00:00 +0000 UTC
sha256:a4 app 2026-01-02 10:00:00 +0000 UTC
sha256:a5 app 2026-01-01 10:00:00 +0000 UTC
sha256:m1 lib 2026-01-01 10:00:00 +0000 UTC
sha256:o1 old 2026-01-03 10:00:00 +0000 UTC
sha256:o2 old 2026-01-02 10:00:00 +0000 UTC
sha256:m1 old 2026-01-01 10:00:00 +0000 UTC
sha256:s1 stale 2026-01-03 10:00:00 +0000 UTC
sha256:s2 stale 2026-01-02 10:00:00 +0000 UTC
sha256:s3 stale 2026-01-01 10:00:00 +0000 UTC
sha256:s3 stale 2026-01-01 10:00:00 +0000 UTC
sha256:d1 <none> 2026-01-01 10:00:00 +0000 UTC
sha256:d2 <none> 2026-01-01 10:00:00 +0000 UTC
- name: containers
content: |
c1
c2
- name: container-images
content: |
c1 sha256:a4
c2 sha256:d2
loop_control:
loop_var: gitea_runner_test_fixture
label: "{{ gitea_runner_test_fixture.name }}"
- name: Run each count prune case
ansible.builtin.shell:
cmd: |
cd {{ gitea_runner_test_dir }} && rm -f rmi fail-*
{{ ('touch fail-' ~ gitea_runner_test_case.fail) if gitea_runner_test_case.fail else ':' }}
/usr/local/sbin/gitea-runner-docker-prune-keep {{ gitea_runner_test_case.keep }} >&2
rc=$?
[ -e rmi ] && LC_ALL=C sort rmi
exit "$rc"
loop:
- {name: keep-two, keep: 2, fail: "", rc: 0, rmi: [rmi --force sha256:s3, rmi sha256:a3, rmi sha256:a5, rmi sha256:d1]}
- {name: image-ls-fails, keep: 2, fail: image, rc: 1, rmi: []}
- {name: ps-fails, keep: 2, fail: ps, rc: 1, rmi: []}
- {name: inspect-fails, keep: 2, fail: container, rc: 1, rmi: []}
- {name: zero-count, keep: 0, fail: "", rc: 2, rmi: []}
loop_control:
loop_var: gitea_runner_test_case
label: "{{ gitea_runner_test_case.name }}"
register: gitea_runner_test_keep
# The rc and the rmi calls are the result under test; the next task asserts them.
failed_when: false
changed_when: false
- name: The count prune removed exactly the expected images, and nothing when a listing failed
ansible.builtin.assert:
that:
- item.rc == item.gitea_runner_test_case.rc
- item.stdout_lines == item.gitea_runner_test_case.rmi
fail_msg: "case {{ item.gitea_runner_test_case.name }}: rc {{ item.rc }}, rmi {{ item.stdout_lines }}, output {{ item.stderr }}"
quiet: true
loop: "{{ gitea_runner_test_keep.results }}"
loop_control:
label: "{{ item.gitea_runner_test_case.name }}"
# The above and at-use cases set the threshold one below and equal to the root's use, read
# just before (df rounds up, so a used root is at least 1%); /run/lock is never above 50%.
- name: Run each disk check case
ansible.builtin.shell:
cmd: |
cd {{ gitea_runner_test_dir }} && rm -f fail-*
{{ ('touch fail-' ~ gitea_runner_test_case.fail) if gitea_runner_test_case.fail else ':' }}
echo '{{ gitea_runner_test_case.root }}' > root
threshold={{ gitea_runner_test_case.threshold }}
{% if gitea_runner_test_case.threshold in ['below-use', 'use'] %}
df -P / > df-root && use=$(awk 'NR == 2 { sub(/%$/, "", $5); print $5 }' df-root)
threshold=$((use - {{ 1 if gitea_runner_test_case.threshold == 'below-use' else 0 }}))
{% endif %}
/usr/local/sbin/gitea-runner-docker-prune-disk-check "$threshold"
loop:
- {name: above, root: /, threshold: below-use, fail: "", rc: 0}
- {name: below, root: /run/lock, threshold: 50, fail: "", rc: 1, out: "% full, not above 50%: skipping the prune"}
- {name: at-use, root: /, threshold: use, fail: "", rc: 1, out: "not above"}
- {name: info-fails, root: /, threshold: below-use, fail: info, rc: 1}
- {name: root-missing, root: /nonexistent, threshold: 1, fail: "", rc: 1}
loop_control:
loop_var: gitea_runner_test_case
label: "{{ gitea_runner_test_case.name }}"
register: gitea_runner_test_pressure
# The rc is the result under test; the next task asserts it.
failed_when: false
changed_when: false
- name: The disk check let the pressure prune run only above the threshold
ansible.builtin.assert:
that:
- item.rc == item.gitea_runner_test_case.rc
- item.gitea_runner_test_case.out | default('') in item.stdout
fail_msg: "case {{ item.gitea_runner_test_case.name }}: rc {{ item.rc }}, output {{ item.stdout }} {{ item.stderr }}"
quiet: true
loop: "{{ gitea_runner_test_pressure.results }}"
loop_control:
label: "{{ item.gitea_runner_test_case.name }}"
- name: Remove the stub docker CLI and its files
ansible.builtin.file:
path: "{{ gitea_runner_test_path }}"
state: absent
loop: [/usr/bin/docker, "{{ gitea_runner_test_dir }}"]
loop_control:
loop_var: gitea_runner_test_path
# 6.0.2 has a wrong checksum file (prepare.yml): the download must fail before anything is
# stopped, so the runner keeps running 6.0.1.
- name: Verify a failed download leaves the runner running
hosts: all
gather_facts: false
tasks:
- name: Update to a release whose checksum does not match
block:
- name: Include the role with gitea_runner_version 6.0.2
ansible.builtin.include_role:
name: mortis.kamino.gitea_runner
vars:
gitea_runner_version: 6.0.2
- name: Fail because the include returned
ansible.builtin.fail:
msg: The role accepted a binary with a wrong checksum
rescue:
- name: The staging failed, and nothing else failed first
ansible.builtin.assert:
that:
- "'Staging gitea-runner 6.0.2 failed' in ansible_failed_result.msg"
- "'still runs 6.0.1' in ansible_failed_result.msg"
quiet: true
- name: Ask the installed binary for its version after the failed update
ansible.builtin.command:
argv: [/usr/local/bin/gitea-runner, --version]
register: gitea_runner_test_version
changed_when: false
- name: Ask systemd about the runner after the failed update
ansible.builtin.systemd:
name: gitea-runner
register: gitea_runner_test_unit
- name: Stat the staged binary after the failed update
ansible.builtin.stat:
path: /usr/local/bin/gitea-runner.new
register: gitea_runner_test_staged
- name: The runner still runs 6.0.1 and no staged file is left
ansible.builtin.assert:
that:
- "'v6.0.1' in gitea_runner_test_version.stdout"
- gitea_runner_test_unit.status.ActiveState == 'active'
- not gitea_runner_test_staged.stat.exists
quiet: true
# Each input assert, through the main entry point. Every one runs in validate.yml, before any
# change.
- name: Verify the input asserts
hosts: all
gather_facts: false
tasks:
- name: Run each refused input
ansible.builtin.include_tasks: tasks/refused_input.yml
loop:
- name: version with a leading v
vars: {gitea_runner_version: v6.0.1}
expect: plain release number
- name: scope with two slashes
vars: {gitea_runner_registration_scope: owner/repo/extra}
expect: gitea_runner_registration_scope must be empty
- name: prune schedule with a newline
vars: {gitea_runner_docker_prune_schedule: "daily\nExecStartPre=/bin/false"}
expect: gitea_runner_docker_prune_schedule must be a plain OnCalendar value
- name: prune age without a unit
vars: {gitea_runner_docker_prune_image_age: "168"}
expect: the two ages a number with s, m or h
- name: negative prune count
vars: {gitea_runner_docker_prune_keep_per_repository: -1}
expect: gitea_runner_docker_prune_keep_per_repository must be 0 (off) or more
- name: disk threshold of 100
vars: {gitea_runner_docker_prune_disk_threshold_percent: 100}
expect: gitea_runner_docker_prune_disk_threshold_percent must be 0 (off) or 1 to 99
- name: disk check schedule with a newline
vars: {gitea_runner_docker_prune_disk_check_schedule: "hourly\nExecStartPre=/bin/false"}
expect: gitea_runner_docker_prune_disk_check_schedule must be a plain OnCalendar value
- name: builder keep-storage with an extra argument
vars: {gitea_runner_docker_prune_builder_keep_storage: "10GB --all"}
expect: gitea_runner_docker_prune_builder_keep_storage must be a number
- name: disk threshold without a count
vars: {gitea_runner_docker_prune_keep_per_repository: 0}
expect: needs gitea_runner_docker_prune_keep_per_repository above 0
loop_control:
loop_var: gitea_runner_test_refused
label: "{{ gitea_runner_test_refused.name }}"
# The CI guard and the mint-before-drop order of a forced re-registration, through a child
# ansible-playbook against this instance (see force_register.yml). Neither case may touch the
# registration or stop the runner.
- name: Verify the forced re-registration guards
hosts: all
gather_facts: false
vars:
gitea_runner_test_inventory: "{{ lookup('ansible.builtin.env', 'MOLECULE_INVENTORY_FILE') }}"
gitea_runner_test_env_blank: {GITHUB_ACTIONS: "", GITEA_ACTIONS: "", CI: "", ANSIBLE_NOCOLOR: "1"}
tasks:
- name: Require the molecule inventory
ansible.builtin.assert:
that: gitea_runner_test_inventory | length > 0
fail_msg: MOLECULE_INVENTORY_FILE is not set, so the child play cannot reach this instance.
quiet: true
- name: Force a re-registration under each CI variable, as a child process with only that one set
delegate_to: localhost
ansible.builtin.command:
argv:
- ansible-playbook
- -i
- "{{ gitea_runner_test_inventory }}"
- --limit
- "{{ inventory_hostname }}"
- "{{ playbook_dir }}/force_register.yml"
environment: "{{ gitea_runner_test_env_blank | combine({item: 'true'}) }}"
loop:
- GITHUB_ACTIONS
- GITEA_ACTIONS
- CI
register: gitea_runner_test_ci
# The child is expected to fail (the CI guard fires). Its rc and output are asserted in the next task.
failed_when: false
changed_when: false
# Ansible 2.19 prints task failures to stderr, so both streams are checked.
- name: The CI guard fired for every variable
ansible.builtin.assert:
that:
- item.rc != 0
- "'refuses to run under CI' in (item.stdout ~ item.stderr)"
- "'Registration needs' not in (item.stdout ~ item.stderr)"
quiet: true
loop: "{{ gitea_runner_test_ci.results }}"
loop_control:
label: "{{ item.item }}"
- name: Force a re-registration outside CI with no token host, as a child process
delegate_to: localhost
ansible.builtin.command:
argv:
- ansible-playbook
- -i
- "{{ gitea_runner_test_inventory }}"
- --limit
- "{{ inventory_hostname }}"
- "{{ playbook_dir }}/force_register.yml"
environment: "{{ gitea_runner_test_env_blank }}"
register: gitea_runner_test_mint
# The child is expected to fail (the mint assert fires). Its rc and output are asserted below.
failed_when: false
changed_when: false
- name: The mint assert stopped it
ansible.builtin.assert:
that:
- gitea_runner_test_mint.rc != 0
- "'Registration needs gitea_runner_token_host' in (gitea_runner_test_mint.stdout ~ gitea_runner_test_mint.stderr)"
- "'refuses to run under CI' not in (gitea_runner_test_mint.stdout ~ gitea_runner_test_mint.stderr)"
quiet: true
- name: Read the registration after the forced runs
ansible.builtin.slurp:
src: /var/lib/gitea-runner/.runner
register: gitea_runner_test_registration
- name: Find registration backups
ansible.builtin.find:
paths: /var/lib/gitea-runner
patterns: ".runner.bak.*"
hidden: true
register: gitea_runner_test_backups
- name: Ask systemd about the runner after the forced runs
ansible.builtin.systemd:
name: gitea-runner
register: gitea_runner_test_unit
- name: The registration is untouched and the runner still runs
ansible.builtin.assert:
that:
- (gitea_runner_test_registration.content | b64decode | from_json) == gitea_runner_test_stand_in
quiet: true
vars:
gitea_runner_test_stand_in: {molecule: not a registration}
- name: No backup was taken and the runner still runs
ansible.builtin.assert:
that:
- gitea_runner_test_backups.files | length == 0
- gitea_runner_test_unit.status.ActiveState == 'active'
quiet: true
# A threshold of 0 removes the pressure units; the run after it, with the scenario's inputs,
# puts them back, so the remove path below still has them to remove.
- name: Verify turning the pressure prune off
hosts: all
gather_facts: false
tasks:
- name: Run the role with the disk threshold at 0
ansible.builtin.include_role:
name: mortis.kamino.gitea_runner
vars:
gitea_runner_docker_prune_disk_threshold_percent: 0
- name: Stat the pressure units and script
ansible.builtin.stat:
path: "{{ gitea_runner_test_path }}"
loop:
- /etc/systemd/system/gitea-runner-docker-prune-pressure.service
- /etc/systemd/system/gitea-runner-docker-prune-pressure.timer
- /usr/local/sbin/gitea-runner-docker-prune-disk-check
loop_control:
loop_var: gitea_runner_test_path
register: gitea_runner_test_pressure_off
- name: Ask systemd about the pressure timer after turning it off
ansible.builtin.systemd:
name: gitea-runner-docker-prune-pressure.timer
register: gitea_runner_test_pressure_timer_off
# The module errors for a unit that no longer exists, which is also a pass.
failed_when: false
- name: The pressure units are gone and the timer is not active
ansible.builtin.assert:
that:
- gitea_runner_test_pressure_off.results | map(attribute='stat') | map(attribute='exists') | select | list | length == 0
- gitea_runner_test_pressure_timer_off.status.ActiveState | default('inactive') != 'active'
quiet: true
- name: Run the role again with the scenario's inputs
ansible.builtin.include_role:
name: mortis.kamino.gitea_runner
- name: Ask systemd about the pressure timer after turning it on again
ansible.builtin.systemd:
name: gitea-runner-docker-prune-pressure.timer
register: gitea_runner_test_pressure_timer_on
- name: The pressure timer is armed again
ansible.builtin.assert:
that: gitea_runner_test_pressure_timer_on.status.ActiveState == 'active'
quiet: true
# The remove path. Last on purpose: it runs once, outside the idempotence step, and nothing runs
# after verify except molecule's own cleanup and destroy of the container. The download URL still
# points at a valid 6.0.1 release, so a role that went on to install after the removal would put
# the binary back; its absence shows the role ended after the removal.
- name: Verify the remove path
hosts: all
gather_facts: false
tasks:
- name: Run the role with the remove flags
ansible.builtin.include_role:
name: mortis.kamino.gitea_runner
vars:
gitea_runner_remove: true
gitea_runner_remove_data: true
- name: Stat what the removal deletes
ansible.builtin.stat:
path: "{{ gitea_runner_test_path }}"
loop:
- /etc/systemd/system/gitea-runner.service
- /usr/local/bin/gitea-runner
- /var/lib/gitea-runner
- /etc/systemd/system/gitea-runner-docker-prune.service
- /etc/systemd/system/gitea-runner-docker-prune.timer
- /usr/local/sbin/gitea-runner-docker-prune-gate
- /etc/systemd/system/gitea-runner-docker-prune-pressure.service
- /etc/systemd/system/gitea-runner-docker-prune-pressure.timer
- /usr/local/sbin/gitea-runner-docker-prune-keep
- /usr/local/sbin/gitea-runner-docker-prune-disk-check
- /etc/systemd/system/multi-user.target.wants/gitea-runner.service
loop_control:
loop_var: gitea_runner_test_path
register: gitea_runner_test_removed
- name: Ask systemd whether the runner and the timer are still active
ansible.builtin.systemd:
name: "{{ gitea_runner_test_unit_name }}"
loop: [gitea-runner, gitea-runner-docker-prune.timer, gitea-runner-docker-prune-pressure.timer]
loop_control:
loop_var: gitea_runner_test_unit_name
register: gitea_runner_test_after
# The module errors for a unit that no longer exists, which is also a pass.
failed_when: false
- name: Everything is gone, nothing was installed again, and nothing runs
ansible.builtin.assert:
that:
- gitea_runner_test_removed.results | map(attribute='stat') | map(attribute='exists') | select | list | length == 0
- >-
gitea_runner_test_after.results | map(attribute='status', default={})
| map(attribute='ActiveState', default='inactive') | select('equalto', 'active') | list | length == 0
quiet: true