Permalink
Browse files

[OpenWrt] Ignore advanced wifi options if zero

  • Loading branch information...
nemesisdesign committed Mar 21, 2016
1 parent c8c95d6 commit a226e90d359060a2afda34748897a579a0c8e4bf
Showing with 46 additions and 3 deletions.
  1. +5 −2 netjsonconfig/backends/openwrt/renderers.py
  2. +1 −1 netjsonconfig/schema.py
  3. +40 −0 tests/openwrt/test_wireless.py
@@ -306,8 +306,11 @@ def _get_wifi_interfaces(self):
'frag_threshold': 'frag'
}
for netjson_key, uci_key in wifi_options.items():
if wireless.get(netjson_key) is not None:
uci_wifi[uci_key] = wireless[netjson_key]
value = wireless.get(netjson_key)
if value is not None:
# ignore if 0 (autogenerated UIs might use 0 as default value)
if value > 0:
uci_wifi[uci_key] = value
del uci_wifi[netjson_key]
# determine encryption for wifi
if uci_wifi.get('encryption'):
@@ -288,7 +288,7 @@
"ack_distance": {
"type": "integer",
"title": "ACK distance",
"minimum": 1,
"minimum": 0,
"propertyOrder": 10,
},
"rts_threshold": {
@@ -918,5 +918,45 @@ def test_wds_ap(self):
option network 'wlan0'
option ssid 'MyWdsAp'
option wds '1'
""")
self.assertEqual(o.render(), expected)
def test_wifi_options_zero(self):
"""
ensure ack_distance, rts_threshold and frag_threshold
are ignored if left empty
"""
o = OpenWrt({
"interfaces": [
{
"name": "wlan0",
"type": "wireless",
"wireless": {
"radio": "radio0",
"mode": "access_point",
"ssid": "MyWifiAP",
"wmm": True,
"ack_distance": 0,
"rts_threshold": 0,
"frag_threshold": 0
}
}
]
})
expected = self._tabs("""package network
config interface 'wlan0'
option ifname 'wlan0'
option proto 'none'
package wireless
config wifi-iface
option device 'radio0'
option ifname 'wlan0'
option mode 'ap'
option network 'wlan0'
option ssid 'MyWifiAP'
option wmm '1'
""")
self.assertEqual(o.render(), expected)

0 comments on commit a226e90

Please sign in to comment.