diff --git a/netjsonconfig/backends/openwrt/renderers.py b/netjsonconfig/backends/openwrt/renderers.py index 25a25c111..453b8aeb6 100644 --- a/netjsonconfig/backends/openwrt/renderers.py +++ b/netjsonconfig/backends/openwrt/renderers.py @@ -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 @@ -302,8 +303,7 @@ 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'] @@ -311,7 +311,7 @@ def _get_radios(self): 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 diff --git a/netjsonconfig/backends/openwrt/schema.py b/netjsonconfig/backends/openwrt/schema.py index 3ad9ebd01..8a5da976f 100644 --- a/netjsonconfig/backends/openwrt/schema.py +++ b/netjsonconfig/backends/openwrt/schema.py @@ -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": { @@ -113,7 +117,6 @@ ] }, "base_radio_settings": { - "required": ["driver"], "properties": { "driver": { "type": "string", @@ -124,6 +127,7 @@ "ath9k", "broadcom" ], + "default": default_radio_driver, "propertyOrder": 2, } } diff --git a/tests/openwrt/test_netjson.py b/tests/openwrt/test_netjson.py index 957d3c744..be46a83b8 100644 --- a/tests/openwrt/test_netjson.py +++ b/tests/openwrt/test_netjson.py @@ -1,5 +1,4 @@ import unittest -from urllib.request import urlopen from netjsonconfig import OpenWrt diff --git a/tests/openwrt/test_radio.py b/tests/openwrt/test_radio.py index 6e6a4c331..7e338108a 100644 --- a/tests/openwrt/test_radio.py +++ b/tests/openwrt/test_radio.py @@ -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)