feat(logins): get_login_sessions through LoginSessionsMixin, 0.26.0 (NetOrk/netork#2881)
driver / lint (pull_request) Successful in 13s
driver / standard (pull_request) Successful in 16s
driver / lowest (pull_request) Successful in 41s
driver / test (3.12) (pull_request) Successful in 1m28s
driver / test (3.13) (pull_request) Successful in 1m16s
driver / types (pull_request) Successful in 1m33s
driver / security (pull_request) Successful in 1m0s
driver / build (pull_request) Successful in 30s
CI / driver (pull_request) Successful in 2m0s
driver / publish (pull_request) Skipped

The interactive logins the host recorded, napalm-device-types' command on
an exec channel as the login user: wtmp is readable to everyone, and sudo
would drop SSH_CONNECTION, which names the driver's own address.
This commit is contained in:
Christian Manivong committed 2026-12-01 09:40:21 +01:00
1 parent 5fc6d96ea7
commit 55507a8a25
5 files changed
+62 -12

No files matched your search

+32
View File
@@ -2227,6 +2227,38 @@ class TestGetLoginAccounts:
assert calls == [True, False]
class TestGetLoginSessions:
"""The interactive logins the host recorded (NetOrk/netork#2881): napalm-device-types'
command on an exec channel as the login user -- sudo would drop ``SSH_CONNECTION``,
and the login records are readable to everyone."""
_REPORT = (
"LOGSESSIONS_BEGIN\n[own]\n198.51.100.2\n[now]\n2026-11-30T12:00:00Z\n[wtmp since]\n"
"alice pts/1 192.0.2.10 2026-11-30T10:15:02+01:00 still logged in\n"
"LOGSESSIONS_END\n"
)
def test_it_reads_the_shared_command_as_the_login_user_on_an_exec_channel(self, driver):
from napalm_device_types import CommandResult, LoginSessionsMixin
assert isinstance(driver, LoginSessionsMixin)
calls = []
def run_command(command, *, privileged=False, timeout=60, stdin=None):
calls.append((command, privileged, stdin))
return CommandResult(self._REPORT, "", 0)
driver.run_command = run_command
reading = driver.get_login_sessions()
assert reading["own_address"] == "198.51.100.2"
assert reading["sessions"][0]["address"] == "192.0.2.10"
assert [(privileged, stdin) for _, privileged, stdin in calls] == [(False, None)]
assert calls[0][0].startswith("sh -c ")
driver._device.send_command.assert_not_called()
# ---------------------------------------------------------------------------
# get_host_firewall (napalm-device-types HostFirewallMixin, NetOrk/netork#1344)
# ---------------------------------------------------------------------------