WIP: tests/k8s: call teardown_common in some policy tests

The teardown_common will print the description of the running pods, kill
them all and print the system's syslogs afterwards.

Signed-off-by: stevenhorsman <steven@uk.ibm.com>
This commit is contained in:
stevenhorsman 2025-08-12 11:29:34 +01:00
parent 8a53ac5618
commit e451e3dcd0
2 changed files with 13 additions and 6 deletions

View File

@ -6,17 +6,18 @@
# #
load "${BATS_TEST_DIRNAME}/../../common.bash" load "${BATS_TEST_DIRNAME}/../../common.bash"
load "${BATS_TEST_DIRNAME}/lib.sh"
load "${BATS_TEST_DIRNAME}/tests_common.sh" load "${BATS_TEST_DIRNAME}/tests_common.sh"
setup() { setup() {
auto_generate_policy_enabled || skip "Auto-generated policy tests are disabled." auto_generate_policy_enabled || skip "Auto-generated policy tests are disabled."
setup_common
get_pod_config_dir get_pod_config_dir
job_name="policy-job" job_name="policy-job"
correct_yaml="${pod_config_dir}/k8s-policy-job.yaml" correct_yaml="${pod_config_dir}/k8s-policy-job.yaml"
incorrect_yaml="${pod_config_dir}/k8s-policy-job-incorrect.yaml" incorrect_yaml="${pod_config_dir}/k8s-policy-job-incorrect.yaml"
set_node "${correct_yaml}" "${node}"
# Save some time by executing genpolicy a single time. # Save some time by executing genpolicy a single time.
if [ "${BATS_TEST_NUMBER}" == "1" ]; then if [ "${BATS_TEST_NUMBER}" == "1" ]; then
# Add an appropriate policy to the correct YAML file. # Add an appropriate policy to the correct YAML file.
@ -163,4 +164,6 @@ teardown() {
if [ "${BATS_TEST_NUMBER}" == "1" ]; then if [ "${BATS_TEST_NUMBER}" == "1" ]; then
delete_tmp_policy_settings_dir "${policy_settings_dir}" delete_tmp_policy_settings_dir "${policy_settings_dir}"
fi fi
teardown_common "${node}" "${node_start_time:-}"
} }

View File

@ -6,20 +6,21 @@
# #
load "${BATS_TEST_DIRNAME}/../../common.bash" load "${BATS_TEST_DIRNAME}/../../common.bash"
load "${BATS_TEST_DIRNAME}/lib.sh"
load "${BATS_TEST_DIRNAME}/tests_common.sh" load "${BATS_TEST_DIRNAME}/tests_common.sh"
issue="https://github.com/kata-containers/kata-containers/issues/10297" issue="https://github.com/kata-containers/kata-containers/issues/10297"
setup() { setup() {
auto_generate_policy_enabled || skip "Auto-generated policy tests are disabled." auto_generate_policy_enabled || skip "Auto-generated policy tests are disabled."
setup_common
configmap_name="policy-configmap" configmap_name="policy-configmap"
pod_name="policy-pod" pod_name="policy-pod"
priority_class_name="test-high-priority" priority_class_name="test-high-priority"
get_pod_config_dir get_pod_config_dir
policy_settings_dir="$(create_tmp_policy_settings_dir "${pod_config_dir}")" policy_settings_dir="$(create_tmp_policy_settings_dir "${pod_config_dir}")"
exec_command=(printenv data-3) exec_command=(printenv data-3)
add_exec_to_policy_settings "${policy_settings_dir}" "${exec_command[@]}" add_exec_to_policy_settings "${policy_settings_dir}" "${exec_command[@]}"
add_requests_to_policy_settings "${policy_settings_dir}" "ReadStreamRequest" add_requests_to_policy_settings "${policy_settings_dir}" "ReadStreamRequest"
@ -43,7 +44,7 @@ setup() {
prometheus_image_supported || replace_prometheus_image prometheus_image_supported || replace_prometheus_image
# Save pre-generated yaml files # Save pre-generated yaml files
cp "${correct_configmap_yaml}" "${pre_generate_configmap_yaml}" cp "${correct_configmap_yaml}" "${pre_generate_configmap_yaml}"
cp "${correct_pod_yaml}" "${pre_generate_pod_yaml}" cp "${correct_pod_yaml}" "${pre_generate_pod_yaml}"
# Add policy to the correct pod yaml file # Add policy to the correct pod yaml file
@ -57,6 +58,9 @@ setup() {
# Also give each testcase a copy of the pre-generated yaml files. # Also give each testcase a copy of the pre-generated yaml files.
cp "${pre_generate_configmap_yaml}" "${testcase_pre_generate_configmap_yaml}" cp "${pre_generate_configmap_yaml}" "${testcase_pre_generate_configmap_yaml}"
cp "${pre_generate_pod_yaml}" "${testcase_pre_generate_pod_yaml}" cp "${pre_generate_pod_yaml}" "${testcase_pre_generate_pod_yaml}"
set_node "${testcase_pre_generate_pod_yaml}" "${node}"
set_node "${correct_pod_yaml}" "${node}"
} }
prometheus_image_supported() { prometheus_image_supported() {
@ -96,7 +100,7 @@ wait_for_pod_ready() {
runtime_class_name=$(yq ".spec.runtimeClassName" < "${testcase_pre_generate_pod_yaml}") runtime_class_name=$(yq ".spec.runtimeClassName" < "${testcase_pre_generate_pod_yaml}")
auto_generate_policy "${pod_config_dir}" "${testcase_pre_generate_pod_yaml}" "${testcase_pre_generate_configmap_yaml}" \ auto_generate_policy "${pod_config_dir}" "${testcase_pre_generate_pod_yaml}" "${testcase_pre_generate_configmap_yaml}" \
"--runtime-class-names=other-runtime-class-name --runtime-class-names=${runtime_class_name}" "--runtime-class-names=other-runtime-class-name --runtime-class-names=${runtime_class_name}"
kubectl create -f "${testcase_pre_generate_configmap_yaml}" kubectl create -f "${testcase_pre_generate_configmap_yaml}"
kubectl create -f "${testcase_pre_generate_pod_yaml}" kubectl create -f "${testcase_pre_generate_pod_yaml}"