4
4
# SPDX-License-Identifier: Apache-2.0
5
5
#
6
6
7
- load " ${BATS_TEST_DIRNAME} /lib.sh"
8
- load " ${BATS_TEST_DIRNAME} /../../confidential/lib.sh"
7
+ load " ${BATS_TEST_DIRNAME} /tests_common.sh"
9
8
10
9
tag_suffix=" "
11
10
if [ " $( uname -m) " != " x86_64" ]; then
@@ -27,84 +26,12 @@ image_unsigned_unprotected="quay.io/prometheus/busybox:latest"
27
26
# # Authenticated Image
28
27
image_authenticated=" quay.io/kata-containers/confidential-containers-auth:test"
29
28
30
- original_kernel_params=$( get_kernel_params)
31
29
# Allow to configure the runtimeClassName on pod configuration.
32
30
RUNTIMECLASS=" ${RUNTIMECLASS:- kata} "
33
31
test_tag=" [cc][agent][kubernetes][containerd]"
34
32
35
- # Create the test pod.
36
- #
37
- # Note: the global $sandbox_name, $pod_config should be set
38
- # already. It also relies on $CI and $DEBUG exported by CI scripts or
39
- # the developer, to decide how to set debug flags.
40
- #
41
- create_test_pod () {
42
- # On CI mode we only want to enable the agent debug for the case of
43
- # the test failure to obtain logs.
44
- if [ " ${CI:- } " == " true" ]; then
45
- enable_full_debug
46
- elif [ " ${DEBUG:- } " == " true" ]; then
47
- enable_full_debug
48
- enable_agent_console
49
- fi
50
-
51
- echo " Create the test sandbox"
52
- echo " Pod config is: $pod_config "
53
- kubernetes_create_cc_pod $pod_config
54
- }
55
-
56
- # Create a pod configuration out of a template file.
57
- #
58
- # Parameters:
59
- # $1 - the container image.
60
- # Return:
61
- # the path to the configuration file. The caller should not care about
62
- # its removal afterwards as it is created under the bats temporary
63
- # directory.
64
- #
65
- # Environment variables:
66
- # RUNTIMECLASS: set the runtimeClassName value from $RUNTIMECLASS.
67
- #
68
- new_pod_config () {
69
- local base_config=" ${FIXTURES_DIR} /pod-config.yaml.in"
70
- local image=" $1 "
71
-
72
- local new_config=$( mktemp " ${BATS_FILE_TMPDIR} /$( basename ${base_config} ) .XXX" )
73
- IMAGE=" $image " RUNTIMECLASS=" $RUNTIMECLASS " envsubst < " $base_config " > " $new_config "
74
- echo " $new_config "
75
- }
76
-
77
33
setup () {
78
- start_date=$( date +" %Y-%m-%d %H:%M:%S" )
79
-
80
- pod_config=" $( new_pod_config " $image_simple_signed " ) "
81
- pod_id=" "
82
-
83
- kubernetes_delete_all_cc_pods_if_any_exists || true
84
-
85
- echo " Prepare containerd for Confidential Container"
86
- SAVED_CONTAINERD_CONF_FILE=" /etc/containerd/config.toml.$$ "
87
- configure_cc_containerd " $SAVED_CONTAINERD_CONF_FILE "
88
-
89
- echo " Reconfigure Kata Containers"
90
- switch_image_service_offload on
91
- clear_kernel_params
92
- add_kernel_params " ${original_kernel_params} "
93
-
94
- setup_proxy
95
- switch_measured_rootfs_verity_scheme none
96
- }
97
-
98
- # Check the logged messages on host have a given message.
99
- # Parameters:
100
- # $1 - the message
101
- #
102
- # Note: get the logs since the global $start_date.
103
- #
104
- assert_logs_contain () {
105
- local message=" $1 "
106
- # Note: with image-rs we get more that the default 1000 lines of logs
107
- journalctl -x -t kata --since " $start_date " -n 100000 | grep " $message "
34
+ setup_common
108
35
}
109
36
110
37
@test " $test_tag Test can launch pod with measured boot enabled" {
@@ -224,20 +151,5 @@ assert_logs_contain() {
224
151
}
225
152
226
153
teardown () {
227
- # Print the logs and cleanup resources.
228
- echo " -- Kata logs:"
229
- sudo journalctl -xe -t kata --since " $start_date " -n 100000
230
-
231
- # Allow to not destroy the environment if you are developing/debugging
232
- # tests.
233
- if [[ " ${CI:- false} " == " false" && " ${DEBUG:- } " == true ]]; then
234
- echo " Leaving changes and created resources untouched"
235
- return
236
- fi
237
-
238
- kubernetes_delete_all_cc_pods_if_any_exists || true
239
- clear_kernel_params
240
- add_kernel_params " ${original_kernel_params} "
241
- switch_image_service_offload off
242
- disable_full_debug
154
+ teardown_common
243
155
}
0 commit comments