feat(gitea_runner): add the gitea_runner role
Copied from the maintainer's local role and reworked for the Collection: the binary swap and rollback of an update go through the internal _binary_update role, input checks move to tasks/validate.yml, the removal ends the role, commands take argv, and the molecule tooling needs an explicit collections requirements file. Adds a molecule scenario with stub Docker, runner and release files. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MmzvM9skAvYcph2c9EiPcm
This commit is contained in:
1 parent
3ed614e00e
commit
e296eea609
28 files changed
+1988
-3
No files matched your search
@@ -0,0 +1,9 @@
|
||||
---
|
||||
# Role variables come from the inventory group_vars in molecule.yml. The first run updates the
|
||||
# stub runner from 6.0.0 to 6.0.1 through mortis.kamino._binary_update; the idempotence run finds
|
||||
# 6.0.1 and changes nothing.
|
||||
- name: Converge
|
||||
hosts: all
|
||||
gather_facts: true
|
||||
roles:
|
||||
- role: mortis.kamino.gitea_runner
|
||||
@@ -0,0 +1,16 @@
|
||||
---
|
||||
# Run by verify.yml in a child ansible-playbook process, because the CI guard reads the
|
||||
# controller's environment (lookup env), which a play cannot change; the child gets its
|
||||
# environment from the task that starts it, so the result does not depend on what the runner
|
||||
# exports. With a CI variable set it fails at the CI guard; with them blank it fails at the
|
||||
# registration inputs assert of the mint, because gitea_runner_token_host is empty. Either way
|
||||
# it must stop before the registration is backed up, stopped or removed.
|
||||
- name: Force a re-registration with a controlled environment
|
||||
hosts: all
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: Run the role with gitea_runner_force_register
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.gitea_runner
|
||||
vars:
|
||||
gitea_runner_force_register: true
|
||||
@@ -0,0 +1,62 @@
|
||||
---
|
||||
# Runs on the repository's own runner (label kamino-molecule), in the molecule-ubuntu2404 image
|
||||
# (MOLECULE_IMAGE, the pin in .gitea/workflows/molecule.yml). No Gitea server and no Docker
|
||||
# daemon: prepare.yml seeds a stub docker.service, a stub runner binary that reports an older
|
||||
# version, and a .runner file, so the role skips the Docker install and the registration, and
|
||||
# the update downloads its new stub from local file:// URLs. The scenario downloads nothing.
|
||||
# The container runs systemd as PID 1 with a writable cgroup; no privileged mode.
|
||||
driver:
|
||||
name: docker
|
||||
platforms:
|
||||
- name: runner-instance
|
||||
image: ${MOLECULE_IMAGE}
|
||||
pre_build_image: true
|
||||
pull: true
|
||||
command: /sbin/init
|
||||
cgroupns_mode: host
|
||||
volumes:
|
||||
- /sys/fs/cgroup:/sys/fs/cgroup:rw
|
||||
tmpfs:
|
||||
- /run
|
||||
- /run/lock
|
||||
security_opts:
|
||||
- apparmor=unconfined
|
||||
provisioner:
|
||||
name: ansible
|
||||
# One source for every play, so a verify play that runs the role again renders the same
|
||||
# configuration.
|
||||
inventory:
|
||||
group_vars:
|
||||
all:
|
||||
gitea_runner_update: true
|
||||
gitea_runner_download_url: "file:///opt/molecule-download/gitea-runner-{{ gitea_runner_version }}-linux-amd64"
|
||||
gitea_runner_checksum_url: "file:///opt/molecule-download/gitea-runner-{{ gitea_runner_version }}-linux-amd64.sha256"
|
||||
gitea_runner_log_level: debug
|
||||
gitea_runner_capacity: 2
|
||||
gitea_runner_labels:
|
||||
- "molecule-docker:docker://ubuntu:24.04"
|
||||
- "molecule-shell:host"
|
||||
gitea_runner_container_docker_host: "-"
|
||||
gitea_runner_container_volumes:
|
||||
- /cache:/cache
|
||||
gitea_runner_docker_prune_enabled: true
|
||||
gitea_runner_docker_prune_job_max_age: 3600
|
||||
verifier:
|
||||
name: ansible
|
||||
scenario:
|
||||
# molecule's default sequence minus its first destroy: the workflow removes what a killed run
|
||||
# left before any scenario starts, so that destroy only waits out the
|
||||
# driver's 5 s poll on a container that is not there. After an aborted local run, run
|
||||
# `molecule destroy` yourself.
|
||||
test_sequence:
|
||||
- dependency
|
||||
- cleanup
|
||||
- syntax
|
||||
- create
|
||||
- prepare
|
||||
- converge
|
||||
- idempotence
|
||||
- side_effect
|
||||
- verify
|
||||
- cleanup
|
||||
- destroy
|
||||
@@ -0,0 +1,85 @@
|
||||
---
|
||||
# Stand-ins for what the scenario cannot have: a Docker daemon (the runner unit requires
|
||||
# docker.service), an installed and registered runner (so the role skips the Docker install and
|
||||
# the registration, which need Docker Hub and a Gitea server), and the release files of two
|
||||
# newer versions behind file:// URLs. 6.0.1 has a matching checksum file, 6.0.2 a wrong one.
|
||||
# The stub binary answers --version and, for `daemon`, sleeps like a running service.
|
||||
- name: Prepare
|
||||
hosts: all
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: Write a stub docker.service
|
||||
ansible.builtin.copy:
|
||||
dest: /etc/systemd/system/docker.service
|
||||
mode: "0644"
|
||||
content: |
|
||||
[Unit]
|
||||
Description=Docker stub for molecule
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/bin/true
|
||||
RemainAfterExit=yes
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
||||
- name: Start the stub docker.service
|
||||
ansible.builtin.systemd:
|
||||
name: docker
|
||||
state: started
|
||||
daemon_reload: true
|
||||
|
||||
- name: Create the download directory
|
||||
ansible.builtin.file:
|
||||
path: /opt/molecule-download
|
||||
state: directory
|
||||
mode: "0755"
|
||||
|
||||
- name: Write the installed stub runner and the release files
|
||||
ansible.builtin.copy:
|
||||
dest: "{{ gitea_runner_test_stub.dest }}"
|
||||
mode: "0755"
|
||||
content: |
|
||||
#!/bin/sh
|
||||
case "$1" in
|
||||
--version) echo "gitea-runner version v{{ gitea_runner_test_stub.version }}" ;;
|
||||
daemon) exec sleep infinity ;;
|
||||
*) echo "stub runner: unexpected arguments: $*" >&2; exit 2 ;;
|
||||
esac
|
||||
loop:
|
||||
- {dest: /usr/local/bin/gitea-runner, version: 6.0.0}
|
||||
- {dest: /opt/molecule-download/gitea-runner-6.0.1-linux-amd64, version: 6.0.1}
|
||||
- {dest: /opt/molecule-download/gitea-runner-6.0.2-linux-amd64, version: 6.0.2}
|
||||
loop_control:
|
||||
loop_var: gitea_runner_test_stub
|
||||
label: "{{ gitea_runner_test_stub.dest }}"
|
||||
|
||||
- name: Hash the 6.0.1 release file
|
||||
ansible.builtin.stat:
|
||||
path: /opt/molecule-download/gitea-runner-6.0.1-linux-amd64
|
||||
checksum_algorithm: sha256
|
||||
register: gitea_runner_test_release
|
||||
|
||||
- name: Write the checksum files, the 6.0.2 one wrong
|
||||
ansible.builtin.copy:
|
||||
dest: "/opt/molecule-download/gitea-runner-{{ gitea_runner_test_sum.version }}-linux-amd64.sha256"
|
||||
mode: "0644"
|
||||
content: "{{ gitea_runner_test_sum.sum }} gitea-runner-{{ gitea_runner_test_sum.version }}-linux-amd64\n"
|
||||
loop:
|
||||
- {version: 6.0.1, sum: "{{ gitea_runner_test_release.stat.checksum }}"}
|
||||
- {version: 6.0.2, sum: "{{ '0' * 64 }}"}
|
||||
loop_control:
|
||||
loop_var: gitea_runner_test_sum
|
||||
label: "{{ gitea_runner_test_sum.version }}"
|
||||
|
||||
# Mode 0644 on purpose: configure must tighten it to 0600.
|
||||
- name: Create the work directory with a stand-in registration
|
||||
ansible.builtin.file:
|
||||
path: /var/lib/gitea-runner
|
||||
state: directory
|
||||
mode: "0750"
|
||||
|
||||
- name: Write the stand-in registration
|
||||
ansible.builtin.copy:
|
||||
dest: /var/lib/gitea-runner/.runner
|
||||
mode: "0644"
|
||||
content: '{"molecule": "not a registration"}'
|
||||
@@ -0,0 +1,28 @@
|
||||
---
|
||||
# One refused input: runs the main entry point with that input and asserts that the expected
|
||||
# assert, not something else, stopped it. Input: gitea_runner_test_refused (name, vars, expect).
|
||||
# Task vars cannot come from a template as a whole, so each input under test is passed with
|
||||
# its usual value as the default.
|
||||
- name: "Run the role, case {{ gitea_runner_test_refused.name }}"
|
||||
block:
|
||||
- name: "Include the role, case {{ gitea_runner_test_refused.name }}"
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.gitea_runner
|
||||
vars:
|
||||
gitea_runner_version: "{{ gitea_runner_test_refused.vars.gitea_runner_version | default('6.0.1') }}"
|
||||
gitea_runner_registration_scope: "{{ gitea_runner_test_refused.vars.gitea_runner_registration_scope | default('') }}"
|
||||
gitea_runner_docker_prune_schedule: "{{ gitea_runner_test_refused.vars.gitea_runner_docker_prune_schedule | default('Sun *-*-* 04:30:00') }}"
|
||||
gitea_runner_docker_prune_image_age: "{{ gitea_runner_test_refused.vars.gitea_runner_docker_prune_image_age | default('168h') }}"
|
||||
gitea_runner_molecule_enabled: "{{ gitea_runner_test_refused.vars.gitea_runner_molecule_enabled | default(false) }}"
|
||||
|
||||
# Only reached when the include returned. The message must not contain the expected
|
||||
# text, so the rescue below cannot mistake it for the assert.
|
||||
- name: "Fail because the include returned, case {{ gitea_runner_test_refused.name }}"
|
||||
ansible.builtin.fail:
|
||||
msg: The role accepted the input
|
||||
rescue:
|
||||
- name: "The expected assert fired, case {{ gitea_runner_test_refused.name }}"
|
||||
ansible.builtin.assert:
|
||||
that: gitea_runner_test_refused.expect in ansible_failed_result.msg | default('')
|
||||
fail_msg: "Expected '{{ gitea_runner_test_refused.expect }}', got: {{ ansible_failed_result.msg | default('') }}"
|
||||
quiet: true
|
||||
@@ -0,0 +1,401 @@
|
||||
---
|
||||
- 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 and the ages
|
||||
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"
|
||||
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
|
||||
{% if gitea_runner_test_case.fail %}touch /tmp/molecule-docker-fail{% endif %}
|
||||
/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
|
||||
|
||||
# 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: plain OnCalendar value
|
||||
- name: prune age without a unit
|
||||
vars: {gitea_runner_docker_prune_image_age: "168"}
|
||||
expect: plain OnCalendar value
|
||||
- name: molecule tooling without a requirements file
|
||||
vars: {gitea_runner_molecule_enabled: true}
|
||||
expect: gitea_runner_collections_requirements_file must name
|
||||
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
|
||||
|
||||
# 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/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]
|
||||
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
|
||||
Reference in new issue
Block a user