From e4ae42fea0204e732af10b17b0ec6a7521786c59 Mon Sep 17 00:00:00 2001 From: Christian Manivong Date: Thu, 12 Nov 2026 19:21:54 +0100 Subject: [PATCH] test: documentation names and addresses in fixtures 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. --- README.md | 4 +- napalm_openwrt/interfaces_mixin.py | 8 +- napalm_openwrt/routing_mixin.py | 8 +- napalm_openwrt/system_mixin.py | 4 +- tests/unit/test_driver.py | 142 ++++++++++++++--------------- tests/unit/test_packages.py | 2 +- tests/unit/test_snmp_agent.py | 12 +-- tests/unit/test_ssh_host_key.py | 8 +- tests/unit/test_time_sync.py | 58 ++++++------ tests/unit/test_updates.py | 2 +- 10 files changed, 125 insertions(+), 123 deletions(-) diff --git a/README.md b/README.md index f117a2c..edc50fe 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ pip install -e . from napalm import get_network_driver driver = get_network_driver("openwrt") -device = driver("192.168.1.1", "root", "") +device = driver("192.0.2.1", "root", "") device.open() @@ -83,7 +83,7 @@ Configuration is managed via [UCI](https://openwrt.org/docs/guide-user/base-syst device.load_merge_candidate( config=""" uci set system.@system[0].hostname='my-router' -uci set network.lan.ipaddr='10.0.0.1' +uci set network.lan.ipaddr='192.0.2.1' """ ) diff --git a/napalm_openwrt/interfaces_mixin.py b/napalm_openwrt/interfaces_mixin.py index 62e6979..a5a101d 100644 --- a/napalm_openwrt/interfaces_mixin.py +++ b/napalm_openwrt/interfaces_mixin.py @@ -95,7 +95,7 @@ class OpenWrtInterfaceMixin: Example output:: 2: eth0: mtu 1500 ... - inet 192.168.1.1/24 brd 192.168.1.255 scope global eth0 + inet 192.0.2.1/24 brd 192.0.2.255 scope global eth0 inet6 fd00::1/64 scope global """ output = self._send_command("ip addr show") @@ -192,8 +192,8 @@ class OpenWrtInterfaceMixin: Uses ``ip neigh show`` (preferred) which produces:: - 192.168.1.100 dev br-lan lladdr aa:bb:cc:dd:ee:ff REACHABLE - 192.168.1.1 dev br-lan lladdr 00:11:22:33:44:55 STALE + 192.0.2.100 dev br-lan lladdr aa:bb:cc:dd:ee:ff REACHABLE + 192.0.2.1 dev br-lan lladdr 00:11:22:33:44:55 STALE """ output = self._send_command(["ip neigh show", "cat /proc/net/arp"]) arp_table = [] @@ -208,7 +208,7 @@ class OpenWrtInterfaceMixin: if "FAILED" in line_s or "INCOMPLETE" in line_s: continue - # ip neigh show: "192.168.1.100 dev br-lan lladdr aa:bb:cc:dd:ee:ff REACHABLE" + # ip neigh show: "192.0.2.100 dev br-lan lladdr aa:bb:cc:dd:ee:ff REACHABLE" m = re.match( r"^(\S+)\s+dev\s+(\S+)\s+lladdr\s+(\S+)", line_s, diff --git a/napalm_openwrt/routing_mixin.py b/napalm_openwrt/routing_mixin.py index 07d504f..b52f795 100644 --- a/napalm_openwrt/routing_mixin.py +++ b/napalm_openwrt/routing_mixin.py @@ -123,8 +123,8 @@ class OpenWrtRoutingMixin: Example ``ip route show`` output:: - default via 192.168.1.1 dev br-wan proto dhcp src 203.0.113.1 metric 100 - 192.168.1.0/24 dev br-lan proto kernel scope link src 192.168.1.1 + default via 192.0.2.1 dev br-wan proto dhcp src 203.0.113.1 metric 100 + 192.0.2.0/24 dev br-lan proto kernel scope link src 192.0.2.1 """ if destination: cmd = f"ip route show {'match ' if longer else ''}{destination}" @@ -141,7 +141,7 @@ class OpenWrtRoutingMixin: # Determine the prefix # "default via ..." → prefix = "0.0.0.0/0" - # "192.168.1.0/24 dev ..." → prefix as-is + # "192.0.2.0/24 dev ..." → prefix as-is if line_s.startswith("default"): prefix = "0.0.0.0/0" rest = line_s[len("default") :].strip() @@ -244,7 +244,7 @@ class OpenWrtRoutingMixin: Example lines:: - 1 192.168.1.1 (192.168.1.1) 1.123 ms 1.456 ms 1.789 ms + 1 192.0.2.1 (192.0.2.1) 1.123 ms 1.456 ms 1.789 ms 2 * * * """ hops: dict[int, dict[str, Any]] = {} diff --git a/napalm_openwrt/system_mixin.py b/napalm_openwrt/system_mixin.py index 447bde9..aadae72 100644 --- a/napalm_openwrt/system_mixin.py +++ b/napalm_openwrt/system_mixin.py @@ -543,11 +543,11 @@ class OpenWrtSystemMixin: ``ntpq -pn`` example line:: - *188.114.101.4 188.114.100.1 4 u 107 256 377 164.228 -13.866 2.695 + *203.0.113.104 203.0.113.100 4 u 107 256 377 164.228 -13.866 2.695 ``chronyc sources -v`` example line:: - ^* 192.168.1.1 2 6 17 8 +2345us[ 0ns] +/- 15ms + ^* 192.0.2.1 2 6 17 8 +2345us[ 0ns] +/- 15ms """ ntpq_out = self._send_command("ntpq -pn") if ntpq_out and not ntpq_out.startswith(("ntpq: ", "sh: ", "ash: ", "command not found")): diff --git a/tests/unit/test_driver.py b/tests/unit/test_driver.py index e645e1f..d266ea5 100644 --- a/tests/unit/test_driver.py +++ b/tests/unit/test_driver.py @@ -17,7 +17,7 @@ def driver(): """Return a driver instance with a mocked Netmiko connection.""" with patch("napalm_openwrt.openwrt.ConnectHandler"): drv = OpenWrtDriver( - hostname="192.168.1.1", + hostname="192.0.2.1", username="root", password="", ) @@ -63,16 +63,16 @@ IP_ADDR_SHOW = """\ link/ether b0:95:75:aa:bb:cc brd ff:ff:ff:ff:ff:ff 4: br-lan: mtu 1500 qdisc noqueue state UP group default qlen 1000 link/ether b0:95:75:aa:bb:cc brd ff:ff:ff:ff:ff:ff - inet 192.168.1.1/24 brd 192.168.1.255 scope global br-lan + inet 192.0.2.1/24 brd 192.0.2.255 scope global br-lan valid_lft forever preferred_lft forever inet6 fd00::1/64 scope global valid_lft forever preferred_lft forever """ IP_NEIGH_SHOW = """\ -192.168.1.100 dev br-lan lladdr aa:bb:cc:dd:ee:ff REACHABLE -192.168.1.101 dev br-lan lladdr 11:22:33:44:55:66 STALE -192.168.1.102 dev br-lan FAILED +192.0.2.100 dev br-lan lladdr aa:bb:cc:dd:ee:ff REACHABLE +192.0.2.101 dev br-lan lladdr 11:22:33:44:55:66 STALE +192.0.2.102 dev br-lan FAILED """ BRIDGE_FDB = """\ @@ -99,7 +99,7 @@ config interface 'loopback' config interface 'lan' \toption device 'br-lan' \toption proto 'static' -\toption ipaddr '192.168.1.1' +\toption ipaddr '192.0.2.1' \toption netmask '255.255.255.0' """ @@ -110,7 +110,7 @@ lldp.eth0.age=0 day, 01:23:45 lldp.eth0.chassis.mac=00:aa:bb:cc:dd:ee lldp.eth0.chassis.name=core-router lldp.eth0.chassis.descr=RouterOS 7.x -lldp.eth0.chassis.mgmt-ip=10.0.0.1 +lldp.eth0.chassis.mgmt-ip=203.0.113.10 lldp.eth0.chassis.cap.available=Router, Bridge lldp.eth0.chassis.cap.enabled=Router lldp.eth0.port.ifname=ether1 @@ -240,8 +240,8 @@ class TestGetInterfacesIP: driver._send_command = lambda cmd, **kw: IP_ADDR_SHOW result = driver.get_interfaces_ip() assert "br-lan" in result - assert "192.168.1.1" in result["br-lan"]["ipv4"] - assert result["br-lan"]["ipv4"]["192.168.1.1"]["prefix_length"] == 24 + assert "192.0.2.1" in result["br-lan"]["ipv4"] + assert result["br-lan"]["ipv4"]["192.0.2.1"]["prefix_length"] == 24 def test_br_lan_ipv6(self, driver): driver._send_command = lambda cmd, **kw: IP_ADDR_SHOW @@ -272,8 +272,8 @@ class TestGetArpTable: driver._send_command = lambda cmd, **kw: IP_NEIGH_SHOW result = driver.get_arp_table() ips = {e["ip"] for e in result} - assert "192.168.1.100" in ips - assert "192.168.1.101" in ips + assert "192.0.2.100" in ips + assert "192.0.2.101" in ips def test_ip_neigh_reports_no_age(self, driver): # REACHABLE or STALE, `ip neigh` says nothing about when the neighbour @@ -284,7 +284,7 @@ class TestGetArpTable: def test_proc_net_arp_reports_no_age(self, driver): driver._send_command = lambda cmd, **kw: ( "IP address HW type Flags HW address Mask Device\n" - "192.168.1.100 0x1 0x2 aa:bb:cc:dd:ee:ff * br-lan\n" + "192.0.2.100 0x1 0x2 aa:bb:cc:dd:ee:ff * br-lan\n" ) assert [e["age"] for e in driver.get_arp_table()] == [-1.0] @@ -358,7 +358,7 @@ lldp.lan1.rid=1 lldp.lan1.age=0 day, 00:10:00 lldp.lan1.chassis.mac=00:11:22:33:44:01 lldp.lan1.chassis.name=desk-phone -lldp.lan1.chassis.mgmt-ip=10.0.0.21 +lldp.lan1.chassis.mgmt-ip=203.0.113.21 lldp.lan1.chassis.mgmt-ip=fe80::211:22ff:fe33:4401 lldp.lan1.port.ifname=lan lldp.lan1.port.descr=phone uplink @@ -812,8 +812,8 @@ system.ntp.enable_server='0' NTPQ_OUTPUT = """\ remote refid st t when poll reach delay offset jitter ============================================================================== -*188.114.101.4 188.114.100.1 4 u 107 256 377 164.228 -13.866 2.695 -+37.187.56.220 192.53.103.108 2 u 22 64 377 30.112 5.123 1.100 +*203.0.113.104 203.0.113.100 4 u 107 256 377 164.228 -13.866 2.695 ++203.0.113.220 203.0.113.108 2 u 22 64 377 30.112 5.123 1.100 """ UCI_SNMPD = """\ @@ -825,7 +825,7 @@ snmpd.@com2sec[0].source='default' snmpd.@com2sec[0].community='public' snmpd.@com2sec[1]=com2sec snmpd.@com2sec[1].secname='private' -snmpd.@com2sec[1].source='10.0.0.0/8' +snmpd.@com2sec[1].source='203.0.113.0/24' snmpd.@com2sec[1].community='private' snmpd.@system[0]=system snmpd.@system[0].sysContact='admin@example.com' @@ -834,18 +834,18 @@ snmpd.@system[0].sysName='MyRouter' """ PING_SUCCESS = """\ -PING 8.8.8.8 (8.8.8.8): 56 data bytes -64 bytes from 8.8.8.8: seq=0 ttl=120 time=7.123 ms -64 bytes from 8.8.8.8: seq=1 ttl=120 time=6.987 ms -64 bytes from 8.8.8.8: seq=2 ttl=120 time=7.234 ms ---- 8.8.8.8 ping statistics --- +PING 203.0.113.8 (203.0.113.8): 56 data bytes +64 bytes from 203.0.113.8: seq=0 ttl=120 time=7.123 ms +64 bytes from 203.0.113.8: seq=1 ttl=120 time=6.987 ms +64 bytes from 203.0.113.8: seq=2 ttl=120 time=7.234 ms +--- 203.0.113.8 ping statistics --- 3 packets transmitted, 3 packets received, 0% packet loss round-trip min/avg/max = 6.987/7.115/7.234 ms """ PING_LOSS = """\ -PING 10.0.0.99 (10.0.0.99): 56 data bytes ---- 10.0.0.99 ping statistics --- +PING 203.0.113.99 (203.0.113.99): 56 data bytes +--- 203.0.113.99 ping statistics --- 3 packets transmitted, 0 packets received, 100% packet loss """ @@ -858,17 +858,17 @@ fe80::1 dev br-lan lladdr 11:22:33:44:55:66 STALE """ IP_ROUTE_SHOW = """\ -default via 192.168.1.1 dev br-wan proto dhcp src 203.0.113.1 metric 100 -192.168.1.0/24 dev br-lan proto kernel scope link src 192.168.1.1 -10.0.0.0/8 via 192.168.1.254 dev br-wan proto static metric 50 +default via 192.0.2.1 dev br-wan proto dhcp src 203.0.113.1 metric 100 +192.0.2.0/24 dev br-lan proto kernel scope link src 192.0.2.1 +203.0.113.0/24 via 192.0.2.254 dev br-wan proto static metric 50 """ TRACEROUTE_OUTPUT = """\ -traceroute to 8.8.8.8 (8.8.8.8), 30 hops max, 38 byte packets - 1 192.168.1.1 (192.168.1.1) 1.123 ms 1.456 ms 1.789 ms - 2 10.0.0.1 (10.0.0.1) 5.123 ms 5.456 ms 5.789 ms +traceroute to 203.0.113.8 (203.0.113.8), 30 hops max, 38 byte packets + 1 192.0.2.1 (192.0.2.1) 1.123 ms 1.456 ms 1.789 ms + 2 203.0.113.10 (203.0.113.10) 5.123 ms 5.456 ms 5.789 ms 3 * * * - 4 8.8.8.8 (8.8.8.8) 7.001 ms 6.999 ms 7.100 ms + 4 203.0.113.8 (203.0.113.8) 7.001 ms 6.999 ms 7.100 ms """ TRACEROUTE_ERROR = "traceroute: unknown host invalid.host" @@ -983,7 +983,7 @@ class TestGetNtpStats: result = driver.get_ntp_stats() synced = [e for e in result if e["synchronized"]] assert len(synced) == 1 - assert synced[0]["remote"] == "188.114.101.4" + assert synced[0]["remote"] == "203.0.113.104" def test_required_keys(self, driver): driver._send_command = lambda cmd, **kw: NTPQ_OUTPUT @@ -1042,14 +1042,14 @@ class TestGetSnmpInformation: class TestPing: def test_success_result(self, driver): driver._send_command = lambda cmd, **kw: PING_SUCCESS - result = driver.ping("8.8.8.8") + result = driver.ping("203.0.113.8") assert "success" in result assert result["success"]["probes_sent"] == 3 assert result["success"]["packet_loss"] == 0 def test_rtt_values(self, driver): driver._send_command = lambda cmd, **kw: PING_SUCCESS - result = driver.ping("8.8.8.8") + result = driver.ping("203.0.113.8") s = result["success"] assert s["rtt_min"] == 6.987 assert s["rtt_max"] == 7.234 @@ -1057,13 +1057,13 @@ class TestPing: def test_probe_results(self, driver): driver._send_command = lambda cmd, **kw: PING_SUCCESS - result = driver.ping("8.8.8.8") + result = driver.ping("203.0.113.8") assert len(result["success"]["results"]) == 3 - assert result["success"]["results"][0]["ip_address"] == "8.8.8.8" + assert result["success"]["results"][0]["ip_address"] == "203.0.113.8" def test_100_percent_loss(self, driver): driver._send_command = lambda cmd, **kw: PING_LOSS - result = driver.ping("10.0.0.99") + result = driver.ping("203.0.113.99") assert "success" in result assert result["success"]["packet_loss"] == 3 @@ -1109,20 +1109,20 @@ class TestGetRouteTo: driver._send_command = lambda cmd, **kw: IP_ROUTE_SHOW result = driver.get_route_to() default = result["0.0.0.0/0"][0] - assert default["next_hop"] == "192.168.1.1" + assert default["next_hop"] == "192.0.2.1" assert default["outgoing_interface"] == "br-wan" def test_connected_route(self, driver): driver._send_command = lambda cmd, **kw: IP_ROUTE_SHOW result = driver.get_route_to() - assert "192.168.1.0/24" in result - assert result["192.168.1.0/24"][0]["protocol"] == "connected" + assert "192.0.2.0/24" in result + assert result["192.0.2.0/24"][0]["protocol"] == "connected" def test_protocol_filter(self, driver): driver._send_command = lambda cmd, **kw: IP_ROUTE_SHOW result = driver.get_route_to(protocol="static") - assert "10.0.0.0/8" in result - assert "192.168.1.0/24" not in result + assert "203.0.113.0/24" in result + assert "192.0.2.0/24" not in result def test_required_keys(self, driver): driver._send_command = lambda cmd, **kw: IP_ROUTE_SHOW @@ -1141,24 +1141,24 @@ class TestGetRouteTo: class TestTraceroute: def test_success_result(self, driver): driver._send_command = lambda cmd, **kw: TRACEROUTE_OUTPUT - result = driver.traceroute("8.8.8.8") + result = driver.traceroute("203.0.113.8") assert "success" in result def test_hop_count(self, driver): driver._send_command = lambda cmd, **kw: TRACEROUTE_OUTPUT - result = driver.traceroute("8.8.8.8") + result = driver.traceroute("203.0.113.8") assert len(result["success"]) == 4 def test_hop_1_rtt(self, driver): driver._send_command = lambda cmd, **kw: TRACEROUTE_OUTPUT - result = driver.traceroute("8.8.8.8") + result = driver.traceroute("203.0.113.8") hop1 = result["success"][1]["probes"][1] assert hop1["rtt"] == 1.123 - assert hop1["ip_address"] == "192.168.1.1" + assert hop1["ip_address"] == "192.0.2.1" def test_star_hop(self, driver): driver._send_command = lambda cmd, **kw: TRACEROUTE_OUTPUT - result = driver.traceroute("8.8.8.8") + result = driver.traceroute("203.0.113.8") hop3 = result["success"][3]["probes"][1] assert hop3["ip_address"] == "*" @@ -1564,11 +1564,11 @@ network.loopback.device='lo' network.lan=interface network.lan.device='br-lan' network.lan.proto='static' -network.lan.ipaddr='192.168.1.1' +network.lan.ipaddr='192.0.2.1' network.mgmt=interface network.mgmt.device='br-lan.9' network.mgmt.proto='static' -network.mgmt.ipaddr='10.10.0.5' +network.mgmt.ipaddr='198.51.100.5' """ UCI_NETWORK_DHCP = """\ @@ -1579,7 +1579,7 @@ network.lan.proto='dhcp' IP_ADDR_BRLAN = """\ 1: lo inet 127.0.0.1/8 scope host lo\\ valid_lft forever preferred_lft forever -7: br-lan inet 10.10.0.5/24 brd 10.10.0.255 scope global br-lan\\ valid_lft forever +7: br-lan inet 198.51.100.5/24 brd 198.51.100.255 scope global br-lan\\ valid_lft forever """ @@ -1641,11 +1641,11 @@ class TestFixSnmpZoneDetection: """The firewall step must resolve the real zone that owns the mgmt address.""" def test_static_mgmt_address_selects_owning_zone(self, driver): - """10.10.0.5 lives on network 'mgmt' → zone 'mgmt', not the 'lan' fallback.""" + """198.51.100.5 lives on network 'mgmt' → zone 'mgmt', not the 'lan' fallback.""" shell = _FakeShell( firewall=UCI_FIREWALL_MGMT_ZONE, network=UCI_NETWORK_STATIC, - ssh_connection="10.10.0.1 51234 10.10.0.5 22", + ssh_connection="198.51.100.1 51234 198.51.100.5 22", ) driver._send_command = shell result = driver.configure_snmp_agent(_SETTINGS) @@ -1657,7 +1657,7 @@ class TestFixSnmpZoneDetection: shell = _FakeShell( firewall=UCI_FIREWALL_HEALTHY, network=UCI_NETWORK_STATIC, - ssh_connection="192.168.1.50 5000 192.168.1.1 22", + ssh_connection="192.0.2.50 5000 192.0.2.1 22", ) driver._send_command = shell result = driver.configure_snmp_agent(_SETTINGS) @@ -1669,7 +1669,7 @@ class TestFixSnmpZoneDetection: firewall=UCI_FIREWALL_HEALTHY, network=UCI_NETWORK_DHCP, ip_addr=IP_ADDR_BRLAN, - ssh_connection="10.10.0.1 51234 10.10.0.5 22", + ssh_connection="198.51.100.1 51234 198.51.100.5 22", ) driver._send_command = shell result = driver.configure_snmp_agent(_SETTINGS) @@ -1680,7 +1680,7 @@ class TestFixSnmpZoneDetection: shell = _FakeShell( firewall=UCI_FIREWALL_NAMELESS_ZONE, network=UCI_NETWORK_STATIC, - ssh_connection="192.168.1.50 5000 192.168.1.1 22", + ssh_connection="192.0.2.50 5000 192.0.2.1 22", ) driver._send_command = shell result = driver.configure_snmp_agent(_SETTINGS) @@ -1693,7 +1693,7 @@ class TestFixSnmpZoneDetection: shell = _FakeShell( firewall=UCI_FIREWALL_NAMELESS_ZONE, network=UCI_NETWORK_STATIC, - ssh_connection="192.168.1.50 5000 192.168.1.1 22", + ssh_connection="192.0.2.50 5000 192.0.2.1 22", ) driver._send_command = shell driver.configure_snmp_agent(_SETTINGS) @@ -1713,7 +1713,7 @@ class TestFixSnmpRuleWriting: shell = _FakeShell( firewall=broken, network=UCI_NETWORK_STATIC, - ssh_connection="192.168.1.50 5000 192.168.1.1 22", + ssh_connection="192.0.2.50 5000 192.0.2.1 22", ) driver._send_command = shell driver.configure_snmp_agent(_SETTINGS) @@ -1732,7 +1732,7 @@ class TestFixSnmpRuleWriting: shell = _FakeShell( firewall=stale, network=UCI_NETWORK_STATIC, - ssh_connection="192.168.1.50 5000 192.168.1.1 22", + ssh_connection="192.0.2.50 5000 192.0.2.1 22", ) driver._send_command = shell driver.configure_snmp_agent(_SETTINGS) @@ -1750,7 +1750,7 @@ class TestFixSnmpRuleWriting: shell = _FakeShell( firewall=stale, network=UCI_NETWORK_STATIC, - ssh_connection="192.168.1.50 5000 192.168.1.1 22", + ssh_connection="192.0.2.50 5000 192.0.2.1 22", ) driver._send_command = shell driver.configure_snmp_agent(_SETTINGS) @@ -1770,7 +1770,7 @@ class TestFixSnmpRuleWriting: shell = _FakeShell( firewall=stale, network=UCI_NETWORK_STATIC, - ssh_connection="192.168.1.50 5000 192.168.1.1 22", + ssh_connection="192.0.2.50 5000 192.0.2.1 22", ) driver._send_command = shell driver.configure_snmp_agent(_SETTINGS) @@ -1791,7 +1791,7 @@ class TestFixSnmpReloadVerification: shell = _FakeShell( firewall=UCI_FIREWALL_HEALTHY, network=UCI_NETWORK_STATIC, - ssh_connection="192.168.1.50 5000 192.168.1.1 22", + ssh_connection="192.0.2.50 5000 192.0.2.1 22", reload_out=self.FW4_ZONE_ERROR, ) driver._send_command = shell @@ -1803,7 +1803,7 @@ class TestFixSnmpReloadVerification: shell = _FakeShell( firewall=UCI_FIREWALL_HEALTHY, network=UCI_NETWORK_STATIC, - ssh_connection="192.168.1.50 5000 192.168.1.1 22", + ssh_connection="192.0.2.50 5000 192.0.2.1 22", reload_out=self.FW4_ZONE_ERROR, ) driver._send_command = shell @@ -1815,7 +1815,7 @@ class TestFixSnmpReloadVerification: shell = _FakeShell( firewall=UCI_FIREWALL_HEALTHY, network=UCI_NETWORK_STATIC, - ssh_connection="192.168.1.50 5000 192.168.1.1 22", + ssh_connection="192.0.2.50 5000 192.0.2.1 22", nft_hits="0", ) driver._send_command = shell @@ -1826,7 +1826,7 @@ class TestFixSnmpReloadVerification: shell = _FakeShell( firewall=UCI_FIREWALL_HEALTHY, network=UCI_NETWORK_STATIC, - ssh_connection="192.168.1.50 5000 192.168.1.1 22", + ssh_connection="192.0.2.50 5000 192.0.2.1 22", listen_hits="0", ) driver._send_command = shell @@ -1837,7 +1837,7 @@ class TestFixSnmpReloadVerification: shell = _FakeShell( firewall=UCI_FIREWALL_HEALTHY, network=UCI_NETWORK_STATIC, - ssh_connection="192.168.1.50 5000 192.168.1.1 22", + ssh_connection="192.0.2.50 5000 192.0.2.1 22", ) driver._send_command = shell result = driver.configure_snmp_agent(_SETTINGS) @@ -1874,11 +1874,11 @@ class TestUciSectionParser: UCI_SYSTEM_WITH_SYSLOG = """\ system.@system[0]=system -system.@system[0].hostname='ap-eze-Garten' +system.@system[0].hostname='ap-01' system.@system[0].timezone='CET-1CEST,M3.5.0,M10.5.0/3' system.@system[0].zonename='Europe/Berlin' system.@system[0].log_remote='1' -system.@system[0].log_ip='10.10.40.2' +system.@system[0].log_ip='192.0.2.40' system.@system[0].log_port='5514' system.@system[0].log_proto='udp' system.ntp=timeserver @@ -1887,7 +1887,7 @@ system.ntp.server='0.openwrt.pool.ntp.org' '1.openwrt.pool.ntp.org' UCI_SYSTEM_NO_SYSLOG = """\ system.@system[0]=system -system.@system[0].hostname='ap-eze-Parkplatz' +system.@system[0].hostname='ap-02' system.@system[0].timezone='GMT0' system.@system[0].zonename='UTC' system.ntp=timeserver @@ -1939,7 +1939,7 @@ class TestGetSystemConfigSyslog: driver._send_command = _system_send() cfg = driver.get_system_config() assert cfg["syslog_remote"] is True - assert cfg["syslog_ip"] == "10.10.40.2" + assert cfg["syslog_ip"] == "192.0.2.40" assert cfg["syslog_port"] == 5514 def test_absent_syslog_reports_as_disabled(self, driver): @@ -1950,13 +1950,13 @@ class TestGetSystemConfigSyslog: def test_log_ip_without_log_remote_is_not_active(self, driver): # OpenWrt only ships logs when log_remote is set, whatever log_ip says. - out = UCI_SYSTEM_NO_SYSLOG + "system.@system[0].log_ip='10.10.40.2'\n" + out = UCI_SYSTEM_NO_SYSLOG + "system.@system[0].log_ip='192.0.2.40'\n" driver._send_command = _system_send(out) assert driver.get_system_config()["syslog_remote"] is False def test_port_falls_back_to_the_openwrt_default(self, driver): out = UCI_SYSTEM_NO_SYSLOG + ( - "system.@system[0].log_remote='1'\nsystem.@system[0].log_ip='10.10.40.2'\n" + "system.@system[0].log_remote='1'\nsystem.@system[0].log_ip='192.0.2.40'\n" ) driver._send_command = _system_send(out) assert driver.get_system_config()["syslog_port"] == 514 @@ -2005,7 +2005,7 @@ class TestOptionalArgs: def test_the_callers_optional_args_are_left_as_they_were(self): optional_args = {"port": 2222, "conn_timeout": 15} - drv = OpenWrtDriver("192.168.1.1", "root", "", optional_args=optional_args) + drv = OpenWrtDriver("192.0.2.1", "root", "", optional_args=optional_args) assert drv.port == 2222 assert optional_args == {"port": 2222, "conn_timeout": 15} diff --git a/tests/unit/test_packages.py b/tests/unit/test_packages.py index 98a913d..13d8653 100644 --- a/tests/unit/test_packages.py +++ b/tests/unit/test_packages.py @@ -29,7 +29,7 @@ APK_ADD_OK_NAMING_FAILED = ( @pytest.fixture def driver(): with patch("napalm_openwrt.openwrt.ConnectHandler"): - drv = OpenWrtDriver(hostname="192.168.1.1", username="root", password="") + drv = OpenWrtDriver(hostname="192.0.2.1", username="root", password="") drv.device = MagicMock() yield drv diff --git a/tests/unit/test_snmp_agent.py b/tests/unit/test_snmp_agent.py index a56bb4a..8a12dd4 100644 --- a/tests/unit/test_snmp_agent.py +++ b/tests/unit/test_snmp_agent.py @@ -13,7 +13,7 @@ from tests.unit.test_driver import UCI_FIREWALL_HEALTHY, UCI_NETWORK_STATIC, _Fa SETTINGS = { "community": "c0mm", - "allowed_sources": ["10.7.224.20", "fd00::20"], + "allowed_sources": ["198.51.100.20", "fd00::20"], "contact": "ops", "location": "rack 1", } @@ -24,7 +24,7 @@ def shell(): return _FakeShell( firewall=UCI_FIREWALL_HEALTHY, network=UCI_NETWORK_STATIC, - ssh_connection="10.7.224.20 51234 192.168.1.1 22", + ssh_connection="198.51.100.20 51234 192.0.2.1 22", ) @@ -50,7 +50,7 @@ def test_community_per_source_in_uci(owrt, shell): owrt.configure_snmp_agent(SETTINGS) uci = _joined(shell) - assert "uci set snmpd.public.source='10.7.224.20/32'" in uci + 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 @@ -64,7 +64,7 @@ def test_without_sources_every_address_may_ask(owrt, shell): def test_ipv4_sources_only_keep_ipv6_to_localhost(owrt, shell): - owrt.configure_snmp_agent({"community": "c0mm", "allowed_sources": ["10.7.224.20"]}) + owrt.configure_snmp_agent({"community": "c0mm", "allowed_sources": ["198.51.100.20"]}) assert "uci set snmpd.public6.source='::1/128'" in _joined(shell) @@ -73,13 +73,13 @@ def test_the_firewall_rule_is_limited_to_the_sources_and_neutrally_named(owrt, s owrt.configure_snmp_agent(SETTINGS) uci = _joined(shell) - assert "uci add_list firewall.allow_snmp_from_lan.src_ip='10.7.224.20/32'" in uci + 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() == "10.7.224.20" + assert owrt.get_management_peer() == "198.51.100.20" @pytest.mark.parametrize("community", ["two words", "it's", ""]) diff --git a/tests/unit/test_ssh_host_key.py b/tests/unit/test_ssh_host_key.py index 03ffddd..2b2d02b 100644 --- a/tests/unit/test_ssh_host_key.py +++ b/tests/unit/test_ssh_host_key.py @@ -34,7 +34,7 @@ def _driver(seen: list, known: SshHostKey | None = None) -> OpenWrtDriver: args: dict = {"port": 2222, OBSERVER_ARG: seen.append} if known is not None: args[KNOWN_KEYS_ARG] = {"2222": known.as_dict()} - return OpenWrtDriver("10.0.0.8", "admin", "s3cret", optional_args=args) + return OpenWrtDriver("192.0.2.8", "admin", "s3cret", optional_args=args) def test_first_use_lets_netmiko_accept_and_reports_the_key(): @@ -48,7 +48,7 @@ def test_first_use_lets_netmiko_accept_and_reports_the_key(): assert kwargs["port"] == 2222 assert seen[0]["accepted"] is True assert seen[0]["seen"]["fingerprint"] == SshHostKey.of(SERVER_KEY).fingerprint - assert (seen[0]["host"], seen[0]["port"]) == ("10.0.0.8", 2222) + assert (seen[0]["host"], seen[0]["port"]) == ("192.0.2.8", 2222) def test_a_known_key_is_the_only_one_netmiko_accepts(): @@ -59,7 +59,7 @@ def test_a_known_key_is_the_only_one_netmiko_accepts(): def connect(**kwargs): files.append(kwargs["alt_key_file"]) with open(kwargs["alt_key_file"]) as f: - assert f.read().strip() == known.known_hosts_line("10.0.0.8", 2222) + assert f.read().strip() == known.known_hosts_line("192.0.2.8", 2222) assert kwargs["ssh_strict"] is True and kwargs["alt_host_keys"] is True return _device() @@ -74,7 +74,7 @@ def test_a_changed_key_is_refused(): def refuse(**kwargs): try: - raise paramiko.BadHostKeyException("10.0.0.8", SERVER_KEY, OTHER_KEY) + raise paramiko.BadHostKeyException("192.0.2.8", SERVER_KEY, OTHER_KEY) except paramiko.SSHException as exc: # what netmiko does with it raise NetmikoTimeoutException(f"A paramiko SSHException occurred: {exc}") from exc diff --git a/tests/unit/test_time_sync.py b/tests/unit/test_time_sync.py index 76b2ca9..4c41b8a 100644 --- a/tests/unit/test_time_sync.py +++ b/tests/unit/test_time_sync.py @@ -45,14 +45,14 @@ system.ntp.enable_server='0' system.ntp.server='0.openwrt.pool.ntp.org' '1.openwrt.pool.ntp.org' '2.openwrt.pool.ntp.org' '3.openwrt.pool.ntp.org' """ -# An AP configured through LuCI (the get_system_config fixture of netOrk#164). +# An AP configured through LuCI (the reading of the get_system_config fixture in test_driver.py). LUCI_BERLIN = """\ system.@system[0]=system -system.@system[0].hostname='ap-eze-Garten' +system.@system[0].hostname='ap-01' system.@system[0].timezone='CET-1CEST,M3.5.0,M10.5.0/3' system.@system[0].zonename='Europe/Berlin' system.@system[0].log_remote='1' -system.@system[0].log_ip='10.10.40.2' +system.@system[0].log_ip='192.0.2.40' system.ntp=timeserver system.ntp.server='0.openwrt.pool.ntp.org' '1.openwrt.pool.ntp.org' """ @@ -63,7 +63,7 @@ system.@system[0]=system system.@system[0].timezone='EST5EDT,M3.2.0,M11.1.0' system.@system[0].zonename='America/New York' system.ntp=timeserver -system.ntp.server='10.0.0.1' +system.ntp.server='203.0.113.10' """ # netOrk#1849: the IANA name written as the rule. libc cannot read it; the AP runs on UTC. @@ -72,7 +72,7 @@ system.@system[0]=system system.@system[0].timezone='Europe/Berlin' system.@system[0].zonename='Europe/Berlin' system.ntp=timeserver -system.ntp.server='10.0.0.1' +system.ntp.server='203.0.113.10' """ # A server list kept as one option, the servers apart by spaces: sysntpd splits it. @@ -96,7 +96,7 @@ def _interface(name: str, ntpserver: str | None = None, **more: Any) -> dict[str LEASE = { "interface": [ _interface("lan", proto="static"), - _interface("wan", "192.168.1.1 192.168.1.2", leasetime=43200), + _interface("wan", "192.0.2.1 192.0.2.2", leasetime=43200), _interface("wan6", proto="dhcpv6"), ] } @@ -250,7 +250,7 @@ def test_the_read_is_one_round_trip_as_the_login_user(): def test_a_lease_s_ntp_servers_are_read_apart_from_the_configured_ones(): reading = _read(STOCK, LEASE) - assert reading["dhcp_ntp_servers"] == ["192.168.1.1", "192.168.1.2"] + assert reading["dhcp_ntp_servers"] == ["192.0.2.1", "192.0.2.2"] assert reading["ntp_servers"] == [ "0.openwrt.pool.ntp.org", "1.openwrt.pool.ntp.org", @@ -262,38 +262,38 @@ def test_a_lease_s_ntp_servers_are_read_apart_from_the_configured_ones(): def test_every_interface_s_lease_counts_in_netifd_s_order_each_once(): dump = { "interface": [ - _interface("wan", "192.168.1.1"), - _interface("iot", "10.40.100.1 192.168.1.1"), + _interface("wan", "192.0.2.1"), + _interface("iot", "198.51.100.1 192.0.2.1"), ] } - assert _read(STOCK, dump)["dhcp_ntp_servers"] == ["192.168.1.1", "10.40.100.1"] + assert _read(STOCK, dump)["dhcp_ntp_servers"] == ["192.0.2.1", "198.51.100.1"] def test_an_interface_without_a_lease_or_with_an_odd_one_brings_nothing(): dump = { "interface": [ "wan", - {"interface": "wan", "data": "192.168.1.1"}, - {"interface": "wan", "data": {"ntpserver": ["192.168.1.1"]}}, + {"interface": "wan", "data": "192.0.2.1"}, + {"interface": "wan", "data": {"ntpserver": ["192.0.2.1"]}}, {"interface": "wan"}, - _interface("iot", "10.40.100.1"), + _interface("iot", "198.51.100.1"), ] } - assert _read(STOCK, dump)["dhcp_ntp_servers"] == ["10.40.100.1"] + assert _read(STOCK, dump)["dhcp_ntp_servers"] == ["198.51.100.1"] def test_dhcp_interface_names_the_interfaces_whose_leases_count(): show = STOCK + "system.ntp.dhcp_interface='iot'\n" dump = { "interface": [ - _interface("wan", "192.168.1.1"), - _interface("iot", "10.40.100.1"), + _interface("wan", "192.0.2.1"), + _interface("iot", "198.51.100.1"), ] } - assert _read(show, dump)["dhcp_ntp_servers"] == ["10.40.100.1"] + assert _read(show, dump)["dhcp_ntp_servers"] == ["198.51.100.1"] def test_use_dhcp_off_takes_nothing_from_a_lease(): @@ -442,11 +442,11 @@ def test_get_ntp_servers_of_a_disabled_client_is_empty(): def test_the_servers_replace_the_list_and_ntpd_restarts(): uci = _Uci(STOCK) - result = _driver(uci).configure_time_sync(ntp_servers=["10.0.0.1", "ntp.example.org"]) + result = _driver(uci).configure_time_sync(ntp_servers=["203.0.113.10", "ntp.example.org"]) assert result["success"] is True, result["output"] assert [s["step"] for s in result["steps"]] == ["ntp_servers", "verify"] - assert uci._section("ntp")["server"] == ["10.0.0.1", "ntp.example.org"] + assert uci._section("ntp")["server"] == ["203.0.113.10", "ntp.example.org"] (write,) = uci.writes() assert write.endswith( "uci commit system && /etc/init.d/sysntpd enable && /etc/init.d/sysntpd restart" @@ -457,7 +457,7 @@ def test_the_servers_replace_the_list_and_ntpd_restarts(): def test_writing_servers_leaves_the_ones_dhcp_brings(): # DHCP option 42 counts (NetOrk/netork#2380): sysntpd keeps adding a lease's servers. uci = _Uci(STOCK, dump=LEASE) - result = _driver(uci).configure_time_sync(ntp_servers=["10.0.0.1"]) + result = _driver(uci).configure_time_sync(ntp_servers=["203.0.113.10"]) assert result["success"] is True, result["output"] assert "use_dhcp" not in uci._section("ntp") @@ -466,7 +466,7 @@ def test_writing_servers_leaves_the_ones_dhcp_brings(): def test_writing_servers_keeps_use_dhcp_as_the_router_has_it(): uci = _Uci(STOCK + "system.ntp.use_dhcp='0'\n") - result = _driver(uci).configure_time_sync(ntp_servers=["10.0.0.1"]) + result = _driver(uci).configure_time_sync(ntp_servers=["203.0.113.10"]) assert result["success"] is True, result["output"] assert uci._section("ntp")["use_dhcp"] == "0" @@ -485,7 +485,7 @@ def test_the_same_servers_with_dhcp_on_write_nothing(): def test_writing_servers_enables_a_disabled_client(): uci = _Uci(STOCK.replace("system.ntp.enabled='1'", "system.ntp.enabled='0'")) - result = _driver(uci).configure_time_sync(ntp_servers=["10.0.0.1"]) + result = _driver(uci).configure_time_sync(ntp_servers=["203.0.113.10"]) assert result["success"] is True, result["output"] assert uci._section("ntp")["enabled"] == "1" @@ -494,7 +494,7 @@ def test_writing_servers_enables_a_disabled_client(): def test_a_missing_ntp_section_is_made(): uci = _Uci("system.@system[0]=system\nsystem.@system[0].timezone='UTC'\n") - result = _driver(uci).configure_time_sync(ntp_servers=["10.0.0.1"]) + result = _driver(uci).configure_time_sync(ntp_servers=["203.0.113.10"]) assert result["success"] is True, result["output"] assert ("ntp", "timeserver") in [(s[0], s[1]) for s in uci.sections] @@ -505,10 +505,10 @@ def test_the_same_servers_again_write_nothing(): # netOrk aligns on every poll: an aligned router must not restart ntpd each time. uci = _Uci(STOCK) drv = _driver(uci) - drv.configure_time_sync(ntp_servers=["10.0.0.1", "10.0.0.2"]) + drv.configure_time_sync(ntp_servers=["203.0.113.10", "203.0.113.11"]) uci.ran.clear() - result = drv.configure_time_sync(ntp_servers=["10.0.0.1", "10.0.0.2"]) + result = drv.configure_time_sync(ntp_servers=["203.0.113.10", "203.0.113.11"]) assert result["success"] is True assert uci.writes() == [] @@ -526,7 +526,7 @@ def test_the_same_servers_in_another_order_are_written(): def test_a_refused_uci_write_restarts_nothing(): uci = _Uci(STOCK, fail="uci commit system") - result = _driver(uci).configure_time_sync(ntp_servers=["10.0.0.1"]) + result = _driver(uci).configure_time_sync(ntp_servers=["203.0.113.10"]) assert result["success"] is False assert result["steps"][-1]["step"] == "ntp_servers" @@ -540,7 +540,7 @@ def test_a_login_other_than_root_writes_nothing(): drv._check_privilege(k.get("privileged", False)) or uci(c, **k) ) - result = drv.configure_time_sync(ntp_servers=["10.0.0.1"]) + result = drv.configure_time_sync(ntp_servers=["203.0.113.10"]) assert result["success"] is False assert "no sudo" in result["output"] @@ -621,7 +621,9 @@ def test_a_zone_twice_writes_once(): def test_both_values_in_one_run(): uci = _Uci(STOCK) - result = _driver(uci).configure_time_sync(ntp_servers=["10.0.0.1"], timezone="Europe/Berlin") + result = _driver(uci).configure_time_sync( + ntp_servers=["203.0.113.10"], timezone="Europe/Berlin" + ) assert result["success"] is True, result["output"] assert [s["step"] for s in result["steps"]] == ["ntp_servers", "timezone", "verify"] diff --git a/tests/unit/test_updates.py b/tests/unit/test_updates.py index 98d3558..66f67c0 100644 --- a/tests/unit/test_updates.py +++ b/tests/unit/test_updates.py @@ -37,7 +37,7 @@ OPKG_PENDING = "dnsmasq - 2.90-4 - 2.90-5\n" @pytest.fixture def driver(): with patch("napalm_openwrt.openwrt.ConnectHandler"): - drv = OpenWrtDriver(hostname="192.168.1.1", username="root", password="") + drv = OpenWrtDriver(hostname="192.0.2.1", username="root", password="") drv.device = MagicMock() yield drv