From 413cc11d6da3c3bf7e3369a5e3762c8d356e0b78 Mon Sep 17 00:00:00 2001 From: Dominik Heidler Date: Wed, 19 Dec 2018 15:51:18 +0100 Subject: [PATCH] Add tool to bootstrap openQA with only one command --- docs/Installing.asciidoc | 30 +++++++++++ openQA.spec | 12 +++++ script/openqa-bootstrap | 90 +++++++++++++++++++++++++++++++ script/openqa-bootstrap-container | 61 +++++++++++++++++++++ 4 files changed, 193 insertions(+) create mode 100755 script/openqa-bootstrap create mode 100755 script/openqa-bootstrap-container diff --git a/docs/Installing.asciidoc b/docs/Installing.asciidoc index 0d143e1264a..4c770630bcc 100644 --- a/docs/Installing.asciidoc +++ b/docs/Installing.asciidoc @@ -19,6 +19,36 @@ assumed that the reader is already familiar with openQA and has already read the Starter Guide, available at the https://github.com/os-autoinst/openQA[official repository]. +== openQA quick bootstrap + +To quickly get a working openQA installation, you can use openQA-bootstrap. + +=== Directly on your machine + +This should work on openSUSE Leap and openSUSE Tumbleweed and will setup openQA +on your machine. + +[source,sh] +------------------------------------------------------------------------------- +zypper in openQA-bootstrap +/usr/share/openqa/script/openqa-bootstrap +------------------------------------------------------------------------------- + +=== openQA in a container + +You can also setup a systemd-nspawn container with openQA with the following +commands. This will only work on Tumbleweed and you need to have no application +listening on port 80 yet because the container will share the host systems +network stack. + +[source,sh] +------------------------------------------------------------------------------- +zypper in openQA-bootstrap +/usr/share/openqa/script/openqa-bootstrap-container + +systemd-run -tM openqa1 /bin/bash # start a shell in the container +------------------------------------------------------------------------------- + == Repositories and installation Keep in mind that there can be disruptive changes between openQA versions. diff --git a/openQA.spec b/openQA.spec index f5db5d4b741..2b5121af7e7 100644 --- a/openQA.spec +++ b/openQA.spec @@ -193,6 +193,14 @@ Supplements: packageand(%name:postgresql-server) You only need this package if you have a local postgresql server next to the webui. +%package bootstrap +Summary: Automated openQA setup +Group: Development/Tools/Other + +%description bootstrap +This can automatically setup openQA - either directly on your system +or within a systemd-nspawn container. + %package doc Summary: The openQA documentation Group: Development/Tools/Other @@ -481,4 +489,8 @@ fi %files local-db %{_unitdir}/openqa-setup-db.service +%files bootstrap +%{_datadir}/openqa/script/openqa-bootstrap +%{_datadir}/openqa/script/openqa-bootstrap-container + %changelog diff --git a/script/openqa-bootstrap b/script/openqa-bootstrap new file mode 100755 index 00000000000..c4059b95a2d --- /dev/null +++ b/script/openqa-bootstrap @@ -0,0 +1,90 @@ +#!/bin/bash -x + + +# add extra repos for leap +source /etc/os-release +if $NAME == "openSUSE Leap" ; then + zypper -n addrepo obs://devel:openQA devel:openQA + zypper -n addrepo obs://devel:openQA:Leap:${VERSION} devel:openQA:Leap:${VERSION} + zypper -n --gpg-auto-import-keys refresh +fi + + +# install packages +zypper -n install --no-recommends openQA-local-db apache2 openQA-worker qemu-kvm sudo + + +# setup database +systemctl enable --now postgresql +su postgres -c "createuser -D geekotest" +su postgres -c "createdb -O geekotest openqa" + + +# setup webserver and fake-auth +# from script/setup-single-instance (https://github.com/os-autoinst/openQA/pull/1933) +for i in headers proxy proxy_http proxy_wstunnel rewrite ; do a2enmod $i ; done +sed -i -e 's/^.*httpsonly.*$/httpsonly = 0/g' /etc/openqa/openqa.ini +sed -i -e 's/#.*method.*OpenID.*$/&\nmethod = Fake/' /etc/openqa/openqa.ini +sed "s/#ServerName.*$/ServerName $(hostname)/" /etc/apache2/vhosts.d/openqa.conf.template > /etc/apache2/vhosts.d/openqa.conf + + +if ping -c1 download.suse.de. && (! 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 + zypper -n addrepo obs://SUSE:CA SUSE:CA + 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 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 +/usr/share/openqa/script/fetchneedles + +if ping -c1 gitlab.suse.de. ; then + # clone SLE needles if run from within SUSE network + git clone https://gitlab.suse.de/openqa/os-autoinst-needles-sles.git /var/lib/openqa/tests/opensuse/products/sle/needles + chown -R geekotest: /var/lib/openqa/tests/opensuse/products/sle/needles +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 +systemctl enable --now apache2.service +systemctl enable --now openqa-webui.service +systemctl enable --now openqa-websockets.service +systemctl enable --now openqa-scheduler.service +systemctl enable --now openqa-resource-allocator.service +systemctl enable --now openqa-livehandler.service +systemctl enable --now openqa-gru.service + +# wait for webui to become available +while ! curl -sI 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 openqa' + +cat >> /etc/openqa/client.conf < /etc/systemd/system/systemd-nspawn-openqa@.service <