File: 195-run-namespaces.bats

package info (click to toggle)
podman 5.4.2%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 23,124 kB
  • sloc: sh: 6,119; perl: 2,710; python: 2,258; ansic: 1,556; makefile: 1,022; xml: 121; ruby: 42; awk: 12; csh: 8
file content (53 lines) | stat: -rw-r--r-- 1,521 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env bats   -*- bats -*-
#
# Tests for the namespace options
#

load helpers

# bats test_tags=distro-integration, ci:parallel
@test "podman test all namespaces" {
    # format is nsname | option name
    tests="
cgroup | cgroupns
ipc    | ipc
net    | network
pid    | pid
uts    | uts
"

    for nstype in private host; do
        while read name option; do
            local cname="c-${name}-$(safename)"
            # ipc is special, private does not allow joining from another container.
            # Instead we must use "shareable".
            local type=$nstype
            if [ "$name" = "ipc" ] && [ "$type" = "private" ]; then
                type="shareable"
            fi

            run_podman run --name $cname --$option $type -d $IMAGE sh -c \
                "readlink /proc/self/ns/$name; sleep inf"

            run_podman run --rm --$option container:$cname $IMAGE readlink /proc/self/ns/$name
            con2_ns="$output"

            run readlink /proc/self/ns/$name
            host_ns="$output"

            run_podman logs $cname
            con1_ns="$output"

            assert "$con1_ns" == "$con2_ns" "($name) namespace matches (type: $type)"
            local matcher="=="
            if [[ "$type" != "host" ]]; then
                matcher="!="
            fi
            assert "$con1_ns" $matcher "$host_ns" "expected host namespace to ($matcher) (type: $type)"

            run_podman rm -f -t0 $cname
        done < <(parse_table "$tests")
    done
}

# vim: filetype=sh