github.com/kata-containers/tests@v0.0.0-20240307153542-772105b56064/functional/agent/agent_test.sh (about) 1 #!/bin/bash 2 # 3 # Copyright (c) 2022 Ant Group 4 # 5 # SPDX-License-Identifier: Apache-2.0 6 # 7 # This will run a containers and then check 8 # whether the kata-agent threads namespaces 9 # were changed during create container processes. 10 11 set -e 12 set -o errexit 13 set -o nounset 14 set -o pipefail 15 16 [ -n "$BASH_VERSION" ] && set -o errtrace 17 [ -n "${DEBUG:-}" ] && set -o xtrace 18 19 dir_path=$(dirname "$0") 20 source "${dir_path}/../../lib/common.bash" 21 source "${dir_path}/../../metrics/lib/common.bash" 22 23 CONTAINER_NAME="${CONTAINER_NAME:-test}" 24 IMAGE="${IMAGE:-quay.io/library/busybox:latest}" 25 26 setup() { 27 restart_containerd_service 28 check_processes 29 } 30 31 test_agent() { 32 sudo ctr image pull "${IMAGE}" 33 [ $? != 0 ] && die "Unable to get image $IMAGE" 34 sudo ctr run --runtime="${CTR_RUNTIME}" -d --privileged --rm --mount type=bind,src=/proc,dst=/proc,options=rbind:ro "${IMAGE}" "${CONTAINER_NAME}" sh -c "tail -f /dev/null" || die "Test failed" 35 36 sudo ctr t exec --exec-id test ${CONTAINER_NAME} sh -c 'ps -ef | grep kata-agent | grep -v grep' 37 38 agent_pid=$(sudo ctr t exec --exec-id test ${CONTAINER_NAME} sh -c 'ps -ef | grep kata-agent | grep -v grep' | awk '{print $1}') 39 agent_tasks=$(sudo ctr t exec --exec-id test ${CONTAINER_NAME} sh -c "ls /proc/$agent_pid/task") 40 41 ns="cgroup ipc mnt net pid user uts" 42 43 for t in $agent_tasks; do 44 for i in $ns; do 45 agent_namespace=$(sudo ctr t exec --exec-id test ${CONTAINER_NAME} sh -c "ls -al /proc/$t/ns/$i" | awk '{print $NF}') 46 root_namespace=$(sudo ctr t exec --exec-id test ${CONTAINER_NAME} sh -c "ls -al /proc/1/ns/$i" | awk '{print $NF}') 47 48 [ "$agent_namespace" == "$root_namespace" ] || die "the agent's namespace $agent_namespace isn't equal to $root_namespace" 49 done 50 done 51 } 52 53 teardown() { 54 clean_env_ctr 55 check_processes 56 } 57 58 trap teardown EXIT 59 60 echo "Running setup" 61 setup 62 63 echo "Running stability integration tests with agent" 64 test_agent