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

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.
This commit is contained in:
Christian Manivong committed 2026-11-01 22:17:59 +01:00
1 parent 03cf40de99
commit 1d5399e51b
5 files changed
+56 -5

No files matched your search

+7
View File
@@ -7,6 +7,7 @@ command output strings. The same parsers are shared by the SSH and Telnet
backends.
"""
import base64
import re
#: get_users' password field: the switch never shows a password, so it stays empty.
@@ -927,3 +928,9 @@ def derive_port_pvids(vlans: dict[int, dict]) -> dict[str, int]:
pvids[port] = 1
return pvids
def parse_cli_answer(answer: dict[str, str]) -> str:
"""The output in a REST ``/cli`` answer: base64, the switch ends it with a NUL byte."""
encoded = answer.get("result_base64_encoded", "")
return base64.b64decode(encoded).decode("utf-8", "replace").rstrip("\x00")
+2 -4
View File
@@ -15,7 +15,6 @@ A specific transport can be forced with ``optional_args={"transport": "ssh"}``.
Netmiko device type: ``hp_procurve`` / ``hp_procurve_telnet``
"""
import base64
import logging
import re
from typing import Any, ClassVar
@@ -1146,7 +1145,7 @@ class ProcurveDriver(ConfigLifecycleMixin, SwitchDriver):
for cmd in commands:
resp = self._api.post("cli", json={"cmd": cmd})
if resp.ok:
results[cmd] = resp.json().get("result_base64_encoded", "")
results[cmd] = parsers.parse_cli_answer(resp.json())
else:
results[cmd] = f"Error: HTTP {resp.status_code}"
return results
@@ -1238,8 +1237,7 @@ class ProcurveDriver(ConfigLifecycleMixin, SwitchDriver):
resp = self._api.post("cli", json={"cmd": command})
if not resp.ok or resp.json().get("status") == "CCS_FAILURE":
raise CommandErrorException(f"{command!r} over REST: HTTP {resp.status_code}")
encoded = resp.json().get("result_base64_encoded", "")
return base64.b64decode(encoded).decode("utf-8", "replace")
return parsers.parse_cli_answer(resp.json())
# ------------------------------------------------------------------
# SNMP agent (napalm-device-types SnmpAgentMixin): the caller's values