From ca27dffea7acb2682c09e912f7390c6c94260537 Mon Sep 17 00:00:00 2001 From: Eric Wild Date: Fri, 5 Jul 2019 15:16:17 +0200 Subject: clean up the net and attached containers to ensure reliable test starts We can't create the net if it exists, and it can't be removed until all attached containers are dead, so ensure this is the case upon net creation. This fixes test failures due to stale nets and half-killed test runs. Change-Id: Id6d13b233ebfd808d8dfe83b6d1d1ba20c3392c8 --- jenkins-common.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/jenkins-common.sh b/jenkins-common.sh index 25ae26f..9fd3857 100644 --- a/jenkins-common.sh +++ b/jenkins-common.sh @@ -28,8 +28,18 @@ docker_images_require() { done } +#kills all containers attached to network +network_clean() { + docker network inspect $NET_NAME | grep Name | cut -d : -f2 | awk -F\" 'NR>1{print $2}' | xargs -rn1 docker kill +} + network_create() { NET=$1 + if docker network ls | grep -q $NET_NAME; then + echo removing stale network and containers... + network_clean + network_remove + fi echo Creating network $NET_NAME docker network create --internal --subnet $NET $NET_NAME } -- cgit v1.2.3