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 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
|
#!/bin/bash -e
[[ $1 = "-h" ]] || [[ $1 = "--help" ]] && echo "Setup a working openQA installation, automating the steps mentioned in the 'custom installation' documentation section. Supports to immediately clone an existing job simply by supplying 'openqa-clone-job' parameters directly for a quickstart" && exit
set -xeuo pipefail
OPENQA_DIR=${OPENQA_DIR:=/usr/share/openqa}
dbname="${dbname:="openqa"}"
dbuser="${dbuser:="geekotest"}"
running_systemd=
skip_suse_specifics="${skip_suse_specifics:=""}"
skip_suse_tests="${skip_suse_tests:=""}"
setup_web_proxy="${setup_web_proxy:=""}"
if [[ $(ps --no-headers -o comm 1) = 'systemd' ]]; then
running_systemd=1
fi
start-database() {
if [[ -z $running_systemd ]]; then
# ensure /run/postgresql exists for PostgreSQL to create lock socket
mkdir -p /run/postgresql
chown postgres:postgres /run/postgresql
su postgres -c '/usr/share/postgresql/postgresql-script stop' || true
su postgres -c '/usr/share/postgresql/postgresql-script start'
else
systemctl enable --now postgresql
fi
}
start-worker() {
if [[ -z $running_systemd ]]; then
/usr/bin/install -d -m 0755 -o _openqa-worker /var/lib/openqa/pool/1
su _openqa-worker -c "$OPENQA_DIR/script/worker --instance 1" &
else
systemctl enable --now openqa-worker@1
fi
}
start-daemons() {
if [[ -z $running_systemd ]]; then
pgrep -f openqa-scheduler-daemon > /dev/null || su geekotest -c "$OPENQA_DIR/script/openqa-scheduler-daemon" &
pgrep -f openqa-websockets-daemon > /dev/null || su geekotest -c "$OPENQA_DIR/script/openqa-websockets-daemon" &
pgrep -f openqa-gru > /dev/null || su geekotest -c "$OPENQA_DIR/script/openqa-gru" &
pgrep -f openqa-livehandler-daemon > /dev/null || su geekotest -c "$OPENQA_DIR/script/openqa-livehandler-daemon" &
if [[ $setup_web_proxy == "nginx" ]]; then
nginx
else
/usr/sbin/start_apache2 -k start
fi
pgrep -f openqa-webui-daemon > /dev/null || su geekotest -c "$OPENQA_DIR/script/openqa-webui-daemon" &
else
if [[ $setup_web_proxy == "nginx" ]]; then
systemctl enable --now nginx
else
systemctl enable --now apache2
fi
systemctl enable --now openqa-webui
systemctl enable --now openqa-scheduler
fi
}
if [[ $# -gt 0 && $1 == start ]]; then
start-database
start-daemons
start-worker
exit
fi
# add extra repos for leap
# shellcheck disable=SC1091
. /etc/os-release
if [[ $NAME = "openSUSE Leap" ]]; then
# avoid using `obs://…` URL to workaround https://bugzilla.opensuse.org/show_bug.cgi?id=1187425
repobase=https://download.opensuse.org/repositories/devel:/openQA
# remove suffixes like " Beta" so e.g. "15.6 Beta" becomes just "15.6"
# shellcheck disable=SC2153
version=${VERSION%% *}
zypper lr -d | grep "$repobase/$version" || zypper -n addrepo -p 95 "$repobase/$version" 'devel:openQA'
zypper lr -d | grep "$repobase:/Leap:/$version/$version" || zypper -n addrepo -p 90 "$repobase:/Leap:/$version/$version" "devel:openQA:Leap:$version"
zypper -n --gpg-auto-import-keys refresh
fi
# Ensure we have retry available to handle temporary package issues later
command -v retry > /dev/null || zypper -n --gpg-auto-import-keys in retry
# install packages
pkgs=(qemu-arm qemu-ppc qemu-x86 qemu-tools sudo iputils os-autoinst-distri-opensuse-deps)
if [[ "$(uname -m)" = "aarch64" ]]; then
pkgs+=(qemu-uefi-aarch64)
fi
if [[ $setup_web_proxy == "nginx" ]]; then
pkgs+=(openQA-single-instance-nginx)
else
pkgs+=(openQA-single-instance)
fi
# this was split into a separate package on newer dist versions - so install it if available
if zypper -n search -x qemu-hw-display-virtio-gpu-pci; then
pkgs+=(qemu-hw-display-virtio-gpu qemu-hw-display-virtio-gpu-pci)
fi
packages="${pkgs[*]}"
retry -e -s 30 -r 7 -- sh -c "zypper -n --gpg-auto-import-keys ref && zypper -n in --no-recommends $packages"
# setup database
chown -R postgres: /var/lib/pgsql/ # fix broken postgres working dir permissions in the nspawn container
start-database
su postgres -c "$OPENQA_DIR/script/setup-db" "$dbuser" "$dbname"
# setup webserver and fake-auth
proxy_args=""
[[ -n "$setup_web_proxy" ]] && proxy_args="--proxy=$setup_web_proxy"
setup=$OPENQA_DIR/script/configure-web-proxy
if command -v $setup; then
bash -ex $setup "$proxy_args"
else
curl -s https://raw.githubusercontent.com/os-autoinst/openQA/master/script/configure-web-proxy | bash -ex -s -- "$proxy_args"
fi
echo -e "[auth]\nmethod = Fake" > /etc/openqa/openqa.ini.d/01-enable-fake-auth.ini
if [[ -z $skip_suse_specifics ]] && ping -c1 download.suse.de. > /dev/null 2>&1 && (! rpm -q ca-certificates-suse); then
# add internal CA if executed within suse network
if ! zypper info ca-certificates-suse | grep -q ':'; then
# add suse ca repo if needed
# use this way of adding the repo to be distro agnostic
if [ "$NAME" = "openSUSE Leap" ]; then
# avoid using `obs://…` URL to workaround https://bugzilla.opensuse.org/show_bug.cgi?id=1187425
zypper -n addrepo "http://download.suse.de/ibs/SUSE:/CA/${VERSION}" 'SUSE:CA'
elif [ "$NAME" = "SLES" ]; then
zypper -n addrepo "http://download.suse.de/ibs/SUSE:/CA/SLE_${VERSION/-/_}" 'SUSE:CA'
else
zypper -n addrepo obs://SUSE:CA SUSE:CA
fi
sed -i -e 's#download.opensuse.org/repositories#download.suse.de/ibs#' /etc/zypp/repos.d/SUSE:CA.repo
sed -i -e 's/https/http/' /etc/zypp/repos.d/SUSE:CA.repo
zypper -n --gpg-auto-import-keys refresh
fi
zypper -n install --no-recommends -ly ca-certificates-suse
fi
# fetch tests and needles
if [[ -z $skip_suse_tests ]]; then
if ping -c1 gitlab.suse.de.; then
# use faster local mirror if run from within SUSE network
export needles_giturl="https://gitlab.suse.de/openqa/os-autoinst-needles-opensuse-mirror.git"
fi
"$OPENQA_DIR/script/fetchneedles"
if [[ ! -e /var/lib/openqa/tests/sle ]]; then
ln -s opensuse /var/lib/openqa/tests/sle
fi
if ping -c1 gitlab.suse.de.; then
sles_needles_giturl="https://gitlab.suse.de/openqa/os-autoinst-needles-sles.git"
sles_needles_directory="/var/lib/openqa/tests/opensuse/products/sle/needles"
# clone SLE needles if run from within SUSE network
if [[ ! -d $sles_needles_directory ]]; then
echo "cloning $sles_needles_giturl shallow. Call 'git fetch --unshallow' for full history"
git clone --depth 1 "$sles_needles_giturl" "$sles_needles_directory"
fi
chown -R "$dbuser:" /var/lib/openqa/tests/opensuse/products/sle/needles
fi
fi
# ensure that the hostname is mapped to 127.0.0.1 (needed for livehandler)
grep -q "$(hostname)" /etc/hosts || echo "127.0.0.1 $(hostname)" >> /etc/hosts
start-daemons
# wait for webui to become available
while ! curl -o /dev/null -w "%{http_code}" -sIL http://localhost/ | grep 200; do
sleep 3
done
# create api key
curl http://localhost/login # create demo user (id=2)
API_KEY=$(hexdump -n 8 -e '2/4 "%08X" 1 "\n"' /dev/random)
API_SECRET=$(hexdump -n 8 -e '2/4 "%08X" 1 "\n"' /dev/random)
echo "INSERT INTO api_keys (key, secret, user_id, t_created, t_updated) VALUES ('${API_KEY}', '${API_SECRET}', 2, NOW(), NOW());" | su postgres -c "psql $dbname"
cat >> /etc/openqa/client.conf << EOF
[localhost]
key = ${API_KEY}
secret = ${API_SECRET}
EOF
start-worker
# clone job if job ID is given passing extra arguments as well
# e.g.: openqa-bootstrap --from openqa.opensuse.org 12345 SCHEDULE=tests/boot/boot_to_desktop,tests/x11/kontact
if [[ $# -ne 0 ]]; then
openqa-clone-job "$@"
fi
# wait forever without systemd (assuming we are running as container entrypoint)
# see https://progress.opensuse.org/issues/164595?#note-5
[[ -n $running_systemd ]] || wait
|