Skip to content

Commit

Permalink
Add test steps for automount with multi images
Browse files Browse the repository at this point in the history
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 <ypu@redhat.com>
  • Loading branch information
ypu committed Jul 25, 2024
1 parent 003527f commit 73d47f6
Showing 1 changed file with 68 additions and 26 deletions.
94 changes: 68 additions & 26 deletions test/system/700-play.bats
Original file line number Diff line number Diff line change
Expand Up @@ -988,52 +988,94 @@ _EOF
}

@test "podman play with automount volume" {
imgname="automount-test-$(safename)"
podname="p-$(safename)"
ctrname="c-$(safename)"

cat >$PODMAN_TMPDIR/Containerfile <<EOF
imgname1="automount-test-$(safename)1"
imgname2="automount-test-$(safename)2"
podname_cmd="p-$(safename)-cmd"
ctrname_cmd="c-$(safename)-cmd"
podname_file="p-$(safename)-file"
ctrname_file="c-$(safename)-file"
ctrname_file_not_mounted="c-$(safename)-not-mounted"

cat >$PODMAN_TMPDIR/Containerfile1 <<EOF
FROM $IMAGE
RUN mkdir /test1 /test2
RUN touch /test1/a /test1/b /test1/c
RUN touch /test2/asdf /test2/ejgre /test2/lteghe
RUN mkdir /test1 /test_same && \
touch /test1/a /test1/b /test1/c && \
echo "I am from test1 image" > /test_same/hello_world
VOLUME /test1
VOLUME /test_same
EOF

cat >$PODMAN_TMPDIR/Containerfile2 <<EOF
FROM $IMAGE
RUN mkdir /test2 /test_same && \
touch /test2/asdf /test2/ejgre /test2/lteghe && \
echo "I am from test2 image" > /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_cmd ctrname=$ctrname_cmd
run_podman kube play --annotation "io.podman.annotations.kube.image.volumes.mount/$ctrname_cmd=$imgname1" $TESTYAML

run_podman run --rm $imgname1 ls -x /
run_podman run --rm $imgname2 ls -x /
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_cmd-$ctrname_cmd 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_test2="$output"
run_podman exec $podname_cmd-$ctrname_cmd cat /test_same/hello_world
assert "$output" = "$run_out_test2" "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 <<EOF
apiVersion: v1
kind: Pod
metadata:
labels:
app: test
name: $podname
name: $podname_file
annotations:
io.podman.annotations.kube.image.volumes.mount/$ctrname_file: $imgname1;$imgname2
spec:
restartPolicy: Never
containers:
- name: $ctrname
- name: $ctrname_file
image: $IMAGE
command:
- top
" > $fname
- name: $ctrname_file_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_file-$ctrname_file" ls -x /test1
assert "a b c" "ls /test1 on image"

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_file-$ctrname_file" ls -x /test2
assert "asdf ejgre lteghe" "ls /test2 on image"

run_podman exec "$podname_file-$ctrname_file" cat /test_same/hello_world
assert "I am from test2 image" "cat /test_same/hello_world inside container"

run_podman 1 exec "$podname_file-$ctrname_file" touch /test1/readonly
assert "$output" =~ "Read-only file system" "image mounted as readonly"

run_podman exec "$podname_file-$ctrname_file_not_mounted" ls /
assert "test" !~ "$output" "No volume should be mounted in $podname_file-$ctrname_file_not_mounted"

run_podman kube down $fname
run_podman rmi $imgname
run_podman rmi $imgname1 $imgname2
}

0 comments on commit 73d47f6

Please sign in to comment.