Skip to content

Commit

Permalink
[OpenWrt] Fixed mac address override
Browse files Browse the repository at this point in the history
  • Loading branch information
nemesifier committed Apr 1, 2016
1 parent 2cbc242 commit 85bd7dc
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
7 changes: 7 additions & 0 deletions netjsonconfig/backends/openwrt/renderers.py
Expand Up @@ -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']
Expand Down Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion runflake8
Expand Up @@ -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 \
Expand Down
18 changes: 18 additions & 0 deletions tests/openwrt/test_network.py
Expand Up @@ -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)
33 changes: 33 additions & 0 deletions tests/openwrt/test_wireless.py
Expand Up @@ -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.