fix(snmp): read the community from the Name column
driver / standard (pull_request) Successful in 14s
driver / lint (pull_request) Successful in 12s
driver / types (pull_request) Successful in 59s
driver / test (3.12) (pull_request) Successful in 58s
driver / test (3.13) (pull_request) Successful in 50s
driver / lowest (pull_request) Successful in 24s
driver / build (pull_request) Successful in 26s
driver / security (pull_request) Successful in 1m2s
CI / driver (pull_request) Successful in 2m26s
driver / publish (pull_request) Skipped
driver / standard (pull_request) Successful in 14s
driver / lint (pull_request) Successful in 12s
driver / types (pull_request) Successful in 59s
driver / test (3.12) (pull_request) Successful in 58s
driver / test (3.13) (pull_request) Successful in 50s
driver / lowest (pull_request) Successful in 24s
driver / build (pull_request) Successful in 26s
driver / security (pull_request) Successful in 1m2s
CI / driver (pull_request) Successful in 2m26s
driver / publish (pull_request) Skipped
The switch's community table starts with an Index column, and get_snmp_config took a row's first word, so it reported the community as "1". The name now comes from the column headed Name, found in the header line above the dashes; the tests read the recorded table. Found while recording fixtures for #3.
This commit is contained in:
1 parent
34f00f9f3a
commit
8e7be0e47e
6 files changed
+55
-22
No files matched your search
@@ -0,0 +1,29 @@
|
||||
"""Pure parsers: the switch's CLI output in, plain values out."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
|
||||
_DASHES = re.compile(r"^-{4,}$")
|
||||
|
||||
|
||||
def parse_snmp_communities(output: str) -> list[str]:
|
||||
"""The community names in ``show snmp-server community``, in the switch's order.
|
||||
|
||||
The table starts with an ``Index`` column: the name is the column headed
|
||||
``Name``, found in the header line above the dashes. Without one, no name.
|
||||
"""
|
||||
names: list[str] = []
|
||||
header: list[str] = []
|
||||
column: int | None = None
|
||||
for line in output.splitlines():
|
||||
words = line.split()
|
||||
if not words:
|
||||
continue
|
||||
if column is None:
|
||||
if _DASHES.match(words[0]):
|
||||
column = next((i for i, w in enumerate(header) if "name" in w.lower()), -1)
|
||||
header = words
|
||||
elif 0 <= column < len(words):
|
||||
names.append(words[column])
|
||||
return names
|
||||
Reference in new issue
Block a user