From 8787fbd8b65bac60b9ce27d48f1f1b6cc8cad96d Mon Sep 17 00:00:00 2001 From: David Galloway Date: Tue, 9 Aug 2022 13:48:25 -0400 Subject: [PATCH] tests: Retry rm'ing container Example where this would be needed: ``` docker rm -f 4fcd7c2012b6 Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg. time="2022-08-09T17:22:11Z" level=error msg="container \"4fcd7c2012b63e6bf9bffd9b7d490d12f1d557ba924e889192ec858821019d91\" does not exist" Error: cannot remove container 4fcd7c2012b63e6bf9bffd9b7d490d12f1d557ba924e889192ec858821019d91 as it could not be stopped: timed out waiting for file /tmp/podman-run-1111/libpod/tmp/exits/4fcd7c2012b63e6bf9bffd9b7d490d12f1d557ba924e889192ec858821019d91: internal libpod error docker rm -f 4fcd7c2012b6 Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg. ERRO[0000] Joining network namespace for container 4fcd7c2012b63e6bf9bffd9b7d490d12f1d557ba924e889192ec858821019d91: error retrieving network namespace at /tmp/podman-run-1111/netns/netns-600d6718-1a5e-2fed-bf39-ad7048004be2: unknown FS magic on "/tmp/podman-run-1111/netns/netns-600d6718-1a5e-2fed-bf39-ad7048004be2": ef53 4fcd7c2012b63e6bf9bffd9b7d490d12f1d557ba924e889192ec858821019d91 ``` See https://github.com/containers/podman/issues/13227 This also makes the function fail fatally. Signed-off-by: David Galloway --- tests/tox.sh | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/tox.sh b/tests/tox.sh index 8a79603fe..257c9b333 100644 --- a/tests/tox.sh +++ b/tests/tox.sh @@ -48,7 +48,17 @@ bash "$WORKSPACE"/travis-builds/purge_cluster.sh containers_to_remove=$(docker ps -a -q) if [ "${containers_to_remove}" ]; then - docker rm -f "$@" "${containers_to_remove}" || echo failed to remove containers + ATTEMPTS=0 + NUM_CONTAINERS=$(docker ps -a -q | wc -l) + until [ "$ATTEMPTS" -eq 5 ] || [ "$NUM_CONTAINERS" -eq 0 ]; do + docker rm -f "$@" "${containers_to_remove}" + ((ATTEMPTS++)) + NUM_CONTAINERS=$(docker ps -a -q | wc -l) + done + if [ "$ATTEMPTS" -eq 5 ]; then + echo "Removing containers failed" + exit 1 + fi fi cd "$WORKSPACE"