From a18bd3e9c060db73a1f31ec63135372b63662076 Mon Sep 17 00:00:00 2001 From: Yiqiao Pu Date: Wed, 17 Jul 2024 14:02:58 +0800 Subject: [PATCH] Add test steps for automount with multi images These test steps check the automount feature with multi images for following item: 1. multi images can be auotmounted with yaml file. 2. if there are same path exist in the images, the last one should trumps. 3. the volume is mounted readonly in the container. 4. the volumes are only mounted in the specific container, but not the whole pods. Signed-off-by: Yiqiao Pu --- test/system/700-play.bats | 80 +++++++++++++++++++++++++++++---------- 1 file changed, 59 insertions(+), 21 deletions(-) diff --git a/test/system/700-play.bats b/test/system/700-play.bats index e547badf18..b1a24c1970 100644 --- a/test/system/700-play.bats +++ b/test/system/700-play.bats @@ -988,29 +988,60 @@ _EOF } @test "podman play with automount volume" { - imgname="automount-test-$(safename)" + imgname1="automount-img1-$(safename)" + imgname2="automount-img2-$(safename)" podname="p-$(safename)" ctrname="c-$(safename)" + ctrname_not_mounted="c-not-mounted-$(safename)" - cat >$PODMAN_TMPDIR/Containerfile <$PODMAN_TMPDIR/Containerfile1 < /test_same/hello_world VOLUME /test1 +VOLUME /test_same +EOF + + cat >$PODMAN_TMPDIR/Containerfile2 < /test_same/hello_world VOLUME /test2 +VOLUME /test_same EOF - run_podman build -t $imgname -f $PODMAN_TMPDIR/Containerfile + run_podman build -t $imgname1 -f $PODMAN_TMPDIR/Containerfile1 + run_podman build -t $imgname2 -f $PODMAN_TMPDIR/Containerfile2 - fname="/tmp/play_kube_wait_$(random_string 6).yaml" - echo " + _write_test_yaml command=top name=$podname ctrname=$ctrname + run_podman kube play --annotation "io.podman.annotations.kube.image.volumes.mount/$ctrname=$imgname1" $TESTYAML + + run_podman run --rm $imgname1 ls -x /test1 + assert "$output" = "a b c" "ls /test1 on image" + run_out_test1="$output" + run_podman exec $podname-$ctrname ls -x /test1 + assert "$output" = "$run_out_test1" "matching ls run/exec volume path test1" + + run_podman run --rm $imgname1 cat /test_same/hello_world + assert "$output" = "I am from test1 image" "cat /test_same/hello_world on image" + run_out_hello_world="$output" + run_podman exec $podname-$ctrname cat /test_same/hello_world + assert "$output" = "$run_out_hello_world" "matching cat /test_same/hello_world volume path test_same" + + run_podman kube down $TESTYAML + + fname="/$PODMAN_TMPDIR/play_kube_wait_$(random_string 6).yaml" + cat >$fname < $fname + - name: $ctrname_not_mounted + image: $IMAGE + command: + - top +EOF - run_podman kube play --annotation "io.podman.annotations.kube.image.volumes.mount/$ctrname=$imgname" $fname + run_podman kube play $fname - run_podman run --rm $imgname ls -x /test1 - assert "$output" = "a b c" "ls /test1 on image" - run_out_test1="$output" - run_podman exec $podname-$ctrname ls -x /test1 - assert "$output" = "$run_out_test1" "matching ls run/exec volume path test1" + run_podman exec "$podname-$ctrname" ls -x /test1 + assert "a b c" "ls /test1 inside container" + + run_podman exec "$podname-$ctrname" ls -x /test2 + assert "asdf ejgre lteghe" "ls /test2 inside container" + + run_podman exec "$podname-$ctrname" cat /test_same/hello_world + assert "I am from test2 image" "cat /test_same/hello_world inside container" + + run_podman 1 exec "$podname-$ctrname" touch /test1/readonly + assert "$output" =~ "Read-only file system" "image mounted as readonly" - run_podman run --rm $imgname ls -x /test2 - assert "$output" = "asdf ejgre lteghe" "ls /test2 on image" - run_out_test2="$output" - run_podman exec $podname-$ctrname ls -x /test2 - assert "$output" = "$run_out_test2" "matching ls run/exec volume path test2" + run_podman exec "$podname-$ctrname_not_mounted" ls / + assert "$output" !~ "test" "No volume should be mounted in no-mount container" run_podman kube down $fname - run_podman rmi $imgname + run_podman rmi $imgname1 $imgname2 } @test "podman kube restore user namespace" {