Skip to content

Commit

Permalink
Update files according to shfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
b10n1k committed Jan 26, 2024
1 parent cc9e32c commit 2c24439
Show file tree
Hide file tree
Showing 40 changed files with 392 additions and 311 deletions.
1 change: 1 addition & 0 deletions .editorconfig
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ prepare-and-launch-container-to-run-tests-within: container-test-build launch-co

# all additional checks not called by prove
.PHONY: test-checkstyle-standalone
test-checkstyle-standalone: test-shellcheck test-yaml test-critic
test-checkstyle-standalone: test-shellcheck test-yaml test-critic test-shfmt
ifeq ($(CONTAINER_TEST),1)
test-checkstyle-standalone: test-check-containers
endif
Expand All @@ -317,6 +317,11 @@ test-yaml:
@# Fall back to find if there is no git, e.g. in package builds
yamllint --strict $$((git ls-files "*.yml" "*.yaml" 2>/dev/null || find -name '*.y*ml') | grep -v ^dbicdh)

.PHONY: test-shfmt
test-yaml:
@which shfmt >/dev/null 2>&1 || (echo "Command 'shfmt' not found, can not execute bash script syntax checks" && false)
shfmt -d .

.PHONY: test-check-containers
test-check-containers:
tools/static_check_containers
Expand Down
12 changes: 6 additions & 6 deletions container/openqa/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ export LC_ALL="en_US.UTF-8"

# First, try to upgrade all container dependencies (or we won't catch bugs
# until a new container image is built)
[ "$UPGRADE_FROM_ZYPPER" -eq 1 ] && \
sudo zypper --gpg-auto-import-keys -n ref --force && \
sudo zypper up -l -y
[ "$UPGRADE_FROM_ZYPPER" -eq 1 ] \
&& sudo zypper --gpg-auto-import-keys -n ref --force \
&& sudo zypper up -l -y

cp -rd /opt/openqa /opt/testing_area
cd /opt/testing_area/openqa

run_as_normal_user() {
if [ "$INSTALL_FROM_CPAN" -eq 1 ]; then
echo ">> Trying to get dependencies from CPAN"
cpanm -M https://cpan.metacpan.org --local-lib=~/perl5 local::lib && cpanm -M https://cpan.metacpan.org -n --installdeps .
echo ">> Trying to get dependencies from CPAN"
cpanm -M https://cpan.metacpan.org --local-lib=~/perl5 local::lib && cpanm -M https://cpan.metacpan.org -n --installdeps .
else
cpanm -n --mirror http://no.where/ --installdeps .
cpanm -n --mirror http://no.where/ --installdeps .
fi
MOJO_TMPDIR=$(mktemp -d)
export MOJO_TMPDIR
Expand Down
2 changes: 1 addition & 1 deletion container/openqa_data/scripts/set_openid
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ read OPENID
awk -v openid="$OPENID" '
/^provider/ {$0 = "provider = " openid}
{print}
' /data/conf/openqa.ini > /data/conf/openqa.ini.new
' /data/conf/openqa.ini >/data/conf/openqa.ini.new
mv /data/conf/openqa.ini.new /data/conf/openqa.ini

echo "The file now contains:"
Expand Down
4 changes: 2 additions & 2 deletions container/webui/nginx-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ set -e

replicas_cfg=""
for i in $(seq "${OPENQA_WEBUI_REPLICAS:-2}"); do
replicas_cfg="server webui_webui_$i:9526;$replicas_cfg"
replicas_cfg="server webui_webui_$i:9526;$replicas_cfg"
done

reg="s/REPLICAS/$replicas_cfg/"
sed "$reg" /etc/nginx/nginx.conf.template > /etc/nginx/nginx.conf
sed "$reg" /etc/nginx/nginx.conf.template >/etc/nginx/nginx.conf
echo 'NGINX configuration:'
cat /etc/nginx/nginx.conf

Expand Down
78 changes: 39 additions & 39 deletions container/webui/run_openqa.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,72 +2,72 @@
set -e

function wait_for_db_creation() {
echo "Waiting for DB creation"
while ! su geekotest -c 'PGPASSWORD=openqa psql -h db -U openqa --list | grep -qe openqa'; do sleep .1; done
echo "Waiting for DB creation"
while ! su geekotest -c 'PGPASSWORD=openqa psql -h db -U openqa --list | grep -qe openqa'; do sleep .1; done
}

function upgradedb() {
wait_for_db_creation
su geekotest -c '/usr/share/openqa/script/upgradedb --upgrade_database'
wait_for_db_creation
su geekotest -c '/usr/share/openqa/script/upgradedb --upgrade_database'
}

function scheduler() {
su geekotest -c /usr/share/openqa/script/openqa-scheduler-daemon
su geekotest -c /usr/share/openqa/script/openqa-scheduler-daemon
}

function websockets() {
su geekotest -c /usr/share/openqa/script/openqa-websockets-daemon
su geekotest -c /usr/share/openqa/script/openqa-websockets-daemon
}

function gru() {
wait_for_db_creation
su geekotest -c /usr/share/openqa/script/openqa-gru
wait_for_db_creation
su geekotest -c /usr/share/openqa/script/openqa-gru
}

function livehandler() {
wait_for_db_creation
su geekotest -c /usr/share/openqa/script/openqa-livehandler-daemon
wait_for_db_creation
su geekotest -c /usr/share/openqa/script/openqa-livehandler-daemon
}

function webui() {
wait_for_db_creation
su geekotest -c /usr/share/openqa/script/openqa-webui-daemon
wait_for_db_creation
su geekotest -c /usr/share/openqa/script/openqa-webui-daemon
}

function all_together_apache() {
# use certificate that comes with Mojolicious if none configured by the user (by making one available via `-v`)
local mojo_resources=$(perl -e 'use Mojolicious; print(Mojolicious->new->home->child("Mojo/IOLoop/resources"))')
cp --no-clobber "$mojo_resources"/server.crt /etc/apache2/ssl.crt/server.crt ||:
cp --no-clobber "$mojo_resources"/server.key /etc/apache2/ssl.key/server.key ||:
cp --no-clobber "$mojo_resources"/server.crt /etc/apache2/ssl.crt/ca.crt ||:
# use certificate that comes with Mojolicious if none configured by the user (by making one available via `-v`)
local mojo_resources=$(perl -e 'use Mojolicious; print(Mojolicious->new->home->child("Mojo/IOLoop/resources"))')
cp --no-clobber "$mojo_resources"/server.crt /etc/apache2/ssl.crt/server.crt || :
cp --no-clobber "$mojo_resources"/server.key /etc/apache2/ssl.key/server.key || :
cp --no-clobber "$mojo_resources"/server.crt /etc/apache2/ssl.crt/ca.crt || :

# run the database within the container if no database is configured by the user (by making one available via `-v`)
if [[ ! -e /data/conf/database.ini ]]; then
mkdir -p /data/conf
echo -e "[production]\ndsn = DBI:Pg:dbname=openqa" > /data/conf/database.ini
chown -R postgres:postgres /var/lib/pgsql # ensure right ownership in case `/var/lib/pgsql` is from host via `-v`
su postgres -c '/usr/share/postgresql/postgresql-script start'
su postgres -c '/usr/bin/openqa-setup-db'
fi
# run the database within the container if no database is configured by the user (by making one available via `-v`)
if [[ ! -e /data/conf/database.ini ]]; then
mkdir -p /data/conf
echo -e "[production]\ndsn = DBI:Pg:dbname=openqa" >/data/conf/database.ini
chown -R postgres:postgres /var/lib/pgsql # ensure right ownership in case `/var/lib/pgsql` is from host via `-v`
su postgres -c '/usr/share/postgresql/postgresql-script start'
su postgres -c '/usr/bin/openqa-setup-db'
fi

# run services and apache2
su geekotest -c /usr/share/openqa/script/openqa-scheduler-daemon &
su geekotest -c /usr/share/openqa/script/openqa-websockets-daemon &
su geekotest -c /usr/share/openqa/script/openqa-gru &
su geekotest -c /usr/share/openqa/script/openqa-livehandler-daemon &
apache2ctl start
su geekotest -c /usr/share/openqa/script/openqa-webui-daemon
# run services and apache2
su geekotest -c /usr/share/openqa/script/openqa-scheduler-daemon &
su geekotest -c /usr/share/openqa/script/openqa-websockets-daemon &
su geekotest -c /usr/share/openqa/script/openqa-gru &
su geekotest -c /usr/share/openqa/script/openqa-livehandler-daemon &
apache2ctl start
su geekotest -c /usr/share/openqa/script/openqa-webui-daemon
}

usermod --shell /bin/sh geekotest

# run services
case "$MODE" in
upgradedb ) upgradedb;;
scheduler ) scheduler;;
websockets ) websockets;;
gru ) gru;;
livehandler ) livehandler;;
webui ) webui;;
* ) all_together_apache;;
upgradedb) upgradedb ;;
scheduler) scheduler ;;
websockets) websockets ;;
gru) gru ;;
livehandler) livehandler ;;
webui) webui ;;
*) all_together_apache ;;
esac
14 changes: 7 additions & 7 deletions container/worker/kvm-mknod.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
# If possible, create the /dev/kvm device node.
set -e

kvm=$({ [[ -f /proc/config.gz ]] && test "$(zgrep CONFIG_KVM=y /proc/config.gz)" ; } || true)
$kvm || lsmod | grep '\<kvm\>' > /dev/null || {
echo >&2 "KVM module not loaded; software emulation will be used"
exit 1
kvm=$({ [[ -f /proc/config.gz ]] && test "$(zgrep CONFIG_KVM=y /proc/config.gz)"; } || true)
$kvm || lsmod | grep '\<kvm\>' >/dev/null || {
echo >&2 "KVM module not loaded; software emulation will be used"
exit 1
}

[[ -c /dev/kvm ]] || mknod /dev/kvm c 10 "$(grep '\<kvm\>' /proc/misc | cut -f 1 -d' ')" || {
echo >&2 "Unable to make /dev/kvm node; software emulation will be used"
echo >&2 "(This can happen if the container is run without -privileged)"
exit 1
echo >&2 "Unable to make /dev/kvm node; software emulation will be used"
echo >&2 "(This can happen if the container is run without -privileged)"
exit 1
}
38 changes: 22 additions & 16 deletions container/worker/launch_workers_pool.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ size=1
cre="${cre:-"podman"}"

usage() {
cat << EOF
cat <<EOF
Usage: $0
To launch a pool of workers with the desired number of workers in individual
containers.
Expand All @@ -20,22 +20,28 @@ opts=$(getopt -o hs: --long help,size: -n "$0" -- "$@") || usage 1
eval set -- "$opts"

while true; do
case "$1" in
-h | --help ) usage 0 ;;
-s | --size ) size=$2; shift ;;
-- ) shift; break ;;
* ) break ;;
esac
case "$1" in
-h | --help) usage 0 ;;
-s | --size)
size=$2
shift
;;
--)
shift
break
;;
*) break ;;
esac
done

for i in $(seq "$size"); do
echo "Creating worker $i"
$cre run \
--detach --rm \
--hostname "openqa_worker_$i" --name "openqa_worker_$i" \
-v "$PWD/conf:/data/conf:ro" \
-v "$PWD/../webui/workdir/data/factory:/data/factory:rw" \
-v "$PWD/../webui/workdir/data/tests:/data/tests:ro" \
--privileged openqa_worker \
-e OPENQA_WORKER_INSTANCE="$i"
echo "Creating worker $i"
$cre run \
--detach --rm \
--hostname "openqa_worker_$i" --name "openqa_worker_$i" \
-v "$PWD/conf:/data/conf:ro" \
-v "$PWD/../webui/workdir/data/factory:/data/factory:rw" \
-v "$PWD/../webui/workdir/data/tests:/data/tests:ro" \
--privileged openqa_worker \
-e OPENQA_WORKER_INSTANCE="$i"
done
20 changes: 10 additions & 10 deletions container/worker/run_openqa_worker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,29 @@
set -e

if [[ -z $OPENQA_WORKER_INSTANCE ]]; then
OPENQA_WORKER_INSTANCE=1
OPENQA_WORKER_INSTANCE=1
fi

mkdir -p "/var/lib/openqa/pool/${OPENQA_WORKER_INSTANCE}/"
chown -R _openqa-worker /var/lib/openqa/pool/

if [[ -z $qemu_no_kvm ]] || [[ $qemu_no_kvm -eq 0 ]]; then
if [ -e "/dev/kvm" ] && getent group kvm > /dev/null; then
/root/qemu/kvm-mknod.sh
if [ -e "/dev/kvm" ] && getent group kvm >/dev/null; then
/root/qemu/kvm-mknod.sh

group=$(ls -lhn /dev/kvm | cut -d ' ' -f 4)
groupmod -g "$group" --non-unique kvm
usermod -a -G kvm _openqa-worker
else
echo "Warning: /dev/kvm doesn't exist. If you want to use KVM, run the container with --device=/dev/kvm"
fi
group=$(ls -lhn /dev/kvm | cut -d ' ' -f 4)
groupmod -g "$group" --non-unique kvm
usermod -a -G kvm _openqa-worker
else
echo "Warning: /dev/kvm doesn't exist. If you want to use KVM, run the container with --device=/dev/kvm"
fi
fi

qemu-system-x86_64 -S &
kill $!

# Install test distribution dependencies
if [[ -z $TEST_DISTRI_DEPS ]] ; then
if [[ -z $TEST_DISTRI_DEPS ]]; then
find -L "/var/lib/openqa/share/tests" -maxdepth 2 -type f -executable -name 'install_deps.*' -exec {} \;
else
zypper -n --gpg-auto-import-keys install $TEST_DISTRI_DEPS
Expand Down
1 change: 1 addition & 0 deletions dependencies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ devel_no_selenium_requires:
devel_requires:
'%devel_no_selenium_requires':
chromedriver:
shfmt:

main_requires:
'%assetpack_requires':
Expand Down
2 changes: 1 addition & 1 deletion dist/rpm/openQA.spec
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
# The following line is generated from dependencies.yaml
%define devel_no_selenium_requires %build_requires %cover_requires %qemu %test_requires curl perl(Perl::Tidy) postgresql-devel rsync sudo tar xorg-x11-fonts
# The following line is generated from dependencies.yaml
%define devel_requires %devel_no_selenium_requires chromedriver
%define devel_requires %devel_no_selenium_requires chromedriver shfmt

Name: openQA
Version: 4.6
Expand Down
40 changes: 23 additions & 17 deletions script/configure-web-proxy
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash -e

usage() {
cat << EOF
cat <<EOF
Usage: configure-web-proxy
Configure a local web proxy for openQA.
Expand All @@ -17,25 +17,31 @@ opts=$(getopt -o hp: -l help -l proxy: -n "$0" -- "$@") || usage 1
eval set -- "$opts"
web_proxy="apache"
while true; do
case "$1" in
-h | --help ) usage 0 ;;
-p | --proxy ) web_proxy=${2#*=}; shift ;;
-- ) shift; break ;;
* ) break ;;
esac
case "$1" in
-h | --help) usage 0 ;;
-p | --proxy)
web_proxy=${2#*=}
shift
;;
--)
shift
break
;;
*) break ;;
esac
done

sed -i -e 's/^.*httpsonly.*$/httpsonly = 0/g' /etc/openqa/openqa.ini

if [[ $web_proxy == "nginx" ]] ; then
echo "Setting up nginx"
sed "s/openqa.example.com/$(hostname)/" /etc/nginx/vhosts.d/openqa.conf.template > /etc/nginx/vhosts.d/openqa.conf
sed -i -e "s/\(^[^#]*server_name localhost;\)/#\1/" /etc/nginx/nginx.conf
elif [[ $web_proxy == "apache" || $web_proxy == "apache2" ]] ; then
echo "Setting up apache"
for i in headers proxy proxy_http proxy_wstunnel rewrite ; do a2enmod $i ; done
sed "s/#ServerName.*$/ServerName $(hostname)/" /etc/apache2/vhosts.d/openqa.conf.template > /etc/apache2/vhosts.d/openqa.conf
if [[ $web_proxy == "nginx" ]]; then
echo "Setting up nginx"
sed "s/openqa.example.com/$(hostname)/" /etc/nginx/vhosts.d/openqa.conf.template >/etc/nginx/vhosts.d/openqa.conf
sed -i -e "s/\(^[^#]*server_name localhost;\)/#\1/" /etc/nginx/nginx.conf
elif [[ $web_proxy == "apache" || $web_proxy == "apache2" ]]; then
echo "Setting up apache"
for i in headers proxy proxy_http proxy_wstunnel rewrite; do a2enmod $i; done
sed "s/#ServerName.*$/ServerName $(hostname)/" /etc/apache2/vhosts.d/openqa.conf.template >/etc/apache2/vhosts.d/openqa.conf
else
echo "No supported proxy: $web_proxy"
exit 1
echo "No supported proxy: $web_proxy"
exit 1
fi
6 changes: 3 additions & 3 deletions script/fetchneedles
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
: "${updateall:="0"}"
: "${force:="0"}"

if [ "$1" = "-h" ] || [ "$1" = "--help" ] ; then
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
printf "Get %s tests and needles from:\n\t\t%s\n" "${dist_name}" "${giturl}"
if [ "$needles_separate" = 1 ] ; then
if [ "$needles_separate" = 1 ]; then
printf "\tand\t%s\n" "${needles_giturl}"
fi
printf "\n(environment variables mentioned in '%s' can be set to change these values)\n" "$0"
Expand Down Expand Up @@ -66,7 +66,7 @@ needlesdir() {

deal_with_stale_lockfile() {
lock_path=.git/index.lock
if [ -e "$lock_path" ] && ! fuser --silent "$lock_path"; then # fuser returns 0 if one or more processes hold the lock
if [ -e "$lock_path" ] && ! fuser --silent "$lock_path"; then # fuser returns 0 if one or more processes hold the lock
echo "removing stale lock $PWD/$lock_path"
rm "$lock_path"
fi
Expand Down
Loading

0 comments on commit 2c24439

Please sign in to comment.