CI: drop support for cached venv + ci runner (MR 2080)

CI started failing with:
/builds/ollieparanoid/pmbootstrap/venv/bin/python3: No module named pytest

I've briefly tried to fix this with the existing scripts. However,
instead of investing more time into that, do the long overdue
refactoring of the scripts that involve dropping the venv logic and
support for a custon gitlab-ci-runner using some python docker image as
base. This configuration hasn't been used for a long time and is
probably broken anyway.

Refactor the logic to skip the qemu test case in gitlab CI by using
pytest markers. The new script is now similar to bpo's .ci/pytest.py.
This commit is contained in:
Oliver Smith 2021-07-03 13:18:18 +02:00
parent 3d651af763
commit d38bd6be2b
No known key found for this signature in database
GPG Key ID: 5AE7F5513E0885CB
10 changed files with 78 additions and 154 deletions

36
.ci/prepare.sh Executable file
View File

@ -0,0 +1,36 @@
#!/bin/sh -e
# Install pmbootstrap depends, set up pmos user with sudo
if [ "$(id -u)" != 0 ]; then
echo "ERROR: this script is meant to be executed in the gitlab-ci"
echo "environment only."
exit 1
fi
topdir="$(realpath "$(dirname "$0")/..")"
cd "$topdir"
ln -sf "$PWD"/pmbootstrap.py /usr/local/bin/pmbootstrap
apk add -q \
git \
openssl \
py3-pytest \
py3-pytest-cov \
sudo
adduser -D pmos
chown -R pmos:pmos .
echo 'pmos ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers
su pmos -c "git config --global user.email postmarketos-ci@localhost"
su pmos -c "git config --global user.name postmarketOS_CI"
echo "Initializing pmbootstrap"
if ! su pmos -c "yes '' | pmbootstrap \
--details-to-stdout \
init \
>/tmp/pmb_init 2>&1"; then
cat /tmp/pmb_init
exit 1
fi
echo ""

24
.ci/pytest.sh Executable file
View File

@ -0,0 +1,24 @@
#!/bin/sh -e
topdir="$(realpath "$(dirname "$0")/..")"
cd "$topdir"
# Make sure that the work folder format is up to date, and that there are no
# mounts from aborted test cases (#1595)
./pmbootstrap.py work_migrate
./pmbootstrap.py -q shutdown
# Make sure we have a valid device (#1128)
device="$(./pmbootstrap.py config device)"
pmaports="$(./pmbootstrap.py config aports)"
deviceinfo="$(ls -1 "$pmaports"/device/*/device-"$device"/deviceinfo)"
if ! [ -e "$deviceinfo" ]; then
echo "ERROR: Could not find deviceinfo file for selected device:" \
"$device"
echo "Expected path: $deviceinfo"
echo "Maybe you have switched to a branch where your device does not"
echo "exist? Use 'pmbootstrap config device qemu-amd64' to switch to"
echo "a valid device."
exit 1
fi
pytest -vv -x --cov=pmb test -m "not skip_ci" "$@"

View File

@ -3,20 +3,6 @@
image: alpine:latest
cache:
paths:
- venv
before_script:
- ./.gitlab/setup-pmos-environment.sh
# venv created in CI_PROJECT_DIR for caching
- "[[ ! -d venv ]] && virtualenv venv -p $(which python3)"
- "source venv/bin/activate"
- "apk -q add py3-pytest-cov py3-coveralls py3-pytest"
- "python3 --version"
- "su pmos -c 'git config --global user.email postmarketos-ci@localhost' || true"
- "su pmos -c 'git config --global user.name postmarketOS_CI' || true"
stages:
- checks
- tests
@ -38,9 +24,10 @@ stages:
static-code-analysis:
stage: checks
<<: *only-default
before_script:
- .ci/prepare.sh
script:
# Note: This script uses CI_PROJECT_DIR
- su pmos -c "CI_PROJECT_DIR=$CI_PROJECT_DIR .gitlab/shared-runner_test-pmbootstrap.sh --static-code-analysis"
- su pmos -c "test/static_code_analysis.sh"
vermin:
image: alpine:latest
@ -61,18 +48,19 @@ mr-settings:
script:
- .gitlab/check_mr_settings.py
test-pmbootstrap:
pytest:
stage: tests
<<: *only-default
before_script:
- .ci/prepare.sh
script:
# Note: This script uses CI_PROJECT_DIR
- su pmos -c "CI_PROJECT_DIR=$CI_PROJECT_DIR .gitlab/shared-runner_test-pmbootstrap.sh --testcases-fast"
- su pmos -c .ci/pytest.sh
after_script:
# Move logs so it can be saved as artifacts
- "[[ -f /home/pmos/.local/var/pmbootstrap/log.txt ]] && mv /home/pmos/.local/var/pmbootstrap/log.txt $CI_PROJECT_DIR/log.txt"
- "[[ -f /home/pmos/.local/var/pmbootstrap/log_testsuite.txt ]] && mv /home/pmos/.local/var/pmbootstrap/log_testsuite.txt $CI_PROJECT_DIR/log_testsuite.txt"
- "[[ -f /home/pmos/.config/pmbootstrap.cfg ]] && cp /home/pmos/.config/pmbootstrap.cfg $CI_PROJECT_DIR/pmbootstrap.cfg"
- "sudo dmesg > $CI_PROJECT_DIR/dmesg.txt"
- "dmesg > $CI_PROJECT_DIR/dmesg.txt"
artifacts:
when: always
paths:

View File

@ -1,22 +0,0 @@
# 'qemu' gitlab runner configuration file
# Author: Clayton Craft <clayton@craftyguy.net>
concurrent = 4
check_interval = 0
log_level = "debug"
[[runners]]
name = "corredor"
url = "https://gitlab.com/"
token = <REDACTED>
executor = "virtualbox"
builds_dir = "/home/pmos/builds"
[runners.ssh]
user = "pmos"
password = <REDACTED>
identity_file = "/home/pmos/.ssh/id_ecdsa"
[runners.virtualbox]
base_name = "pmbootstrap-vm"
base_snapshot = "ci-snapshot-python-3.6"
#disable_snapshots = false
disable_snapshots = true
[runners.cache]

View File

@ -1,22 +0,0 @@
#!/bin/sh
#
# This script is meant for the gitlab CI shared runners, not for
# any specific runners. Specific runners are expected to provide
# all of these configurations to save time, at least for now.
# Author: Clayton Craft <clayton@craftyguy.net>
# skip non-shared runner
[ -d "/home/pmos" ] && echo "pmos user already exists, assume running on pre-configured runner" && exit
# mount binfmt_misc
mount -t binfmt_misc none /proc/sys/fs/binfmt_misc
# install dependencies
apk update
apk -q add git sudo bash openssl py3-virtualenv
# create pmos user
echo "Creating pmos user"
adduser -s /bin/sh -h /home/pmos pmos
chown -R pmos:pmos .
echo 'pmos ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers

View File

@ -1,40 +0,0 @@
#!/bin/bash
#
# This script is meant to be executed by a non-root user, since pmbootstrap
# commands will fail otherwise. This is primarily used by the gitlab CI shared
# runners.
# This script also assumes, if run outside a gitlab CI runner, that cwd is
# the root of the pmbootstrap project. For gitlab CI runners, $CI_PROJECT_DIR
# is used.
# Author: Clayton Craft <clayton@craftyguy.net>
# Return failure on any failure of commands below
set -e
# Fail quickly if run as root, since other commands here will fail
[[ "$(id -u)" != "0" ]]
# These are specific to the gitlab CI
[[ $CI_PROJECT_DIR ]] && cd "$CI_PROJECT_DIR"
# shellcheck disable=SC1091
[[ -d venv ]] && source ./venv/bin/activate
# Init test (pipefail disabled so 'yes' doesn't fail test)
set +o pipefail
yes ''| ./pmbootstrap.py init
set -o pipefail
# this seems to be needed for some tests to pass
set +o pipefail
yes | ./pmbootstrap.py zap -m -p
set -o pipefail
case $1 in
--static-code-analysis )
./test/static_code_analysis.sh
;;
--testcases-fast )
# testcases_fast (qemu is omitted by not passing --all)
./test/testcases_fast.sh
;;
esac

View File

@ -201,7 +201,7 @@ $ pmbootstrap log_distccd
You also need to install the following python packages (pip can be useful if you distribution hasn't got them packaged):
* `pytest`
* `pytest-cov` (only needed for `test/testcases_fast.sh`, which is what CI runs)
* `pytest-cov`
* `flake8`
On Alpine Linux it can be done with:
@ -220,11 +220,11 @@ You can now run `pytest -vv` inside the pmbootstrap folder to run all available
CI runs slightly reduces set of tests (it skips tests that require running qemu) by this:
```shell
$ ./test/testcases_fast.sh
$ .ci/pytest.sh
```
This is the easiest way to do the same as CI.
Alternatively you can run a single test if you wish:
Alternatively you can run a single test file if you wish:
```shell
$ pytest -vv ./test/test_keys.py
```

4
test/pytest.ini Normal file
View File

@ -0,0 +1,4 @@
[pytest]
addopts = --strict-markers
markers =
skip_ci

View File

@ -164,6 +164,7 @@ def is_running(args, programs, timeout=300, sleep_before_retry=1):
return False
@pytest.mark.skip_ci
def test_none(args, tmpdir, qemu):
qemu.run(args, tmpdir)
@ -175,12 +176,14 @@ def test_none(args, tmpdir, qemu):
assert is_running(args, ["invalid-process"], 1) is False
@pytest.mark.skip_ci
def test_xfce4(args, tmpdir, qemu):
qemu.run(args, tmpdir, "xfce4")
assert is_running(args, ["xfce4-session", "xfdesktop", "xfce4-panel",
"Thunar", "dbus-daemon", "xfwm4"])
@pytest.mark.skip_ci
def test_plasma_mobile(args, tmpdir, qemu):
# NOTE: Once we have plasma mobile running properly without GL, we can
# check for more processes

View File

@ -1,47 +0,0 @@
#!/bin/sh -e
# usage: testcases_fast.sh [--all]
# Disable QEMU test, it runs on a special CI runner in parallel (see #1610).
disabled="qemu_running_processes"
# Optionally enable all test cases
if [ "$1" = "--all" ]; then
disabled=""
else
echo "Disabled test case(s): $disabled"
echo "Use '$(basename "$0") --all' to enable all test cases."
fi
# Make sure that the work folder format is up to date, and that there are no
# mounts from aborted test cases (#1595)
cd "$(dirname "$0")/.."
./pmbootstrap.py work_migrate
./pmbootstrap.py -q shutdown
# Make sure we have a valid device (#1128)
device="$(./pmbootstrap.py config device)"
pmaports="$(./pmbootstrap.py config aports)"
deviceinfo="$pmaports/device/*/device-$device/deviceinfo"
# shellcheck disable=SC2086
if ! [ -e $deviceinfo ]; then
echo "ERROR: Could not find deviceinfo file for selected device '$device'."
echo "Expected path: $deviceinfo"
echo "Maybe you have switched to a branch where your device does not exist?"
echo "Use 'pmbootstrap config device qemu-amd64' to switch to a valid device."
exit 1
fi
# Filter out disabled testcases
enabled=""
for file in test/test_*.py; do
for test in $disabled; do
[ "test/test_${test}.py" = "$file" ] && continue 2
done
enabled="$enabled $file"
done
# Run enabled testcases with coverage enabled
# Note: Pytest is called through python so that this is compatible with
# running from a venv (e.g. in gitlab CI)
# shellcheck disable=SC2086
python3 -m pytest -vv -x --cov=pmb $enabled --tb=native