ci(molecule): check container removal by listing what is left
A removal that fails because another run's sweep was first is harmless, but checking that with `docker container inspect` also passed when the daemon could not be reached. Both removal steps now remove what they can and then list the containers they meant to remove; a failing list or a container still listed fails the step. The workflow rules name the test that holds the sweep's age bound to the job timeout. Assisted-by: Claude Code:claude-opus-5-5
This commit is contained in:
1 parent
3726b5c53f
commit
1885b3fe99
3 files changed
+20
-16
No files matched your search
@@ -87,8 +87,10 @@ issue.
|
||||
older than its timeout, which a cancelled run left, and finally its own. The scenarios of one
|
||||
run overlap (`scripts/run_molecule_scenarios.sh`, `MOLECULE_LANES` at a time), so no two
|
||||
scenarios may share a platform name. *Why:* a cancelled run is killed before it can remove its
|
||||
instances, and a younger container may belong to a run still going. *Held:* review; the names
|
||||
and labels are held by the test the `test_sequence` rule below names.
|
||||
instances, and a younger container may belong to a run still going. *Held:* review; control:
|
||||
the names and labels by the test the `test_sequence` rule below names, and the sweep's age bound
|
||||
equal to the job timeout by `test_the_sweep_spares_containers_younger_than_the_job_timeout` in
|
||||
`tests/scripts/test_run_molecule_scenarios.py`.
|
||||
- **Molecule tests the pull request's pins, as Lint and Build do.** It runs molecule in the pinned
|
||||
`ci` image and, when a pin file differs from `/opt/ci-pins.sha256`, installs the pull request's
|
||||
tools and the collections of `requirements.yml` and `extensions/molecule/requirements.yml` first.
|
||||
|
||||
@@ -98,16 +98,20 @@ jobs:
|
||||
# The job's timeout-minutes (a script test holds them equal): a shorter bound would remove a
|
||||
# live run's containers.
|
||||
cutoff="$(date -d '30 minutes ago' +%s)"
|
||||
old=""
|
||||
for id in $ids; do
|
||||
# a container removed since the listing, by its run or another run's sweep, is skipped
|
||||
created="$(docker inspect --format '{{.Created}}' "$id")" || continue
|
||||
created="$(date -d "$created" +%s)"
|
||||
if [ "$created" -ge "$cutoff" ]; then continue; fi
|
||||
if ! docker rm -f "$id" >/dev/null && docker container inspect "$id" >/dev/null 2>&1; then
|
||||
echo "::error::could not remove container $id"
|
||||
exit 1
|
||||
if [ "$created" -lt "$cutoff" ]; then
|
||||
old="$old $id"
|
||||
docker rm -f "$id" >/dev/null || true
|
||||
fi
|
||||
done
|
||||
# A removal may fail because another run's sweep was first; only one still listed counts.
|
||||
left=""
|
||||
for id in $old; do left="$left$(docker ps -aq --filter "id=$id")"; done
|
||||
if [ -n "$left" ]; then echo "::error::could not remove ${left//$'\n'/ }"; exit 1; fi
|
||||
|
||||
# A pull request runs only the scenarios of the roles it changes (scripts/select_molecule_scenarios.py
|
||||
# explains the rules); the nightly run and a manual dispatch run all of them, a few at a time.
|
||||
@@ -159,10 +163,8 @@ jobs:
|
||||
run: |
|
||||
# Assigned first so that a failing `docker ps` fails the step instead of looking empty.
|
||||
ids="$(docker ps -aq --filter "label=net.rkdr.mortis.molecule-run=$KAMINO_RUN_ID")"
|
||||
for id in $ids; do
|
||||
# another run's sweep may have removed it first, once this run passed its timeout
|
||||
if ! docker rm -f "$id" >/dev/null && docker container inspect "$id" >/dev/null 2>&1; then
|
||||
echo "::error::could not remove container $id"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
# A removal may fail because another run's sweep was first, once this run passed its
|
||||
# timeout; only a container still listed counts.
|
||||
for id in $ids; do docker rm -f "$id" >/dev/null || true; done
|
||||
left="$(docker ps -aq --filter "label=net.rkdr.mortis.molecule-run=$KAMINO_RUN_ID")"
|
||||
if [ -n "$left" ]; then echo "::error::could not remove ${left//$'\n'/ }"; exit 1; fi
|
||||
@@ -398,11 +398,11 @@ class ScenarioPlatformsTest(unittest.TestCase):
|
||||
def test_the_workflow_finds_the_containers_by_the_run_label(self):
|
||||
# the sweep of earlier runs filters by the key, the cleanup of this run by key and value
|
||||
self.assertEqual(
|
||||
label_filters("Remove the containers earlier runs left"), [RUN_LABEL]
|
||||
set(label_filters("Remove the containers earlier runs left")), {RUN_LABEL}
|
||||
)
|
||||
self.assertEqual(
|
||||
label_filters("Remove this run's containers"),
|
||||
[f"{RUN_LABEL}=$KAMINO_RUN_ID"],
|
||||
set(label_filters("Remove this run's containers")),
|
||||
{f"{RUN_LABEL}=$KAMINO_RUN_ID"},
|
||||
)
|
||||
|
||||
def test_the_sweep_spares_containers_younger_than_the_job_timeout(self):
|
||||
|
||||
Reference in new issue
Block a user