Permalink
Browse files

[OpenWrt] Fixed mac address override

  • Loading branch information...
nemesisdesign committed Apr 1, 2016
1 parent 2cbc242 commit 85bd7dc44e091cc62e1dedc1af42b3026f67ad65
Showing with 59 additions and 1 deletion.
  1. +7 −0 netjsonconfig/backends/openwrt/renderers.py
  2. +1 −1 runflake8
  3. +18 −0 tests/openwrt/test_network.py
  4. +33 −0 tests/openwrt/test_wireless.py
@@ -44,6 +44,10 @@ def _get_interfaces(self):
uci_interface = deepcopy(interface)
if network:
del uci_interface['network']
if 'mac' in uci_interface:
if interface.get('type') != 'wireless':
uci_interface['macaddr'] = interface['mac']
del uci_interface['mac']
if 'autostart' in uci_interface:
uci_interface['auto'] = interface['autostart']
del uci_interface['autostart']
@@ -318,6 +322,9 @@ def _get_wifi_interfaces(self):
# rename radio to device
uci_wifi['device'] = wireless['radio']
del uci_wifi['radio']
# mac address override
if 'mac' in wifi_interface:
uci_wifi['macaddr'] = wifi_interface['mac']
# map netjson wifi modes to uci wifi modes
modes = {
'access_point': 'ap',
@@ -2,7 +2,7 @@
set -e
flake8 --max-line-length=110 \
--max-complexity=22 \
--max-complexity=24 \
./netjsonconfig/backends/openwrt/renderers.py || exit 1
flake8 --max-line-length=110 \
--max-complexity=10 \
@@ -1059,3 +1059,21 @@ def test_autostart(self):
""")
self.assertEqual(o.render(), expected)
def test_macaddr_override(self):
o = OpenWrt({
"interfaces": [
{
"name": "eth0",
"type": "ethernet",
"mac": "E8:94:F6:33:8C:00"
}
]
})
expected = self._tabs("""package network
config interface 'eth0'
option ifname 'eth0'
option macaddr 'E8:94:F6:33:8C:00'
option proto 'none'
""")
self.assertEqual(o.render(), expected)
@@ -1410,3 +1410,36 @@ def test_isolate(self):
o.config['interfaces'][0]['wireless']['isolate'] = 'wrong'
with self.assertRaises(ValidationError):
o.validate()
def test_macaddr_override(self):
o = OpenWrt({
"interfaces": [
{
"name": "wlan0",
"type": "wireless",
"mac": "E8:94:F6:33:8C:00",
"wireless": {
"radio": "radio0",
"mode": "access_point",
"ssid": "open"
}
}
]
})
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 macaddr 'E8:94:F6:33:8C:00'
option mode 'ap'
option network 'wlan0'
option ssid 'open'
""")
self.assertEqual(o.render(), expected)

0 comments on commit 85bd7dc

Please sign in to comment.