fix(snmp): open the REST side session's SSH on port 22

configure_snmp_agent over the REST API opened its temporary SSH session
on optional_args["port"], which names the REST API's port when REST is
the transport. It now uses port 22, as the running-config fallback
already did.

The second finding of the issue, the unverified REST certificate, needs
a decision and stays open.

Refs #17
This commit is contained in:
Christian Manivong committed 2026-11-01 21:44:52 +01:00
1 parent 58428042f1
commit 874e25a1ce
3 files changed
+24 -6

No files matched your search

+5
View File
@@ -14,6 +14,11 @@ All notable changes to this driver. The format follows
- The floor on urllib3 is 1.26.5: older releases bundle a `six` that Python 3.12
cannot import.
### Fixed
- `configure_snmp_agent` over the REST API opens its temporary SSH session on port 22.
It used `optional_args["port"]`, which names the REST API's port when REST is the
transport, so the SNMP setup failed on switches managed over REST.
## [0.6.0] - 2026-10-23
The first release on PyPI.
+5 -5
View File
@@ -79,6 +79,7 @@ _SSH_DISABLED_LEGACY = {
}
_SSH_PORT_BESIDE_API = 22 # SSH beside the REST API: ``port`` then is the API's (#17)
#: What may stand in a quoted CLI value: no whitespace, quote or #.
_CLI_WORD = re.compile(r'^[^\s"#]+$')
@@ -663,11 +664,10 @@ class ProcurveDriver(ConfigLifecycleMixin, SwitchDriver):
HP ProCurve switches do not support exec_channel SSH; they require
an interactive shell (invoke_shell), which netmiko's hp_procurve
device type handles correctly. Port 22 is used explicitly because
self.port is the REST API port (443) in API transport mode.
device type handles correctly. Port 22: ``port`` is the REST API's.
"""
try:
conn = self._ssh_connect(port=22) # always SSH — self.port is the REST API port
conn = self._ssh_connect(port=_SSH_PORT_BESIDE_API)
try:
return conn.send_command("show running-config")
finally:
@@ -1254,7 +1254,7 @@ class ProcurveDriver(ConfigLifecycleMixin, SwitchDriver):
"""The agent is built in; configure community, contact and location, then save.
The REST API has no writable SNMP endpoint, so over REST a temporary SSH
session runs the config-mode CLI.
session on port 22 runs the config-mode CLI.
"""
steps = [
("install", lambda: {"ok": True, "output": "the SNMP agent is built in"}),
@@ -1269,7 +1269,7 @@ class ProcurveDriver(ConfigLifecycleMixin, SwitchDriver):
ssh_error = ""
for legacy in (False, True):
try:
self._device = self._ssh_connect(legacy)
self._device = self._ssh_connect(legacy, port=_SSH_PORT_BESIDE_API)
self._transport = "ssh_legacy" if legacy else "ssh"
break
except SshHostKeyMismatch as exc: # the same host either way
+14 -1
View File
@@ -104,7 +104,7 @@ def test_the_config_fallback_checks_the_key_of_port_22():
def test_the_snmp_fix_over_rest_stops_at_a_changed_key():
seen: list = []
driver = _driver(seen, {"443": SshHostKey.of(OTHER_KEY).as_dict()}, port=443)
driver = _driver(seen, {"22": SshHostKey.of(OTHER_KEY).as_dict()}, port=443)
driver._transport = "api"
driver._api = MagicMock()
with patch(HANDLER, side_effect=_refuse) as handler:
@@ -112,3 +112,16 @@ def test_the_snmp_fix_over_rest_stops_at_a_changed_key():
assert result["success"] is False
assert handler.call_count == 1
assert "host key" in str(result)
def test_the_snmp_fix_over_rest_opens_ssh_on_port_22_not_the_api_port():
"""``port`` is the REST API's port when REST is the transport (#17)."""
seen: list = []
driver = _driver(seen, {"22": SshHostKey.of(SERVER_KEY).as_dict()}, port=443)
driver._transport = "api"
driver._api = MagicMock()
with patch(HANDLER, return_value=_device()) as handler:
driver.configure_snmp_agent({"community": "c0mm", "allowed_sources": []})
assert handler.call_args.kwargs["port"] == 22
assert handler.call_args.kwargs["ssh_strict"] is True
assert (seen[0]["port"], seen[0]["accepted"]) == (22, True)