podman

Форк
0
/
280-update.bats 
152 строки · 5.4 Кб
1
#!/usr/bin/env bats   -*- bats -*-
2
#
3
# Tests for podman update
4
#
5

6
load helpers
7

8
LOOPDEVICE=
9

10
function teardown() {
11
    if [[ -n "$LOOPDEVICE" ]]; then
12
        losetup -d $LOOPDEVICE
13
        LOOPDEVICE=
14
    fi
15
    basic_teardown
16
}
17

18

19
# bats test_tags=distro-integration
20
@test "podman update - test all options" {
21
    local cgv=1
22
    if is_cgroupsv2; then
23
        cgv=2;
24
    fi
25

26
    # Need a block device for blkio-weight-device testing
27
    local pass_loop_device=
28
    if ! is_rootless; then
29
        if is_cgroupsv2; then
30
            lofile=${PODMAN_TMPDIR}/disk.img
31
            fallocate -l 1k  ${lofile}
32
            LOOPDEVICE=$(losetup --show -f $lofile)
33
            pass_loop_device="--device $LOOPDEVICE"
34

35
            # Get maj:min (tr needed because losetup seems to use %2d)
36
            lomajmin=$(losetup -l --noheadings --output MAJ:MIN $LOOPDEVICE | tr -d ' ')
37
        fi
38
    fi
39

40
    # Shortcuts to make the table narrower
41
    local -a gig=(0 1073741824 2147483648 3221225472)
42
    local devicemax="1:5 rbps=10485760 wbps=31457280 riops=2000 wiops=4000"
43
    local mm=memory/memory
44

45
    # Format:
46
    #   --<option> = <value>  | rootless? | check: cgroups v1            | check: cgroups v2
47
    #
48
    # Requires very wide window to read. Sorry.
49
    #
50
    # FIXMEs:
51
    #  cpu-rt-period  (cgv1 only, on cpu/cpu.rt_period_us) works on RHEL8 but not on Ubuntu
52
    #  cpu-rt-runtime (cgv1 only, on cpu/cpu.rt_runtime_us) fails: error setting cgroup config for procHooks ...
53
    tests="
54
cpu-shares          =            512 | - | cpu/cpu.shares       = 512              | cpu.weight      = 20
55
cpus                =              5 | - | cpu/cpu.cfs_quota_us = 500000           | cpu.max         = 500000 100000
56
cpuset-cpus         =              0 | - | cpuset/cpuset.cpus   = 0                | cpuset.cpus     = 0
57
cpuset-mems         =              0 | - | cpuset/cpuset.mems   = 0                | cpuset.mems     = 0
58

59
memory              =             1G | 2 | $mm.limit_in_bytes       = ${gig[1]}    | memory.max      = ${gig[1]}
60
memory-swap         =             3G | 2 | $mm.memsw.limit_in_bytes = ${gig[3]}    | memory.swap.max = ${gig[2]}
61
memory-reservation  =           400M | 2 | $mm.soft_limit_in_bytes  = 419430400    | memory.low      = 419430400
62

63
blkio-weight        =            321 | - | -                                       | io.bfq.weight   = default 321 $lomajmin 98
64
blkio-weight-device = $LOOPDEVICE:98 | - | -                                       | io.bfq.weight   = default 321 $lomajmin 98
65

66
device-read-bps     = /dev/zero:10mb | - | -                                       | io.max          = $devicemax
67
device-read-iops    = /dev/zero:2000 | - | -                                       | io.max          = $devicemax
68
device-write-bps    = /dev/zero:30mb | - | -                                       | io.max          = $devicemax
69
device-write-iops   = /dev/zero:4000 | - | -                                       | io.max          = $devicemax
70
"
71

72
    # Run a container
73
    run_podman run ${pass_loop_device} -d $IMAGE sleep infinity
74
    cid="$output"
75

76
    # Pass 1: read the table above, gather up the options applicable
77
    # to this test environment (root/rootless, cgroups v1/v2)
78
    local -a opts
79
    local -A check
80
    while read opt works_rootless cgv1 cgv2; do
81
        if is_rootless; then
82
            local skipping="skipping --$opt : does not work rootless"
83
            if [[ $works_rootless = '-' ]]; then
84
                echo "[ $skipping ]"
85
                continue
86
            fi
87
            if [[ ! $works_rootless =~ $cgv ]]; then
88
                echo "[ $skipping on cgroups v$cgv ]"
89
                continue
90
            fi
91
        fi
92

93
        tuple=$cgv1
94
        if is_cgroupsv2; then
95
            tuple=$cgv2
96
        fi
97
        if [[ $tuple = '-' ]]; then
98
            echo "[ skipping --$opt : N/A on cgroups v$cgv ]"
99
            continue
100
        fi
101

102
        # OK: setting is applicable. Preserve it. (First removing whitespace)
103
        opt=${opt// /}
104
        opts+=("--$opt")
105
        check["--$opt"]=$tuple
106
    done < <(parse_table "$tests")
107

108
    # Now do the update in one fell swoop
109
    run_podman update "${opts[@]}" $cid
110

111
    # ...and check one by one
112
    for opt in "${opts[@]}"; do
113
        read path op expect <<<"${check[$opt]}"
114
        run_podman exec $cid cat /sys/fs/cgroup/$path
115

116
        # Magic echo of unquoted-output converts newlines to spaces;
117
        # important for otherwise multiline blkio file.
118
        updated="$(echo $output)"
119
        assert "$updated" $op "$expect" "$opt ($path)"
120
    done
121

122
    # Clean up
123
    run_podman rm -f -t0 $cid
124
    if [[ -n "$LOOPDEVICE" ]]; then
125
        losetup -d $LOOPDEVICE
126
        LOOPDEVICE=
127
    fi
128
}
129

130
@test "podman update - set restart policy" {
131
    touch ${PODMAN_TMPDIR}/sentinel
132
    run_podman run --security-opt label=disable --name testctr -v ${PODMAN_TMPDIR}:/testdir -d $IMAGE sh -c "touch /testdir/alive; while test -e /testdir/sentinel; do sleep 0.1; done;"
133

134
    run_podman container inspect testctr --format "{{ .HostConfig.RestartPolicy.Name }}"
135
    is "$output" "no"
136

137
    run_podman update --restart always testctr
138

139
    run_podman container inspect testctr --format "{{ .HostConfig.RestartPolicy.Name }}"
140
    is "$output" "always"
141

142
    # Ensure the container is alive
143
    wait_for_file ${PODMAN_TMPDIR}/alive
144

145
    rm -f ${PODMAN_TMPDIR}/alive
146
    rm -f ${PODMAN_TMPDIR}/sentinel
147

148
    # Restart should ensure that the container comes back up and recreates the file
149
    wait_for_file ${PODMAN_TMPDIR}/alive
150
}
151

152
# vim: filetype=sh
153

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.