Skip to content

Commit

Permalink
ci: split root and non-root storage tests
Browse files Browse the repository at this point in the history
Most of vdsm code run as vdsm:kvm, but vdsm tests run
as root by default in the CI, causing several problems, e.g.:
- Different behaviour, when run locally and the CI
- Some tests are skipped as root

We can separate the tests in two different jobs:
- storage-tests: run test marked as "not root".
  It still requires the container to be privileged
  for setting up the storage.
- storage-tests-root: run tests marked as "root".

Fixes: #128
Signed-off-by: Albert Esteve <[email protected]>
  • Loading branch information
aesteve-rh committed Jul 8, 2022
1 parent 7629494 commit 6a47a06
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 17 deletions.
14 changes: 12 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,18 @@ jobs:
options: --privileged
steps:
- uses: actions/checkout@v2
- name: Run storage tests
run: ./automation/tests-storage.sh
- name: Run storage tests as vdsm
run: ./automation/tests-storage.sh vdsm
test-storage-root:
runs-on: ubuntu-latest
container:
image: quay.io/ovirt/vdsm-test-centos-8
# Required to create loop devices.
options: --privileged
steps:
- uses: actions/checkout@v2
- name: Run storage tests as root
run: ./automation/tests-storage.sh root
tests:
runs-on: ubuntu-latest
container:
Expand Down
64 changes: 49 additions & 15 deletions automation/tests-storage.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
#!/bin/sh -e

print_help() {
echo "Usage: $0 USER"
echo ""
echo " Helper script to setup and run storage tests as USER."
echo ""
echo "Examples:"
echo " Run tests as root user"
echo " $ $0 root"
echo " Run tests as vdsm user"
echo " $ $0 vdsm"
}

create_loop_devices() {
local last=$(($1-1))
local min
Expand All @@ -12,28 +24,50 @@ create_loop_devices() {
}

setup_storage() {
python3 tests/storage/userstorage.py setup
# Configure lvm to ignore udev events, otherwise some lvm tests hang.
mkdir -p /etc/lvm
cp docker/lvmlocal.conf /etc/lvm/

# Make sure we have enough loop device nodes. Using 16 devices since with 8
# devices we have random mount failures.
create_loop_devices 16

# Build vdsm.
./autogen.sh --system
make

# Setup user storage during the tests.
make storage
}

teardown_storage() {
python3 tests/storage/userstorage.py teardown \
make clean-storage \
|| echo "WARNING: Ingoring error while tearing down user storage"
}

# Configure lvm to ignore udev events, otherwise some lvm tests hang.
mkdir -p /etc/lvm
cp docker/lvmlocal.conf /etc/lvm/

# Make sure we have enough loop device nodes. Using 16 devices since with 8
# devices we have random mount failures.
create_loop_devices 16
# Process user argument
user=$1
if [ -z "$user" ]; then
echo "ERROR: user required"
print_help
exit 1
fi

# Build vdsm.
./autogen.sh --system
make
echo "Running tests as user $user"

# Setup user stoage during the tests.
trap teardown_storage EXIT
setup_storage
if [ "$user" != "root" ]; then
# Change ownership of current and storage folders
# to allow non-privileged access.
chown -R vdsm:kvm ./ /var/tmp/vdsm*
fi
# Teardown storage before exit.
trap teardown_storage EXIT

make tests-storage
if [ "$user" = "root" ]; then
# Run only tests marked as root
make tests-storage-root
else
# Run tests not marked as root as $user
su -c "make tests-storage-user" -- ${user}
fi

0 comments on commit 6a47a06

Please sign in to comment.