feat(updates): raise PackageIndexMissing when the index is not in RAM
driver / lint (pull_request) Successful in 13s
driver / standard (pull_request) Successful in 16s
driver / types (pull_request) Successful in 46s
driver / test (3.13) (pull_request) Successful in 44s
driver / test (3.12) (pull_request) Successful in 51s
driver / lowest (pull_request) Successful in 25s
driver / build (pull_request) Successful in 25s
driver / security (pull_request) Successful in 55s
CI / driver (pull_request) Successful in 1m55s
driver / publish (pull_request) Skipped
driver / lint (pull_request) Successful in 13s
driver / standard (pull_request) Successful in 16s
driver / types (pull_request) Successful in 46s
driver / test (3.13) (pull_request) Successful in 44s
driver / test (3.12) (pull_request) Successful in 51s
driver / lowest (pull_request) Successful in 25s
driver / build (pull_request) Successful in 25s
driver / security (pull_request) Successful in 55s
CI / driver (pull_request) Successful in 1m55s
driver / publish (pull_request) Skipped
After a reboot apk and opkg have no package index. get_available_updates() raised a bare RuntimeError for that, which netOrk could not tell from a read that failed. It now raises napalm-device-types' PackageIndexMissing, so netOrk loads the index instead of reporting a communication error. Needs napalm-device-types 4.39.0. Refs NetOrk/netork#2527
This commit is contained in:
1 parent
de11d16749
commit
ec88cfd734
4 files changed
+18
-9
No files matched your search
+5
-1
@@ -8,7 +8,11 @@ recorded here; their history is the git log.
|
|||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
- Needs napalm-device-types 4.36.0 or later (`TimeSyncDict.dhcp_ntp_servers`).
|
- Needs napalm-device-types 4.39.0 or later (`PackageIndexMissing`).
|
||||||
|
- `get_available_updates()` raises napalm-device-types' `PackageIndexMissing` when the
|
||||||
|
package index is not in RAM (after a reboot), for apk and opkg alike, instead of a bare
|
||||||
|
`RuntimeError`: a caller can load the index instead of reporting a failed read
|
||||||
|
(NetOrk/netork#2527).
|
||||||
- A time sync write no longer sets `use_dhcp=0`, as the first time sync commit (#36) did;
|
- A time sync write no longer sets `use_dhcp=0`, as the first time sync commit (#36) did;
|
||||||
a router that commit wrote keeps `use_dhcp=0` until it is set back.
|
a router that commit wrote keeps `use_dhcp=0` until it is set back.
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ import logging
|
|||||||
import re
|
import re
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
|
from napalm_device_types import PackageIndexMissing
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
#: Printed after a command so its exit status survives the shell session.
|
#: Printed after a command so its exit status survives the shell session.
|
||||||
@@ -447,8 +449,9 @@ class OpenWrtSystemMixin:
|
|||||||
|
|
||||||
OpenWrt keeps its package index in RAM. Without it -- after a reboot,
|
OpenWrt keeps its package index in RAM. Without it -- after a reboot,
|
||||||
before ``refresh_available_updates`` -- ``apk version`` only warns and
|
before ``refresh_available_updates`` -- ``apk version`` only warns and
|
||||||
``opkg list-upgradable`` prints nothing. Both raise here instead of
|
``opkg list-upgradable`` prints nothing. Both raise
|
||||||
reporting "nothing pending".
|
:exc:`~napalm_device_types.PackageIndexMissing` here instead of reporting
|
||||||
|
"nothing pending".
|
||||||
"""
|
"""
|
||||||
if self._pm_type() == "apk":
|
if self._pm_type() == "apk":
|
||||||
updates = self._updates_apk()
|
updates = self._updates_apk()
|
||||||
@@ -463,7 +466,7 @@ class OpenWrtSystemMixin:
|
|||||||
if status != 0:
|
if status != 0:
|
||||||
raise RuntimeError(f"apk version failed (exit {status}): {output[-200:]}")
|
raise RuntimeError(f"apk version failed (exit {status}): {output[-200:]}")
|
||||||
if _APK_INDEX_MISSING.search(output):
|
if _APK_INDEX_MISSING.search(output):
|
||||||
raise RuntimeError("The package index is not loaded (run apk update first)")
|
raise PackageIndexMissing("The package index is not loaded (run apk update first)")
|
||||||
updates: list[dict[str, Any]] = []
|
updates: list[dict[str, Any]] = []
|
||||||
for line in output.splitlines():
|
for line in output.splitlines():
|
||||||
# Output format: "pkgname-current_ver < new_ver"
|
# Output format: "pkgname-current_ver < new_ver"
|
||||||
@@ -484,7 +487,7 @@ class OpenWrtSystemMixin:
|
|||||||
"opkg list-upgradable 2>/dev/null"
|
"opkg list-upgradable 2>/dev/null"
|
||||||
)
|
)
|
||||||
if "__NO_INDEX__" in raw:
|
if "__NO_INDEX__" in raw:
|
||||||
raise RuntimeError("The package index is not loaded (run opkg update first)")
|
raise PackageIndexMissing("The package index is not loaded (run opkg update first)")
|
||||||
updates: list[dict[str, Any]] = []
|
updates: list[dict[str, Any]] = []
|
||||||
for line in raw.splitlines():
|
for line in raw.splitlines():
|
||||||
# opkg output: "pkgname - current_ver - new_ver"
|
# opkg output: "pkgname - current_ver - new_ver"
|
||||||
|
|||||||
+1
-1
@@ -21,7 +21,7 @@ classifiers = [
|
|||||||
]
|
]
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"napalm>=5.1", # older releases import pkg_resources, which a 3.12 venv lacks
|
"napalm>=5.1", # older releases import pkg_resources, which a 3.12 venv lacks
|
||||||
"napalm_device_types>=4.36.0", # TimeSyncMixin with dhcp_ntp_servers, posix_tz
|
"napalm_device_types>=4.39.0", # PackageIndexMissing
|
||||||
"netmiko>=4.0.0",
|
"netmiko>=4.0.0",
|
||||||
"paramiko>=5.0.0", # CVE-2026-44405
|
"paramiko>=5.0.0", # CVE-2026-44405
|
||||||
"netaddr>=0.7.19", # IPAddress; below it the package has none (CI lowest job)
|
"netaddr>=0.7.19", # IPAddress; below it the package has none (CI lowest job)
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ from __future__ import annotations
|
|||||||
from unittest.mock import MagicMock, patch
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
from napalm_device_types import PackageIndexMissing
|
||||||
|
|
||||||
from napalm_openwrt.openwrt import OpenWrtDriver
|
from napalm_openwrt.openwrt import OpenWrtDriver
|
||||||
|
|
||||||
@@ -60,7 +61,7 @@ class TestAvailableUpdates:
|
|||||||
def test_apk_without_its_index_raises_instead_of_reporting_nothing(self, driver):
|
def test_apk_without_its_index_raises_instead_of_reporting_nothing(self, driver):
|
||||||
_answer(driver, "apk", APK_INDEX_MISSING)
|
_answer(driver, "apk", APK_INDEX_MISSING)
|
||||||
|
|
||||||
with pytest.raises(RuntimeError, match="index"):
|
with pytest.raises(PackageIndexMissing, match="apk update"):
|
||||||
driver.get_available_updates()
|
driver.get_available_updates()
|
||||||
|
|
||||||
def test_apk_with_its_index_lists_what_is_pending(self, driver):
|
def test_apk_with_its_index_lists_what_is_pending(self, driver):
|
||||||
@@ -75,13 +76,14 @@ class TestAvailableUpdates:
|
|||||||
def test_apk_that_failed_raises(self, driver):
|
def test_apk_that_failed_raises(self, driver):
|
||||||
_answer(driver, "apk", "ERROR: unable to lock database\n__OWRT_RC=99\n")
|
_answer(driver, "apk", "ERROR: unable to lock database\n__OWRT_RC=99\n")
|
||||||
|
|
||||||
with pytest.raises(RuntimeError):
|
with pytest.raises(RuntimeError) as raised:
|
||||||
driver.get_available_updates()
|
driver.get_available_updates()
|
||||||
|
assert not isinstance(raised.value, PackageIndexMissing)
|
||||||
|
|
||||||
def test_opkg_without_its_lists_raises(self, driver):
|
def test_opkg_without_its_lists_raises(self, driver):
|
||||||
_answer(driver, "opkg", "__NO_INDEX__\n")
|
_answer(driver, "opkg", "__NO_INDEX__\n")
|
||||||
|
|
||||||
with pytest.raises(RuntimeError, match="index"):
|
with pytest.raises(PackageIndexMissing, match="opkg update"):
|
||||||
driver.get_available_updates()
|
driver.get_available_updates()
|
||||||
|
|
||||||
def test_opkg_with_its_lists(self, driver):
|
def test_opkg_with_its_lists(self, driver):
|
||||||
|
|||||||
Reference in new issue
Block a user