refactor: the SNMP agent config step keeps under the complexity ratchet (#36)
driver / standard (pull_request) Successful in 18s
driver / lint (pull_request) Successful in 16s
driver / types (pull_request) Successful in 1m10s
driver / test (3.12) (pull_request) Successful in 1m22s
driver / test (3.13) (pull_request) Successful in 1m18s
driver / lowest (pull_request) Successful in 34s
driver / build (pull_request) Successful in 25s
driver / security (pull_request) Successful in 55s
CI / driver (pull_request) Successful in 55s
driver / publish (pull_request) Skipped

_write_snmp_agent_config came out at complexity 11 and failed the
standard job. The community check and the listen address now live in
their own helpers; the baseline follows the file's new length.
This commit is contained in:
Christian Manivong committed 2026-11-01 07:25:49 +01:00
1 parent 8bf76aa346
commit 0bb59b60a0
2 files changed
+12 -6

No files matched your search

+11 -5
View File
@@ -2454,15 +2454,21 @@ class OPNsenseDriver(
time.sleep(5) # the install settles before its API answers
return {"ok": result.get("status") == "ok", "output": f"os-net-snmp install: {result}"}
def _write_snmp_agent_config(self, settings: SnmpAgentSettingsDict) -> FixStepOutcomeDict:
community = settings["community"]
@staticmethod
def _check_snmp_community(community: str) -> None:
if not community or any(c.isspace() or c in '"#' for c in community):
raise ValueError("the community must be one word without quotes or #")
listen = settings.get("listen") or self.hostname
def _snmp_listen_address(self, settings: SnmpAgentSettingsDict) -> str:
try:
listen_val = str(ipaddress.ip_address(listen))
return str(ipaddress.ip_address(settings.get("listen") or self.hostname))
except ValueError:
listen_val = "" # a DNS name binds nothing; snmpd then listens everywhere
return "" # a DNS name binds nothing; snmpd then listens everywhere
def _write_snmp_agent_config(self, settings: SnmpAgentSettingsDict) -> FixStepOutcomeDict:
community = settings["community"]
self._check_snmp_community(community)
listen_val = self._snmp_listen_address(settings)
general = {"enabled": "1", "community": community, "listen": listen_val}
# Only what the caller gives: an empty one would blank the operator's.
for key, field in self._SNMP_SYSTEM_FIELDS.items():
+1 -1
View File
@@ -57,7 +57,7 @@
"napalm_opnsense.resolver_mixin"
],
"python_file_lines": {
"napalm_opnsense/opnsense.py": 3082
"napalm_opnsense/opnsense.py": 3083
},
"untyped_public": [
"napalm_opnsense/opnsense.py::OPNsenseDriver.get_snmp_config"