@@ -6,20 +6,11 @@ set -o pipefail
66
77cd " $( dirname $0 ) /../.."
88
9- declare MOUNT_FLAGS=" "
109declare -A MOUNT_TARGETS=(
1110 [' nodeadm' ]=$PWD /_bin/nodeadm
1211 [' nodeadm-internal' ]=$PWD /_bin/nodeadm-internal
1312)
1413
15- for binary in " ${! MOUNT_TARGETS[@]} " ; do
16- if [ ! -f " ${MOUNT_TARGETS[$binary]} " ]; then
17- echo >&2 " error: you must build nodeadm (run \` make\` ) before you can run the e2e tests!"
18- exit 1
19- fi
20- MOUNT_FLAGS+=" -v ${MOUNT_TARGETS[$binary]} :/usr/local/bin/$binary "
21- done
22-
2314# build image
2415printf " 🛠️ Building test infra image with containerd v1..."
2516CONTAINERD_V1_IMAGE=$( docker build -q -f test/e2e/infra/Dockerfile --build-arg CONTAINERD_VERSION=1.7.* .)
@@ -32,47 +23,67 @@ echo "done! Test image with containerd v2: $CONTAINERD_V2_IMAGE"
3223FAILED=" false"
3324
3425function runTest() {
35- local case_name =$1
26+ local case_dir =$1
3627 local image=$2
37- if [[ $image == " $CONTAINERD_V1_IMAGE " ]]; then
38- printf " 🧪 Testing %s with containerd v1 image..." " $case_name "
28+
29+ local case_name
30+ case_name=$( basename " $case_dir " )
31+
32+ if [ $image = " $CONTAINERD_V1_IMAGE " ]; then
33+ echo -n " 🧪 Testing $case_name with containerd v1 image..."
3934 else
40- printf " 🧪 Testing %s with containerd v2 image..." " $case_name "
35+ echo -n " 🧪 Testing $case_name with containerd v2 image..."
4136 fi
4237
43- # NOTE: we force the mac address of the container to be the one from the
44- # ec2-metadata-mock to make expectations match.
45- CONTAINER_ID=$( docker run \
46- -d \
47- --rm \
48- --privileged \
49- --mac-address 0e:49:61:0f:c3:11 \
50- $MOUNT_FLAGS \
51- -v " $PWD /$CASE_DIR " :/test-case \
52- " $image " )
53-
54- LOG_FILE=$( mktemp)
55- if docker exec " $CONTAINER_ID " bash -c " cd /test-case && ./run.sh" > " $LOG_FILE " 2>&1 ; then
38+ local workdir=/test-case
39+ local docker_args=(
40+ --detach
41+ --rm
42+ --privileged
43+ # NOTE: we force the mac address of the container to be the one from the
44+ # ec2-metadata-mock to make expectations match.
45+ --mac-address " $( jq -r ' .metadata.values.mac' $case_dir /../../infra/aemm-default-config.json) "
46+ --workdir " $workdir "
47+ --volume " $( pwd) /$case_dir :$workdir "
48+ )
49+
50+ for binary in " ${! MOUNT_TARGETS[@]} " ; do
51+ if [ ! -f " ${MOUNT_TARGETS[$binary]} " ]; then
52+ echo >&2 " error: you must build nodeadm (run \` make\` ) before you can run the e2e tests!"
53+ exit 1
54+ fi
55+ docker_args+=(--volume " ${MOUNT_TARGETS[$binary]} :/usr/local/bin/$binary " )
56+ done
57+
58+ local containerd_id
59+ containerd_id=$( docker run " ${docker_args[@]} " " $image " )
60+
61+ local logfile
62+ logfile=$( mktemp)
63+
64+ if docker exec " $containerd_id " ./run.sh > " $logfile " 2>&1 ; then
5665 echo " passed! ✅"
5766 else
5867 echo " failed! ❌"
59- cat " $LOG_FILE "
68+ cat " $logfile "
6069 FAILED=" true"
6170 fi
62- docker kill " $CONTAINER_ID " > /dev/null 2>&1
71+
72+ # killing a container should not take more than 5 seconds.
73+ timeout 5 docker kill " $containerd_id " > /dev/null 2>&1
6374}
6475
6576# Run tests
6677CASE_PREFIX=${1:- }
6778for CASE_DIR in test/e2e/cases/${CASE_PREFIX} * ; do
6879 CASE_NAME=$( basename " $CASE_DIR " )
6980 if [[ " $CASE_NAME " == containerdv2-* ]]; then
70- runTest " $CASE_NAME " " $CONTAINERD_V2_IMAGE "
81+ runTest " $CASE_DIR " " $CONTAINERD_V2_IMAGE "
7182 continue
7283 elif [[ " $CASE_NAME " == containerd-* ]]; then
73- runTest " $CASE_NAME " " $CONTAINERD_V2_IMAGE "
84+ runTest " $CASE_DIR " " $CONTAINERD_V2_IMAGE "
7485 fi
75- runTest " $CASE_NAME " " $CONTAINERD_V1_IMAGE "
86+ runTest " $CASE_DIR " " $CONTAINERD_V1_IMAGE "
7687done
7788
7889if [ " $FAILED " = " true" ]; then
0 commit comments