driver / types (pull_request) Successful in 1m0s
driver / standard (pull_request) Successful in 16s
driver / lint (pull_request) Successful in 15s
driver / test (3.12) (pull_request) Successful in 1m9s
driver / test (3.13) (pull_request) Successful in 1m3s
driver / lowest (pull_request) Successful in 32s
driver / build (pull_request) Successful in 44s
driver / security (pull_request) Successful in 1m19s
CI / driver (pull_request) Successful in 2m56s
driver / publish (pull_request) Skipped
Fixtures, docstring examples and the README use neutral host names (ap-01, ap-02) and addresses from the documentation ranges 192.0.2.0/24, 198.51.100.0/24 and 203.0.113.0/24, mapped one to one so every test keeps its meaning: the management network test still has its address inside that network, a route still covers its prefix. Loopback, the wildcard address and netmasks are unchanged.
97 lines
3.0 KiB
Python
97 lines
3.0 KiB
Python
"""configure_snmp_agent's values: community, sources, contact, location (netOrk #1105).
|
|
|
|
The old fix_snmp set no community at all and opened the management zone to every
|
|
source; the rule was named after an application. Every value is the caller's now.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
from napalm_openwrt import OpenWrtDriver
|
|
from tests.unit.test_driver import UCI_FIREWALL_HEALTHY, UCI_NETWORK_STATIC, _FakeShell
|
|
|
|
SETTINGS = {
|
|
"community": "c0mm",
|
|
"allowed_sources": ["198.51.100.20", "fd00::20"],
|
|
"contact": "ops",
|
|
"location": "rack 1",
|
|
}
|
|
|
|
|
|
@pytest.fixture
|
|
def shell():
|
|
return _FakeShell(
|
|
firewall=UCI_FIREWALL_HEALTHY,
|
|
network=UCI_NETWORK_STATIC,
|
|
ssh_connection="198.51.100.20 51234 192.0.2.1 22",
|
|
)
|
|
|
|
|
|
@pytest.fixture
|
|
def owrt(shell):
|
|
d = OpenWrtDriver("ap", "root", "pw")
|
|
d._send_command = shell
|
|
return d
|
|
|
|
|
|
def _joined(shell):
|
|
return " ".join(shell.issued)
|
|
|
|
|
|
def test_the_steps_run_in_order_and_succeed(owrt):
|
|
result = owrt.configure_snmp_agent(SETTINGS)
|
|
|
|
assert result["success"] is True
|
|
assert [s["step"] for s in result["steps"]] == ["install", "configure", "firewall", "start"]
|
|
|
|
|
|
def test_community_per_source_in_uci(owrt, shell):
|
|
owrt.configure_snmp_agent(SETTINGS)
|
|
|
|
uci = _joined(shell)
|
|
assert "uci set snmpd.public.source='198.51.100.20/32'" in uci
|
|
assert "uci set snmpd.public.community='c0mm'" in uci
|
|
assert "uci set snmpd.public6.source='fd00::20/128'" in uci
|
|
assert "snmpd.@system[0].sysLocation='rack 1'" in uci
|
|
assert "uci commit snmpd" in uci
|
|
|
|
|
|
def test_without_sources_every_address_may_ask(owrt, shell):
|
|
owrt.configure_snmp_agent({"community": "c0mm", "allowed_sources": []})
|
|
|
|
assert "uci set snmpd.public.source='default'" in _joined(shell)
|
|
|
|
|
|
def test_ipv4_sources_only_keep_ipv6_to_localhost(owrt, shell):
|
|
owrt.configure_snmp_agent({"community": "c0mm", "allowed_sources": ["198.51.100.20"]})
|
|
|
|
assert "uci set snmpd.public6.source='::1/128'" in _joined(shell)
|
|
|
|
|
|
def test_the_firewall_rule_is_limited_to_the_sources_and_neutrally_named(owrt, shell):
|
|
owrt.configure_snmp_agent(SETTINGS)
|
|
|
|
uci = _joined(shell)
|
|
assert "uci add_list firewall.allow_snmp_from_lan.src_ip='198.51.100.20/32'" in uci
|
|
assert "firewall.allow_snmp_from_lan.name='Allow-SNMP'" in uci
|
|
assert "netork" not in uci.lower()
|
|
|
|
|
|
def test_the_management_peer_is_the_ssh_client(owrt):
|
|
assert owrt.get_management_peer() == "198.51.100.20"
|
|
|
|
|
|
@pytest.mark.parametrize("community", ["two words", "it's", ""])
|
|
def test_a_community_that_would_break_uci_is_refused(owrt, shell, community):
|
|
result = owrt.configure_snmp_agent({"community": community, "allowed_sources": []})
|
|
|
|
assert result["success"] is False
|
|
assert "uci commit snmpd" not in _joined(shell)
|
|
|
|
|
|
def test_the_old_actions_are_gone():
|
|
gone = ("run_device_action", "_action_fix_snmp", "_action_install_lldpd", "_action_install_auc")
|
|
for name in gone:
|
|
assert not hasattr(OpenWrtDriver, name), name
|