Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c85df7402d | ||
|
|
5427cc015e |
No files matched your search
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#define AppName "NetBox Synchronizer"
|
#define AppName "NetBox Synchronizer"
|
||||||
#ifndef AppVersion
|
#ifndef AppVersion
|
||||||
#define AppVersion "4.16.2"
|
#define AppVersion "4.16.3"
|
||||||
#endif
|
#endif
|
||||||
#define AppPublisher "Louis-Alexander Kerst"
|
#define AppPublisher "Louis-Alexander Kerst"
|
||||||
#define AppExeName "NetBoxSynchronizer.exe"
|
#define AppExeName "NetBoxSynchronizer.exe"
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
"""NetBox Synchronizer – VMs, switches and clients from the field into NetBox."""
|
"""NetBox Synchronizer – VMs, switches and clients from the field into NetBox."""
|
||||||
|
|
||||||
APP_NAME = "NetBox Synchronizer"
|
APP_NAME = "NetBox Synchronizer"
|
||||||
APP_VERSION = "4.16.2"
|
APP_VERSION = "4.16.3"
|
||||||
APP_PUBLISHER = "Louis-Alexander Kerst"
|
APP_PUBLISHER = "Louis-Alexander Kerst"
|
||||||
APP_USER_MODEL_ID = "Louis-AlexanderKerst.NetBoxSynchronizer"
|
APP_USER_MODEL_ID = "Louis-AlexanderKerst.NetBoxSynchronizer"
|
||||||
|
|
||||||
|
|||||||
@@ -11,10 +11,10 @@ import time
|
|||||||
|
|
||||||
from netbox_sync.core.switches import (
|
from netbox_sync.core.switches import (
|
||||||
CLI_ERROR,
|
CLI_ERROR,
|
||||||
_interface,
|
CLI_PROMPT,
|
||||||
_compress_vlans,
|
_compress_vlans,
|
||||||
|
_interface,
|
||||||
_membership,
|
_membership,
|
||||||
_run_cli_command as _run_with_newline,
|
|
||||||
clean_output,
|
clean_output,
|
||||||
parse_vlan_list,
|
parse_vlan_list,
|
||||||
)
|
)
|
||||||
@@ -35,9 +35,33 @@ COMMANDS = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# The CLI pages long outputs ("-- more --, next page: Space, ..., q to quit") and cannot be told not to.
|
||||||
|
PAGER = re.compile(r"(?im)^[^\n]*(?:q to quit|-+\s*more\s*-+)[^\n]*\Z")
|
||||||
|
|
||||||
|
|
||||||
def _run_cli_command(channel, command, timeout=20):
|
def _run_cli_command(channel, command, timeout=20):
|
||||||
"""This CLI executes a command only on "\r"; "\n" is just echoed."""
|
"""Run a command; this CLI executes it only on "\r" ("\n" is just echoed).
|
||||||
return _run_with_newline(channel, command, timeout=timeout, newline="\r")
|
|
||||||
|
Paging prompts are answered with Space and removed from the output.
|
||||||
|
"""
|
||||||
|
channel.send(command + "\r")
|
||||||
|
chunks, started = [], time.monotonic()
|
||||||
|
while time.monotonic() - started < timeout:
|
||||||
|
if channel.recv_ready():
|
||||||
|
chunks.append(channel.recv(65535).decode("utf-8", errors="replace"))
|
||||||
|
text = clean_output("".join(chunks))
|
||||||
|
if PAGER.search(text):
|
||||||
|
chunks = [PAGER.sub("", text)]
|
||||||
|
channel.send(" ")
|
||||||
|
started = time.monotonic() # every page gets the full timeout
|
||||||
|
continue
|
||||||
|
if CLI_PROMPT.search(text):
|
||||||
|
return text
|
||||||
|
time.sleep(0.05)
|
||||||
|
text = clean_output("".join(chunks))
|
||||||
|
tail = " | ".join(line.strip() for line in text.splitlines()[-3:] if line.strip())
|
||||||
|
raise TimeoutError(f"CLI-Befehl nicht vollständig abgeschlossen: {command}. Der Switch hat die CLI-Ausgabe nicht "
|
||||||
|
f"mit einem vollständigen Prompt abgeschlossen. Letzte Ausgabe: {tail[-300:] or '–'}")
|
||||||
|
|
||||||
|
|
||||||
def probe(channel):
|
def probe(channel):
|
||||||
|
|||||||
@@ -214,6 +214,9 @@ def _quick_reads(monkeypatch):
|
|||||||
real = switches._read_available
|
real = switches._read_available
|
||||||
monkeypatch.setattr(switches, "_read_available", lambda channel, timeout=20, initialize_session=False:
|
monkeypatch.setattr(switches, "_read_available", lambda channel, timeout=20, initialize_session=False:
|
||||||
real(channel, timeout=min(timeout, 0.3), initialize_session=initialize_session))
|
real(channel, timeout=min(timeout, 0.3), initialize_session=initialize_session))
|
||||||
|
command = lancom._run_cli_command
|
||||||
|
monkeypatch.setattr(lancom, "_run_cli_command", lambda channel, text, timeout=20:
|
||||||
|
command(channel, text, timeout=min(timeout, 0.3)))
|
||||||
return switches
|
return switches
|
||||||
|
|
||||||
|
|
||||||
@@ -244,3 +247,23 @@ def test_session_is_attached_to_errors(monkeypatch):
|
|||||||
with pytest.raises(TimeoutError) as caught:
|
with pytest.raises(TimeoutError) as caught:
|
||||||
switches.run_switch_commands({"host": "x", "platform": "lancom_sx3"})
|
switches.run_switch_commands({"host": "x", "platform": "lancom_sx3"})
|
||||||
assert "SW-08#" in caught.value.transcript and "»» system" in caught.value.transcript
|
assert "SW-08#" in caught.value.transcript and "»» system" in caught.value.transcript
|
||||||
|
|
||||||
|
|
||||||
|
def test_paging_is_answered_with_space():
|
||||||
|
class Paging(FakeChannel):
|
||||||
|
def send(self, data):
|
||||||
|
if data == " ":
|
||||||
|
self.sent.append("<space>")
|
||||||
|
self.buffer += "\r \rFlash Size : 32\nSW-08(system)# "
|
||||||
|
elif data.strip() == "show" and self.mode == "system":
|
||||||
|
self.sent.append("show")
|
||||||
|
self.buffer += "show\nModel Name : LANCOM GS-2326P+\nRAM Size : 128\n -- more --, next page: Space, q to quit"
|
||||||
|
else:
|
||||||
|
super().send(data)
|
||||||
|
|
||||||
|
channel = Paging()
|
||||||
|
channel.mode = "system"
|
||||||
|
output = lancom._run_cli_command(channel, "show", timeout=2)
|
||||||
|
assert channel.sent == ["show", "<space>"]
|
||||||
|
assert "RAM Size : 128" in output and "Flash Size : 32" in output
|
||||||
|
assert "quit" not in output and "more" not in output
|
||||||
Reference in new issue
Block a user