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