feat!: report the package proxy as a fact; no warnings of its own (0.9.0)
CI / test (3.10) (push) Successful in 34s
CI / test (3.11) (push) Successful in 32s
CI / test (3.12) (push) Successful in 29s
CI / test (3.10) (pull_request) Successful in 25s
CI / test (3.11) (pull_request) Successful in 23s
CI / test (3.12) (pull_request) Successful in 25s
CI / test (3.10) (push) Successful in 34s
CI / test (3.11) (push) Successful in 32s
CI / test (3.12) (push) Successful in 29s
CI / test (3.10) (pull_request) Successful in 25s
CI / test (3.11) (pull_request) Successful in 23s
CI / test (3.12) (pull_request) Successful in 25s
get_device_warnings decided two things for the application: that any pending update is a warning (it re-read the updates for that), and whether apt's proxy is the one the application's setting wants, which it was handed as optional_args["apt_proxy_url"]. The driver reports facts instead (napalm-device-types 4.14): get_package_proxy() says which proxy apt fetches through, None for none or on a non-apt host; the updates are get_available_updates() as before. get_device_warnings and the apt_proxy_url argument go. BREAKING CHANGE: get_device_warnings and optional_args["apt_proxy_url"] are removed. Requires napalm-device-types 4.14. Closes #28
This commit is contained in:
1 parent
40f6ecd583
commit
decd64b876
5 files changed
+39
-37
No files matched your search
+7
-34
@@ -346,8 +346,6 @@ class LinuxDriver(
|
||||
# Optional sudo password for privilege escalation (e.g. apt-get update)
|
||||
self._sudo_password: str | None = optional_args.get("sudo_password")
|
||||
# Expected apt proxy URL — checked as a device warning on apt systems.
|
||||
# Only set when apt_proxy_enabled=true in NetOrk settings; empty string disables the check.
|
||||
self._apt_proxy_url: str = optional_args.get("apt_proxy_url", "")
|
||||
|
||||
if optional_args.get("debugging"):
|
||||
logger.setLevel(logging.DEBUG)
|
||||
@@ -1510,38 +1508,13 @@ class LinuxDriver(
|
||||
f"Package manager '{self._pkg_manager}' is not supported"
|
||||
)
|
||||
|
||||
def get_device_warnings(self) -> List[dict[str, Any]]:
|
||||
"""Return warning dicts for issues detected on this device.
|
||||
|
||||
Currently detects:
|
||||
- package updates available (uses local package cache)
|
||||
- apt proxy not configured (apt systems only)
|
||||
"""
|
||||
warnings: List[dict[str, Any]] = []
|
||||
try:
|
||||
updates = self.get_available_updates()
|
||||
except Exception as exc:
|
||||
logger.warning("get_device_warnings: get_available_updates() failed: %s", exc)
|
||||
updates = []
|
||||
if updates:
|
||||
warnings.append({
|
||||
"code": "updates_available",
|
||||
"meta": {
|
||||
"count": len(updates),
|
||||
"packages": [u.get("name", "") for u in updates],
|
||||
},
|
||||
})
|
||||
if self._pkg_manager == "apt" and self._apt_proxy_url:
|
||||
try:
|
||||
current = self._send("cat /etc/apt/apt.conf.d/00proxy 2>/dev/null || true").strip()
|
||||
if self._apt_proxy_url not in current:
|
||||
warnings.append({
|
||||
"code": "apt_proxy_missing",
|
||||
"meta": {"expected_url": self._apt_proxy_url},
|
||||
})
|
||||
except Exception as exc:
|
||||
logger.warning("get_device_warnings: apt proxy check failed: %s", exc)
|
||||
return warnings
|
||||
def get_package_proxy(self) -> str | None:
|
||||
"""The proxy apt fetches through (``00proxy``); None for none or a non-apt host."""
|
||||
if self._pkg_manager != "apt":
|
||||
return None
|
||||
conf = self._send(f"cat {_APT_PROXY_CONF} 2>/dev/null || true")
|
||||
found = re.search(r'Acquire::http::Proxy\s+"([^"]+)"', conf)
|
||||
return found.group(1) if found else None
|
||||
|
||||
def _get_updates_apt(self) -> list[UpdateDict]:
|
||||
# apt list --upgradable does not need root; avoid sudo so it works even
|
||||
|
||||
Reference in new issue
Block a user