Skip to content

Commit

Permalink
Added driver and protocol in OpenWRT JSON Schema
Browse files Browse the repository at this point in the history
  • Loading branch information
nemesifier committed Sep 17, 2015
1 parent cd63861 commit 8a112e2
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
33 changes: 33 additions & 0 deletions netjsonconfig/backends/openwrt/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,43 @@
from netjsonconfig.schema import schema as default_schema

schema = default_schema.copy()

# add timezone to general
schema['properties']['general']['properties'].update({
"timezone": {
"id": "timezone",
"type": "string",
"default": "UTC"
}
})

# add driver and protocol
schema['properties']['radios']['items']['properties'].update({
"driver": {
"id": "driver",
"type": "string",
"enum": [
"mac80211",
"ath5k",
"ath9k",
"broadcom"
]
},
"protocol": {
"id": "protocol",
"type": "string",
"enum": [
"802.11a",
"802.11b",
"802.11g",
"802.11n",
"802.11ac"
]
}
})

# mark driver and protocol as required
schema['properties']['radios']['items']['required'] += [
'driver',
'protocol'
]
36 changes: 36 additions & 0 deletions tests/test_openwrt.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,3 +510,39 @@ def test_radio_ac(self):
option type 'mac80211'
"""
self.assertEqual(o.render(), expected)

def test_radio_wrong_driver(self):
o = OpenWrt({
"type": "DeviceConfiguration",
"radios": [
{
"name": "radio0",
"phy": "phy0",
"driver": "iamwrong",
"protocol": "802.11ac",
"channel": 132,
"channel_width": 80,
"tx_power": 8
}
]
})
with self.assertRaises(ValidationError):
o.validate()

def test_radio_wrong_protocol(self):
o = OpenWrt({
"type": "DeviceConfiguration",
"radios": [
{
"name": "radio0",
"phy": "phy0",
"driver": "mac80211",
"protocol": "802.11ad", # ad is not supported by OpenWRT yet
"channel": 132,
"channel_width": 80,
"tx_power": 8
}
]
})
with self.assertRaises(ValidationError):
o.validate()

0 comments on commit 8a112e2

Please sign in to comment.