|
| 1 | +#!/usr/bin/env bats |
| 2 | +# Copyright (c) 2022 IBM Corporation |
| 3 | +# |
| 4 | +# SPDX-License-Identifier: Apache-2.0 |
| 5 | +# |
| 6 | + |
| 7 | +load "${BATS_TEST_DIRNAME}/lib.sh" |
| 8 | +load "${BATS_TEST_DIRNAME}/../../confidential/lib.sh" |
| 9 | + |
| 10 | +tag_suffix="" |
| 11 | +if [ "$(uname -m)" != "x86_64" ]; then |
| 12 | + tag_suffix="-$(uname -m)" |
| 13 | +fi |
| 14 | + |
| 15 | +# Images used on the tests. |
| 16 | + |
| 17 | +image_unsigned_protected="quay.io/kata-containers/confidential-containers:unsigned${tag_suffix}" |
| 18 | + |
| 19 | +original_kernel_params=$(get_kernel_params) |
| 20 | +# Allow to configure the runtimeClassName on pod configuration. |
| 21 | +RUNTIMECLASS="${RUNTIMECLASS:-kata}" |
| 22 | +test_tag="[cc][agent][kubernetes][containerd]" |
| 23 | + |
| 24 | +# Create the test pod. |
| 25 | +# |
| 26 | +# Note: the global $sandbox_name, $pod_config should be set |
| 27 | +# already. It also relies on $CI and $DEBUG exported by CI scripts or |
| 28 | +# the developer, to decide how to set debug flags. |
| 29 | +# |
| 30 | +create_test_pod() { |
| 31 | + local pod_config="$1" |
| 32 | + |
| 33 | + echo "Create the test sandbox" |
| 34 | + echo "Pod config is: $pod_config" |
| 35 | + crictl crictl run --with-pull -r kata-qemu $pod_config nydus-sandbox.yaml |
| 36 | +} |
| 37 | + |
| 38 | +# Create a pod configuration out of a template file. |
| 39 | +# |
| 40 | +# Parameters: |
| 41 | +# $1 - the container image. |
| 42 | +# Return: |
| 43 | +# the path to the configuration file. The caller should not care about |
| 44 | +# its removal afterwards as it is created under the bats temporary |
| 45 | +# directory. |
| 46 | +# |
| 47 | +# Environment variables: |
| 48 | +# RUNTIMECLASS: set the runtimeClassName value from $RUNTIMECLASS. |
| 49 | +# |
| 50 | +new_pod_config() { |
| 51 | + local base_config="${FIXTURES_DIR}/cri-pod-config.yaml.in" |
| 52 | + local image="$1" |
| 53 | + local index="$2" |
| 54 | + |
| 55 | + local new_config=$(mktemp "${BATS_FILE_TMPDIR}/$(basename ${base_config}).XXX") |
| 56 | + IMAGE="$image" RUNTIMECLASS="$RUNTIMECLASS" INDEX="$2" envsubst <"$base_config" >"$new_config" |
| 57 | + echo "$new_config" |
| 58 | +} |
| 59 | + |
| 60 | +setup() { |
| 61 | + start_date=$(date +"%Y-%m-%d %H:%M:%S") |
| 62 | + setup_proxy |
| 63 | + switch_measured_rootfs_verity_scheme none |
| 64 | +} |
| 65 | + |
| 66 | +@test "$test_tag Test can pull an image as a raw block disk image to guest with dm-verity enabled" { |
| 67 | + if [ "$SNAPSHOTTER" = "nydus" ]; then |
| 68 | + EXPORT_MODE="image_block_with_verity" RUNTIMECLASS="$RUNTIMECLASS" SNAPSHOTTER="nydus" configure_remote_snapshotter |
| 69 | + pod_config="$(new_pod_config "$image_unsigned_unprotected")" |
| 70 | + echo $pod_config |
| 71 | + create_test_pod "$pod_config" |
| 72 | + remove_test_image "$image_unsigned_unprotected" |
| 73 | + fi |
| 74 | +} |
| 75 | + |
| 76 | +@test "$test_tag Test can create two pods with pulling the image only once" { |
| 77 | + if [ "$SNAPSHOTTER" = "nydus" ]; then |
| 78 | + EXPORT_MODE="image_block_with_verity" RUNTIMECLASS="$RUNTIMECLASS" SNAPSHOTTER="nydus" configure_remote_snapshotter |
| 79 | + |
| 80 | + pod_config_1="$(new_pod_config "$image_unsigned_unprotected" "1")" |
| 81 | + echo $pod_config_1 |
| 82 | + create_test_pod $pod_config_1 |
| 83 | + pod_config_2="$(new_pod_config "$image_unsigned_unprotected" "2")" |
| 84 | + echo $pod_config_2 |
| 85 | + create_test_pod $pod_config_2 |
| 86 | + |
| 87 | + pull_times=$(journalctl -g "PullImage \"$image_unsigned_unprotected\" with snapshotter nydus" | wc -l) |
| 88 | + [ ${#pull_times[@]} -eq 1 ] |
| 89 | + remove_test_image "$image_unsigned_unprotected" |
| 90 | + fi |
| 91 | +} |
| 92 | + |
| 93 | +@test "$test_tag Test can pull an image inside the guest with remote-snapshotter" { |
| 94 | + skip |
| 95 | + switch_image_service_offload on |
| 96 | + if [ "$SNAPSHOTTER" = "nydus" ]; then |
| 97 | + EXPORT_MODE="image_guest_pull" RUNTIMECLASS="$RUNTIMECLASS" SNAPSHOTTER="nydus" configure_remote_snapshotter |
| 98 | + create_test_pod |
| 99 | + remove_test_image "$image_unsigned_unprotected" |
| 100 | + fi |
| 101 | +} |
| 102 | + |
| 103 | +teardown() { |
| 104 | + remove_nydus_snapshotter_from_containerd |
| 105 | +} |
0 commit comments