Skip to content

Commit

Permalink
Merge pull request #23301 from ypu/automount-volume
Browse files Browse the repository at this point in the history
test/system: Add a test case for automount with multi images
  • Loading branch information
openshift-merge-bot[bot] authored Jul 29, 2024
2 parents ce71f3d + a18bd3e commit c7f00b6
Showing 1 changed file with 59 additions and 21 deletions.
80 changes: 59 additions & 21 deletions test/system/700-play.bats
Original file line number Diff line number Diff line change
Expand Up @@ -988,54 +988,92 @@ _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 <<EOF
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 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 <<EOF
apiVersion: v1
kind: Pod
metadata:
labels:
app: test
name: $podname
annotations:
io.podman.annotations.kube.image.volumes.mount/$ctrname: $imgname1;$imgname2
spec:
restartPolicy: Never
containers:
- name: $ctrname
image: $IMAGE
command:
- top
" > $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" {
Expand Down

0 comments on commit c7f00b6

Please sign in to comment.