From 0493520e5fff1eeacadd68e8bb77416244873ada Mon Sep 17 00:00:00 2001 From: Christian Manivong Date: Tue, 2 Jun 2026 13:28:07 +0200 Subject: [PATCH] fix: extract clean package names in updates_available warning meta opkg list-upgradable and apk version output contains version strings and comparison operators; meta.packages now stores only the bare package name so the schedule-updates API validation passes. Co-Authored-By: Claude Sonnet 4.6 --- napalm_openwrt/openwrt.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/napalm_openwrt/openwrt.py b/napalm_openwrt/openwrt.py index 84bf77d..04c1932 100644 --- a/napalm_openwrt/openwrt.py +++ b/napalm_openwrt/openwrt.py @@ -1711,6 +1711,21 @@ class OpenWrtDriver(AccessPointDriver): pm = self._pm_type() # 2. Package updates available (local cache only – no opkg update) + def _pkg_name(line: str, pm_type: str) -> str: + """Extract just the package name from an upgradable line. + + apk: 'luci-app-firewall-26.143~abc < 26.151~def' → 'luci-app-firewall' + opkg: 'luci-app-firewall - 1.0 - 1.1' → 'luci-app-firewall' + """ + import re as _re + if pm_type == "apk": + # Strip trailing ' < ...' then remove the version suffix (-\d...) + name_ver = line.split(" ")[0] + m = _re.match(r'^(.*?)-\d', name_ver) + return m.group(1) if m else name_ver + else: + return line.split(" - ")[0].strip() + try: if pm == "apk": raw_upg = self._send_command("apk version 2>/dev/null | grep '<'") @@ -1721,13 +1736,14 @@ class OpenWrtDriver(AccessPointDriver): upgradable = [] if upgradable: + pkg_names = [_pkg_name(ln, pm) for ln in upgradable] warnings.append({ "code": "updates_available", "severity": "info", "action": None, "meta": { "count": len(upgradable), - "packages": upgradable[:10], + "packages": pkg_names[:10], }, })