github.com/dmaizel/tests@v0.0.0-20210728163746-cae6a2d9cee8/integration/stability/hypervisor_stability_kill_test.sh (about) 1 #!/bin/bash 2 # 3 # Copyright (c) 2019-2021 HyperHQ Inc, Intel Corporation. 4 # 5 # SPDX-License-Identifier: Apache-2.0 6 # 7 # This test will kill a running container's 8 # hypervisor, and see how we react to cleanup. 9 10 set -e 11 12 cidir=$(dirname "$0") 13 14 source "${cidir}/../../metrics/lib/common.bash" 15 16 # Environment variables 17 IMAGE="${IMAGE:-quay.io/prometheus/busybox:latest}" 18 CONTAINER_NAME="${CONTAINER_NAME:-test}" 19 PAYLOAD_ARGS="${PAYLOAD_ARGS:-tail -f /dev/null}" 20 21 setup() { 22 sudo systemctl restart containerd 23 extract_kata_env 24 clean_env_ctr 25 HYPERVISOR_NAME=$(basename ${HYPERVISOR_PATH}) 26 sudo ctr image pull $IMAGE 27 [ $? != 0 ] && die "Unable to get image $IMAGE" 28 29 sudo ctr run --runtime=$CONTAINERD_RUNTIME -d $IMAGE $CONTAINER_NAME sh -c $PAYLOAD_ARGS 30 num=$(pidof ${HYPERVISOR_NAME} | wc -w) 31 [ ${num} -eq 1 ] || die "hypervisor count:${num} expected:1" 32 } 33 34 kill_hypervisor() { 35 pid=$(pidof ${HYPERVISOR_NAME}) 36 [ -n ${pid} ] || die "failed to find hypervisor pid" 37 sudo kill -KILL ${pid} || die "failed to kill hypervisor (pid ${pid})" 38 # signal is async and we've seen failures hypervisor not being killed immediately. 39 sleep 1 40 num=$(pidof ${HYPERVISOR_NAME} | wc -w) 41 [ ${num} -eq 0 ] || die "hypervisor count:${num} expected:0" 42 sudo ctr tasks rm -f $(sudo ctr task list -q) 43 sudo ctr c rm $(sudo ctr c list -q) 44 [ $? -eq 0 ] || die "failed to force removing container $CONTAINER_NAME" 45 } 46 47 teardown() { 48 echo "Ending hypervisor stability test" 49 clean_env_ctr 50 } 51 52 trap teardown EXIT 53 54 echo "Starting hypervisor stability test" 55 setup 56 57 echo "Running hypervisor stability test" 58 kill_hypervisor