1
#!/usr/bin/env bats -*- bats -*-
3
# Tests for podman update
11
if [[ -n "$LOOPDEVICE" ]]; then
12
losetup -d $LOOPDEVICE
19
# bats test_tags=distro-integration
20
@test "podman update - test all options" {
26
# Need a block device for blkio-weight-device testing
27
local pass_loop_device=
28
if ! is_rootless; then
30
lofile=${PODMAN_TMPDIR}/disk.img
31
fallocate -l 1k ${lofile}
32
LOOPDEVICE=$(losetup --show -f $lofile)
33
pass_loop_device="--device $LOOPDEVICE"
35
# Get maj:min (tr needed because losetup seems to use %2d)
36
lomajmin=$(losetup -l --noheadings --output MAJ:MIN $LOOPDEVICE | tr -d ' ')
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
46
# --<option> = <value> | rootless? | check: cgroups v1 | check: cgroups v2
48
# Requires very wide window to read. Sorry.
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 ...
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
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
63
blkio-weight = 321 | - | - | io.bfq.weight = default 321 $lomajmin 98
64
blkio-weight-device = $LOOPDEVICE:98 | - | - | io.bfq.weight = default 321 $lomajmin 98
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
73
run_podman run ${pass_loop_device} -d $IMAGE sleep infinity
76
# Pass 1: read the table above, gather up the options applicable
77
# to this test environment (root/rootless, cgroups v1/v2)
80
while read opt works_rootless cgv1 cgv2; do
82
local skipping="skipping --$opt : does not work rootless"
83
if [[ $works_rootless = '-' ]]; then
87
if [[ ! $works_rootless =~ $cgv ]]; then
88
echo "[ $skipping on cgroups v$cgv ]"
97
if [[ $tuple = '-' ]]; then
98
echo "[ skipping --$opt : N/A on cgroups v$cgv ]"
102
# OK: setting is applicable. Preserve it. (First removing whitespace)
105
check["--$opt"]=$tuple
106
done < <(parse_table "$tests")
108
# Now do the update in one fell swoop
109
run_podman update "${opts[@]}" $cid
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
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)"
123
run_podman rm -f -t0 $cid
124
if [[ -n "$LOOPDEVICE" ]]; then
125
losetup -d $LOOPDEVICE
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;"
134
run_podman container inspect testctr --format "{{ .HostConfig.RestartPolicy.Name }}"
137
run_podman update --restart always testctr
139
run_podman container inspect testctr --format "{{ .HostConfig.RestartPolicy.Name }}"
140
is "$output" "always"
142
# Ensure the container is alive
143
wait_for_file ${PODMAN_TMPDIR}/alive
145
rm -f ${PODMAN_TMPDIR}/alive
146
rm -f ${PODMAN_TMPDIR}/sentinel
148
# Restart should ensure that the container comes back up and recreates the file
149
wait_for_file ${PODMAN_TMPDIR}/alive