fix(ssh): raise when a node command cannot run, drop the execute call
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 1m9s
driver / test (3.13) (pull_request) Successful in 1m4s
driver / lowest (pull_request) Successful in 35s
driver / build (pull_request) Successful in 40s
driver / security (pull_request) Successful in 1m15s
CI / driver (pull_request) Successful in 2m53s
driver / publish (pull_request) Skipped
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 1m9s
driver / test (3.13) (pull_request) Successful in 1m4s
driver / lowest (pull_request) Successful in 35s
driver / build (pull_request) Successful in 40s
driver / security (pull_request) Successful in 1m15s
CI / driver (pull_request) Successful in 2m53s
driver / publish (pull_request) Skipped
_exec_ssh_command returned "" on any failure (no SSH credential, a
refused login or host key, an unreachable node, a timeout), so a
getter that could not look read like one that found nothing; on
API-token-only nodes get_snmp_config answered None and the SSH-backed
getters empty lists on every poll. It now raises ConnectionException
with the cause (SshHostKeyMismatch as it is), and refuses before
connecting when there is neither a password nor a usable key.
It returned stderr when stdout was empty; output is stdout now. It
first posted every command to /nodes/{node}/execute, which runs a
batch of API calls rather than a shell; that dead round trip is gone.
The key types, the key before the password, the host-key check and the
single connect path were done in f491f9f and 6bb3035. The shared
transport is NAPALM/napalm-device-types#35.
Closes #17
This commit is contained in:
1 parent
bfba804ec2
commit
daf1b519eb
13 files changed
+261
-108
No files matched your search
@@ -1,7 +1,7 @@
|
||||
"""The node's SSH session verifies its host key, and reports the one it sees (NetOrk/netork#1167).
|
||||
|
||||
Both ways onto the node's shell — the best-effort ``_exec_ssh_command`` and the
|
||||
provisioning steps' ``_run_node_command`` — share one session, opened on port 22.
|
||||
Both ways onto the node's shell — ``_exec_ssh_command`` and the provisioning
|
||||
steps' ``_run_node_command`` — share one session, opened on port 22.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -87,7 +87,6 @@ def _driver(seen: list, known: dict | None = None) -> ProxmoxDriver:
|
||||
if known is not None:
|
||||
args[KNOWN_KEYS_ARG] = known
|
||||
driver = ProxmoxDriver("10.0.0.9", "root", "s3cret", optional_args=args)
|
||||
driver._node_api = MagicMock(side_effect=RuntimeError("no exec endpoint")) # type: ignore[method-assign]
|
||||
return driver
|
||||
|
||||
|
||||
@@ -116,10 +115,12 @@ def test_a_changed_key_stops_a_provisioning_step(client):
|
||||
assert seen[0]["accepted"] is False
|
||||
|
||||
|
||||
def test_a_changed_key_leaves_the_best_effort_read_empty(client):
|
||||
def test_a_changed_key_stops_a_read_too(client):
|
||||
"""It used to read as empty output, "nothing there" (#17)."""
|
||||
seen: list = []
|
||||
driver = _driver(seen, {"22": SshHostKey.of(OTHER_KEY).as_dict()})
|
||||
assert driver._exec_ssh_command("cat /etc/os-release") == ""
|
||||
with pytest.raises(SshHostKeyMismatch):
|
||||
driver._exec_ssh_command("cat /etc/os-release")
|
||||
assert client.commands == []
|
||||
assert seen[0]["accepted"] is False
|
||||
|
||||
|
||||
Reference in new issue
Block a user