diff --git a/.gitea/workflows/molecule.yml b/.gitea/workflows/molecule.yml index 8bc3239..7a69038 100644 --- a/.gitea/workflows/molecule.yml +++ b/.gitea/workflows/molecule.yml @@ -36,15 +36,25 @@ on: # yamllint disable-line rule:truthy - 'meta/**' - 'galaxy.yml' - '.gitea/workflows/molecule.yml' + # Every scenario, nightly: a pull request runs only the scenarios of the roles it changes, so + # drift in the others (a package mirror, the runner's molecule venv) would otherwise wait for + # the next push to main. After Renovate's 03:17 run, which can take 30 minutes of the one slot. + schedule: + - cron: "43 4 * * *" workflow_dispatch: {} permissions: contents: read -# Scenarios use fixed container names on the runner's shared Docker daemon. +# A pull request run is cancelled when a newer commit is pushed to the same pull request (the +# same rule as lint.yml and build.yml); a run on main is never cancelled, so its group is the +# commit SHA. Scenarios use fixed container names on the runner's shared Docker daemon, so two +# runs must not overlap. The group no longer guarantees that (it is per pull request now): the +# runner's single slot does (gitea_runner_capacity: 1 in the maintainer's environment +# repository). Raise that capacity and this needs a lock or a shared group again. concurrency: - group: molecule - cancel-in-progress: false + group: molecule-${{ github.event_name == 'pull_request' && github.ref || github.sha }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} jobs: molecule: @@ -100,7 +110,9 @@ jobs: # A pull request runs only the scenarios of the roles it changes (scripts/select_molecule_scenarios.py # explains the rules); a push to main and a manual dispatch run all of them. - # molecule test destroys its instance on success and on failure. + # molecule test destroys its instance on success and on failure; a cancelled run is killed + # before it can, so the step first removes what such a run left, since the next run may not + # select the same scenarios. - name: Run the scenarios working-directory: ac/ansible_collections/mortis/kamino env: @@ -108,6 +120,13 @@ jobs: # The workflow only runs for pull requests to main; lint.yml uses the same constant. BASE_REF: origin/main run: | + # The platform names of every scenario, anchored: -instance and image-smoke[-2604]. + # Assigned first so that a failing `docker ps` fails the step instead of looking empty. + stale="$(docker ps -aq --filter 'name=^/[a-z0-9-]+-instance$' --filter 'name=^/image-smoke(-2604)?$')" + if [ -n "$stale" ]; then + # shellcheck disable=SC2086 # container ids, one word each + docker rm -f $stale + fi # molecule calls ansible-config and ansible-playbook by name export PATH="$MOLECULE_VENV/bin:$PATH" # The collection under test first, then what the roles use. molecule also diff --git a/CLAUDE.md b/CLAUDE.md index 4031921..fc613db 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -63,8 +63,13 @@ Single-context: `GLOSSARY.md` and `docs/adr/` at the root, both created lazily. What a pull request runs is chosen by `scripts/select_molecule_scenarios.py`, run from the base branch's copy (a pull request cannot edit its own rules): only the scenarios of the roles it changes, none for a diff of only its IGNORED paths, a failure for a changed role with no scenario, and every scenario for any other file, - for every push to `main` and for manual dispatch. A new file outside `roles//` runs everything until it - is added to IGNORED, which is right only when no scenario reads it. + for every push to `main`, for manual dispatch and for the nightly run (04:43 UTC, after Renovate's). A new file outside `roles//` runs everything until it + is added to IGNORED, which is right only when no scenario reads it. A new commit cancels the pull request's + running Molecule run, and the step first removes containers a cancelled run left; two runs never overlap + because the runner has a single slot, so raising its capacity needs a lock or a shared concurrency group. +- Every scenario sets `scenario.test_sequence` to molecule's default minus the leading `destroy` (the workflow + clears stale containers first, and the molecule state lives in the job's own `ANSIBLE_HOME`, so a killed run leaves + none behind); copy it into a new scenario. - Molecule discovers `extensions/molecule/*/` and `roles/*/molecule/*/`. The `image-smoke` and `image-smoke-2604` scenarios test the molecule images themselves (24.04 and 26.04); a role scenario that must pass on both takes `image: ${MOLECULE_IMAGE}` or `${MOLECULE_IMAGE_2604}` per platform. diff --git a/extensions/molecule/image-smoke-2604/molecule.yml b/extensions/molecule/image-smoke-2604/molecule.yml index e2d5479..00db4cd 100644 --- a/extensions/molecule/image-smoke-2604/molecule.yml +++ b/extensions/molecule/image-smoke-2604/molecule.yml @@ -25,3 +25,20 @@ provisioner: name: ansible 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 diff --git a/extensions/molecule/image-smoke/molecule.yml b/extensions/molecule/image-smoke/molecule.yml index 94e7c07..ff89ab1 100644 --- a/extensions/molecule/image-smoke/molecule.yml +++ b/extensions/molecule/image-smoke/molecule.yml @@ -25,3 +25,20 @@ provisioner: name: ansible 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 diff --git a/roles/docker/molecule/default/molecule.yml b/roles/docker/molecule/default/molecule.yml index bc10d73..ecc4f9b 100644 --- a/roles/docker/molecule/default/molecule.yml +++ b/roles/docker/molecule/default/molecule.yml @@ -26,3 +26,20 @@ provisioner: name: ansible 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 diff --git a/roles/fail2ban/molecule/default/molecule.yml b/roles/fail2ban/molecule/default/molecule.yml index 453236e..44d84b3 100644 --- a/roles/fail2ban/molecule/default/molecule.yml +++ b/roles/fail2ban/molecule/default/molecule.yml @@ -24,3 +24,20 @@ provisioner: name: ansible 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 diff --git a/roles/network_interfaces/molecule/default/molecule.yml b/roles/network_interfaces/molecule/default/molecule.yml index e8380d5..4e79c56 100644 --- a/roles/network_interfaces/molecule/default/molecule.yml +++ b/roles/network_interfaces/molecule/default/molecule.yml @@ -24,3 +24,20 @@ provisioner: name: ansible 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 diff --git a/roles/system_baseline/molecule/default/molecule.yml b/roles/system_baseline/molecule/default/molecule.yml index f67f633..38d5d54 100644 --- a/roles/system_baseline/molecule/default/molecule.yml +++ b/roles/system_baseline/molecule/default/molecule.yml @@ -31,3 +31,20 @@ provisioner: skip-tags: molecule-notest,notest,sysctl,secure_tmp,update,timezone 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 diff --git a/roles/systemd_hardening/molecule/default/molecule.yml b/roles/systemd_hardening/molecule/default/molecule.yml index 7b5f79b..2794fc6 100644 --- a/roles/systemd_hardening/molecule/default/molecule.yml +++ b/roles/systemd_hardening/molecule/default/molecule.yml @@ -24,3 +24,20 @@ provisioner: name: ansible 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