diff --git a/.gitea/workflows/AGENTS.md b/.gitea/workflows/AGENTS.md index f2a1145..1b81bf2 100644 --- a/.gitea/workflows/AGENTS.md +++ b/.gitea/workflows/AGENTS.md @@ -92,10 +92,11 @@ issue. raises the ansible-core floor must be behaviour-tested on the new core before it automerges. *Held:* aspirational until #225 runs Molecule from the `ci` image with the pin comparison against `/opt/ci-pins.sha256`; today it runs from the runner's own venv. -- **Every scenario sets `scenario.test_sequence` to molecule's default minus the leading - `destroy`;** copy it into a new scenario. *Why:* 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. *Held:* review. +- **Every scenario sets `scenario.test_sequence` to molecule's default minus both `destroy` + steps, and names its platforms literally in its `molecule.yml`;** copy it into a new scenario. + *Why:* the workflow clears stale containers first and removes each scenario's containers by + those names as soon as it ends, which skips the driver's destroy wait, and the molecule state + lives in the job's own `ANSIBLE_HOME`, so a killed run leaves none behind. *Held:* review. - **Scenarios live in `roles/*/molecule/*/` and `extensions/molecule/*/`.** A role scenario that must pass on Ubuntu 24.04 and 26.04 takes `image: ${MOLECULE_IMAGE}` or `${MOLECULE_IMAGE_2604}` per platform; the image-smoke scenarios are described in diff --git a/.gitea/workflows/molecule.yml b/.gitea/workflows/molecule.yml index a467f55..32dc456 100644 --- a/.gitea/workflows/molecule.yml +++ b/.gitea/workflows/molecule.yml @@ -128,9 +128,11 @@ 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; 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. + # The scenarios leave out molecule's destroy (see their test_sequence): the step removes each + # scenario's containers itself, by the platform names in its molecule.yml, as soon as it ends. + # That skips the driver's destroy playbook: its deletion wait is about 5.6 s per scenario (about + # 84 s over 15), and the whole destroy phase measured about 103 s a full run. A cancelled run + # is killed before it can, so the step first removes what one left. - name: Run the scenarios working-directory: ac/ansible_collections/mortis/kamino env: @@ -169,6 +171,17 @@ jobs: echo "::notice::no base copy of $sel; running this checkout's copy" fi selected="$(python3 -I "$sel" "$BASE_REF")" || exit 1 + # Removes the containers of the scenario in directory $1 by its platform names (literal in + # molecule.yml), whether or not they exist; a failure fails the step. + remove_instances() { + local names ids + local py='import sys, yaml; print(*(p["name"] for p in yaml.safe_load(open(sys.argv[1]))["platforms"]))' + names="$("$MOLECULE_VENV/bin/python3" -I -c "$py" "$1/molecule.yml")" && [ -n "$names" ] || return 1 + # shellcheck disable=SC2046,SC2086 # names and ids are one word each + ids="$(docker ps -aq $(printf -- '--filter name=^/%s$ ' $names))" || return 1 + # shellcheck disable=SC2086 + [ -z "$ids" ] || docker rm -f $ids >/dev/null + } failed="" ran=0 while IFS= read -r dir; do @@ -188,6 +201,7 @@ jobs: (cd "roles/$role" && molecule test -s "$name"