forked from rhinstaller/kickstart-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlaunch
executable file
·152 lines (135 loc) · 6.69 KB
/
launch
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/bin/sh
# Run a set of tests (positional command line arguments) in the runner container in podman or docker.
# Tests are taken from the current kickstart-tests checkout
# If data/images/boot.iso exists, that is tested, otherwise it downloads the current Fedora Rawhide version.
# Runs --recommended-jobs number of parallel tests by default, which can be changed by setting $TEST_JOBS.
set -eu
BASEDIR=$(dirname $(dirname $(dirname $(realpath $0))))
CRUN=${CRUN:-$(which podman docker 2>/dev/null | head -n1)}
CONTAINER=quay.io/rhinstaller/kstest-runner
# Podman in rootless mode does not have access to /dev/kvm socket https://bugzilla.redhat.com/show_bug.cgi?id=1901462
# disable selinux container separation when podman is executed as user
PODMAN_SELINUX_FIX=
RUN_COMMAND=/kickstart-tests/containers/runner/run-kstest
# Get number of jobs to be run in parallel based on number of CPUs and amount of RAM
recommended_jobs() {
local ram_for_test=2.5
mem_limit=$(awk -F":" -v ram_for_test=${ram_for_test} '$1~/MemTotal/{print int($2 / 1024^2 / ram_for_test) }' /proc/meminfo )
cpu_limit=$(nproc)
if [ $mem_limit -lt $cpu_limit ]; then
echo ${mem_limit}
else
echo ${cpu_limit}
fi
}
TEST_JOBS=${TEST_JOBS:-$(recommended_jobs)}
if ! test -w /dev/kvm; then
echo "FATAL: /dev/kvm not accessible" >&2
exit 1
fi
usage() {
cat <<EOF
Usage:
Run individual tests:
$0 [options] test1 test2 ...
Run all tests:
$0 [options] all
Options:
-j, --jobs N Run N jobs in parallel (default: $(recommended_jobs))
-p, --platform NAME See fragments/platform/ (default: fedora_rawhide)
-t, --testtype TYPE Only run TYPE tests
-s, --skip-testtypes TYPE[,TYPE..] Don't run tests with given types
-u, --updates PATH|URL Set updates.img path or URL
-r, --retry Retry failed tests once, to guard against random
infrastructure failures
-c, --connect-shell Connect to the container and do not run the tests
automatically
--daily-iso TOKEN_FILE Download and use daily boot.iso instead of rawhide's
(This requires a GitHub token that can read
rhinstaller/kickstart-tests workflow artifacts.)
--defaults DEFAULTS_SH_FILE Path to file with overrides to scripts/defaults.sh
--run-args ARGUMENTS Extra $CRUN options/arguments (space separated)
--recommended-jobs Print the number of jobs (--jobs option) used
by default and exit. It is calulated from the number
of CPUs and the size of RAM.
-h, --help Show this help
EOF
}
# parse options
eval set -- "$(getopt -o j:p:t:s:u:rch --long jobs:,platform:,testtype:,skip-testtypes:,updates:,retry,connect-shell,daily-iso:,defaults:,run-args:,recommended-jobs,help -- "$@")"
while true; do
case "${1:-}" in
-j|--jobs) shift; TEST_JOBS=$1 ;;
-p|--platform) shift; PLATFORM=$1 ;;
-t|--testtype) shift; TESTTYPE="$1" ;;
-s|--skip-testtypes) shift; SKIP_TESTTYPES="$1" ;;
-u|--updates) shift; UPDATES_IMAGE="$1" ;;
-r|--retry) TEST_RETRY=1 ;;
-c|--connect-shell) RUN_COMMAND=/bin/bash ;;
--daily-iso) shift; DAILY_ISO_TOKEN="$1" ;;
--defaults) shift; DEFAULTS_SH="$1" ;;
--run-args) shift; CONTAINER_RUN_ARGS="$1" ;;
--recommended-jobs) recommended_jobs; exit 0 ;;
-h|--help) usage; exit 0 ;;
--) shift; break ;;
esac
shift
done
# avoid accidentally running all tests
if [ -z "${1:-}" ] && [ -z "${TESTTYPE:-}" ]; then
usage
exit 1
elif [ "${1:-}" = all ] && [ -z "${2:-}" ]; then
KSTESTS_TEST=""
else
KSTESTS_TEST="$*"
fi
# prepare data directory
mkdir -p data/images
mkdir -p -m 777 data/logs
if ! [ -e data/images/boot.iso ]; then
if [ -n "${DAILY_ISO_TOKEN:-}" ]; then
echo "INFO: data/images/boot.iso does not exist, downloading daily iso..."
CURL="curl -u token:$(cat $DAILY_ISO_TOKEN) --show-error --fail"
RESPONSE=$($CURL --silent https://api.github.com/repos/rhinstaller/kickstart-tests/actions/artifacts)
ZIP=$(echo "$RESPONSE" | jq --raw-output '.artifacts | map(select(.name == "images"))[0].archive_download_url')
echo "INFO: Downloading $ZIP ..."
$CURL -L -o data/images.zip "$ZIP"
# there is on unzip on RHEL 7, so fall back to 7za (p7zip package)
(cd data/images && if type unzip >/dev/null 2>&1; then unzip ../images.zip; else 7za x ../images.zip; fi)
else
echo "INFO: data/images/boot.iso does not exist, downloading current Fedora Rawhide Server image..."
curl -L https://download.fedoraproject.org/pub/fedora/linux/development/rawhide/Server/x86_64/os/images/boot.iso --output data/images/boot.iso
fi
fi
# support both path and URL for --updates
if [ -e "${UPDATES_IMAGE:-}" ]; then
# local file; bind mount into container
UPDATES_IMG_ARGS="-v $UPDATES_IMAGE:/updates.img:ro,Z --env UPDATES_IMAGE=/updates.img"
elif [ -n "${UPDATES_IMAGE:-}" ]; then
# URL, pass through
UPDATES_IMG_ARGS="--env UPDATES_IMAGE=$UPDATES_IMAGE"
fi
if [ -n "${DEFAULTS_SH:-}" ]; then
DEFAULTS_SH_ARGS="-v $DEFAULTS_SH:/home/kstest/.kstests.defaults.sh:ro,z"
fi
# if there is enough RAM (2 GB per test with 2x safety margin), and we don't keep VM images, put the VMs on tmpfs for faster tests
if awk "/MemAvailable:/ { exit (\$2 > 4000000*${TEST_JOBS}) ? 0 : 1 }" /proc/meminfo; then
VAR_TMP="--tmpfs /var/tmp/"
# for many parallel jobs, use a anonymous volume, so that the container does not go ENOSPC
elif [ ${TEST_JOBS} -gt 4 ]; then
VAR_TMP="-v /var/tmp"
fi
if [ "${CRUN%podman*}" != "$CRUN" ] && [ $(id -u) -ne 0 ]; then
echo "Disabling SELinux container separation to enable /dev/kvm socket access."
PODMAN_SELINUX_FIX="--security-opt label=disable"
fi
# Run container against the local repository, to test changes easily
# Expose the container's libvirt to the host; check "podman ps" for the port, and use e.g.:
# virsh -c qemu+tcp://localhost:<port>/session list
set -x
$CRUN run -it --rm --device=/dev/kvm --publish 127.0.0.1::16509 $PODMAN_SELINUX_FIX \
--env KSTESTS_TEST="$KSTESTS_TEST" --env TESTTYPE="${TESTTYPE:-}" --env SKIP_TESTTYPES="${SKIP_TESTTYPES:-}" \
--env TEST_JOBS="$TEST_JOBS" --env PLATFORM="${PLATFORM:-}" --env TEST_RETRY="${TEST_RETRY:-}" ${UPDATES_IMG_ARGS:-} ${CONTAINER_RUN_ARGS:-} \
${VAR_TMP:-} -v "$PWD/data:/opt/kstest/data:z" -v "$BASEDIR:/kickstart-tests:ro,z" ${DEFAULTS_SH_ARGS:-} \
$CONTAINER $RUN_COMMAND