2021-02-18 11:11:29 +00:00
#!/usr/bin/env bats -*- bats -*-
2019-10-29 21:08:15 +00:00
#
2021-02-18 11:11:29 +00:00
# Test podman play
#
load helpers
2021-02-24 21:24:26 +00:00
# This is a long ugly way to clean up pods and remove the pause image
function teardown() {
run_podman pod rm -f -a
run_podman rm -f -a
run_podman image list --format '{{.ID}} {{.Repository}}'
while read id name; do
if [[ "$name" =~ /pause ]]; then
run_podman rmi $id
fi
done <<<"$output"
basic_teardown
}
2021-02-18 11:11:29 +00:00
testYaml="
2019-10-29 21:08:15 +00:00
apiVersion: v1
kind: Pod
metadata:
labels:
app: test
2021-02-18 11:11:29 +00:00
name: test_pod
2019-10-29 21:08:15 +00:00
spec:
containers:
- command:
- sleep
- "100"
env:
- name: PATH
value: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
- name: TERM
value: xterm
- name: container
value: podman
2021-02-24 21:24:26 +00:00
image: $IMAGE
2019-10-29 21:08:15 +00:00
name: test
resources: {}
securityContext:
2019-11-04 23:07:58 +00:00
runAsUser: 1000
runAsGroup: 3000
fsGroup: 2000
2019-10-29 21:08:15 +00:00
allowPrivilegeEscalation: true
capabilities: {}
privileged: false
seLinuxOptions:
2021-02-18 11:11:29 +00:00
level: "s0:c1,c2"
2019-10-29 21:08:15 +00:00
readOnlyRootFilesystem: false
2021-05-14 09:56:24 +00:00
volumeMounts:
- mountPath: /testdir:z
name: home-podman-testdir
2019-10-29 21:08:15 +00:00
workingDir: /
2021-05-14 09:56:24 +00:00
volumes:
- hostPath:
path: TESTDIR
type: Directory
name: home-podman-testdir
2019-10-29 21:08:15 +00:00
status: {}
2021-02-18 11:11:29 +00:00
"
2021-05-14 09:56:24 +00:00
RELABEL="system_u:object_r:container_file_t:s0"
2021-02-18 11:11:29 +00:00
@test "podman play with stdin" {
2021-05-14 09:56:24 +00:00
TESTDIR=$PODMAN_TMPDIR/testdir
mkdir -p $TESTDIR
echo "$testYaml" | sed "s|TESTDIR|${TESTDIR}|g" > $PODMAN_TMPDIR/test.yaml
2021-02-18 11:11:29 +00:00
run_podman play kube - < $PODMAN_TMPDIR/test.yaml
2021-05-14 09:56:24 +00:00
if [ -e /usr/sbin/selinuxenabled -a /usr/sbin/selinuxenabled ]; then
run ls -Zd $TESTDIR
is "$output" ${RELABEL} "selinux relabel should have happened"
fi
2021-02-18 11:11:29 +00:00
run_podman pod rm -f test_pod
}
@test "podman play" {
2021-05-14 09:56:24 +00:00
TESTDIR=$PODMAN_TMPDIR/testdir
mkdir -p $TESTDIR
echo "$testYaml" | sed "s|TESTDIR|${TESTDIR}|g" > $PODMAN_TMPDIR/test.yaml
2021-02-18 11:11:29 +00:00
run_podman play kube $PODMAN_TMPDIR/test.yaml
2021-05-14 09:56:24 +00:00
if [ -e /usr/sbin/selinuxenabled -a /usr/sbin/selinuxenabled ]; then
run ls -Zd $TESTDIR
is "$output" ${RELABEL} "selinux relabel should have happened"
fi
2021-02-18 11:11:29 +00:00
run_podman pod rm -f test_pod
}
2021-05-18 14:37:54 +00:00
2021-06-29 18:18:46 +00:00
@test "podman play --network" {
TESTDIR=$PODMAN_TMPDIR/testdir
mkdir -p $TESTDIR
echo "$testYaml" | sed "s|TESTDIR|${TESTDIR}|g" > $PODMAN_TMPDIR/test.yaml
run_podman 125 play kube --network bridge $PODMAN_TMPDIR/test.yaml
2021-08-11 14:09:05 +00:00
is "$output" ".*invalid value passed to --network: bridge or host networking must be configured in YAML" "podman plan-network should fail with --network host"
2021-06-29 18:18:46 +00:00
run_podman 125 play kube --network host $PODMAN_TMPDIR/test.yaml
2021-08-11 14:09:05 +00:00
is "$output" ".*invalid value passed to --network: bridge or host networking must be configured in YAML" "podman plan-network should fail with --network host"
2021-06-29 18:18:46 +00:00
run_podman play kube --network slirp4netns:port_handler=slirp4netns $PODMAN_TMPDIR/test.yaml
run_podman pod rm -f test_pod
}
2021-05-18 14:37:54 +00:00
@test "podman play with user from image" {
TESTDIR=$PODMAN_TMPDIR/testdir
mkdir -p $TESTDIR
testUserYaml="
apiVersion: v1
kind: Pod
metadata:
labels:
app: test
name: test_pod
spec:
containers:
- command:
- id
env:
- name: PATH
value: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
- name: TERM
value: xterm
- name: container
value: podman
image: userimage
name: test
resources: {}
status: {}
"
cat > $PODMAN_TMPDIR/Containerfile << _EOF
from $IMAGE
USER bin
_EOF
echo "$testUserYaml" | sed "s|TESTDIR|${TESTDIR}|g" > $PODMAN_TMPDIR/test.yaml
run_podman build -t userimage $PODMAN_TMPDIR
run_podman play kube --start=false $PODMAN_TMPDIR/test.yaml
run_podman inspect --format "{{ .Config.User }}" test_pod-test
is "$output" bin "expect container within pod to run as the bin user"
run_podman pod rm -f test_pod
}