tests: functional: Integrate into Salsa CI

Functional tests are run in parallel on Debian testing and Debian
unstable using the latest freedombox package built in the pipeline.

Commits by Weblate are ignored.

Fixes freedombox-team/infrastructure#34
Closes freedombox-team/infrastructure!48

Signed-off-by: Joseph Nuthalapati <njoseph@riseup.net>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
Joseph Nuthalapati 2022-02-05 14:34:35 +05:30 committed by Sunil Mohan Adapa
parent b6d3e21608
commit f86ed032a3
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2
2 changed files with 98 additions and 1 deletions

59
.ci/functional-tests.yml Normal file
View File

@ -0,0 +1,59 @@
---
# SPDX-License-Identifier: AGPL-3.0-or-later
.app-server:
needs:
- job: build
except:
- '$CI_COMMIT_TITLE =~ /^Weblate.*/'
script:
- BUILD_JOB_ID=$(curl -s "https://salsa.debian.org/api/v4/projects/$CI_PROJECT_ID/pipelines/$CI_PIPELINE_ID/jobs" | jq -r '.[] | select(.name=="build") | .id')
- export AWS_DEFAULT_REGION=us-east-1
- LAUNCH_TEMPLATE_ID=$(aws ec2 describe-launch-templates --launch-template-names $LAUNCH_TEMPLATE_NAME | jq -r ".LaunchTemplates[0].LaunchTemplateId")
- INSTANCE_ID=$(aws ec2 run-instances --launch-template LaunchTemplateId="$LAUNCH_TEMPLATE_ID" --associate-public-ip-address --tag-specifications "ResourceType=instance, Tags=[{Key=salsa:project-id,Value=$CI_PROJECT_ID},{Key=salsa:build-job-id,Value=$BUILD_JOB_ID},{Key=Name,Value=$INSTANCE_NAME}]" | jq -r ".Instances[0].InstanceId")
- APP_SERVER_IP=$(aws ec2 describe-instances --instance-ids $INSTANCE_ID | jq -r ".Reservations[0].Instances[0].PublicIpAddress")
- echo "APP_SERVER_IP=$APP_SERVER_IP" >> app-servers.env
- echo "INSTANCE_ID=$INSTANCE_ID" >> app-servers.env
tags:
- functional-tests
artifacts:
reports:
dotenv: app-servers.env
.run-functional-tests:
needs:
- job: app-server-unstable
artifacts: true
timeout: 2h
# Need to find a way of running the cleanup step even on failure
allow_failure: true
when: delayed
# Wait for the app-server to come up. Saves time for the CI runners.
start_in: 3 minutes
before_script:
- apt-get update
- apt-get install -y sudo curl wget
- ./plinth/tests/functional/install.sh
- adduser tester --gecos "First Last,RoomNumber,WorkPhone,HomePhone" --disabled-password && echo "tester:password" | chpasswd
script:
- cp -r . /home/tester/freedombox && chown -R tester:tester /home/tester/freedombox
- sudo -u tester bash -c 'pip3 install --user splinter pytest-splinter pytest-reporter-html1'
- sudo FREEDOMBOX_URL="https://$APP_SERVER_IP" -u tester bash -c 'cd /home/tester/freedombox && py.test-3 -v --durations=10 --include-functional --splinter-headless --template=html1/index.html --report=functional-tests.html'
after_script:
- echo "INSTANCE_ID=$INSTANCE_ID" >> app-servers.env
- cp /home/tester/freedombox/functional-tests.html .
- cp -r /home/tester/freedombox/screenshots/ .
artifacts:
when: always
reports:
dotenv: app-servers.env
paths:
- functional-tests.html
- screenshots/
# Does not run if the previous job times out or is cancelled
.terminate-app-server:
script:
- aws ec2 --region us-east-1 terminate-instances --instance-ids $INSTANCE_ID > /dev/null
tags:
- functional-tests

View File

@ -1,5 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-or-later
include: https://salsa.debian.org/salsa-ci-team/pipeline/raw/master/salsa-ci.yml
include:
- remote: https://salsa.debian.org/salsa-ci-team/pipeline/raw/master/salsa-ci.yml
- local: /.ci/functional-tests.yml
image: registry.salsa.debian.org/freedombox-team/freedombox:gitlabci
@ -41,6 +43,42 @@ doc-tests:
script:
- doc/scripts/wikiparser.py
app-server-testing:
variables:
LAUNCH_TEMPLATE_NAME: functional-tests-testing
INSTANCE_NAME: app-server-testing
extends: .app-server
run-functional-tests-testing:
needs:
- job: app-server-testing
artifacts: true
extends: .run-functional-tests
terminate-app-server-testing:
needs:
- job: run-functional-tests-testing
artifacts: true
extends: .terminate-app-server
app-server-unstable:
variables:
LAUNCH_TEMPLATE_NAME: functional-tests-unstable
INSTANCE_NAME: app-server-unstable
extends: .app-server
run-functional-tests-unstable:
needs:
- job: app-server-unstable
artifacts: true
extends: .run-functional-tests
terminate-app-server-unstable:
needs:
- job: run-functional-tests-unstable
artifacts: true
extends: .terminate-app-server
extract-source:
extends: .provisioning-extract-source