5.7 KiB
Linux System Updater: Developer Guide
This guide provides technical specifications, architectural details, and developer workflows for contributing to linux-updater.
1. Architectural Overview
linux-updater follows a clean separation of concerns:
linux_updater/
├── __init__.py # Package version definition
├── __main__.py # CLI invocation entrypoint (python3 -m linux_updater)
├── cli.py # Argument parsing, formatting, execution controller
├── config.py # JSON configuration loader & default thresholds
├── models.py # Core data transfer objects (DistroInfo, CheckResult, etc.)
├── core/
│ ├── detector.py # Distro detection via /etc/os-release parsing
│ ├── health.py # Pre-flight health diagnostics & lock checking
│ ├── remediation.py # Automated remediation actions (cache, stale locks)
│ └── runner.py # Subprocess runner with timestamped file logging
└── managers/
├── __init__.py # get_manager() factory
├── base.py # PackageManager abstract base class interface
├── apt.py # Debian/Ubuntu (APT) driver
├── dnf.py # RHEL/Fedora/CentOS/AlmaLinux/Rocky (DNF) driver
└── pacman.py # Arch Linux (Pacman) driver
2. Hard Constraints & Coding Standards
- Python >= 3.6 Standard Library Baseline:
- NO external
pipdependencies. Zero third-party packages allowed. - NO
dataclasses(introduced in Python 3.7). Use standard classes orNamedTuple. - NO
subprocess.run(capture_output=True)(introduced in Python 3.7). Usestdout=subprocess.PIPE, stderr=subprocess.PIPE. - NO modern union operators like
int | None(introduced in Python 3.10). UseOptional[int].
- NO external
- Deterministic Return Codes:
- Always map execution outcomes to standard exit codes (
0clean,1error,2reboot required,3user abort).
- Always map execution outcomes to standard exit codes (
- Container-First Verification:
- All tests against actual package managers and distributions MUST be run inside clean Podman containers, never on the host system.
3. Implementing a New Package Manager Driver
To add support for a new package manager (e.g. zypper for openSUSE or apk for Alpine):
- Subclass
PackageManagerinlinux_updater/managers/<name>.py:
from pathlib import Path
from typing import List, Optional
from linux_updater.managers.base import PackageManager
from linux_updater.models import CommandResult, PackageUpdate, RebootStatus
class ZypperManager(PackageManager):
@property
def name(self) -> str:
return "zypper"
def refresh_repositories(self) -> CommandResult:
return self.runner.run(["zypper", "refresh"])
def check_updates(self) -> List[PackageUpdate]:
# Parse 'zypper list-updates'
...
def apply_updates(self, packages=None, dry_run=False, non_interactive=False) -> CommandResult:
cmd = ["zypper", "update"]
if dry_run:
cmd.append("--dry-run")
if non_interactive:
cmd.append("-y")
if packages:
cmd.extend(packages)
return self.runner.run(cmd)
def release_upgrade(self, target_release=None, dry_run=False, non_interactive=False) -> CommandResult:
cmd = ["zypper", "dup"]
if dry_run:
cmd.append("--dry-run")
if non_interactive:
cmd.append("-y")
return self.runner.run(cmd)
def clean_cache(self) -> CommandResult:
return self.runner.run(["zypper", "clean", "-a"])
def autoremove(self) -> CommandResult:
return self.runner.run(["zypper", "rm", "-u"])
def is_reboot_required(self) -> RebootStatus:
res = self.runner.run(["zypper", "needs-rebooting"])
return RebootStatus(required=(res.return_code != 0))
def get_lock_files(self) -> List[Path]:
return [Path("/var/run/zypp.pid")]
- Register in
linux_updater/managers/__init__.py:
def get_manager(family: str, runner: Optional[CommandRunner] = None) -> PackageManager:
...
elif family == "suse":
return ZypperManager(runner=runner)
- Add Distro Mapping in
linux_updater/models.pyandcore/detector.py: Ensure/etc/os-releaseIDorID_LIKEvalues map to the new family.
4. Testing & Quality Assurance
Local Unit Tests
Unit tests use mocks and run locally with Python's built-in unittest runner:
python3 -m unittest discover tests
Container Integration Tests (Podman)
Automated multi-distro container integration testing is orchestrated by tests/containers/run_tests.sh:
# Test all distributions (Debian 12, Ubuntu 22.04, Fedora 40, AlmaLinux 8):
./tests/containers/run_tests.sh all
# Test a single distribution:
./tests/containers/run_tests.sh debian
./tests/containers/run_tests.sh ubuntu
./tests/containers/run_tests.sh fedora
./tests/containers/run_tests.sh almalinux8
The script automatically mounts /workspace:Z, builds .deb or .rpm packages from source, installs the package inside the container, verifies the binary, runs health checks, tests routine update (dry-run), tests release-upgrade (dry-run), and verifies /var/log/linux-updater/ logging.
5. Building Distribution Packages
Run the pure Python builder script:
python3 packaging/build_packages.py
Generated artifacts:
dist/linux-updater-1.0.0.tar.gz: Standalone distribution archive containinginstall.sh.dist/linux-updater_1.0.0_all.deb: Native Debian/Ubuntu binary package.dist/rpm/RPMS/noarch/linux-updater-1.0.0-1.*.noarch.rpm: Native RPM package.