Skip to content

Test WebUI on RH based OS #173

Test WebUI on RH based OS

Test WebUI on RH based OS #173

Workflow file for this run

---
name: Test WebUI on RH based OS
on:
workflow_dispatch:
inputs:
git-ref:
description: Git Ref Branch
default: master
required: true
schedule:
- cron: "05 15 * * *"
jobs:
test_ui:
name: Test on RH based (fedora container)
runs-on: ubuntu-latest
env:
GITHUB_DEF_BR: ${{ github.event.repository.default_branch }}
strategy:
matrix:
python-version: [python3.11]
req-version: [py311]
container:
image: fedora:39
options: --privileged
steps:
- name: Clone Repository (Master)
uses: actions/checkout@v4
if: github.event.inputs.git-ref == ''
- name: Clone Repository (Custom Ref)
uses: actions/checkout@v4
if: github.event.inputs.git-ref != ''
with:
ref: ${{ github.event.inputs.git-ref }}
- name: Set up Python ${{ matrix.python-version }} and install OQ
run: |
set -x
if [ -z ${{ github.event.inputs.git-ref }} ];
then
BRANCH=master
else
BRANCH=${{ github.event.inputs.git-ref }}
fi
# Add openquake user
useradd -m -u 1000 -s /bin/bash openquake
# update system and install utilities
dnf update -y
dnf install -y ${{ matrix.python-version }}
dnf install -y git git-lfs nc procps
# define it
mypython=${{ matrix.python-version }}
reqpython=${{ matrix.req-version }}
#run it
eval '$mypython -c "import sys; print(sys.version)"'
#
# Add PIP to $mypython
eval '$mypython -m ensurepip --upgrade'
export PIP_DEFAULT_TIMEOUT=100
#
echo "branch to test: ${BRANCH}"
cd /__w/oq-engine/oq-engine/
eval '$mypython -m pip install -U pip setuptools wheel'
eval '$mypython -m venv /opt/openquake/venv '
source /opt/openquake/venv/bin/activate
eval '$mypython -m pip install -r "requirements-$reqpython-linux64.txt"'
eval '$mypython -m pip install -e . '
## Standalone apps
echo "Downloading standalone apps"
for app in oq-platform-standalone oq-platform-ipt oq-platform-taxtweb oq-platform-taxonomy; do
git clone -b ${BRANCH} --depth=1 https://github.com/gem/${app}.git
eval '$mypython -m pip install -e ./${app}'
if [ "$app" = "oq-platform-taxtweb" ]; then
export PYBUILD_NAME="oq-taxonomy"
eval '$mypython -m pip install -e ./${app}'
unset PYBUILD_NAME
fi
done
deactivate
- name: Test WebUI and run https calculation
run: |
set -x
source /opt/openquake/venv/bin/activate
pip freeze
mkdir /var/log/oq-engine/
chown -R openquake /var/log/oq-engine/
runuser -l openquake -c '/opt/openquake/venv/bin/oq dbserver upgrade &'
# Wait the DbServer to come up
#echo "Waiting DBServer up on port 1907...."
#while ! nc -z localhost 1907; do
# sleep 2 # wait for 1/10 of the second before check again
#done
#sleep 3
oq --version
#
echo "Add settings for login and logging on webui before to start"
cd /__w/oq-engine/oq-engine/
cd openquake/server
cat > local_settings.py << EOF
LOCKDOWN = True
#
WEBUI_ACCESS_LOG_DIR = '/var/log/oq-engine'
EOF
echo "DISPLAY content of local_settings"
cat local_settings.py
# START WEBUI
runuser -l openquake -c '/opt/openquake/venv/bin/oq webui start 127.0.0.1:8800 -s &'
echo "Waiting WEBUI up on port 8800...."
while ! nc -z localhost 8800; do
sleep 5 # wait for 1/10 of the second before check again
done
echo "Test WebUI with curl before to test django"
sleep 1
# Perform migration after setup local_settings
cd /__w/oq-engine/oq-engine/openquake/engine/
runuser -l openquake -c 'cd /__w/oq-engine/oq-engine/openquake/server/; /opt/openquake/venv/bin/python3 manage.py migrate'
sleep 1
curl --fail -L -I -X GET http://127.0.0.1:8800/accounts/login/
echo -n "Test Standalone Tools pages"
curl --fail -I -L -X GET http://127.0.0.1:8800/
curl --fail -I -L -X GET http://127.0.0.1:8800/taxtweb
curl --fail -I -L -X GET http://127.0.0.1:8800/taxonomy
curl --fail -I -L -X GET http://127.0.0.1:8800/ipt
echo -n "TEST DJANGO LOGIN "
LOGIN_URL=http://127.0.0.1:8800/accounts/login/
YOUR_USER='username'
YOUR_PASS='password'
COOKIES=cookies.txt
CURL_BIN="curl -s -c $COOKIES -b $COOKIES -e $LOGIN_URL"
echo -n "Django Auth: get csrftoken ..."
$CURL_BIN $LOGIN_URL > /dev/null
DJANGO_TOKEN="csrfmiddlewaretoken=$(grep csrftoken $COOKIES | sed 's/^.*csrftoken\s*//')"
echo " perform login ..."
$CURL_BIN \
-d "$DJANGO_TOKEN&username=$YOUR_USER&password=$YOUR_PASS" \
-X POST $LOGIN_URL > /dev/null
echo "--------------------"
echo "display log of webui"
echo "--------------------"
cat /var/log/oq-engine/webui-access.log
if [ -s /var/log/oq-engine/webui-access.log ]; then
# The file is not-empty.
cat /var/log/oq-engine/webui-access.log
else
## The file is empty.
echo "Something not work as expected"
exit 1
fi
# Run a calcs using https
oq engine --run https://downloads.openquake.org/jobs/risk_test.zip