Skip to content

Commit

Permalink
[openwrt] Radio driver now defaults to mac80211 #73
Browse files Browse the repository at this point in the history
Radio driver has a default value and is not required anymore.
  • Loading branch information
nemesifier committed May 23, 2017
1 parent 52486da commit cec9dcd
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 22 deletions.
6 changes: 3 additions & 3 deletions netjsonconfig/backends/openwrt/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from ...utils import sorted_dict
from ..base import BaseRenderer
from ..openvpn.renderers import OpenVpnRenderer as BaseOpenVpnRenderer
from .schema import default_radio_driver
from .timezones import timezones


Expand Down Expand Up @@ -302,16 +303,15 @@ def _get_radios(self):
uci_radio['txpower'] = radio['tx_power']
del uci_radio['tx_power']
# rename driver to type
uci_radio['type'] = radio['driver']
del uci_radio['driver']
uci_radio['type'] = uci_radio.pop('driver', default_radio_driver)
# determine hwmode option
uci_radio['hwmode'] = self.__get_hwmode(radio)
del uci_radio['protocol']
# check if using channel 0, that means "auto"
if uci_radio['channel'] is 0:
uci_radio['channel'] = 'auto'
# determine channel width
if radio['driver'] == 'mac80211':
if uci_radio['type'] == 'mac80211':
uci_radio['htmode'] = self.__get_htmode(radio)
del uci_radio['channel_width']
# ensure country is uppercase
Expand Down
6 changes: 5 additions & 1 deletion netjsonconfig/backends/openwrt/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
from ..openvpn.schema import base_openvpn_schema
from .timezones import timezones


default_radio_driver = "mac80211"


schema = merge_config(default_schema, {
"definitions": {
"interface_settings": {
Expand Down Expand Up @@ -113,7 +117,6 @@
]
},
"base_radio_settings": {
"required": ["driver"],
"properties": {
"driver": {
"type": "string",
Expand All @@ -124,6 +127,7 @@
"ath9k",
"broadcom"
],
"default": default_radio_driver,
"propertyOrder": 2,
}
}
Expand Down
18 changes: 0 additions & 18 deletions tests/openwrt/test_netjson.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import unittest
from urllib.request import urlopen

from netjsonconfig import OpenWrt

Expand All @@ -24,23 +23,6 @@
"revision": "r43321",
"description": "OpenWrt Barrier Breaker 14.07"
},
"resources": {
"memory": {
"total": 67108864
},
"swap": {
"total": 0
},
"cpu": {
"frequency": 400000000
},
"flash": {
"total": 8388608
},
"storage": {
"total": None
}
},
"radios": [
{
"name": "radio0",
Expand Down
29 changes: 29 additions & 0 deletions tests/openwrt/test_radio.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,5 +380,34 @@ def test_htmode_override(self):
option hwmode '11a'
option phy 'phy0'
option type 'mac80211'
""")
self.assertEqual(o.render(), expected)

def test_default_driver(self):
o = OpenWrt({
"radios": [
{
"name": "radio0",
"protocol": "802.11ac",
"channel": 1,
"channel_width": 80,
"phy": "phy0",
"country": "US",
"tx_power": 10,
"disabled": False,
}
]
})
expected = self._tabs("""package wireless
config wifi-device 'radio0'
option channel '1'
option country 'US'
option disabled '0'
option htmode 'VHT80'
option hwmode '11g'
option phy 'phy0'
option txpower '10'
option type 'mac80211'
""")
self.assertEqual(o.render(), expected)

0 comments on commit cec9dcd

Please sign in to comment.