feat!: configure_snmp_agent with the caller's values replaces fix_snmp (0.3.0)
CI / test (3.10) (push) Successful in 24s
CI / test (3.11) (push) Successful in 23s
CI / test (3.12) (push) Successful in 25s
CI / test (3.10) (pull_request) Successful in 24s
CI / test (3.11) (pull_request) Successful in 23s
CI / test (3.12) (pull_request) Successful in 24s
CI / test (3.10) (push) Successful in 24s
CI / test (3.11) (push) Successful in 23s
CI / test (3.12) (push) Successful in 25s
CI / test (3.10) (pull_request) Successful in 24s
CI / test (3.11) (pull_request) Successful in 23s
CI / test (3.12) (pull_request) Successful in 24s
fix_snmp hard-coded community "public" and sent its config-mode line through _send_command, which waits for the exec prompt: in config mode it ran into its timeout and left the session there (#6). netgear_smart implements napalm-device-types 4.13's configure_snmp_agent steps: community (read-only), contact and location from the caller through _apply_config_lines, which waits for any prompt and reports a refused line; config mode is left in all cases; the configuration is saved and the community checked in show snmp. v7 firmware, which has no SNMP commands in its CLI, says so. A value that would break the CLI is refused. napalm-device-types is now declared in pyproject.toml and requirements.txt (#7). BREAKING CHANGE: run_device_action is removed. Closes #6. Part of #7 and #8.
This commit is contained in:
1 parent
16bd276e82
commit
34554eade9
4 files changed
+134
-41
No files matched your search
@@ -0,0 +1,77 @@
|
||||
"""The SNMP agent through napalm-device-types' configure_snmp_agent (netOrk #1105).
|
||||
|
||||
fix_snmp hard-coded community "public" and sent the config-mode command through
|
||||
_send_command, which waits for the exec prompt and so ran into its timeout in
|
||||
config mode (#6). The caller's values go through _apply_config_lines now, which
|
||||
waits for any prompt and reports a rejected line.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
|
||||
from napalm_netgear.netgear_smart import NetgearSmartDriver
|
||||
|
||||
SETTINGS = {"community": "c0mm", "allowed_sources": [], "contact": "ops", "location": "rack 1"}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def driver():
|
||||
d = NetgearSmartDriver("10.0.0.30", "admin", "pw")
|
||||
d.device = MagicMock()
|
||||
d.applied: list[str] = []
|
||||
d._detect_cli_v7 = lambda: False
|
||||
d._enter_config_mode = MagicMock()
|
||||
d._exit_config_mode = MagicMock()
|
||||
d._save_config = MagicMock()
|
||||
d._apply_config_lines = lambda text: d.applied.extend(text.splitlines()) or []
|
||||
d._send_command = MagicMock(
|
||||
return_value="Community-String Community-Access\nc0mm Read Only\n"
|
||||
)
|
||||
return d
|
||||
|
||||
|
||||
def test_community_contact_and_location_through_the_config_helper(driver):
|
||||
result = driver.configure_snmp_agent(SETTINGS)
|
||||
|
||||
assert result["success"] is True
|
||||
assert driver.applied == [
|
||||
"snmp-server community c0mm ro",
|
||||
'snmp-server contact "ops"',
|
||||
'snmp-server location "rack 1"',
|
||||
]
|
||||
driver._exit_config_mode.assert_called_once()
|
||||
driver._save_config.assert_called_once()
|
||||
|
||||
|
||||
def test_config_mode_is_left_even_when_a_line_is_refused(driver):
|
||||
driver._apply_config_lines = lambda text: [" 'snmp-server community c0mm ro': Invalid input"]
|
||||
|
||||
result = driver.configure_snmp_agent(SETTINGS)
|
||||
|
||||
assert result["success"] is False
|
||||
driver._exit_config_mode.assert_called_once()
|
||||
driver._save_config.assert_not_called()
|
||||
|
||||
|
||||
def test_v7_firmware_says_it_has_no_snmp_cli(driver):
|
||||
driver._detect_cli_v7 = lambda: True
|
||||
|
||||
result = driver.configure_snmp_agent(SETTINGS)
|
||||
|
||||
assert result["success"] is False
|
||||
assert "web UI" in result["output"] and "warning" not in result["output"]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("community", ["two words", 'q"uote', ""])
|
||||
def test_a_community_that_would_break_the_cli_is_refused(driver, community):
|
||||
result = driver.configure_snmp_agent({"community": community, "allowed_sources": []})
|
||||
assert result["success"] is False
|
||||
assert driver.applied == []
|
||||
|
||||
|
||||
def test_the_old_action_is_gone():
|
||||
assert not hasattr(NetgearSmartDriver, "run_device_action")
|
||||
assert not hasattr(NetgearSmartDriver, "_action_fix_snmp")
|
||||
Reference in new issue
Block a user