tests: add kata-runtime debug-console test

The test will retrieve the sandbox id and check if the
kata-agent is on the PATH using the debug console

Signed-Off-By: Ryan Savino <ryan.savino@amd.com>
This commit is contained in:
Ryan Savino 2025-04-10 17:52:43 -05:00
parent aef6083eb3
commit c05346cc65
4 changed files with 89 additions and 0 deletions

View File

@ -0,0 +1,55 @@
#!/usr/bin/env bats
# Copyright (c) 2025 Advanced Micro Devices, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
load "${BATS_TEST_DIRNAME}/../../common.bash"
load "${BATS_TEST_DIRNAME}/tests_common.sh"
load "${BATS_TEST_DIRNAME}/lib.sh"
# For kata-runtime
export KATA_HOME="/opt/kata"
export KATA_RUNTIME="${KATA_HOME}/bin/kata-runtime"
timeout=${timeout:-30}
setup() {
if [[ "${K8S_TEST_HOST_TYPE}" != "baremetal" ]]; then
skip "Debug console only available from baremetal systems"
fi
pod_name="busybox-base-pod"
get_pod_config_dir
yaml_file="${pod_config_dir}/pod-busybox-base.yaml"
}
@test "Access and verify that the debug console is working" {
# Create pod
kubectl apply -f "${yaml_file}"
# Check pod creation
kubectl wait --for=condition=Ready --timeout=${timeout} pod "${pod_name}"
# Get sandbox ID
sandbox_id=$(get_kata_sandbox_id_by_pod_name "${pod_name}")
echo "Sandbox ID for pod [${pod_name}]: ${sandbox_id}"
# Test debug console
local kata_agent_path=$(sudo "${KATA_RUNTIME}" exec "${sandbox_id}" which kata-agent)
if [[ ! "${kata_agent_path}" =~ "kata-agent" ]]; then
echo "ERROR: The debug console could not locate the kata-agent: ${kata_agent_path}" >&2
return 1
fi
}
teardown() {
if [[ "${K8S_TEST_HOST_TYPE}" != "baremetal" ]]; then
skip "Debug console only available from baremetal systems"
fi
# Debugging information
kubectl describe "pod/${pod_name}"
kubectl delete pod "${pod_name}"
}

View File

@ -372,3 +372,19 @@ get_node_kata_sandbox_id() {
done
echo $kata_sandbox_id
}
get_kata_sandbox_id_by_pod_name() {
local pod_name="${1}"
# Get sandbox ID from crictl
local sandbox_id=$(sudo crictl inspectp --name "${pod_name}" | jq -r '.status.id')
# Error handle
if [ -z "${sandbox_id}" ]; then
echo "ERROR: Could not determine sandbox ID for pod with name: ${pod_name}" >&2
return 1
fi
# Return
echo "${sandbox_id}"
}

View File

@ -91,6 +91,7 @@ else
)
K8S_TEST_NORMAL_HOST_UNION=( \
"k8s-debug-console.bats" \
"k8s-number-cpus.bats" \
"k8s-parallel.bats" \
"k8s-sandbox-vcpus-allocation.bats" \

View File

@ -0,0 +1,17 @@
#
# Copyright (c) 2025 Advanced Micro Devices, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
apiVersion: v1
kind: Pod
metadata:
name: busybox-base-pod
spec:
runtimeClassName: kata
containers:
- name: busybox-base
image: quay.io/prometheus/busybox:latest
command: ["/bin/sh", "-c"]
args:
- sleep 180