osmith has uploaded this change for review. ( https://gerrit.osmocom.org/c/docker-playground/+/27284 )
Change subject: ttcn3-fr-test/jenkins.sh: make use of clean_up() ......................................................................
ttcn3-fr-test/jenkins.sh: make use of clean_up()
Move cleaning up logic to clean_up(), so it runs as part of the clean_up_trap if any command in the previous code fails.
For example, if the first docker container started properly, but the second docker container failed to start: without this patch, it would just stop the script without running the clean up code.
Change-Id: I4624e37d5d2fa90b71b32d72067b3645f69805da --- M ttcn3-fr-test/jenkins.sh 1 file changed, 12 insertions(+), 9 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/docker-playground refs/changes/84/27284/1
diff --git a/ttcn3-fr-test/jenkins.sh b/ttcn3-fr-test/jenkins.sh index 4531e3a..182f512 100755 --- a/ttcn3-fr-test/jenkins.sh +++ b/ttcn3-fr-test/jenkins.sh @@ -8,6 +8,16 @@ set_clean_up_trap set -e
+clean_up() { + # kill the frnet container to avoid "You cannot remove a running container " below in 'rm' + docker kill ${BUILD_TAG}-frnet || true + + # store execution logs for both containers + docker logs --timestamps ${BUILD_TAG}-ttcn3-fr-test > $VOL_BASE_DIR/fr-tester/exec.log || true + docker logs --timestamps ${BUILD_TAG}-frnet > $VOL_BASE_DIR/frnet/exec.log || true + docker container rm ${BUILD_TAG}-frnet ${BUILD_TAG}-ttcn3-fr-test +} + SUBNET=26 network_create $SUBNET
@@ -25,7 +35,7 @@
echo Starting container with FRNET docker run \ - `# --rm is done in below` \ + `# --rm is done in clean_up()` \ --cap-add=NET_RAW --cap-add=SYS_RAWIO \ $(docker_network_params $SUBNET 10) \ --ulimit core=-1 \ @@ -45,7 +55,7 @@
echo Starting container with FR testsuite docker run \ - `# --rm is done in below` \ + `# --rm is done in clean_up()` \ --cap-add=NET_RAW --cap-add=SYS_RAWIO \ $(docker_network_params $SUBNET 103) \ --ulimit core=-1 \ @@ -66,10 +76,3 @@ # emulate running container in foreground, which is no longer possible as we # must shift the net-devices into the container _after_ it is started docker logs -f ${BUILD_TAG}-ttcn3-fr-test -# kill the frnet container to avoid "You cannot remove a running container " below in 'rm' -docker kill ${BUILD_TAG}-frnet - -# store execution logs for both containers -docker logs --timestamps ${BUILD_TAG}-ttcn3-fr-test > $VOL_BASE_DIR/fr-tester/exec.log -docker logs --timestamps ${BUILD_TAG}-frnet > $VOL_BASE_DIR/frnet/exec.log -docker container rm ${BUILD_TAG}-frnet ${BUILD_TAG}-ttcn3-fr-test