fix: report only the retired services a host actually had
CI / check (pull_request) Successful in 17s
CI / check (pull_request) Successful in 17s
`docker rm -f` exits 0 for a container that does not exist, so the "Removing retired services" step printed "removed container netork-registry-1" on every deploy of every host, long after the container was gone. That read as something recreating the registry each time, and it would hide the one deploy that really removed it. Check with `docker inspect` first, so only an existing container is removed and reported. The volume branch needed nothing: `docker volume rm` already fails for a missing volume. Closes #7
This commit is contained in:
1 parent
1d8353046e
commit
1d99e401b9
3 files changed
+51
-2
No files matched your search
@@ -71,3 +71,47 @@ def test_the_infrastructure_reconcile_no_longer_starts_the_registry(tmp_path: Pa
|
||||
reconcile = [c for c in commands if "up -d --no-deps" in c and "--force-recreate" not in c]
|
||||
assert reconcile, "the infrastructure reconcile step is missing"
|
||||
assert " registry" not in reconcile[0].split("up -d --no-deps", 1)[1]
|
||||
|
||||
|
||||
# ── It says it removed only what was there (NetOrk/deploy#7) ──────────────────
|
||||
#
|
||||
# `docker rm -f` exits 0 for a container that does not exist, so the step said
|
||||
# "removed container netork-registry-1" on every deploy of every host, long after
|
||||
# the container was gone -- which read as something recreating it each time.
|
||||
|
||||
_FAKE_DOCKER = """#!/bin/sh
|
||||
case "$1" in
|
||||
inspect) [ "{exists}" = yes ] ;;
|
||||
rm) exit 0 ;;
|
||||
volume) exit 1 ;;
|
||||
esac
|
||||
"""
|
||||
|
||||
|
||||
def _removal_output(tmp_path: Path, *, exists: bool) -> str:
|
||||
"""Run the deploy's removal command against a docker that has the container or not."""
|
||||
_, commands = _deploy(tmp_path)
|
||||
removal = next(c for c in commands if "netork-registry-1" in c)
|
||||
docker_dir = tmp_path / "docker-bin"
|
||||
docker_dir.mkdir()
|
||||
docker = docker_dir / "docker"
|
||||
docker.write_text(_FAKE_DOCKER.replace("{exists}", "yes" if exists else "no"))
|
||||
docker.chmod(0o755)
|
||||
run = subprocess.run(
|
||||
["sh", "-c", removal],
|
||||
env={"PATH": f"{docker_dir}:{os.environ['PATH']}"},
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=30,
|
||||
check=False,
|
||||
)
|
||||
assert run.returncode == 0, run.stderr
|
||||
return run.stdout
|
||||
|
||||
|
||||
def test_a_container_that_is_not_there_is_not_reported_removed(tmp_path: Path) -> None:
|
||||
assert "removed container" not in _removal_output(tmp_path, exists=False)
|
||||
|
||||
|
||||
def test_one_that_was_there_is(tmp_path: Path) -> None:
|
||||
assert "removed container netork-registry-1" in _removal_output(tmp_path, exists=True)
|
||||
Reference in new issue
Block a user