fix: the SNMP agent setup sends only what os-net-snmp 26.x knows (#36)
driver / lint (pull_request) Successful in 15s
driver / standard (pull_request) Failing after 16s
driver / types (pull_request) Successful in 1m9s
driver / test (3.13) (pull_request) Successful in 1m1s
driver / test (3.12) (pull_request) Successful in 1m9s
driver / lowest (pull_request) Successful in 31s
driver / build (pull_request) Successful in 28s
driver / security (pull_request) Successful in 58s
CI / driver (pull_request) Failing after 2m15s
driver / publish (pull_request) Skipped

The configure step posted contact, location, sysobjid and bindip, and
listen in the shape get returns. OPNsense 26.x refuses a field its model
does not have with HTTP 500, so the setup failed on every current box.
It now sends syscontact/syslocation, listen as a string, and contact and
location only when the caller gives them: an empty one would have blanked
the operator's.
This commit is contained in:
Christian Manivong committed 2026-10-31 07:17:04 +01:00
1 parent c02a745bb3
commit 8bf76aa346
3 files changed
+53 -21

No files matched your search

+35 -4
View File
@@ -12,9 +12,25 @@ from __future__ import annotations
from unittest.mock import MagicMock
import pytest
import requests
from napalm_opnsense.opnsense import OPNsenseDriver
#: The plugin's settings as OPNsense 26.7 serves them (gw-01, 2026-10-31). Its
#: model knows exactly these fields, and a set naming any other one, or giving a
#: field anything but a string, is a 500 (#36).
MODEL = {
"enabled": "0",
"community": "public",
"syslocation": "Home",
"syscontact": "admin@example.org",
"l3visibility": "1",
"versionoid": "1",
"enableagentx": "1",
"enableobservium": "1",
"listen": {"10.0.0.1": {"value": "10.0.0.1", "selected": 1}},
}
SETTINGS = {
"community": "c0mm",
"allowed_sources": ["10.7.224.20", "10.7.225.0/24"],
@@ -34,12 +50,15 @@ class _Api:
def get(self, path):
if path == "/api/netsnmp/general/get":
return {"general": {"enabled": "0"}} if self.installed else {}
return {"general": dict(MODEL)} if self.installed else {}
raise AssertionError(path)
def post(self, path, body=None):
self.posts.append((path, body))
if path == "/api/netsnmp/general/set":
general = (body or {}).get("general", {})
if any(k not in MODEL or not isinstance(v, str) for k, v in general.items()):
raise requests.HTTPError(f"500 Server Error: Internal Server Error for url: {path}")
return {"result": self.saved}
if path == "/api/firewall/filter/searchRule":
return {"rows": self.rules}
@@ -83,12 +102,24 @@ class TestTheCallersValues:
assert result["success"] is True
general = _body(api, "/api/netsnmp/general/set")["general"]
assert general["enabled"] == "1"
assert (general["community"], general["contact"], general["location"]) == (
assert (general["community"], general["syscontact"], general["syslocation"]) == (
"c0mm",
"ops",
"rack 1",
)
assert general["listen"] == {"10.0.0.1": {"selected": 1}}
assert general["listen"] == "10.0.0.1"
def test_only_fields_the_plugins_model_has_are_sent(self, driver, api):
result = driver.configure_snmp_agent({**SETTINGS, "listen": "10.0.0.1"})
assert result["success"] is True
assert set(_body(api, "/api/netsnmp/general/set")["general"]) <= set(MODEL)
def test_contact_and_location_the_caller_leaves_out_stay_as_they_are(self, driver, api):
driver.configure_snmp_agent({"community": "c0mm", "allowed_sources": []})
general = _body(api, "/api/netsnmp/general/set")["general"]
assert "syscontact" not in general and "syslocation" not in general
def test_nothing_of_an_application_is_built_in(self, driver, api):
driver.configure_snmp_agent({"community": "c0mm", "allowed_sources": []})
@@ -103,7 +134,7 @@ class TestTheCallersValues:
d.configure_snmp_agent({"community": "c0mm", "allowed_sources": []})
assert _body(api, "/api/netsnmp/general/set")["general"]["listen"] == {}
assert _body(api, "/api/netsnmp/general/set")["general"]["listen"] == ""
def test_a_rejected_configuration_fails_the_fix(self, driver, api):
api.saved = "failed"