-
Notifications
You must be signed in to change notification settings - Fork 173
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·92 lines (74 loc) · 2.36 KB
/
test.sh
File metadata and controls
executable file
·92 lines (74 loc) · 2.36 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/bash
## kola:
## tags: "platform-independent needs-internet"
## # Toolbox container is currently available only for x86_64 and aarch64 in Fedora
## architectures: x86_64 aarch64
## description: Make sure that basic toolbox functionality works (creating,
## running commands, and removing).
set -xeuo pipefail
# shellcheck disable=SC1091
. "$KOLA_EXT_DATA/commonlib.sh"
# IMPORTANT: Commands are run indirectly via `su - core` to re-create the
# user environment needed for unprivileged podman functionality.
run_as_core() {
su - core -c "$(printf '%q ' "$@")"
}
# Functions for testing basic functionality - overridden depending on toolbox being used
toolbox_create() {
run_as_core /bin/toolbox create --assumeyes 1> /dev/null
}
toolbox_run_basic() {
run_as_core /bin/toolbox run touch ok_toolbox
}
toolbox_list() {
run_as_core /bin/toolbox list --containers
}
toolbox_count() {
toolbox_list | grep --count -E "(fedora|rhel)-toolbox-" || true
}
toolbox_rm() {
toolbox="$(toolbox_list | awk '/(fedora|rhel)-toolbox-/ {print $2}')"
run_as_core /bin/toolbox rm -f "${toolbox}"
}
# Older variants (e.g. RHEL-9.8) use https://github.com/coreos/toolbox
# NOTE: script uses privileged podman
if file /bin/toolbox | grep -q "shell script"; then
echo "Using toolbox script <https://github.com/coreos/toolbox>"
toolbox_create() {
# Container created on first run of any command
run_as_core /bin/toolbox true
}
toolbox_run_basic() {
run_as_core /bin/toolbox touch /host/home/core/ok_toolbox
}
toolbox_list() {
/bin/podman ps -a
}
toolbox_rm() {
toolbox="$(toolbox_list | awk '/(fedora|rhel)-toolbox-/ {print $1}')"
/bin/podman rm -f "${toolbox}"
}
fi
# Try five times to create the toolbox to avoid container registry infra flakes
for i in {1..5}; do
toolbox_create || true
if [[ $(toolbox_count) -eq 1 ]]; then
break
fi
if [[ $i -eq 5 ]]; then
fatal "Could not create toolbox after 5 attempts"
fi
echo "Could not create toolbox on try: $i"
sleep 10
done
ok toolbox create
toolbox_run_basic
if [[ ! -f '/home/core/ok_toolbox' ]]; then
fatal "Could not run a simple command inside a toolbox"
fi
ok toolbox run
toolbox_rm
if [[ $(toolbox_count) -ne 0 ]]; then
fatal "Could not remove the toolbox container"
fi
ok toolbox rm