driver / standard (pull_request) Successful in 17s
driver / lint (pull_request) Successful in 13s
driver / types (pull_request) Successful in 1m14s
driver / test (3.12) (pull_request) Successful in 1m9s
driver / test (3.13) (pull_request) Successful in 1m10s
driver / lowest (pull_request) Successful in 30s
driver / build (pull_request) Successful in 33s
driver / security (pull_request) Successful in 1m10s
CI / driver (pull_request) Successful in 2m49s
driver / publish (pull_request) Skipped
ProcurveApiClient.get() answered {} for a timeout, a refused session or
any HTTP error, so every REST getter reported a failed read as a switch
with no hostname, ports, VLANs or neighbours. get() now raises
ConnectionException (no answer, 401/403) or RuntimeError (other
non-2xx, a body that is not JSON); the getters that expect a resource
to be missing on some firmware pass missing_ok for its 404.
get_config no longer returns an empty configuration when both the REST
read and the SSH fallback failed, and cli() over REST raises instead of
returning "Error: HTTP <status>" as the command's output.
Closes #22
42 lines
1.4 KiB
Python
42 lines
1.4 KiB
Python
"""cli() over REST returns the command's output, not the API's base64 of it.
|
|
|
|
The REST ``/cli`` endpoint answers ``{"result_base64_encoded": ...}``: the output in
|
|
base64, ending in a NUL byte. cli() returned that string as it came.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
from unittest.mock import MagicMock
|
|
|
|
from napalm_procurve.api_client import ProcurveApiClient
|
|
from napalm_procurve.procurve import ProcurveDriver
|
|
|
|
FIXTURES = Path(__file__).parent.parent / "fixtures"
|
|
|
|
SHOW_SNMP_SERVER = (FIXTURES / "procurve-show-snmp-server.txt").read_text(encoding="utf-8")
|
|
SHOW_SNMP_SERVER_REST = (FIXTURES / "procurve-rest-cli-show-snmp-server.b64").read_text().strip()
|
|
|
|
|
|
def _rest_driver(resp: MagicMock) -> ProcurveDriver:
|
|
driver = ProcurveDriver("10.0.0.40", "manager", "s3cret")
|
|
driver._transport = "api"
|
|
driver._api = ProcurveApiClient("10.0.0.40", "manager", "s3cret")
|
|
driver._api.setup("v7", "https")
|
|
driver._api._session = MagicMock()
|
|
driver._api._session.request.return_value = resp
|
|
return driver
|
|
|
|
|
|
def test_over_rest_cli_returns_the_decoded_output():
|
|
resp = MagicMock(ok=True, status_code=200)
|
|
resp.json.return_value = {
|
|
"cmd": "show snmp-server",
|
|
"result_base64_encoded": SHOW_SNMP_SERVER_REST,
|
|
"status": "CCS_SUCCESS",
|
|
}
|
|
|
|
out = _rest_driver(resp).cli(["show snmp-server"])
|
|
|
|
assert out == {"show snmp-server": SHOW_SNMP_SERVER}
|