Skip to content

Commit

Permalink
tests/int: simplify teardown_running_container
Browse files Browse the repository at this point in the history
In its current form, it is complicated, unreliable, and error prone.

Using runc delete -f will kill and remove any container, running or not,
and it won't error if a container with a given name does not exist.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
  • Loading branch information
kolyshkin committed Oct 27, 2020
1 parent 4aecc2b commit d3ed331
Showing 1 changed file with 2 additions and 18 deletions.
20 changes: 2 additions & 18 deletions tests/integration/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -468,27 +468,11 @@ function setup_debian() {
}

function teardown_running_container() {
runc list
# $1 should be a container name such as "test_busybox"
# here we detect "test_busybox "(with one extra blank) to avoid conflict prefix
# e.g. "test_busybox" and "test_busybox_update"
if [[ "${output}" == *"$1 "* ]]; then
runc kill $1 KILL
retry 10 1 eval "__runc state '$1' | grep -q 'stopped'"
runc delete $1
fi
__runc delete -f "$1"
}

function teardown_running_container_inroot() {
ROOT=$2 runc list
# $1 should be a container name such as "test_busybox"
# here we detect "test_busybox "(with one extra blank) to avoid conflict prefix
# e.g. "test_busybox" and "test_busybox_update"
if [[ "${output}" == *"$1 "* ]]; then
ROOT=$2 runc kill $1 KILL
retry 10 1 eval "ROOT='$2' __runc state '$1' | grep -q 'stopped'"
ROOT=$2 runc delete $1
fi
ROOT="$2" __runc delete -f "$1"
}

function teardown_busybox() {
Expand Down

0 comments on commit d3ed331

Please sign in to comment.