mirror of
https://github.com/containers/podman.git
synced 2025-12-01 18:49:18 +08:00
Merge pull request #23301 from ypu/automount-volume
test/system: Add a test case for automount with multi images
This commit is contained in:
@@ -988,29 +988,60 @@ _EOF
|
|||||||
}
|
}
|
||||||
|
|
||||||
@test "podman play with automount volume" {
|
@test "podman play with automount volume" {
|
||||||
imgname="automount-test-$(safename)"
|
imgname1="automount-img1-$(safename)"
|
||||||
|
imgname2="automount-img2-$(safename)"
|
||||||
podname="p-$(safename)"
|
podname="p-$(safename)"
|
||||||
ctrname="c-$(safename)"
|
ctrname="c-$(safename)"
|
||||||
|
ctrname_not_mounted="c-not-mounted-$(safename)"
|
||||||
|
|
||||||
cat >$PODMAN_TMPDIR/Containerfile <<EOF
|
cat >$PODMAN_TMPDIR/Containerfile1 <<EOF
|
||||||
FROM $IMAGE
|
FROM $IMAGE
|
||||||
RUN mkdir /test1 /test2
|
RUN mkdir /test1 /test_same && \
|
||||||
RUN touch /test1/a /test1/b /test1/c
|
touch /test1/a /test1/b /test1/c && \
|
||||||
RUN touch /test2/asdf /test2/ejgre /test2/lteghe
|
echo "I am from test1 image" > /test_same/hello_world
|
||||||
VOLUME /test1
|
VOLUME /test1
|
||||||
VOLUME /test2
|
VOLUME /test_same
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
run_podman build -t $imgname -f $PODMAN_TMPDIR/Containerfile
|
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
|
||||||
|
|
||||||
fname="/tmp/play_kube_wait_$(random_string 6).yaml"
|
run_podman build -t $imgname1 -f $PODMAN_TMPDIR/Containerfile1
|
||||||
echo "
|
run_podman build -t $imgname2 -f $PODMAN_TMPDIR/Containerfile2
|
||||||
|
|
||||||
|
_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
|
apiVersion: v1
|
||||||
kind: Pod
|
kind: Pod
|
||||||
metadata:
|
metadata:
|
||||||
labels:
|
labels:
|
||||||
app: test
|
app: test
|
||||||
name: $podname
|
name: $podname
|
||||||
|
annotations:
|
||||||
|
io.podman.annotations.kube.image.volumes.mount/$ctrname: $imgname1;$imgname2
|
||||||
spec:
|
spec:
|
||||||
restartPolicy: Never
|
restartPolicy: Never
|
||||||
containers:
|
containers:
|
||||||
@@ -1018,24 +1049,31 @@ spec:
|
|||||||
image: $IMAGE
|
image: $IMAGE
|
||||||
command:
|
command:
|
||||||
- top
|
- 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
|
run_podman exec "$podname-$ctrname" ls -x /test1
|
||||||
assert "$output" = "a b c" "ls /test1 on image"
|
assert "a b c" "ls /test1 inside container"
|
||||||
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 $imgname ls -x /test2
|
run_podman exec "$podname-$ctrname" ls -x /test2
|
||||||
assert "$output" = "asdf ejgre lteghe" "ls /test2 on image"
|
assert "asdf ejgre lteghe" "ls /test2 inside container"
|
||||||
run_out_test2="$output"
|
|
||||||
run_podman exec $podname-$ctrname ls -x /test2
|
run_podman exec "$podname-$ctrname" cat /test_same/hello_world
|
||||||
assert "$output" = "$run_out_test2" "matching ls run/exec volume path test2"
|
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 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 kube down $fname
|
||||||
run_podman rmi $imgname
|
run_podman rmi $imgname1 $imgname2
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "podman kube restore user namespace" {
|
@test "podman kube restore user namespace" {
|
||||||
|
|||||||
Reference in New Issue
Block a user