diff --git a/docs/source/backends/openwrt.rst b/docs/source/backends/openwrt.rst index dc332f735..9aa2ed786 100644 --- a/docs/source/backends/openwrt.rst +++ b/docs/source/backends/openwrt.rst @@ -407,7 +407,7 @@ Will be rendered as follows: package network config interface 'lo' - option ifname 'lo' + option device 'lo' option ipaddr '127.0.0.1' option netmask '255.0.0.0' option proto 'static' @@ -449,7 +449,7 @@ Will be rendered as follows: package network config interface 'eth0' - option ifname 'eth0' + option device 'eth0' option ip6addr 'fdb4:5f35:e8fd::1/48' option ipaddr '10.27.251.1' option netmask '255.255.255.0' @@ -506,18 +506,18 @@ Will return the following UCI output: config interface 'eth0' option dns '10.11.12.13 8.8.8.8' option dns_search 'openwisp.org netjson.org' - option ifname 'eth0' + option device 'eth0' option ipaddr '192.168.1.1' option netmask '255.255.255.0' option proto 'static' config interface 'eth1' option dns_search 'openwisp.org netjson.org' - option ifname 'eth1' + option device 'eth1' option proto 'dhcp' config interface 'eth1_31' - option ifname 'eth1.31' + option device 'eth1.31' option proto 'none' DHCP ipv6 ethernet interface @@ -545,14 +545,14 @@ Will be rendered as follows: package network config interface 'lan' - option ifname 'eth0' + option device 'eth0' option proto 'dchpv6' Using different protocols ~~~~~~~~~~~~~~~~~~~~~~~~~ -OpenWRT and LEDE support many protocols (pppoe, pppoa, pptp, l2tp, ecc) -and the list of supported protocols evolves over time. +OpenWRT supports many protocols (pppoe, pppoa, pptp, l2tp, ecc) and the +list of supported protocols evolves over time. OpenWISP and netjsonconfig try to stay out of your way by leaving you maximum flexibility to use any protocol and any configuration option you @@ -680,11 +680,11 @@ Will be rendered as follows: package network config interface 'lan' - option ifname 'eth0.1' + option device 'eth0.1' option proto 'none' config interface 'wan' - option ifname 'eth0.2' + option device 'eth0.2' option proto 'none' config device 'device_br_lan' @@ -697,13 +697,9 @@ Will be rendered as follows: config interface 'br_lan' option device 'br-lan' - option ifname 'eth0.1 eth0.2' - option igmp_snooping '1' option ipaddr '172.17.0.2' option netmask '255.255.255.0' option proto 'static' - option stp '1' - option type 'bridge' Wireless settings ----------------- @@ -828,12 +824,6 @@ UCI output: :: - package network - - config interface 'wlan0' - option ifname 'wlan0' - option proto 'none' - package wireless config wifi-iface 'wifi_wlan0' @@ -841,7 +831,6 @@ UCI output: option ifname 'wlan0' option isolate '1' option mode 'ap' - option network 'wlan0' option ssid 'myWiFi' option wmm '1' @@ -892,23 +881,18 @@ Will be rendered as follows: package network config interface 'eth0' - option ifname 'eth0' - option proto 'none' - - config interface 'wlan0' - option ifname 'wlan0' + option device 'eth0' option proto 'none' config device 'device_lan' - option name 'lan' + option name 'br-lan' list ports 'eth0' list ports 'wlan0' option type 'bridge' config interface 'lan' - option ifname 'eth0 wlan0' + option device 'br-lan' option proto 'dhcp' - option type 'bridge' package wireless @@ -952,12 +936,6 @@ UCI output: :: - package network - - config interface 'wlan0' - option ifname 'wlan0' - option proto 'none' - package wireless config wifi-iface 'wifi_wlan0' @@ -967,7 +945,6 @@ UCI output: list maclist 'E8:94:F6:33:8C:1D' list maclist '42:6c:8f:95:0f:00' option mode 'ap' - option network 'wlan0' option ssid 'MyWifiAP' Wireless access point with roaming (802.11r) @@ -1007,12 +984,6 @@ UCI output: :: - package network - - config interface 'wlan0' - option ifname 'wlan0' - option proto 'none' - package wireless config wifi-iface 'wifi_wlan0' @@ -1077,25 +1048,20 @@ UCI output: package network config interface 'eth0' - option ifname 'eth0' - option proto 'none' - - config interface 'mesh0' - option ifname 'mesh0' + option device 'eth0' option proto 'none' config device 'device_lan' - option name 'lan' + option name 'br-lan' list ports 'eth0' list ports 'mesh0' option type 'bridge' config interface 'lan' - option ifname 'eth0 mesh0' + option device 'br-lan' option ipaddr '192.168.0.1' option netmask '255.255.255.0' option proto 'static' - option type 'bridge' package wireless @@ -1134,12 +1100,6 @@ Will result in: :: - package network - - config interface 'wlan0' - option ifname 'wlan0' - option proto 'none' - package wireless config wifi-iface 'wifi_wlan0' @@ -1147,7 +1107,6 @@ Will result in: option device 'radio0' option ifname 'wlan0' option mode 'adhoc' - option network 'wlan0' option ssid 'freifunk' WDS repeater example @@ -1204,14 +1163,6 @@ Will result in: package network - config interface 'wlan0' - option ifname 'wlan0' - option proto 'none' - - config interface 'wlan1' - option ifname 'wlan1' - option proto 'none' - config device 'device_wds_bridge' option name 'br-wds' list ports 'wlan0' @@ -1219,9 +1170,8 @@ Will result in: option type 'bridge' config interface 'wds_bridge' - option ifname 'wlan0 wlan1' + option device 'br-wds' option proto 'dhcp' - option type 'bridge' package wireless @@ -1274,12 +1224,6 @@ UCI output: :: - package network - - config interface 'wlan0' - option ifname 'wlan0' - option proto 'none' - package wireless config wifi-iface 'wifi_wlan0' @@ -1288,7 +1232,6 @@ UCI output: option ifname 'wlan0' option key 'passphrase012345' option mode 'ap' - option network 'wlan0' option ssid 'wpa2-personal' WPA2 Enterprise (802.1x) ap @@ -1328,24 +1271,21 @@ UCI Output: :: - package network - - config interface 'wlan0' - option ifname 'wlan0' - option proto 'none' - package wireless config wifi-iface 'wifi_wlan0' option acct_port '1813' + option acct_secret 'radius_secret' option acct_server '192.168.0.2' + option auth_port '1812' + option auth_secret 'radius_secret' + option auth_server '192.168.0.1' option device 'radio0' option encryption 'wpa2' option ifname 'wlan0' option key 'radius_secret' option mode 'ap' option nasid 'hostname' - option network 'wlan0' option port '1812' option server '192.168.0.1' option ssid 'eduroam' @@ -1383,12 +1323,6 @@ UCI Output: :: - package network - - config interface 'wlan0' - option ifname 'wlan0' - option proto 'none' - package wireless config wifi-iface 'wifi_wlan0' @@ -1399,7 +1333,6 @@ UCI Output: option identity 'test-identity' option ifname 'wlan0' option mode 'sta' - option network 'wlan0' option password 'test-password' option ssid 'enterprise-client' @@ -1437,12 +1370,6 @@ UCI output: :: - package network - - config interface `'wlan0' - option ifname 'wlan0' - option proto 'none' - package wireless config wifi-iface 'wifi_wlan0' @@ -1452,10 +1379,9 @@ UCI output: option ifname 'wlan0' option key 'passphrase012345' option mode 'ap' - option network 'wlan0' option ssid 'wpa3-personal' -WPA3 Enterprise (802.1x) ap +WPA3 Enterprise (802.1x) AP ~~~~~~~~~~~~~~~~~~~~~~~~~~~ The following example shows a typical wireless access point using *WPA3 @@ -1494,17 +1420,15 @@ UCI Output: :: - package network - - config interface 'wlan0' - option ifname 'wlan0' - option proto 'none' - package wireless config wifi-iface 'wifi_wlan0' option acct_port '1813' + option acct_secret 'radius_secret' option acct_server '192.168.0.2' + option auth_port '1812' + option auth_secret 'radius_secret' + option auth_server '192.168.0.1' option device 'radio0' option encryption 'wpa3+ccmp' option ieee80211w '2' @@ -1512,7 +1436,6 @@ UCI Output: option key 'radius_secret' option mode 'ap' option nasid 'hostname' - option network 'wlan0' option port '1812' option server '192.168.0.1' option ssid 'eduroam' @@ -1552,12 +1475,6 @@ UCI Output: :: - package network - - config interface 'wlan0' - option ifname 'wlan0' - option proto 'none' - package wireless config wifi-iface 'wifi_wlan0' @@ -1569,7 +1486,6 @@ UCI Output: option ieee80211w '2' option ifname 'wlan0' option mode 'sta' - option network 'wlan0' option password 'test-password' option ssid 'enterprise-client' @@ -1604,26 +1520,19 @@ UCI Output: :: - package network - - config interface 'wlan0' - option ifname 'wlan0' - option proto 'none' - package wireless config wifi-iface 'wifi_wlan0' - option auth 'MSCHAPV2' - option bssid '00:26:b9:20:5f:09' - option device 'radio0' - option eap_type 'ttls' - option encryption 'wpa2' - option identity 'test-identity' - option ifname 'wlan0' - option mode 'sta' - option network 'wlan0' - option password 'test-password' - option ssid 'enterprise-client' + option auth 'MSCHAPV2' + option bssid '00:26:b9:20:5f:09' + option device 'radio0' + option eap_type 'ttls' + option encryption 'wpa2' + option identity 'test-identity' + option ifname 'wlan0' + option mode 'sta' + option password 'test-password' + option ssid 'enterprise-client' *WPA2 Enterprise (802.1x)* client with EAP-PEAP example: @@ -1656,26 +1565,19 @@ UCI Output: :: - package network - - config interface 'wlan0' - option ifname 'wlan0' - option proto 'none' - package wireless config wifi-iface 'wifi_wlan0' - option auth 'EAP-MSCHAPV2' - option bssid '00:26:b9:20:5f:09' - option device 'radio0' - option eap_type 'peap' - option encryption 'wpa2' - option identity 'test-identity' - option ifname 'wlan0' - option mode 'sta' - option network 'wlan0' - option password 'test-password' - option ssid 'enterprise-client' + option auth 'EAP-MSCHAPV2' + option bssid '00:26:b9:20:5f:09' + option device 'radio0' + option eap_type 'peap' + option encryption 'wpa2' + option identity 'test-identity' + option ifname 'wlan0' + option mode 'sta' + option password 'test-password' + option ssid 'enterprise-client' Dialup settings --------------- @@ -1707,6 +1609,7 @@ The following *configuration dictionary*: { "name": "dsl0", "network": "xdsl", + "type": "dialup", "proto": "pppoe", "password": "jf93nf82o023$", "username": "dsluser", @@ -1723,10 +1626,10 @@ Will be rendered as follows: config interface 'xdsl' option ifname 'dsl0' + option mtu '1448' + option password 'jf93nf82o023$' option proto 'pppoe' option username 'dsluser' - option password 'jf93nf82o023$' - option mtu '1448' Modem Manager settings ---------------------- @@ -1867,20 +1770,19 @@ Will be rendered as follows: package wireless config wifi-device 'radio0' + option band '2g' option channel '11' option country 'IT' option htmode 'HT20' - option band '2g' option phy 'phy0' option txpower '5' option type 'mac80211' config wifi-device 'radio1' + option band '5g' option channel '36' option country 'IT' - option disabled '0' option htmode 'HT20' - option band '5g' option phy 'phy1' option txpower '4' option type 'mac80211' @@ -1931,16 +1833,16 @@ UCI output: package wireless config wifi-device 'radio0' + option band '2g' option channel 'auto' option htmode 'HT20' - option band '2g' option phy 'phy0' option type 'mac80211' config wifi-device 'radio1' + option band '5g' option channel 'auto' option htmode 'VHT80' - option band '5g' option phy 'phy1' option type 'mac80211' @@ -1972,9 +1874,9 @@ UCI output: package wireless config wifi-device 'radio0' + option band '5g' option channel '36' option htmode 'VHT80' - option band '5g' option phy 'phy0' option type 'mac80211' @@ -2006,9 +1908,9 @@ UCI output: package wireless config wifi-device 'radio0' + option band '5g' option channel '36' option htmode 'HE80' - option band '5g' option phy 'phy0' option type 'mac80211' diff --git a/netjsonconfig/backends/openwrt/converters/interfaces.py b/netjsonconfig/backends/openwrt/converters/interfaces.py index 6f1a838cc..f3f6ebd02 100644 --- a/netjsonconfig/backends/openwrt/converters/interfaces.py +++ b/netjsonconfig/backends/openwrt/converters/interfaces.py @@ -28,7 +28,7 @@ class Interfaces(OpenWrtConverter): 'hash_max', 'robustness', ], - 'all': ['vlan_filtering', 'macaddr'], + 'all': ['vlan_filtering', 'macaddr', 'mtu'], } _device_config = {} _custom_protocols = ['ppp'] @@ -57,7 +57,7 @@ def to_intermediate_loop(self, block, result, index=None): interface = self.__intermediate_interface(block, uci_name) self.__set_dsa_interface(interface) if self.dsa_interface: - uci_device = self.__intermediate_device(interface) + uci_device = self.__intermediate_device(interface, address_list) if uci_device: result.setdefault('network', []) result['network'].append(self.sorted_dict(uci_device)) @@ -176,7 +176,7 @@ def __intermediate_interface(self, interface, uci_name): if 'addresses' in interface: del interface['addresses'] # specific transformation - type_ = self._get_uci_name(interface["type"]) + type_ = self._get_uci_name(interface['type']) method = getattr(self, f'_intermediate_{type_}', None) if method: interface = method(interface) @@ -210,31 +210,30 @@ def __intermediate_address(self, address): del address[key] return address - def __intermediate_device(self, interface): + def __intermediate_device(self, interface, address_list): """ Converts NetJSON bridge to intermediate data structure compatible with new syntax introduced in OpenWrt 21.02. """ device = {} - # ignore wireless interfaces - if interface['type'] == 'wireless': - return device # Add L2 options (needed for > OpenWrt 21.02) self._add_l2_options(device, interface) - device.update( - { - '.type': 'device', - '.name': 'device_{}'.format(interface['.name']), - 'name': interface['ifname'], - } - ) + base = { + '.type': 'device', + '.name': 'device_{}'.format(interface['.name']), + 'name': interface['ifname'], + } + device.update(base) + # Add 'device' option in related interface configuration if not interface.get('device', None): interface['device'] = device['name'] if interface['type'] != 'bridge': # A non-bridge interface that contains L2 options. + if device == base: + return {} return device device['type'] = 'bridge' if not interface['ifname'].startswith('br-'): @@ -486,13 +485,20 @@ def __netjson_dsa_interface(self, interface): else: interface[option] = device_config[option] # Merging L2 options to interface - for options in ( + for option in ( self._bridge_interface_options['all'] + self._bridge_interface_options['stp'] + self._bridge_interface_options['igmp_snooping'] ): - if options in device_config: - interface[options] = device_config.pop(options) + if option in device_config: + interface[option] = device_config.pop(option) + # if device_config is empty but the interface references it + elif 'device' in interface and 'ifname' not in interface: + # .name may have '.' substituted with _, + # which will yield unexpected results + # for this reason we use the name stored + # in the device property before removing it + interface['ifname'] = interface.pop('device') return interface def __netjson_device(self, interface): diff --git a/netjsonconfig/backends/openwrt/converters/wireless.py b/netjsonconfig/backends/openwrt/converters/wireless.py index 17cae4bcd..6609861ed 100644 --- a/netjsonconfig/backends/openwrt/converters/wireless.py +++ b/netjsonconfig/backends/openwrt/converters/wireless.py @@ -63,25 +63,35 @@ def __intermediate_wireless(self, interface): encryption = self.__intermediate_encryption(wireless) wireless.update(encryption) wireless = self.__intermediate_roaming(wireless) + wireless = self.__intermediate_auto_network(wireless, interface) + wireless['network'] = ( + ' '.join(wireless['network']).replace('.', '_').replace('-', '_') + ) + return self.sorted_dict(wireless) + + def __intermediate_auto_network(self, wireless, interface): # attached networks (openwrt specific) # by default the wifi interface is attached # to its defining interface # but this behaviour can be overridden - if not wireless.get('network'): - # try to automatically determine whether - # we should attach this interface to a bridge - try: - bridges = self._bridged_wifi[interface['name']] - except KeyError: + if wireless.get('network'): + return wireless + # try to automatically determine whether + # we should attach this interface to a bridge + try: + bridges = self._bridged_wifi[interface['name']] + except KeyError: + # if interface has any address specified, + # we need to attach it in the OpenWrt config + if interface.get('addresses', []): + network = [interface['name']] + else: # don't bridge to anything unless explicitly specified network = [] - else: - network = bridges - wireless['network'] = network - wireless['network'] = ( - ' '.join(wireless['network']).replace('.', '_').replace('-', '_') - ) - return self.sorted_dict(wireless) + else: + network = bridges + wireless['network'] = network + return wireless def __get_auto_name(self, interface): wifi_name = self._get_uci_name(interface['name']) @@ -295,7 +305,8 @@ def __netjson_encryption(self, wifi): # noqa: C901 wps = False # move encryption keys for key in self._encryption_keys: - if key in wifi: + value = wifi.get(key, None) + if key in wifi and value: settings[key] = wifi.pop(key) if key.startswith('wps_'): wps = True diff --git a/tests/openwrt/test_backend.py b/tests/openwrt/test_backend.py index 4562b7ae7..4dde116c7 100644 --- a/tests/openwrt/test_backend.py +++ b/tests/openwrt/test_backend.py @@ -157,6 +157,7 @@ def test_generate(self): contents = tar.extractfile(network).read().decode() expected = self._tabs( """config interface 'wlan0' + option device 'wlan0' option ipaddr '192.168.1.1' option netmask '255.255.255.0' option proto 'static' @@ -181,6 +182,7 @@ def test_generate(self): option hidden '1' option ifname 'wlan0' option mode 'ap' + option network 'wlan0' option ssid 'MyWifiAP' """ ) diff --git a/tests/openwrt/test_interfaces_dsa.py b/tests/openwrt/test_interfaces_dsa.py index 05373f905..427167267 100644 --- a/tests/openwrt/test_interfaces_dsa.py +++ b/tests/openwrt/test_interfaces_dsa.py @@ -31,9 +31,6 @@ def test_render_loopback(self): expected = self._tabs( """package network -config device 'device_lo' - option name 'lo' - config interface 'lo' option device 'lo' option ipaddr '127.0.0.1' @@ -335,9 +332,6 @@ def test_parse_ipv4_list(self): _multi_ip_uci = """package network -config device 'device_eth0_1' - option name 'eth0.1' - config interface 'eth0_1' option auto '1' option device 'eth0.1' @@ -381,9 +375,6 @@ def test_render_single_ipv6(self): expected = self._tabs( """package network -config device 'device_eth0' - option name 'eth0' - config interface 'eth0' option device 'eth0' option ip6addr 'fd87::2/64' @@ -407,9 +398,6 @@ def test_render_dhcp(self): expected = self._tabs( """package network -config device 'device_eth0' - option name 'eth0' - config interface 'eth0' option device 'eth0' option proto 'dhcp' @@ -418,12 +406,20 @@ def test_render_dhcp(self): self.assertEqual(o.render(), expected) def test_parse_dhcp(self): - native = self._tabs( + native1 = self._tabs( """package network config device 'device_eth0' option name 'eth0' +config interface 'eth0' + option device 'eth0' + option proto 'dhcp' +""" + ) + native2 = self._tabs( + """package network + config interface 'eth0' option device 'eth0' option proto 'dhcp' @@ -438,7 +434,9 @@ def test_parse_dhcp(self): } ] } - o = OpenWrt(native=native) + o = OpenWrt(native=native1) + self.assertEqual(o.config, expected) + o = OpenWrt(native=native2) self.assertEqual(o.config, expected) def test_parse_dhcpv6(self): @@ -483,9 +481,6 @@ def test_render_multiple_dhcp(self): expected = self._tabs( """package network -config device 'device_eth0' - option name 'eth0' - config interface 'eth0' option device 'eth0' option proto 'dhcp' @@ -560,9 +555,6 @@ def test_render_multiple_ip_and_dhcp(self): expected = self._tabs( """package network -config device 'device_eth0' - option name 'eth0' - config interface 'eth0' option device 'eth0' list ipaddr '192.168.1.1/24' @@ -691,9 +683,6 @@ def test_render_interface_disabled(self): expected = self._tabs( """package network -config device 'device_eth0' - option name 'eth0' - config interface 'eth0' option device 'eth0' option enabled '0' @@ -791,16 +780,10 @@ def test_parse_interface_custom_attrs(self): } _simple_bridge_uci = """package network -config device 'device_eth0' - option name 'eth0' - config interface 'eth0' option device 'eth0' option proto 'none' -config device 'device_eth1' - option name 'eth1' - config interface 'eth1' option device 'eth1' option proto 'none' @@ -859,16 +842,10 @@ def test_parse_simple_bridge(self): _complex_bridge_uci = """package network -config device 'device_eth0' - option name 'eth0' - config interface 'eth0' option device 'eth0' option proto 'none' -config device 'device_eth1' - option name 'eth1' - config interface 'eth1' option device 'eth1' option proto 'none' @@ -1013,12 +990,6 @@ def test_bridge_members_unique(self): _bridge_21_bridge_uci = """package network -config device 'device_eth0' - option name 'eth0' - -config device 'device_eth1' - option name 'eth1' - config interface 'eth0' option device 'eth0' option proto 'none' @@ -1069,16 +1040,10 @@ def test_parse_bridge_21(self): } _l2_options_bridge_uci = """package network -config device 'device_eth0' - option name 'eth0' - config interface 'eth0' option device 'eth0' option proto 'none' -config device 'device_eth1' - option name 'eth1' - config interface 'eth1' option device 'eth1' option proto 'none' @@ -1169,9 +1134,6 @@ def test_render_dns(self): expected = self._tabs( """package network -config device 'device_eth0' - option name 'eth0' - config interface 'eth0' option device 'eth0' option dns '10.11.12.13 8.8.8.8' @@ -1206,9 +1168,6 @@ def test_parse_dns(self): native = self._tabs( """package network -config device 'device_eth0' - option name 'eth0' - config interface 'eth0' option dns '10.11.12.13 8.8.8.8' option dns_search 'netjson.org openwisp.org' @@ -1259,9 +1218,6 @@ def test_dns_dhcpv4_ignored(self): expected = self._tabs( """package network -config device 'device_eth0' - option name 'eth0' - config interface 'eth0' option device 'eth0' option dns_search 'netjson.org openwisp.org' @@ -1287,9 +1243,6 @@ def test_dns_dhcpv6_ignored(self): expected = self._tabs( """package network -config device 'device_eth0' - option name 'eth0' - config interface 'eth0' option device 'eth0' option dns_search 'netjson.org openwisp.org' @@ -1309,9 +1262,6 @@ def test_dhcp_ignored_proto_none(self): expected = self._tabs( """package network -config device 'device_eth0' - option name 'eth0' - config interface 'eth0' option device 'eth0' option proto 'none' @@ -1324,9 +1274,6 @@ def test_empty_interface(self): expected = self._tabs( """package network -config device 'device_eth0' - option name 'eth0' - config interface 'eth0' option device 'eth0' option proto 'none' @@ -1405,9 +1352,6 @@ def test_render_network_attribute(self): expected = self._tabs( """package network -config device 'device_lan' - option name 'eth0' - config interface 'lan' option device 'eth0' option ipaddr '192.168.1.1' @@ -1446,9 +1390,6 @@ def test_network_dot_conversion(self): expected = self._tabs( """package network -config device 'device_lan_1' - option name 'eth0.1' - config interface 'lan_1' option device 'eth0.1' option proto 'none' @@ -1463,9 +1404,6 @@ def test_network_dash_conversion(self): expected = self._tabs( """package network -config device 'device_lan_0' - option name 'eth-0' - config interface 'lan_0' option device 'eth-0' option proto 'none' @@ -1545,9 +1483,6 @@ def test_render_interface_list_option(self): expected = self._tabs( """package network -config device 'device_eth0' - option name 'eth0' - config interface 'eth0' option device 'eth0' list ip6class 'wan6' @@ -1574,9 +1509,6 @@ def test_render_address_list_option(self): expected = self._tabs( """package network -config device 'device_eth0' - option name 'eth0' - config interface 'eth0' option device 'eth0' option proto 'dhcp' @@ -1620,9 +1552,6 @@ def test_dns_override(self): expected = self._tabs( """package network -config device 'device_eth0' - option name 'eth0' - config interface 'eth0' option device 'eth0' list dns '8.8.8.8' @@ -1648,9 +1577,6 @@ def test_dns_search_override(self): expected = self._tabs( """package network -config device 'device_eth0' - option name 'eth0' - config interface 'eth0' option device 'eth0' list dns_search 'openwisp.org' @@ -1787,9 +1713,6 @@ def test_render_autostart_false(self): expected = self._tabs( """package network -config device 'device_eth0' - option name 'eth0' - config interface 'eth0' option auto '0' option device 'eth0' @@ -1802,9 +1725,6 @@ def test_parse_autostart_false(self): native = self._tabs( """package network -config device 'device_eth0' - option name 'eth0' - config interface 'eth0' option auto '0' option device 'eth0' @@ -1877,9 +1797,6 @@ def test_empty_network(self): expected = self._tabs( """package network -config device 'device_eth0' - option name 'eth0' - config interface 'eth0' option device 'eth0' option proto 'none' @@ -1898,9 +1815,6 @@ def test_empty_dns(self): expected = self._tabs( """package network -config device 'device_eth0' - option name 'eth0' - config interface 'eth0' option device 'eth0' option proto 'none' diff --git a/tests/openwrt/test_wireless.py b/tests/openwrt/test_wireless.py index 0943dc3a7..a3039a49f 100644 --- a/tests/openwrt/test_wireless.py +++ b/tests/openwrt/test_wireless.py @@ -38,6 +38,7 @@ class TestWireless(unittest.TestCase, _TabsMixin): _wifi_uci = """package network config interface 'wlan0' + option device 'wlan0' option ipaddr '192.168.1.1' option netmask '255.255.255.0' option proto 'static' @@ -52,6 +53,7 @@ class TestWireless(unittest.TestCase, _TabsMixin): option ifname 'wlan0' option isolate '1' option mode 'ap' + option network 'wlan0' option rts '1300' option ssid 'MyWifiAP' """ @@ -123,9 +125,11 @@ def test_parse_wifi_interface_partial(self): _multiple_wifi_uci = """package network config interface 'wlan0' + option device 'wlan0' option proto 'dhcp' config interface 'wlan1' + option device 'wlan1' option proto 'dhcp' package wireless @@ -134,6 +138,7 @@ def test_parse_wifi_interface_partial(self): option device 'radio0' option ifname 'wlan0' option mode 'ap' + option network 'wlan0' option ssid 'ap-ssid' config wifi-iface 'wifi_wlan1' @@ -141,6 +146,7 @@ def test_parse_wifi_interface_partial(self): option device 'radio1' option ifname 'wlan1' option mode 'adhoc' + option network 'wlan1' option ssid 'adhoc-ssid' """ @@ -178,9 +184,6 @@ def test_parse_multiple_wifi(self): } _wifi_bridge_uci = """package network -config device 'device_eth0_1' - option name 'eth0.1' - config interface 'eth0_1' option device 'eth0.1' option proto 'none' @@ -234,6 +237,7 @@ def test_parse_wifi_bridge(self): _wifi_networks_uci = """package network config interface 'wsta0' + option device 'wsta0' option proto 'dhcp' package wireless @@ -242,6 +246,7 @@ def test_parse_wifi_bridge(self): option device 'radio0' option ifname 'wsta0' option mode 'sta' + option network 'wsta0' option ssid 'open' option wds '0' """ @@ -1167,3 +1172,101 @@ def test_render_wireless_only(self): def test_parse_wireless_only(self): o = OpenWrt(native=self._wireless_only_uci) self.assertDictEqual(o.config, self._wireless_only_netjson) + + _sta_in_dhcp_client_json = { + "interfaces": [ + { + "name": "wwan", + "type": "wireless", + "mac": "00:11:22:33:44:55", + "mtu": 1500, + "addresses": [{"proto": "dhcp", "family": "ipv4"}], + "wireless": { + "mode": "station", + "radio": "radio1", + "ssid": "SSID", + "wds": False, + "encryption": { + "cipher": "auto", + "ieee80211w": "1", + "protocol": "wpa2_enterprise", + "eap_type": "ttls", + "auth": "PAP", + "identity": "username", + "password": "password123", + }, + }, + } + ] + } + _sta_in_dhcp_client_uci = """package network + +config device 'device_wwan' + option mtu '1500' + option name 'wwan' + +config interface 'wwan' + option device 'wwan' + option proto 'dhcp' + +package wireless + +config wifi-iface 'wifi_wwan' + option auth 'PAP' + option device 'radio1' + option eap_type 'ttls' + option encryption 'wpa2' + option identity 'username' + option ieee80211w '1' + option ifname 'wwan' + option macaddr '00:11:22:33:44:55' + option mode 'sta' + option network 'wwan' + option password 'password123' + option ssid 'SSID' + option wds '0' +""" + + _sta_in_dhcp_client_no_mtu_json = deepcopy(_sta_in_dhcp_client_json) + del _sta_in_dhcp_client_no_mtu_json['interfaces'][0]['mtu'] + _sta_in_dhcp_client_no_mtu_uci = """package network + +config interface 'wwan' + option device 'wwan' + option proto 'dhcp' + +package wireless + +config wifi-iface 'wifi_wwan' + option auth 'PAP' + option device 'radio1' + option eap_type 'ttls' + option encryption 'wpa2' + option identity 'username' + option ieee80211w '1' + option ifname 'wwan' + option macaddr '00:11:22:33:44:55' + option mode 'sta' + option network 'wwan' + option password 'password123' + option ssid 'SSID' + option wds '0' +""" + + def test_render_sta_in_dhcp_client(self): + o = OpenWrt(self._sta_in_dhcp_client_json) + expected = self._tabs(self._sta_in_dhcp_client_uci) + self.assertEqual(o.render(), expected) + + def test_parse_sta_in_dhcp_client(self): + o = OpenWrt(native=self._sta_in_dhcp_client_uci) + self.assertDictEqual(o.config, self._sta_in_dhcp_client_json) + + def test_render_sta_in_dhcp_client_no_mtu(self): + o = OpenWrt(self._sta_in_dhcp_client_no_mtu_json) + expected = self._tabs(self._sta_in_dhcp_client_no_mtu_uci) + self.assertEqual(o.render(), expected) + + def test_parse_sta_in_dhcp_client_no_mtu(self): + o = OpenWrt(native=self._sta_in_dhcp_client_no_mtu_uci) + self.assertDictEqual(o.config, self._sta_in_dhcp_client_no_mtu_json) diff --git a/tests/openwrt/test_wireless_legacy.py b/tests/openwrt/test_wireless_legacy.py index d93f1a0b1..42acf637a 100644 --- a/tests/openwrt/test_wireless_legacy.py +++ b/tests/openwrt/test_wireless_legacy.py @@ -51,6 +51,7 @@ class TestWireless(unittest.TestCase, _TabsMixin): option hidden '1' option ifname 'wlan0' option mode 'ap' + option network 'wlan0' option rts '1300' option ssid 'MyWifiAP' """ @@ -132,6 +133,7 @@ def test_parse_wifi_interface_partial(self): option device 'radio0' option ifname 'wlan0' option mode 'ap' + option network 'wlan0' option ssid 'ap-ssid' config wifi-iface 'wifi_wlan1' @@ -139,6 +141,7 @@ def test_parse_wifi_interface_partial(self): option device 'radio1' option ifname 'wlan1' option mode 'adhoc' + option network 'wlan1' option ssid 'adhoc-ssid' """