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
@@ -3,14 +3,24 @@
|
||||
It started from "public" and kept it when no table row parsed, so a switch
|
||||
whose community table could not be read reported a running agent with the
|
||||
community "public".
|
||||
|
||||
The fixture is ``show snmp-server community`` recorded from a JetStream switch: its
|
||||
table starts with an ``Index`` column, which was read as the community.
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
|
||||
from napalm_tplink_jetstream.tplink_jetstream import TPLinkJetstreamDriver
|
||||
|
||||
FIXTURES = Path(__file__).parent.parent / "fixtures"
|
||||
|
||||
SHOW_SNMP_COMMUNITY = (FIXTURES / "jetstream-show-snmp-server-community.txt").read_text()
|
||||
#: The recording without its only row.
|
||||
NO_COMMUNITY = "".join(SHOW_SNMP_COMMUNITY.splitlines(keepends=True)[:2])
|
||||
|
||||
|
||||
def _driver(output: str) -> TPLinkJetstreamDriver:
|
||||
driver = TPLinkJetstreamDriver("10.0.0.30", "admin", "pw")
|
||||
@@ -19,18 +29,18 @@ def _driver(output: str) -> TPLinkJetstreamDriver:
|
||||
|
||||
|
||||
def test_the_listed_community_is_reported():
|
||||
out = "Index Community-Name Access\n----- -------------- ------\nc0mm read-only x\n"
|
||||
config = _driver(SHOW_SNMP_COMMUNITY).get_snmp_config()
|
||||
|
||||
config = _driver(out).get_snmp_config()
|
||||
|
||||
assert config == {"running": True, "community": "c0mm", "port": 161, "version": "2c"}
|
||||
assert config == {"running": True, "community": "public", "port": 161, "version": "2c"}
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"output",
|
||||
[
|
||||
"Index Community-Name Access\n----- -------------- ------\n",
|
||||
"Index Community-Name Access\n",
|
||||
NO_COMMUNITY,
|
||||
SHOW_SNMP_COMMUNITY.splitlines(keepends=True)[0],
|
||||
# A table without a column headed Name: its rows name no community.
|
||||
SHOW_SNMP_COMMUNITY.replace("Name ", "Comm ", 1),
|
||||
"something the parser does not know\n",
|
||||
],
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user