From 6e9d8f3603a56047672a3a47e295a5da42517faa 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 | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/tox.sh b/tests/tox.sh index 8a79603fe..a43267c8d 100644 --- a/tests/tox.sh +++ b/tests/tox.sh @@ -48,7 +48,13 @@ 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 fi cd "$WORKSPACE"