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], }, })