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
+34
-4
@@ -120,6 +120,36 @@ PVE_USERS = [
|
||||
]
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# The node's shell
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
class _Stream:
|
||||
def __init__(self, data: str) -> None:
|
||||
self._data = data.encode()
|
||||
|
||||
def read(self) -> bytes:
|
||||
return self._data
|
||||
|
||||
|
||||
class NodeShell:
|
||||
"""The node's SSH session for the driver fixtures.
|
||||
|
||||
Every command prints ``output`` on stdout, or ``outputs[command]`` when the
|
||||
command is there. A test sets either through ``driver._node_ssh()``.
|
||||
"""
|
||||
|
||||
def __init__(self, output: str = "") -> None:
|
||||
self.output = output
|
||||
self.outputs: dict[str, str] = {}
|
||||
self.commands: list[str] = []
|
||||
|
||||
def exec_command(self, command: str, timeout: int | None = None):
|
||||
self.commands.append(command)
|
||||
return None, _Stream(self.outputs.get(command, self.output)), _Stream("")
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Driver fixture
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -137,7 +167,6 @@ def _build_mock_api(
|
||||
ntp=None,
|
||||
netstat=None,
|
||||
pve_users=None,
|
||||
exec_return="",
|
||||
sensors=None,
|
||||
cluster_status=None,
|
||||
):
|
||||
@@ -159,7 +188,6 @@ def _build_mock_api(
|
||||
node_res.dns.get.return_value = dns or DNS_INFO
|
||||
node_res.ntp.get.return_value = ntp or NTP_INFO
|
||||
node_res.netstat.get.return_value = netstat or NODE_NETSTAT
|
||||
node_res.execute.post.return_value = {"data": exec_return}
|
||||
node_res.hardware.sensors.get.return_value = sensors or []
|
||||
node_res.time.get.return_value = {}
|
||||
node_res.subscription.get.return_value = {}
|
||||
@@ -204,12 +232,13 @@ def driver():
|
||||
mock_api = _build_mock_api()
|
||||
with patch("napalm_proxmox.driver.ProxmoxAPI", return_value=mock_api):
|
||||
drv.open()
|
||||
drv._node_ssh = MagicMock(return_value=NodeShell())
|
||||
return drv
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def driver_with_exec(request):
|
||||
"""Return a driver whose exec endpoint returns a parametrised string."""
|
||||
"""Return a driver whose node shell prints a parametrised string."""
|
||||
exec_output = getattr(request, "param", "")
|
||||
drv = ProxmoxDriver(
|
||||
hostname="pve1.example.com",
|
||||
@@ -217,7 +246,8 @@ def driver_with_exec(request):
|
||||
password="secret",
|
||||
optional_args={"verify_ssl": False},
|
||||
)
|
||||
mock_api = _build_mock_api(exec_return=exec_output)
|
||||
mock_api = _build_mock_api()
|
||||
with patch("napalm_proxmox.driver.ProxmoxAPI", return_value=mock_api):
|
||||
drv.open()
|
||||
drv._node_ssh = MagicMock(return_value=NodeShell(exec_output))
|
||||
return drv
|
||||
+32
-42
@@ -26,19 +26,19 @@ class TestGetNTPStats:
|
||||
)
|
||||
|
||||
def test_synchronized_server(self, driver):
|
||||
driver._node_api().execute.post.return_value = {"data": self.NTP_OUTPUT}
|
||||
driver._node_ssh().output = self.NTP_OUTPUT
|
||||
stats = driver.get_ntp_stats()
|
||||
synced = [s for s in stats if s["synchronized"]]
|
||||
assert len(synced) == 1
|
||||
assert synced[0]["remote"] == "192.168.1.1"
|
||||
|
||||
def test_stratum(self, driver):
|
||||
driver._node_api().execute.post.return_value = {"data": self.NTP_OUTPUT}
|
||||
driver._node_ssh().output = self.NTP_OUTPUT
|
||||
stats = driver.get_ntp_stats()
|
||||
assert stats[0]["stratum"] == 4
|
||||
|
||||
def test_empty_when_no_ntp_command(self, driver):
|
||||
driver._node_api().execute.post.return_value = {"data": ""}
|
||||
driver._node_ssh().output = ""
|
||||
stats = driver.get_ntp_stats()
|
||||
assert stats == []
|
||||
|
||||
@@ -53,7 +53,7 @@ class TestGetSNMPInformation:
|
||||
)
|
||||
|
||||
def test_communities(self, driver):
|
||||
driver._node_api().execute.post.return_value = {"data": self.SNMP_CONF}
|
||||
driver._node_ssh().output = self.SNMP_CONF
|
||||
result = driver.get_snmp_information()
|
||||
assert "public" in result["community"]
|
||||
assert result["community"]["public"]["mode"] == "ro"
|
||||
@@ -61,30 +61,30 @@ class TestGetSNMPInformation:
|
||||
assert result["community"]["private"]["mode"] == "rw"
|
||||
|
||||
def test_location(self, driver):
|
||||
driver._node_api().execute.post.return_value = {"data": self.SNMP_CONF}
|
||||
driver._node_ssh().output = self.SNMP_CONF
|
||||
result = driver.get_snmp_information()
|
||||
assert result["location"] == "Server Room A"
|
||||
|
||||
def test_contact(self, driver):
|
||||
driver._node_api().execute.post.return_value = {"data": self.SNMP_CONF}
|
||||
driver._node_ssh().output = self.SNMP_CONF
|
||||
result = driver.get_snmp_information()
|
||||
assert result["contact"] == "admin@example.com"
|
||||
|
||||
def test_chassis_id_is_node_name(self, driver):
|
||||
driver._node_api().execute.post.return_value = {"data": ""}
|
||||
driver._node_ssh().output = ""
|
||||
result = driver.get_snmp_information()
|
||||
assert result["chassis_id"] == "pve1"
|
||||
|
||||
|
||||
class TestGetUsers:
|
||||
def test_pve_users_returned(self, driver):
|
||||
driver._node_api().execute.post.return_value = {"data": ""}
|
||||
driver._node_ssh().output = ""
|
||||
result = driver.get_users()
|
||||
assert "root@pam" in result
|
||||
assert "napalm@pam" in result
|
||||
|
||||
def test_user_has_required_keys(self, driver):
|
||||
driver._node_api().execute.post.return_value = {"data": ""}
|
||||
driver._node_ssh().output = ""
|
||||
result = driver.get_users()
|
||||
for _user, data in result.items():
|
||||
assert "level" in data
|
||||
@@ -93,7 +93,7 @@ class TestGetUsers:
|
||||
|
||||
def test_root_local_user_from_passwd(self, driver):
|
||||
passwd_output = "root:x:0:0:root:/root:/bin/bash\n"
|
||||
driver._node_api().execute.post.return_value = {"data": passwd_output}
|
||||
driver._node_ssh().output = passwd_output
|
||||
result = driver.get_users()
|
||||
assert "root" in result
|
||||
assert result["root"]["level"] == 15
|
||||
@@ -136,14 +136,14 @@ class TestConfigManagement:
|
||||
assert diff == ""
|
||||
|
||||
def test_get_config_running(self, driver):
|
||||
driver._node_api().execute.post.return_value = {"data": self.RUNNING}
|
||||
driver._node_ssh().output = self.RUNNING
|
||||
result = driver.get_config(retrieve="running")
|
||||
assert self.RUNNING in result["running"]
|
||||
assert result["candidate"] == ""
|
||||
|
||||
def test_get_config_sanitized_redacts_password(self, driver):
|
||||
raw = "password mysecret\nauto eth0\n"
|
||||
driver._node_api().execute.post.return_value = {"data": raw}
|
||||
driver._node_ssh().output = raw
|
||||
result = driver.get_config(retrieve="running", sanitized=True)
|
||||
assert "mysecret" not in result["running"]
|
||||
assert "****" in result["running"]
|
||||
@@ -168,7 +168,7 @@ class TestPing:
|
||||
)
|
||||
|
||||
def test_success(self, driver):
|
||||
driver._node_api().execute.post.return_value = {"data": self.PING_SUCCESS}
|
||||
driver._node_ssh().output = self.PING_SUCCESS
|
||||
result = driver.ping("8.8.8.8")
|
||||
assert "success" in result
|
||||
assert result["success"]["probes_sent"] == 2
|
||||
@@ -177,7 +177,7 @@ class TestPing:
|
||||
|
||||
def test_every_reply_is_a_result(self, driver):
|
||||
"""iputils puts "from <ip>" before icmp_seq (napalm-proxmox#12)."""
|
||||
driver._node_api().execute.post.return_value = {"data": self.PING_SUCCESS}
|
||||
driver._node_ssh().output = self.PING_SUCCESS
|
||||
result = driver.ping("8.8.8.8")
|
||||
assert result["success"]["results"] == [
|
||||
{"ip_address": "8.8.8.8", "rtt": 10.5},
|
||||
@@ -193,7 +193,7 @@ class TestPing:
|
||||
"2 packets transmitted, 2 received, 0% packet loss, time 1001ms\n"
|
||||
"rtt min/avg/max/mdev = 0.045/61.5/123.0/61.4 ms\n"
|
||||
)
|
||||
driver._node_api().execute.post.return_value = {"data": output}
|
||||
driver._node_ssh().output = output
|
||||
result = driver.ping("dns.google")
|
||||
assert result["success"]["results"] == [
|
||||
{"ip_address": "8.8.4.4", "rtt": 123.0},
|
||||
@@ -201,12 +201,12 @@ class TestPing:
|
||||
]
|
||||
|
||||
def test_failure(self, driver):
|
||||
driver._node_api().execute.post.return_value = {"data": self.PING_FAIL}
|
||||
driver._node_ssh().output = self.PING_FAIL
|
||||
result = driver.ping("badhost")
|
||||
assert "error" in result
|
||||
|
||||
def test_exec_unavailable(self, driver):
|
||||
driver._node_api().execute.post.return_value = {"data": ""}
|
||||
def test_no_output(self, driver):
|
||||
driver._node_ssh().output = ""
|
||||
result = driver.ping("8.8.8.8")
|
||||
assert "error" in result
|
||||
|
||||
@@ -220,44 +220,34 @@ class TestTraceroute:
|
||||
)
|
||||
|
||||
def test_success_hops(self, driver):
|
||||
driver._node_api().execute.post.return_value = {"data": self.TR_OUTPUT}
|
||||
driver._node_ssh().output = self.TR_OUTPUT
|
||||
result = driver.traceroute("8.8.8.8")
|
||||
assert "success" in result
|
||||
assert 1 in result["success"]
|
||||
assert 3 in result["success"]
|
||||
|
||||
def test_hop_rtt(self, driver):
|
||||
driver._node_api().execute.post.return_value = {"data": self.TR_OUTPUT}
|
||||
driver._node_ssh().output = self.TR_OUTPUT
|
||||
result = driver.traceroute("8.8.8.8")
|
||||
hop1 = result["success"][1]["probes"]
|
||||
assert hop1[1]["ip_address"] == "10.0.0.254"
|
||||
|
||||
def test_empty_returns_error(self, driver):
|
||||
driver._node_api().execute.post.return_value = {"data": ""}
|
||||
driver._node_ssh().output = ""
|
||||
result = driver.traceroute("8.8.8.8")
|
||||
assert "error" in result
|
||||
|
||||
|
||||
class TestCLI:
|
||||
def test_cli_single_command(self, driver):
|
||||
driver._node_api().execute.post.return_value = {"data": "hello world"}
|
||||
driver._node_ssh().output = "hello world"
|
||||
result = driver.cli(["echo hello world"])
|
||||
assert result["echo hello world"] == "hello world"
|
||||
|
||||
def test_cli_multiple_commands(self, driver):
|
||||
responses = {"uptime": "up 2 days", "hostname": "pve1"}
|
||||
call_count = 0
|
||||
|
||||
def _exec(command):
|
||||
nonlocal call_count
|
||||
cmd = command
|
||||
call_count += 1
|
||||
return {"data": responses.get(cmd, "")}
|
||||
|
||||
driver._node_api().execute.post.side_effect = _exec
|
||||
driver._node_ssh().outputs = {"uptime": "up 2 days", "hostname": "pve1"}
|
||||
result = driver.cli(["uptime", "hostname"])
|
||||
assert "uptime" in result
|
||||
assert "hostname" in result
|
||||
assert result == {"uptime": "up 2 days", "hostname": "pve1"}
|
||||
|
||||
|
||||
class TestGetRouteTo:
|
||||
@@ -267,12 +257,12 @@ class TestGetRouteTo:
|
||||
)
|
||||
|
||||
def test_returns_routes(self, driver):
|
||||
driver._node_api().execute.post.return_value = {"data": self.ROUTE_OUTPUT}
|
||||
driver._node_ssh().output = self.ROUTE_OUTPUT
|
||||
result = driver.get_route_to(destination="10.0.0.0/24")
|
||||
assert "10.0.0.0/24" in result
|
||||
|
||||
def test_route_fields(self, driver):
|
||||
driver._node_api().execute.post.return_value = {"data": self.ROUTE_OUTPUT}
|
||||
driver._node_ssh().output = self.ROUTE_OUTPUT
|
||||
result = driver.get_route_to()
|
||||
for _prefix, routes in result.items():
|
||||
for route in routes:
|
||||
@@ -281,7 +271,7 @@ class TestGetRouteTo:
|
||||
assert "outgoing_interface" in route
|
||||
|
||||
def test_protocol_filter(self, driver):
|
||||
driver._node_api().execute.post.return_value = {"data": self.ROUTE_OUTPUT}
|
||||
driver._node_ssh().output = self.ROUTE_OUTPUT
|
||||
result = driver.get_route_to(protocol="dhcp")
|
||||
for _prefix, routes in result.items():
|
||||
for route in routes:
|
||||
@@ -316,7 +306,7 @@ class TestLLDPNeighbors:
|
||||
assert result["eth0"][0]["hostname"] == "sw01.example.com"
|
||||
|
||||
def test_empty_when_no_lldp(self, driver):
|
||||
driver._node_api().execute.post.return_value = {"data": ""}
|
||||
driver._node_ssh().output = ""
|
||||
result = driver.get_lldp_neighbors()
|
||||
assert result == {}
|
||||
|
||||
@@ -329,18 +319,18 @@ class TestIPv6Neighbors:
|
||||
)
|
||||
|
||||
def test_neighbors_parsed(self, driver):
|
||||
driver._node_api().execute.post.return_value = {"data": self.IPV6_NEIGH}
|
||||
driver._node_ssh().output = self.IPV6_NEIGH
|
||||
result = driver.get_ipv6_neighbors_table()
|
||||
assert len(result) == 2 # FAILED entry excluded
|
||||
|
||||
def test_mac_normalized(self, driver):
|
||||
driver._node_api().execute.post.return_value = {"data": self.IPV6_NEIGH}
|
||||
driver._node_ssh().output = self.IPV6_NEIGH
|
||||
result = driver.get_ipv6_neighbors_table()
|
||||
macs = {e["mac"] for e in result}
|
||||
assert "aa:bb:cc:dd:ee:ff" in macs
|
||||
|
||||
def test_state_present(self, driver):
|
||||
driver._node_api().execute.post.return_value = {"data": self.IPV6_NEIGH}
|
||||
driver._node_ssh().output = self.IPV6_NEIGH
|
||||
result = driver.get_ipv6_neighbors_table()
|
||||
states = {e["state"] for e in result}
|
||||
assert "REACHABLE" in states
|
||||
@@ -348,7 +338,7 @@ class TestIPv6Neighbors:
|
||||
def test_age_is_unknown(self, driver):
|
||||
# `ip neigh` reports no age, as for the IPv4 table; 0.0 would read as
|
||||
# "confirmed just now" (NetOrk/netork#1327).
|
||||
driver._node_api().execute.post.return_value = {"data": self.IPV6_NEIGH}
|
||||
driver._node_ssh().output = self.IPV6_NEIGH
|
||||
result = driver.get_ipv6_neighbors_table()
|
||||
assert {e["age"] for e in result} == {-1.0}
|
||||
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
"""Commands on the node run over its SSH session, and a failure to run one raises (#17).
|
||||
|
||||
``_exec_ssh_command`` used to post to ``/nodes/{node}/execute`` first (a batch of API
|
||||
calls, not a shell), to return stderr as output, and to return ``""`` whenever the
|
||||
command could not run at all: no credential, a refused login, a changed host key, a
|
||||
timeout. "Nothing there" and "could not look" read the same.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import paramiko
|
||||
import pytest
|
||||
from napalm.base.exceptions import ConnectionException
|
||||
|
||||
from napalm_proxmox.driver import ProxmoxDriver
|
||||
from tests.test_ssh_host_key import client # noqa: F401 - the fake paramiko client
|
||||
|
||||
|
||||
class _Stream:
|
||||
def __init__(self, data: bytes | Exception) -> None:
|
||||
self._data = data
|
||||
|
||||
def read(self) -> bytes:
|
||||
if isinstance(self._data, Exception):
|
||||
raise self._data
|
||||
return self._data
|
||||
|
||||
|
||||
class _Shell:
|
||||
"""The node's SSH session: prints *out* on stdout and *err* on stderr."""
|
||||
|
||||
def __init__(self, out: bytes | Exception = b"", err: bytes = b"") -> None:
|
||||
self.out, self.err = out, err
|
||||
self.commands: list[str] = []
|
||||
|
||||
def exec_command(self, command: str, timeout: int | None = None):
|
||||
self.commands.append(command)
|
||||
return None, _Stream(self.out), _Stream(self.err)
|
||||
|
||||
|
||||
def _driver(shell: _Shell | None = None, **kwargs) -> ProxmoxDriver:
|
||||
driver = ProxmoxDriver("10.0.0.9", "root", kwargs.pop("password", "s3cret"), **kwargs)
|
||||
driver._node_name = "pve1"
|
||||
driver._api = MagicMock()
|
||||
if shell is not None:
|
||||
driver._node_ssh = MagicMock(return_value=shell) # type: ignore[method-assign]
|
||||
return driver
|
||||
|
||||
|
||||
def test_a_command_goes_straight_to_the_ssh_session():
|
||||
shell = _Shell(b"6.8.12-4-pve\n")
|
||||
driver = _driver(shell)
|
||||
|
||||
assert driver._exec_ssh_command("uname -r") == "6.8.12-4-pve"
|
||||
assert shell.commands == ["uname -r"]
|
||||
driver._api.nodes.return_value.execute.post.assert_not_called()
|
||||
|
||||
|
||||
def test_stderr_is_not_output():
|
||||
shell = _Shell(b"", b"cat: /etc/snmp/snmpd.conf: No such file or directory\n")
|
||||
|
||||
assert _driver(shell)._exec_ssh_command("cat /etc/snmp/snmpd.conf") == ""
|
||||
|
||||
|
||||
def test_a_refused_login_raises():
|
||||
driver = _driver()
|
||||
driver._node_ssh = MagicMock( # type: ignore[method-assign]
|
||||
side_effect=paramiko.AuthenticationException("Authentication failed.")
|
||||
)
|
||||
|
||||
with pytest.raises(ConnectionException, match="Authentication failed") as err:
|
||||
driver._exec_ssh_command("uptime")
|
||||
assert isinstance(err.value.__cause__, paramiko.AuthenticationException)
|
||||
|
||||
|
||||
def test_an_unreachable_node_raises():
|
||||
driver = _driver()
|
||||
driver._node_ssh = MagicMock( # type: ignore[method-assign]
|
||||
side_effect=OSError(113, "No route to host")
|
||||
)
|
||||
|
||||
with pytest.raises(ConnectionException, match="No route to host"):
|
||||
driver._exec_ssh_command("uptime")
|
||||
|
||||
|
||||
def test_a_timeout_raises():
|
||||
shell = _Shell(TimeoutError("timed out"))
|
||||
|
||||
with pytest.raises(ConnectionException, match="timed out"):
|
||||
_driver(shell)._exec_ssh_command("apt list --upgradable")
|
||||
|
||||
|
||||
def test_without_an_ssh_credential_nothing_connects(client): # noqa: F811
|
||||
# An API-token-only node: no API password, no SSH password, no key.
|
||||
driver = _driver(password="", optional_args={"token_name": "root@pam!t", "token_value": "x"})
|
||||
|
||||
with pytest.raises(ConnectionException, match="no SSH credential"):
|
||||
driver._exec_ssh_command("command -v lldpd")
|
||||
assert client.connected_with is None
|
||||
|
||||
|
||||
def test_get_snmp_config_raises_where_it_cannot_look(client): # noqa: F811
|
||||
"""netOrk reads an exception as "SSH not available" and raises no SNMP alarm."""
|
||||
driver = _driver(password="", optional_args={"token_name": "root@pam!t", "token_value": "x"})
|
||||
|
||||
with pytest.raises(ConnectionException):
|
||||
driver.get_snmp_config()
|
||||
@@ -103,23 +103,23 @@ class TestGetARPTable:
|
||||
)
|
||||
|
||||
def test_arp_entries_returned(self, driver):
|
||||
driver._node_api().execute.post.return_value = {"data": self.PROC_ARP}
|
||||
driver._node_ssh().output = self.PROC_ARP
|
||||
result = driver.get_arp_table()
|
||||
assert len(result) == 2 # 00:00:00:00:00:00 excluded
|
||||
|
||||
def test_mac_normalized(self, driver):
|
||||
driver._node_api().execute.post.return_value = {"data": self.PROC_ARP}
|
||||
driver._node_ssh().output = self.PROC_ARP
|
||||
result = driver.get_arp_table()
|
||||
macs = {e["mac"] for e in result}
|
||||
assert "aa:bb:cc:dd:ee:ff" in macs
|
||||
|
||||
def test_vrf_filter(self, driver):
|
||||
driver._node_api().execute.post.return_value = {"data": self.PROC_ARP}
|
||||
driver._node_ssh().output = self.PROC_ARP
|
||||
result = driver.get_arp_table(vrf="vmbr0")
|
||||
assert all(e["interface"] == "vmbr0" for e in result)
|
||||
|
||||
def test_empty_when_exec_unavailable(self, driver):
|
||||
driver._node_api().execute.post.return_value = {"data": ""}
|
||||
def test_empty_when_the_node_prints_nothing(self, driver):
|
||||
driver._node_ssh().output = ""
|
||||
result = driver.get_arp_table()
|
||||
assert result == []
|
||||
|
||||
|
||||
@@ -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