feat(packaging): implement packaging (.tar.gz, .deb, .rpm), FHS logging, and container integration test matrix

This commit is contained in:
soda64 committed 2026-10-02 12:33:37 +02:00
1 parent 6e18bdf7b7
commit e1a99d7e6f
20 files changed
+789 -21

No files matched your search

+128
View File
@@ -0,0 +1,128 @@
#!/bin/sh
set -e
# Container integration test suite for Linux System Updater
# Runs inside clean Podman containers on macOS
DISTRO="${1:-all}"
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
WORKSPACE="$(cd "${SCRIPT_DIR}/../.." && pwd)"
run_distro_test() {
D="$1"
echo ""
echo "=========================================================="
echo " [TEST] Starting container testing for: ${D}"
echo "=========================================================="
case "${D}" in
debian)
IMAGE="docker.io/library/debian:12-slim"
CMD="
apt-get update -qq && apt-get install -y -qq python3 > /dev/null
echo '=== 1. Building packages inside Debian container ==='
python3 packaging/build_packages.py
echo '=== 2. Installing .deb package ==='
dpkg -i dist/linux-updater_1.0.0_all.deb
echo '=== 3. Testing installed command ==='
linux-updater --version
echo '=== 4. Testing pre-flight health checks ==='
linux-updater health
echo '=== 5. Testing regular update (dry-run) ==='
linux-updater update --dry-run -y
echo '=== 6. Testing major release upgrade (dry-run) ==='
linux-updater release-upgrade --dry-run -y -t trixie
echo '=== 7. Verifying standard /var/log/linux-updater logging ==='
ls -la /var/log/linux-updater
test -f /var/log/linux-updater/latest.log
"
;;
ubuntu)
IMAGE="docker.io/library/ubuntu:22.04"
CMD="
apt-get update -qq && apt-get install -y -qq python3 > /dev/null
echo '=== 1. Building packages inside Ubuntu container ==='
python3 packaging/build_packages.py
echo '=== 2. Installing .deb package ==='
dpkg -i dist/linux-updater_1.0.0_all.deb
echo '=== 3. Testing installed command ==='
linux-updater --version
echo '=== 4. Testing pre-flight health checks ==='
linux-updater health
echo '=== 5. Testing regular update (dry-run) ==='
linux-updater update --dry-run -y
echo '=== 6. Testing major release upgrade (dry-run) ==='
linux-updater release-upgrade --dry-run -y -t 24.04
echo '=== 7. Verifying standard /var/log/linux-updater logging ==='
ls -la /var/log/linux-updater
test -f /var/log/linux-updater/latest.log
"
;;
fedora)
IMAGE="docker.io/library/fedora:40"
CMD="
dnf install -y -q python3 rpm-build python3-dnf-plugins-core > /dev/null
rm -rf dist/rpm
echo '=== 1. Building packages and RPM inside Fedora container ==='
python3 packaging/build_packages.py
echo '=== 2. Installing generated .rpm package ==='
rpm -Uvh --replacepkgs --replacefiles dist/rpm/RPMS/noarch/linux-updater-*.noarch.rpm
echo '=== 3. Testing installed command ==='
linux-updater --version
echo '=== 4. Testing pre-flight health checks ==='
linux-updater health
echo '=== 5. Testing regular update (dry-run) ==='
linux-updater update --dry-run -y
echo '=== 6. Testing major release upgrade (dry-run) ==='
linux-updater release-upgrade --dry-run -y -t 41
echo '=== 7. Verifying standard /var/log/linux-updater logging ==='
ls -la /var/log/linux-updater
test -f /var/log/linux-updater/latest.log
"
;;
almalinux8)
IMAGE="docker.io/library/almalinux:8"
CMD="
dnf install -y -q python3 rpm-build > /dev/null
rm -rf dist/rpm
echo '=== 1. Verifying Native Python on AlmaLinux 8 ==='
python3 --version
echo '=== 2. Building packages and RPM inside AlmaLinux 8 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 on Python 3.6 ==='
linux-updater --version
echo '=== 5. Testing pre-flight health checks ==='
linux-updater health
echo '=== 6. Testing regular update (dry-run) ==='
linux-updater update --dry-run -y
echo '=== 7. Testing major release upgrade (dry-run) ==='
linux-updater release-upgrade --dry-run -y
echo '=== 8. Verifying standard /var/log/linux-updater logging ==='
ls -la /var/log/linux-updater
test -f /var/log/linux-updater/latest.log
"
;;
*)
echo "Unknown distro: ${D}" >&2
return 1
;;
esac
podman run --rm -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
run_distro_test "${target}"
done
else
run_distro_test "${DISTRO}"
fi
echo ""
echo "=========================================================="
echo " ALL REQUESTED CONTAINER TESTS COMPLETED SUCCESSFULLY!"
echo "=========================================================="
+38
View File
@@ -122,6 +122,7 @@ class TestCLIIntegration(unittest.TestCase):
self.assertEqual(code, 0)
mock_manager.release_upgrade.assert_called_once_with(
target_release="41",
dry_run=False,
non_interactive=True,
)
@@ -143,6 +144,43 @@ class TestCLIIntegration(unittest.TestCase):
if t_path.exists():
t_path.unlink()
@patch("linux_updater.cli.DistroDetector.detect")
@patch("linux_updater.cli.get_manager")
def test_logging_creates_timestamped_log_and_symlink(self, mock_get_manager, mock_detect):
mock_detect.return_value = DistroInfo(DistroFamily.DEBIAN, "ubuntu", "24.04", "Ubuntu 24.04")
mock_manager = MagicMock()
mock_manager.get_lock_files.return_value = []
mock_get_manager.return_value = mock_manager
with tempfile.TemporaryDirectory() as tmp_dir:
config_data = {
"logging": {"log_dir": tmp_dir, "verbose": True}
}
cfg_file = Path(tmp_dir) / "config.json"
cfg_file.write_text(json.dumps(config_data))
with patch("os.statvfs") as mock_statvfs:
mock_stat = MagicMock()
mock_stat.f_bavail = 10 * 1024 * 1024
mock_stat.f_frsize = 1024
mock_statvfs.return_value = mock_stat
code = main(["-c", str(cfg_file), "health"])
self.assertEqual(code, 0)
# Check that log file was created
log_files = list(Path(tmp_dir).glob("linux-updater-*.log"))
self.assertEqual(len(log_files), 1)
# Check latest.log symlink
latest_link = Path(tmp_dir) / "latest.log"
self.assertTrue(latest_link.is_symlink())
self.assertEqual(latest_link.resolve(), log_files[0].resolve())
# Check content of log file
content = log_files[0].read_text()
self.assertIn("Linux System Updater", content)
self.assertIn("started", content)
if __name__ == "__main__":
unittest.main()
+31 -1
View File
@@ -24,7 +24,7 @@ class DummyManager(PackageManager):
def apply_updates(self, packages=None, dry_run=False, non_interactive=False):
pass
def release_upgrade(self, target_release=None, non_interactive=False):
def release_upgrade(self, target_release=None, dry_run=False, non_interactive=False):
pass
def clean_cache(self):
@@ -133,6 +133,36 @@ class TestHealthChecker(unittest.TestCase):
if lock_p.exists():
lock_p.unlink()
def test_locks_advisory_lock_free(self):
lock_p = Path("/tmp/test_dummy.lock")
lock_p.touch()
try:
results = self.checker.check_locks()
self.assertEqual(len(results), 1)
self.assertEqual(results[0].status, CheckStatus.PASS)
self.assertIn("No lock active", results[0].message)
finally:
if lock_p.exists():
lock_p.unlink()
def test_locks_advisory_lock_held(self):
import fcntl
lock_p = Path("/tmp/test_dummy.lock")
lock_p.touch()
f = open(str(lock_p), "r+")
fcntl.flock(f.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB)
try:
results = self.checker.check_locks()
self.assertEqual(len(results), 1)
self.assertEqual(results[0].status, CheckStatus.FAIL)
self.assertIn("Advisory lock actively held", results[0].message)
self.assertFalse(results[0].can_remediate)
finally:
fcntl.flock(f.fileno(), fcntl.LOCK_UN)
f.close()
if lock_p.exists():
lock_p.unlink()
def test_memory_sufficient(self):
meminfo = """MemTotal: 8147284 kB
MemFree: 2145124 kB
+62
View File
@@ -0,0 +1,62 @@
import os
import tarfile
import tempfile
import unittest
from pathlib import Path
from packaging.build_packages import PackageBuilder
class TestPackaging(unittest.TestCase):
def setUp(self):
self.temp_dir = tempfile.TemporaryDirectory()
self.out_dir = Path(self.temp_dir.name)
self.root_dir = Path(__file__).resolve().parent.parent
self.builder = PackageBuilder(source_root=self.root_dir, output_dir=self.out_dir, version="1.0.0")
def tearDown(self):
self.temp_dir.cleanup()
def test_build_tarball_creates_valid_archive(self):
tar_path = self.builder.build_tarball()
self.assertTrue(tar_path.exists())
self.assertTrue(tar_path.name.endswith(".tar.gz"))
# Verify archive contents
with tarfile.open(str(tar_path), "r:gz") as tar:
names = tar.getnames()
self.assertTrue(any("install.sh" in n for n in names))
self.assertTrue(any("linux_updater/__init__.py" in n for n in names))
self.assertTrue(any("linux-updater.json.example" in n for n in names))
def test_build_deb_creates_package_or_tree(self):
deb_path = self.builder.build_deb()
self.assertTrue(deb_path.exists())
self.assertTrue(str(deb_path).endswith(".deb"))
# Check ar header '!<arch>\n'
with open(str(deb_path), "rb") as f:
header = f.read(8)
self.assertEqual(header, b"!<arch>\n")
def test_build_rpm_spec_and_source(self):
rpm_result = self.builder.build_rpm()
self.assertTrue(rpm_result.exists())
spec_path = self.out_dir / "rpm" / "SPECS" / "linux-updater.spec"
self.assertTrue(spec_path.exists())
content = spec_path.read_text(encoding="utf-8")
self.assertIn("Name: linux-updater", content)
self.assertIn("Requires: python3 >= 3.6", content)
self.assertIn("BuildArch: noarch", content)
def test_build_all(self):
results = self.builder.build_all()
self.assertIn("tarball", results)
self.assertIn("deb", results)
self.assertIn("rpm", results)
for k, p in results.items():
self.assertTrue(p.exists(), f"Artifact {k} at {p} does not exist")
if __name__ == "__main__":
unittest.main()