feat: real-time streaming runner, --releasever alias, enriched help examples, and Fedora offline upgrade guidance
This commit is contained in:
1 parent
5940327b54
commit
b1c0f22ce7
8 files changed
+247
-37
No files matched your search
+98
-11
@@ -59,8 +59,22 @@ def create_parser() -> argparse.ArgumentParser:
|
|||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
prog="linux-updater",
|
prog="linux-updater",
|
||||||
description="Unified, safe multi-distribution Linux system updater and health inspector.",
|
description="Unified, safe multi-distribution Linux system updater and health inspector.",
|
||||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||||
parents=[common],
|
parents=[common],
|
||||||
|
epilog="""
|
||||||
|
Examples:
|
||||||
|
linux-updater health # Run pre-flight health diagnostic checks
|
||||||
|
linux-updater check # Check for available updates without applying
|
||||||
|
sudo linux-updater update # Update system packages interactively
|
||||||
|
sudo linux-updater update -y # Non-interactive automated update
|
||||||
|
sudo linux-updater update --packages curl # Selectively update specific package(s)
|
||||||
|
sudo linux-updater release-upgrade -t 44 # Upgrade distribution release (Fedora/RHEL/Debian/Ubuntu)
|
||||||
|
sudo linux-updater clean --all # Clean package cache and unused dependencies
|
||||||
|
|
||||||
|
Subcommand Help:
|
||||||
|
Run 'linux-updater <subcommand> --help' for options specific to that subcommand.
|
||||||
|
Example: 'linux-updater release-upgrade --help'
|
||||||
|
""",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-v", "--version",
|
"-v", "--version",
|
||||||
@@ -76,7 +90,15 @@ def create_parser() -> argparse.ArgumentParser:
|
|||||||
"update",
|
"update",
|
||||||
parents=[common],
|
parents=[common],
|
||||||
help="Inspect health, auto-remediate safe issues, and apply package updates.",
|
help="Inspect health, auto-remediate safe issues, and apply package updates.",
|
||||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||||
|
description="Inspect health, auto-remediate safe issues, and apply package updates.",
|
||||||
|
epilog="""
|
||||||
|
Examples:
|
||||||
|
sudo linux-updater update
|
||||||
|
sudo linux-updater update -y
|
||||||
|
sudo linux-updater update --dry-run
|
||||||
|
sudo linux-updater update --packages nginx redis
|
||||||
|
""",
|
||||||
)
|
)
|
||||||
update_parser.add_argument(
|
update_parser.add_argument(
|
||||||
"--packages",
|
"--packages",
|
||||||
@@ -90,7 +112,13 @@ def create_parser() -> argparse.ArgumentParser:
|
|||||||
"check",
|
"check",
|
||||||
parents=[common],
|
parents=[common],
|
||||||
help="Check system health and list available updates without making modifications.",
|
help="Check system health and list available updates without making modifications.",
|
||||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||||
|
description="Check system health and list available updates without making modifications.",
|
||||||
|
epilog="""
|
||||||
|
Examples:
|
||||||
|
linux-updater check
|
||||||
|
linux-updater check --json
|
||||||
|
""",
|
||||||
)
|
)
|
||||||
|
|
||||||
# Subcommand: release-upgrade
|
# Subcommand: release-upgrade
|
||||||
@@ -98,12 +126,26 @@ def create_parser() -> argparse.ArgumentParser:
|
|||||||
"release-upgrade",
|
"release-upgrade",
|
||||||
parents=[common],
|
parents=[common],
|
||||||
help="Perform a major distribution release upgrade with additional safety guardrails.",
|
help="Perform a major distribution release upgrade with additional safety guardrails.",
|
||||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||||
|
description="Perform a major distribution release upgrade with safety checks (e.g. Fedora, Ubuntu, AlmaLinux/Rocky).",
|
||||||
|
epilog="""
|
||||||
|
Target Release Specification:
|
||||||
|
On Fedora and Red Hat-based systems, you must specify the target release version.
|
||||||
|
Both '-t / --target-release' and '--releasever' are supported.
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
sudo linux-updater release-upgrade -t 44 # Fedora: upgrade to version 44
|
||||||
|
sudo linux-updater release-upgrade --releasever 44 # Fedora: alias syntax
|
||||||
|
sudo linux-updater release-upgrade -t 24.04 # Ubuntu/Debian: upgrade to 24.04
|
||||||
|
sudo linux-updater release-upgrade -t 9 # AlmaLinux / Rocky: upgrade to EL 9
|
||||||
|
sudo linux-updater release-upgrade -t 44 --dry-run # Simulate upgrade without applying
|
||||||
|
""",
|
||||||
)
|
)
|
||||||
release_parser.add_argument(
|
release_parser.add_argument(
|
||||||
"-t", "--target-release",
|
"-t", "--target-release", "--releasever",
|
||||||
|
dest="target_release",
|
||||||
type=str,
|
type=str,
|
||||||
help="Specify the target distribution version number/codename (e.g. 24.04, 41).",
|
help="Specify target distribution version number/codename (e.g. 44 for Fedora, 24.04 for Ubuntu, 9 for AlmaLinux).",
|
||||||
)
|
)
|
||||||
|
|
||||||
# Subcommand: clean
|
# Subcommand: clean
|
||||||
@@ -111,7 +153,13 @@ def create_parser() -> argparse.ArgumentParser:
|
|||||||
"clean",
|
"clean",
|
||||||
parents=[common],
|
parents=[common],
|
||||||
help="Clean downloaded package cache and remove orphaned packages.",
|
help="Clean downloaded package cache and remove orphaned packages.",
|
||||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||||
|
description="Clean downloaded package cache and remove orphaned packages.",
|
||||||
|
epilog="""
|
||||||
|
Examples:
|
||||||
|
sudo linux-updater clean
|
||||||
|
sudo linux-updater clean --all
|
||||||
|
""",
|
||||||
)
|
)
|
||||||
clean_parser.add_argument(
|
clean_parser.add_argument(
|
||||||
"--all",
|
"--all",
|
||||||
@@ -124,7 +172,14 @@ def create_parser() -> argparse.ArgumentParser:
|
|||||||
"health",
|
"health",
|
||||||
parents=[common],
|
parents=[common],
|
||||||
help="Run only the pre-flight health diagnostic checks.",
|
help="Run only the pre-flight health diagnostic checks.",
|
||||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||||
|
description="Run only the pre-flight health diagnostic checks and print a formatted report.",
|
||||||
|
epilog="""
|
||||||
|
Examples:
|
||||||
|
linux-updater health
|
||||||
|
linux-updater health --json
|
||||||
|
linux-updater health --no-remediation
|
||||||
|
""",
|
||||||
)
|
)
|
||||||
|
|
||||||
return parser
|
return parser
|
||||||
@@ -247,6 +302,9 @@ def _run(
|
|||||||
json_output: bool,
|
json_output: bool,
|
||||||
config_path: str,
|
config_path: str,
|
||||||
) -> int:
|
) -> int:
|
||||||
|
if json_output:
|
||||||
|
os.environ["LINUX_UPDATER_NO_STREAM"] = "1"
|
||||||
|
|
||||||
config = UpdaterConfig.load(Path(config_path) if config_path else None)
|
config = UpdaterConfig.load(Path(config_path) if config_path else None)
|
||||||
if non_interactive:
|
if non_interactive:
|
||||||
config.non_interactive = True
|
config.non_interactive = True
|
||||||
@@ -430,6 +488,30 @@ def _run(
|
|||||||
# 6. Release-Upgrade Command
|
# 6. Release-Upgrade Command
|
||||||
if args.command == "release-upgrade":
|
if args.command == "release-upgrade":
|
||||||
target = getattr(args, "target_release", None)
|
target = getattr(args, "target_release", None)
|
||||||
|
|
||||||
|
if distro.distro_id.lower() == "fedora" and not target:
|
||||||
|
current_ver = distro.version_id.strip() if distro.version_id else ""
|
||||||
|
suggested = f"-t {int(current_ver) + 1}" if current_ver.isdigit() else "-t <version>"
|
||||||
|
if not json_output:
|
||||||
|
print(
|
||||||
|
f"\nError: Fedora major release upgrade requires specifying the target version.\n"
|
||||||
|
f"Current system version: Fedora {distro.version_id or 'unknown'}\n\n"
|
||||||
|
f"Usage:\n"
|
||||||
|
f" sudo linux-updater release-upgrade -t <version>\n"
|
||||||
|
f" sudo linux-updater release-upgrade --releasever <version>\n\n"
|
||||||
|
f"Examples:\n"
|
||||||
|
f" sudo linux-updater release-upgrade {suggested}\n"
|
||||||
|
f" sudo linux-updater release-upgrade {suggested} --dry-run\n",
|
||||||
|
file=sys.stderr,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
print(json.dumps({
|
||||||
|
"success": False,
|
||||||
|
"error": "Target release version required for Fedora",
|
||||||
|
"current_version": distro.version_id,
|
||||||
|
}, indent=2))
|
||||||
|
return 1
|
||||||
|
|
||||||
if not json_output:
|
if not json_output:
|
||||||
print("\n" + "=" * 65)
|
print("\n" + "=" * 65)
|
||||||
print(" WARNING: MAJOR DISTRIBUTION RELEASE UPGRADE")
|
print(" WARNING: MAJOR DISTRIBUTION RELEASE UPGRADE")
|
||||||
@@ -470,9 +552,14 @@ def _run(
|
|||||||
"reboot_required": reboot.required,
|
"reboot_required": reboot.required,
|
||||||
}, indent=2))
|
}, indent=2))
|
||||||
else:
|
else:
|
||||||
print("\nRelease upgrade completed successfully!")
|
print("\nRelease upgrade preparation completed successfully!")
|
||||||
if reboot.required:
|
if distro.distro_id.lower() == "fedora" and not dry_run:
|
||||||
print("\n[!] ATTENTION: A system reboot is required to boot into the new release.")
|
print("\n[!] ATTENTION: Fedora offline upgrade packages have been downloaded.")
|
||||||
|
print(" To execute the upgrade and reboot into the new release, run:")
|
||||||
|
print(" sudo dnf system-upgrade reboot")
|
||||||
|
return 2
|
||||||
|
elif reboot.required:
|
||||||
|
print(f"\n[!] ATTENTION: A system reboot is required to boot into the new release ({reboot.reason}).")
|
||||||
return 2
|
return 2
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ class CommandRunner:
|
|||||||
check: bool = False,
|
check: bool = False,
|
||||||
env: Optional[Dict[str, str]] = None,
|
env: Optional[Dict[str, str]] = None,
|
||||||
timeout: Optional[int] = None,
|
timeout: Optional[int] = None,
|
||||||
|
stream: bool = False,
|
||||||
) -> CommandResult:
|
) -> CommandResult:
|
||||||
full_env = os.environ.copy()
|
full_env = os.environ.copy()
|
||||||
if env:
|
if env:
|
||||||
@@ -38,16 +39,48 @@ class CommandRunner:
|
|||||||
self._log(f"Executing: {' '.join(cmd)}")
|
self._log(f"Executing: {' '.join(cmd)}")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
proc = subprocess.run(
|
if stream and not os.environ.get("LINUX_UPDATER_NO_STREAM"):
|
||||||
cmd,
|
import selectors
|
||||||
stdout=subprocess.PIPE,
|
proc = subprocess.Popen(
|
||||||
stderr=subprocess.PIPE,
|
cmd,
|
||||||
env=full_env,
|
stdout=subprocess.PIPE,
|
||||||
timeout=timeout,
|
stderr=subprocess.PIPE,
|
||||||
)
|
env=full_env,
|
||||||
stdout = proc.stdout.decode("utf-8", errors="replace")
|
)
|
||||||
stderr = proc.stderr.decode("utf-8", errors="replace")
|
stdout_acc: List[str] = []
|
||||||
success = (proc.returncode == 0)
|
stderr_acc: List[str] = []
|
||||||
|
|
||||||
|
sel = selectors.DefaultSelector()
|
||||||
|
sel.register(proc.stdout, selectors.EVENT_READ, data=(sys.stdout, stdout_acc))
|
||||||
|
sel.register(proc.stderr, selectors.EVENT_READ, data=(sys.stderr, stderr_acc))
|
||||||
|
|
||||||
|
while sel.get_map():
|
||||||
|
events = sel.select(timeout=0.2)
|
||||||
|
for key, _ in events:
|
||||||
|
raw = os.read(key.fileobj.fileno(), 1024)
|
||||||
|
if not raw:
|
||||||
|
sel.unregister(key.fileobj)
|
||||||
|
continue
|
||||||
|
text = raw.decode("utf-8", errors="replace")
|
||||||
|
key.data[0].write(text)
|
||||||
|
key.data[0].flush()
|
||||||
|
key.data[1].append(text)
|
||||||
|
|
||||||
|
proc.wait(timeout=timeout)
|
||||||
|
stdout = "".join(stdout_acc)
|
||||||
|
stderr = "".join(stderr_acc)
|
||||||
|
success = (proc.returncode == 0)
|
||||||
|
else:
|
||||||
|
proc = subprocess.run(
|
||||||
|
cmd,
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.PIPE,
|
||||||
|
env=full_env,
|
||||||
|
timeout=timeout,
|
||||||
|
)
|
||||||
|
stdout = proc.stdout.decode("utf-8", errors="replace")
|
||||||
|
stderr = proc.stderr.decode("utf-8", errors="replace")
|
||||||
|
success = (proc.returncode == 0)
|
||||||
|
|
||||||
self._log(f"Exit code: {proc.returncode}")
|
self._log(f"Exit code: {proc.returncode}")
|
||||||
|
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ class AptManager(PackageManager):
|
|||||||
'-o', 'Dpkg::Options::=--force-confold',
|
'-o', 'Dpkg::Options::=--force-confold',
|
||||||
])
|
])
|
||||||
|
|
||||||
return self.runner.run(cmd, env=self._env(non_interactive))
|
return self.runner.run(cmd, env=self._env(non_interactive), stream=not dry_run)
|
||||||
|
|
||||||
def release_upgrade(
|
def release_upgrade(
|
||||||
self,
|
self,
|
||||||
@@ -88,7 +88,7 @@ class AptManager(PackageManager):
|
|||||||
cmd.append("-d")
|
cmd.append("-d")
|
||||||
if non_interactive:
|
if non_interactive:
|
||||||
cmd.extend(["-f", "DistUpgradeViewNonInteractive"])
|
cmd.extend(["-f", "DistUpgradeViewNonInteractive"])
|
||||||
return self.runner.run(cmd, env=self._env(non_interactive))
|
return self.runner.run(cmd, env=self._env(non_interactive), stream=not dry_run)
|
||||||
|
|
||||||
# Standard Debian dist-upgrade
|
# Standard Debian dist-upgrade
|
||||||
cmd = ["apt-get", "dist-upgrade", "-y"]
|
cmd = ["apt-get", "dist-upgrade", "-y"]
|
||||||
@@ -99,7 +99,7 @@ class AptManager(PackageManager):
|
|||||||
'-o', 'Dpkg::Options::=--force-confdef',
|
'-o', 'Dpkg::Options::=--force-confdef',
|
||||||
'-o', 'Dpkg::Options::=--force-confold',
|
'-o', 'Dpkg::Options::=--force-confold',
|
||||||
])
|
])
|
||||||
return self.runner.run(cmd, env=self._env(non_interactive))
|
return self.runner.run(cmd, env=self._env(non_interactive), stream=not dry_run)
|
||||||
|
|
||||||
def clean_cache(self) -> CommandResult:
|
def clean_cache(self) -> CommandResult:
|
||||||
return self.runner.run(["apt-get", "clean"])
|
return self.runner.run(["apt-get", "clean"])
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ class DnfManager(PackageManager):
|
|||||||
if packages:
|
if packages:
|
||||||
cmd.extend(packages)
|
cmd.extend(packages)
|
||||||
|
|
||||||
res = self.runner.run(cmd)
|
res = self.runner.run(cmd, stream=not dry_run)
|
||||||
if dry_run and res.return_code == 1:
|
if dry_run and res.return_code == 1:
|
||||||
combined = res.stdout + res.stderr
|
combined = res.stdout + res.stderr
|
||||||
if "Operation aborted" in combined or "Nothing to do" in combined:
|
if "Operation aborted" in combined or "Nothing to do" in combined:
|
||||||
@@ -224,15 +224,30 @@ class DnfManager(PackageManager):
|
|||||||
)
|
)
|
||||||
return CommandResult(return_code=1, stdout="", stderr=msg, success=False)
|
return CommandResult(return_code=1, stdout="", stderr=msg, success=False)
|
||||||
|
|
||||||
|
if not target_release:
|
||||||
|
current_ver = distro.version_id.strip() if distro.version_id else ""
|
||||||
|
suggested = f"-t {int(current_ver) + 1}" if current_ver.isdigit() else "-t <target_version>"
|
||||||
|
err_msg = (
|
||||||
|
"Fedora major release upgrade requires specifying the target release version.\n"
|
||||||
|
f"Current system version: Fedora {distro.version_id or 'unknown'}\n\n"
|
||||||
|
"Usage:\n"
|
||||||
|
f" sudo linux-updater release-upgrade -t <version>\n"
|
||||||
|
f" sudo linux-updater release-upgrade --releasever <version>\n\n"
|
||||||
|
"Examples:\n"
|
||||||
|
f" sudo linux-updater release-upgrade {suggested}\n"
|
||||||
|
f" sudo linux-updater release-upgrade {suggested} --dry-run"
|
||||||
|
)
|
||||||
|
self.runner._log(f"[ERROR] {err_msg}")
|
||||||
|
return CommandResult(return_code=1, stdout="", stderr=err_msg, success=False)
|
||||||
|
|
||||||
cmd = [self.binary, "system-upgrade", "download"]
|
cmd = [self.binary, "system-upgrade", "download"]
|
||||||
if dry_run:
|
if dry_run:
|
||||||
cmd.append("--assumeno")
|
cmd.append("--assumeno")
|
||||||
elif non_interactive:
|
elif non_interactive:
|
||||||
cmd.append("-y")
|
cmd.append("-y")
|
||||||
if target_release:
|
cmd.append(f"--releasever={target_release}")
|
||||||
cmd.append(f"--releasever={target_release}")
|
|
||||||
|
|
||||||
res = self.runner.run(cmd)
|
res = self.runner.run(cmd, stream=not dry_run)
|
||||||
if dry_run and res.return_code == 1:
|
if dry_run and res.return_code == 1:
|
||||||
combined = res.stdout + res.stderr
|
combined = res.stdout + res.stderr
|
||||||
if "Operation aborted" in combined or "Nothing to do" in combined:
|
if "Operation aborted" in combined or "Nothing to do" in combined:
|
||||||
@@ -278,7 +293,7 @@ class DnfManager(PackageManager):
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
self.runner._log("[UPGRADE] Starting Leapp in-place upgrade ('leapp upgrade')...")
|
self.runner._log("[UPGRADE] Starting Leapp in-place upgrade ('leapp upgrade')...")
|
||||||
res = self.runner.run(["leapp", "upgrade"])
|
res = self.runner.run(["leapp", "upgrade"], stream=True)
|
||||||
if res.return_code != 0:
|
if res.return_code != 0:
|
||||||
err_msg = (
|
err_msg = (
|
||||||
f"Leapp in-place upgrade failed with exit code {res.return_code}.\n"
|
f"Leapp in-place upgrade failed with exit code {res.return_code}.\n"
|
||||||
@@ -325,7 +340,7 @@ class DnfManager(PackageManager):
|
|||||||
res = self.runner.run(["leapp", "preupgrade"])
|
res = self.runner.run(["leapp", "preupgrade"])
|
||||||
return CommandResult(return_code=0, stdout=f"[DRY-RUN] Leapp pre-upgrade simulation:\n{res.stdout}", stderr="", success=True)
|
return CommandResult(return_code=0, stdout=f"[DRY-RUN] Leapp pre-upgrade simulation:\n{res.stdout}", stderr="", success=True)
|
||||||
else:
|
else:
|
||||||
return self.runner.run(["leapp", "upgrade"])
|
return self.runner.run(["leapp", "upgrade"], stream=True)
|
||||||
|
|
||||||
# 4. Fallback for other DNF-based systems
|
# 4. Fallback for other DNF-based systems
|
||||||
check = self.runner.run([self.binary, "system-upgrade", "--help"])
|
check = self.runner.run([self.binary, "system-upgrade", "--help"])
|
||||||
@@ -352,7 +367,7 @@ class DnfManager(PackageManager):
|
|||||||
if target_release:
|
if target_release:
|
||||||
cmd.append(f"--releasever={target_release}")
|
cmd.append(f"--releasever={target_release}")
|
||||||
|
|
||||||
res = self.runner.run(cmd)
|
res = self.runner.run(cmd, stream=not dry_run)
|
||||||
if dry_run and res.return_code == 1:
|
if dry_run and res.return_code == 1:
|
||||||
combined = res.stdout + res.stderr
|
combined = res.stdout + res.stderr
|
||||||
if "Operation aborted" in combined or "Nothing to do" in combined:
|
if "Operation aborted" in combined or "Nothing to do" in combined:
|
||||||
@@ -373,6 +388,17 @@ class DnfManager(PackageManager):
|
|||||||
return self.runner.run(cmd)
|
return self.runner.run(cmd)
|
||||||
|
|
||||||
def is_reboot_required(self) -> RebootStatus:
|
def is_reboot_required(self) -> RebootStatus:
|
||||||
|
# Check if dnf system-upgrade downloaded packages are staged
|
||||||
|
system_upgrade_dir = Path("/var/lib/dnf/system-upgrade")
|
||||||
|
if system_upgrade_dir.exists():
|
||||||
|
try:
|
||||||
|
if any(system_upgrade_dir.iterdir()):
|
||||||
|
return RebootStatus(
|
||||||
|
required=True,
|
||||||
|
reason="System upgrade packages downloaded. Run: 'sudo dnf system-upgrade reboot' to perform the upgrade.",
|
||||||
|
)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
# Check needs-restarting -r
|
# Check needs-restarting -r
|
||||||
if shutil.which("needs-restarting"):
|
if shutil.which("needs-restarting"):
|
||||||
res = self.runner.run(["needs-restarting", "-r"])
|
res = self.runner.run(["needs-restarting", "-r"])
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ class PacmanManager(PackageManager):
|
|||||||
if dry_run:
|
if dry_run:
|
||||||
cmd.append("-p")
|
cmd.append("-p")
|
||||||
|
|
||||||
return self.runner.run(cmd)
|
return self.runner.run(cmd, stream=not dry_run)
|
||||||
|
|
||||||
def release_upgrade(
|
def release_upgrade(
|
||||||
self,
|
self,
|
||||||
@@ -81,7 +81,7 @@ class PacmanManager(PackageManager):
|
|||||||
cmd.append("-p")
|
cmd.append("-p")
|
||||||
elif non_interactive:
|
elif non_interactive:
|
||||||
cmd.append("--noconfirm")
|
cmd.append("--noconfirm")
|
||||||
return self.runner.run(cmd)
|
return self.runner.run(cmd, stream=not dry_run)
|
||||||
|
|
||||||
def clean_cache(self) -> CommandResult:
|
def clean_cache(self) -> CommandResult:
|
||||||
return self.runner.run(["pacman", "-Sc", "--noconfirm"])
|
return self.runner.run(["pacman", "-Sc", "--noconfirm"])
|
||||||
|
|||||||
+2
-2
@@ -39,8 +39,8 @@ Runs pre-flight diagnostics, cleans caches if needed, checks for available updat
|
|||||||
.B check
|
.B check
|
||||||
Non-destructively inspects pre-flight health diagnostics and lists all pending package upgrades without modifying system state.
|
Non-destructively inspects pre-flight health diagnostics and lists all pending package upgrades without modifying system state.
|
||||||
.TP
|
.TP
|
||||||
.B release\-upgrade \fR[\fB\-t \fITARGET\fR|\fB\-\-target\-release \fITARGET\fR]
|
.B release\-upgrade \fR[\fB\-t \fITARGET\fR|\fB\-\-target\-release \fITARGET\fR|\fB\-\-releasever \fITARGET\fR]
|
||||||
Executes a major OS distribution upgrade (e.g. Debian 12 to 13, Ubuntu 22.04 to 24.04, Fedora 40 to 41, or RHEL/AlmaLinux leapp upgrade). Requires explicit user confirmation unless \fB\-y\fR is passed.
|
Executes a major OS distribution upgrade (e.g. Debian 12 to 13, Ubuntu 22.04 to 24.04, Fedora 43 to 44, or RHEL/AlmaLinux leapp upgrade). On Fedora, the target release version is mandatory via \fB\-t\fR or \fB\-\-releasever\fR. Requires explicit user confirmation unless \fB\-y\fR is passed.
|
||||||
.TP
|
.TP
|
||||||
.B clean \fR[\fB\-\-all\fR]
|
.B clean \fR[\fB\-\-all\fR]
|
||||||
Cleans the local package cache. When \fB\-\-all\fR is given, also removes unused orphaned dependencies.
|
Cleans the local package cache. When \fB\-\-all\fR is given, also removes unused orphaned dependencies.
|
||||||
|
|||||||
+49
-1
@@ -122,13 +122,61 @@ class TestCLIIntegration(unittest.TestCase):
|
|||||||
mock_statvfs.return_value = mock_stat
|
mock_statvfs.return_value = mock_stat
|
||||||
|
|
||||||
code = main(["-y", "release-upgrade", "--target-release", "41"])
|
code = main(["-y", "release-upgrade", "--target-release", "41"])
|
||||||
self.assertEqual(code, 0)
|
self.assertEqual(code, 2)
|
||||||
mock_manager.release_upgrade.assert_called_once_with(
|
mock_manager.release_upgrade.assert_called_once_with(
|
||||||
target_release="41",
|
target_release="41",
|
||||||
dry_run=False,
|
dry_run=False,
|
||||||
non_interactive=True,
|
non_interactive=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@patch("linux_updater.cli.check_root_privileges", return_value=True)
|
||||||
|
@patch("linux_updater.cli.DistroDetector.detect")
|
||||||
|
@patch("linux_updater.cli.get_manager")
|
||||||
|
def test_cli_release_upgrade_accepts_releasever_alias(self, mock_get_manager, mock_detect, mock_root):
|
||||||
|
mock_detect.return_value = DistroInfo(
|
||||||
|
family=DistroFamily.RHEL,
|
||||||
|
distro_id="fedora",
|
||||||
|
version_id="43",
|
||||||
|
pretty_name="Fedora 43",
|
||||||
|
)
|
||||||
|
mock_manager = MagicMock()
|
||||||
|
mock_manager.get_lock_files.return_value = []
|
||||||
|
mock_manager.release_upgrade.return_value = CommandResult(0, "success", "", True)
|
||||||
|
mock_manager.is_reboot_required.return_value = RebootStatus(required=False)
|
||||||
|
mock_get_manager.return_value = mock_manager
|
||||||
|
|
||||||
|
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(["-y", "release-upgrade", "--releasever", "44"])
|
||||||
|
self.assertEqual(code, 2)
|
||||||
|
mock_manager.release_upgrade.assert_called_once_with(
|
||||||
|
target_release="44",
|
||||||
|
dry_run=False,
|
||||||
|
non_interactive=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
@patch("linux_updater.cli.check_root_privileges", return_value=True)
|
||||||
|
@patch("linux_updater.cli.DistroDetector.detect")
|
||||||
|
def test_cli_release_upgrade_fedora_requires_target(self, mock_detect, mock_root):
|
||||||
|
mock_detect.return_value = DistroInfo(
|
||||||
|
family=DistroFamily.RHEL,
|
||||||
|
distro_id="fedora",
|
||||||
|
version_id="43",
|
||||||
|
pretty_name="Fedora 43",
|
||||||
|
)
|
||||||
|
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(["-y", "release-upgrade"])
|
||||||
|
self.assertEqual(code, 1)
|
||||||
|
|
||||||
@patch("linux_updater.cli.check_root_privileges", return_value=False)
|
@patch("linux_updater.cli.check_root_privileges", return_value=False)
|
||||||
@patch("linux_updater.cli.DistroDetector.detect")
|
@patch("linux_updater.cli.DistroDetector.detect")
|
||||||
def test_cli_root_required_for_mutating_commands(self, mock_detect, mock_root):
|
def test_cli_root_required_for_mutating_commands(self, mock_detect, mock_root):
|
||||||
|
|||||||
+17
-1
@@ -2,7 +2,7 @@ import unittest
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from unittest.mock import MagicMock, patch
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
from linux_updater.models import CommandResult, DistroFamily, RebootStatus
|
from linux_updater.models import CommandResult, DistroFamily, DistroInfo, RebootStatus
|
||||||
from linux_updater.core.runner import CommandRunner
|
from linux_updater.core.runner import CommandRunner
|
||||||
from linux_updater.managers.apt import AptManager
|
from linux_updater.managers.apt import AptManager
|
||||||
from linux_updater.managers.dnf import DnfManager
|
from linux_updater.managers.dnf import DnfManager
|
||||||
@@ -156,6 +156,22 @@ systemd 255.5-1 -> 255.6-1 [extra]
|
|||||||
self.assertEqual(called_cmds[1], ["dnf", "install", "-y", "python3-dnf-plugins-core"])
|
self.assertEqual(called_cmds[1], ["dnf", "install", "-y", "python3-dnf-plugins-core"])
|
||||||
self.assertIn("--releasever=41", called_cmds[3])
|
self.assertIn("--releasever=41", called_cmds[3])
|
||||||
|
|
||||||
|
def test_dnf_fedora_release_upgrade_missing_target_fails_cleanly(self):
|
||||||
|
fedora_info = DistroInfo(
|
||||||
|
family=DistroFamily.RHEL,
|
||||||
|
distro_id="fedora",
|
||||||
|
version_id="43",
|
||||||
|
pretty_name="Fedora 43",
|
||||||
|
)
|
||||||
|
manager = DnfManager(runner=self.mock_runner, distro_info=fedora_info)
|
||||||
|
self.mock_runner.run.return_value = CommandResult(0, "Usage: dnf system-upgrade", "", True)
|
||||||
|
|
||||||
|
res = manager.release_upgrade(target_release=None)
|
||||||
|
self.assertFalse(res.success)
|
||||||
|
self.assertIn("Fedora major release upgrade requires specifying the target release version", res.stderr)
|
||||||
|
self.assertIn("-t 44", res.stderr)
|
||||||
|
|
||||||
|
|
||||||
def test_dnf_almalinux_auto_install_elevate_and_leapp(self):
|
def test_dnf_almalinux_auto_install_elevate_and_leapp(self):
|
||||||
from linux_updater.models import DistroInfo
|
from linux_updater.models import DistroInfo
|
||||||
alma_info = DistroInfo(
|
alma_info = DistroInfo(
|
||||||
|
|||||||
Reference in new issue
Block a user