ci(molecule): remove each scenario's containers in the workflow instead of molecule's destroy

molecule's trailing destroy runs the Docker driver's destroy playbook, whose
"Wait for instance(s) deletion to complete" task alone costs about 5.6 s per
scenario, about 84 s over the 15 scenarios of a full run. The whole destroy
phase measured about 103 s per full run (the median across full runs, among
them 4764, 4714, 4698 and 4578). The workflow already removes stale
containers before the run, so it can remove each scenario's containers itself
with `docker rm -f` as soon as the scenario ends, pass or fail, and skip the
playbook.

The names come from each scenario's molecule.yml (platforms[].name) via the
molecule venv's Python and PyYAML, so no list is kept in the workflow. A
failed removal fails the step. The test_sequence rule in the workflow guidance
now says both destroys are left out and that platform names are literal.

Assisted-by: Claude Code:claude-opus-5-5
This commit is contained in:
Defame1297 committed 2026-11-22 22:33:52 +00:00
1 parent 00c6cbeba4
commit f77586dc60
17 files changed
+67 -82

No files matched your search

+5 -4
View File
@@ -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
+17 -3
View File
@@ -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" </dev/null) || failed="$failed $label"
;;
esac
remove_instances "$dir" || failed="$failed $label(removal)"
ran=$((ran + 1))
echo "::endgroup::"
done <<< "$selected"
@@ -26,10 +26,9 @@ provisioner:
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.
# molecule's default sequence minus both destroys: the workflow removes the container before the
# run and as soon as this scenario ends; molecule's destroy only adds the driver's poll wait.
# After a local run, run `molecule destroy` yourself.
test_sequence:
- dependency
- cleanup
@@ -41,4 +40,3 @@ scenario:
- side_effect
- verify
- cleanup
- destroy
+3 -5
View File
@@ -26,10 +26,9 @@ provisioner:
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.
# molecule's default sequence minus both destroys: the workflow removes the container before the
# run and as soon as this scenario ends; molecule's destroy only adds the driver's poll wait.
# After a local run, run `molecule destroy` yourself.
test_sequence:
- dependency
- cleanup
@@ -41,4 +40,3 @@ scenario:
- side_effect
- verify
- cleanup
- destroy
@@ -26,10 +26,9 @@ provisioner:
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.
# molecule's default sequence minus both destroys: the workflow removes the container before the
# run and as soon as this scenario ends; molecule's destroy only adds the driver's poll wait.
# After a local run, run `molecule destroy` yourself.
test_sequence:
- dependency
- cleanup
@@ -40,4 +39,3 @@ scenario:
- check
- verify
- cleanup
- destroy
@@ -26,10 +26,9 @@ provisioner:
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.
# molecule's default sequence minus both destroys: the workflow removes the container before the
# run and as soon as this scenario ends; molecule's destroy only adds the driver's poll wait.
# After a local run, run `molecule destroy` yourself.
test_sequence:
- dependency
- cleanup
@@ -41,4 +40,3 @@ scenario:
- side_effect
- verify
- cleanup
- destroy
+3 -5
View File
@@ -27,10 +27,9 @@ provisioner:
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.
# molecule's default sequence minus both destroys: the workflow removes the container before the
# run and as soon as this scenario ends; molecule's destroy only adds the driver's poll wait.
# After a local run, run `molecule destroy` yourself.
test_sequence:
- dependency
- cleanup
@@ -42,4 +41,3 @@ scenario:
- side_effect
- verify
- cleanup
- destroy
+3 -5
View File
@@ -25,10 +25,9 @@ provisioner:
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.
# molecule's default sequence minus both destroys: the workflow removes the container before the
# run and as soon as this scenario ends; molecule's destroy only adds the driver's poll wait.
# After a local run, run `molecule destroy` yourself.
test_sequence:
- dependency
- cleanup
@@ -40,4 +39,3 @@ scenario:
- side_effect
- verify
- cleanup
- destroy
+3 -5
View File
@@ -36,10 +36,9 @@ provisioner:
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.
# molecule's default sequence minus both destroys: the workflow removes the container before the
# run and as soon as this scenario ends; molecule's destroy only adds the driver's poll wait.
# After a local run, run `molecule destroy` yourself.
test_sequence:
- dependency
- cleanup
@@ -51,4 +50,3 @@ scenario:
- side_effect
- verify
- cleanup
- destroy
@@ -44,10 +44,9 @@ provisioner:
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.
# molecule's default sequence minus both destroys: the workflow removes the container before the
# run and as soon as this scenario ends; molecule's destroy only adds the driver's poll wait.
# After a local run, run `molecule destroy` yourself.
test_sequence:
- dependency
- cleanup
@@ -59,4 +58,3 @@ scenario:
- side_effect
- verify
- cleanup
- destroy
@@ -25,10 +25,9 @@ provisioner:
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.
# molecule's default sequence minus both destroys: the workflow removes the container before the
# run and as soon as this scenario ends; molecule's destroy only adds the driver's poll wait.
# After a local run, run `molecule destroy` yourself.
test_sequence:
- dependency
- cleanup
@@ -40,4 +39,3 @@ scenario:
- side_effect
- verify
- cleanup
- destroy
+3 -5
View File
@@ -26,10 +26,9 @@ provisioner:
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.
# molecule's default sequence minus both destroys: the workflow removes the container before the
# run and as soon as this scenario ends; molecule's destroy only adds the driver's poll wait.
# After a local run, run `molecule destroy` yourself.
test_sequence:
- dependency
- cleanup
@@ -41,4 +40,3 @@ scenario:
- side_effect
- verify
- cleanup
- destroy
@@ -32,10 +32,9 @@ provisioner:
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.
# molecule's default sequence minus both destroys: the workflow removes the container before the
# run and as soon as this scenario ends; molecule's destroy only adds the driver's poll wait.
# After a local run, run `molecule destroy` yourself.
test_sequence:
- dependency
- cleanup
@@ -47,4 +46,3 @@ scenario:
- side_effect
- verify
- cleanup
- destroy
@@ -25,10 +25,9 @@ provisioner:
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.
# molecule's default sequence minus both destroys: the workflow removes the container before the
# run and as soon as this scenario ends; molecule's destroy only adds the driver's poll wait.
# After a local run, run `molecule destroy` yourself.
test_sequence:
- dependency
- cleanup
@@ -40,4 +39,3 @@ scenario:
- side_effect
- verify
- cleanup
- destroy
+3 -5
View File
@@ -46,10 +46,9 @@ provisioner:
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.
# molecule's default sequence minus both destroys: the workflow removes the container before the
# run and as soon as this scenario ends; molecule's destroy only adds the driver's poll wait.
# After a local run, run `molecule destroy` yourself.
test_sequence:
- dependency
- cleanup
@@ -61,4 +60,3 @@ scenario:
- side_effect
- verify
- cleanup
- destroy
+3 -5
View File
@@ -25,10 +25,9 @@ provisioner:
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.
# molecule's default sequence minus both destroys: the workflow removes the container before the
# run and as soon as this scenario ends; molecule's destroy only adds the driver's poll wait.
# After a local run, run `molecule destroy` yourself.
test_sequence:
- dependency
- cleanup
@@ -40,4 +39,3 @@ scenario:
- side_effect
- verify
- cleanup
- destroy
@@ -33,10 +33,9 @@ provisioner:
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.
# molecule's default sequence minus both destroys: the workflow removes the container before the
# run and as soon as this scenario ends; molecule's destroy only adds the driver's poll wait.
# After a local run, run `molecule destroy` yourself.
test_sequence:
- dependency
- cleanup
@@ -48,4 +47,3 @@ scenario:
- side_effect
- verify
- cleanup
- destroy