feat: add root check, singleton lock, RHEL/Fedora upgrade auto-installer & container tests for AlmaLinux 9 and Arch Linux

This commit is contained in:
soda64 committed 2026-10-02 13:12:01 +02:00
1 parent 507a3fd310
commit 44c9423166
10 files changed
+711 -27

No files matched your search

+107 -2
View File
@@ -104,18 +104,123 @@ run_distro_test() {
test -f /var/log/linux-updater/latest.log
"
;;
almalinux9)
IMAGE="docker.io/library/almalinux:9"
CMD="
set -e
dnf install -y -q python3 rpm-build procps-ng > /dev/null
rm -rf dist/rpm
echo '=== 1. Verifying Native Python on AlmaLinux 9 ==='
python3 --version
echo '=== 2. Building packages and RPM inside AlmaLinux 9 container ==='
python3 packaging/build_packages.py
echo '=== 3. Installing generated .rpm package ==='
rpm -Uvh --replacepkgs --replacefiles dist/rpm/RPMS/noarch/linux-updater-*.noarch.rpm
echo '=== 4. Testing installed command ==='
linux-updater --version
echo '=== 5. Testing pre-flight health checks ==='
linux-updater health
echo '=== 6. Testing root privilege guardrails ==='
id -u testuser >/dev/null 2>&1 || useradd -m testuser
if su - testuser -c 'linux-updater update'; then
echo 'FAIL: Unprivileged update succeeded without root!' >&2
exit 1
else
echo 'OK: Unprivileged update correctly blocked.'
fi
echo 'OK: Verifying non-root dry-run and health check allowed:'
su - testuser -c 'linux-updater update --dry-run -y'
su - testuser -c 'linux-updater health'
echo '=== 7. Testing singleton concurrency lock ==='
python3 -c 'from linux_updater.core.lock import InstanceLock; import time; lock = InstanceLock(); lock.acquire(); time.sleep(3)' &
LOCK_PID=\$!
sleep 0.5
if linux-updater health; then
echo 'FAIL: Second instance succeeded despite active lock!' >&2
kill \$LOCK_PID 2>/dev/null || true
exit 1
else
echo 'OK: Second instance correctly blocked by singleton lock.'
fi
wait \$LOCK_PID 2>/dev/null || true
echo '=== 8. Testing package updates (check, dry-run, actual) ==='
linux-updater check
linux-updater update --dry-run -y
linux-updater update -y
echo '=== 9. Testing major release upgrade (dry-run with ELevate) ==='
linux-updater release-upgrade --dry-run -y
echo '=== 10. Verifying standard /var/log/linux-updater logging ==='
ls -la /var/log/linux-updater
test -f /var/log/linux-updater/latest.log
echo '=== AlmaLinux 9 verification complete ==='
"
;;
archlinux)
IMAGE="docker.io/library/archlinux:latest"
EXTRA_FLAGS="--platform linux/amd64"
CMD="
set -e
sed -i 's/^DownloadUser/#DownloadUser/' /etc/pacman.conf
sed -i 's/^#DisableSandboxSyscalls/DisableSandboxSyscalls/' /etc/pacman.conf
pacman -Sy --noconfirm python tar gzip procps-ng which > /dev/null
rm -rf dist/linux-updater-*.tar.gz linux-updater-1.0.0
echo '=== 1. Verifying Python on Arch Linux ==='
python3 --version
echo '=== 2. Building packages (tarball distribution) ==='
python3 packaging/build_packages.py
echo '=== 3. Installing from generated tarball via install.sh ==='
tar -xzf dist/linux-updater-1.0.0.tar.gz
(cd linux-updater-1.0.0 && ./install.sh)
echo '=== 4. Testing installed command ==='
linux-updater --version
echo '=== 5. Testing pre-flight health checks ==='
linux-updater health
echo '=== 6. Testing root privilege guardrails ==='
id -u testuser >/dev/null 2>&1 || useradd -m testuser
if su - testuser -c 'linux-updater update'; then
echo 'FAIL: Unprivileged update succeeded without root!' >&2
exit 1
else
echo 'OK: Unprivileged update correctly blocked.'
fi
echo 'OK: Verifying non-root dry-run and health check allowed:'
su - testuser -c 'linux-updater update --dry-run -y'
su - testuser -c 'linux-updater health'
echo '=== 7. Testing singleton concurrency lock ==='
python3 -c 'from linux_updater.core.lock import InstanceLock; import time; lock = InstanceLock(); lock.acquire(); time.sleep(3)' &
LOCK_PID=\$!
sleep 0.5
if linux-updater health; then
echo 'FAIL: Second instance succeeded despite active lock!' >&2
kill \$LOCK_PID 2>/dev/null || true
exit 1
else
echo 'OK: Second instance correctly blocked by singleton lock.'
fi
wait \$LOCK_PID 2>/dev/null || true
echo '=== 8. Testing package updates (check & dry-run) ==='
linux-updater check
linux-updater update --dry-run -y
echo '=== 9. Testing rolling release upgrade (dry-run) ==='
linux-updater release-upgrade --dry-run -y
echo '=== 10. Verifying standard /var/log/linux-updater logging ==='
ls -la /var/log/linux-updater
test -f /var/log/linux-updater/latest.log
echo '=== Arch Linux verification complete ==='
"
;;
*)
echo "Unknown distro: ${D}" >&2
return 1
;;
esac
podman run --rm -v "${WORKSPACE}:/workspace:Z" -w /workspace "${IMAGE}" bash -c "${CMD}"
podman run --rm ${EXTRA_FLAGS} -v "${WORKSPACE}:/workspace:Z" -w /workspace "${IMAGE}" bash -c "${CMD}"
echo ">>> [SUCCESS] Testing for ${D} PASSED!"
}
if [ "${DISTRO}" = "all" ]; then
for target in debian ubuntu fedora almalinux8; do
for target in debian ubuntu fedora almalinux8 almalinux9 archlinux; do
run_distro_test "${target}"
done
else