fix: REST side session port, connect reasons, SNMP config over REST (#17, #13, #10) #21

Merged
christianmanivong merged 5 commits from fix/bugs-2026-11 into main 2026-11-01 22:00:20 +00:00
Owner

Three bug fixes, one commit each.

  • fix(snmp): the SNMP setup over REST opened its SSH side session on optional_args["port"] (the REST port); it now uses port 22, like the running-config fallback (#17, first half).
  • fix(connect): "maximum number of telnet sessions" is a connection error ("telnet: the switch has no free session …"), an HTML answer to the REST login is a connection error naming the web page, and a non-timeout SSH failure names the underlying paramiko/socket error (#13). The Telnet greeting is kept in an in-memory session log (≤ 4 KB, only what the switch sent, never the password) — this needs netmiko ≥ 4.3.0, so the floor is raised from 4.0.0.
  • fix(snmp): over REST, get_snmp_config runs show snmp-server through the /cli endpoint and uses the SSH path's parser; a failed read raises (#10). The show snmp-server fixture is recorded from a ProCurve (trap receiver address replaced).
  • fix(cli): over REST, cli() returned the raw base64 answer (with a trailing NUL); a new pure parse_cli_answer decodes it for cli() and get_snmp_config (found while recording the fixture).

Still open in #17: the REST certificate is never verified in practice (_try_api silently retries without verification). Strictly honouring ssl_verify would make every self-signed ProCurve fall back to SSH and then Telnet; that needs a decision, so #17 stays open.

Tested: fixtures only. pytest 106 passed, ruff, mypy, napalm-standard check/ratchet green (baseline only shrank).

Closes #13
Closes #10

Three bug fixes, one commit each. - `fix(snmp)`: the SNMP setup over REST opened its SSH side session on `optional_args["port"]` (the REST port); it now uses port 22, like the running-config fallback (#17, first half). - `fix(connect)`: "maximum number of telnet sessions" is a connection error ("telnet: the switch has no free session …"), an HTML answer to the REST login is a connection error naming the web page, and a non-timeout SSH failure names the underlying paramiko/socket error (#13). The Telnet greeting is kept in an in-memory session log (≤ 4 KB, only what the switch sent, never the password) — this needs netmiko ≥ 4.3.0, so the floor is raised from 4.0.0. - `fix(snmp)`: over REST, `get_snmp_config` runs `show snmp-server` through the `/cli` endpoint and uses the SSH path's parser; a failed read raises (#10). The `show snmp-server` fixture is recorded from a ProCurve (trap receiver address replaced). - `fix(cli)`: over REST, `cli()` returned the raw base64 answer (with a trailing NUL); a new pure `parse_cli_answer` decodes it for `cli()` and `get_snmp_config` (found while recording the fixture). **Still open in #17:** the REST certificate is never verified in practice (`_try_api` silently retries without verification). Strictly honouring `ssl_verify` would make every self-signed ProCurve fall back to SSH and then Telnet; that needs a decision, so #17 stays open. Tested: fixtures only. pytest 106 passed, ruff, mypy, `napalm-standard check`/`ratchet` green (baseline only shrank). Closes #13 Closes #10
christianmanivong added 3 commits 2026-11-01 20:57:13 +00:00
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
A switch whose Telnet sessions were all taken, and a REST API answering
the login with the web UI's HTML page, were both reported as an
authentication failure, which sent the operator after the password. The
Telnet login now keeps the switch's greeting in an in-memory session log
and reports a full switch as a connection error; an HTML answer to the
REST login says so. An SSH attempt records netmiko's underlying error
instead of "timed out" when it was not a timeout.

Session log objects need netmiko 4.3.0, which becomes the floor.

Closes #13
fix(snmp): read the communities over the REST API too
driver / standard (pull_request) Successful in 15s
driver / lint (pull_request) Successful in 12s
driver / types (pull_request) Successful in 57s
driver / test (3.12) (pull_request) Successful in 56s
driver / test (3.13) (pull_request) Successful in 47s
driver / lowest (pull_request) Successful in 25s
driver / build (pull_request) Successful in 25s
driver / security (pull_request) Successful in 1m6s
CI / driver (pull_request) Successful in 2m29s
driver / publish (pull_request) Skipped
b26584c7da
get_snmp_config sent "show snmp-server" through the CLI session, which
does not exist on the REST transport, and returned None, so every switch
managed over REST read as "SNMP not configured". Over REST the command
now runs through the API's /cli endpoint and the output goes through the
parser the SSH path uses. A failed REST read raises.

Closes #10
christianmanivong added 2 commits 2026-11-01 21:20:37 +00:00
The #10 tests read a hand-written show snmp-server. They now read the
output recorded from a ProCurve switch: as the CLI prints it, and as the
REST /cli endpoint answers it, base64 with a trailing NUL byte. The
trap receiver's address is replaced. The read-only preference and the
no-community case put a line into, or take one out of, the recording.
fix(cli): decode the REST CLI answer
driver / standard (pull_request) Successful in 14s
driver / lint (pull_request) Successful in 14s
driver / types (pull_request) Successful in 58s
driver / test (3.12) (pull_request) Successful in 1m0s
driver / test (3.13) (pull_request) Successful in 49s
driver / lowest (pull_request) Successful in 24s
driver / build (pull_request) Successful in 26s
driver / security (pull_request) Successful in 56s
CI / driver (pull_request) Successful in 2m25s
driver / publish (pull_request) Skipped
1d5399e51b
Over the REST API, cli() returned the /cli endpoint's
result_base64_encoded field as it came: base64 instead of the command's
output. It now decodes it and drops the NUL byte the switch ends it with,
in the same parser the SNMP read over REST uses.

New finding, confirmed by the show snmp-server answer recorded from a
ProCurve switch; no issue filed.
christianmanivong merged commit 9bce1b4e47 into main 2026-11-01 22:00:20 +00:00
christianmanivong deleted branch fix/bugs-2026-11 2026-11-01 22:00:20 +00:00
Sign in to join this conversation.