Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
[OpenWrt] Fixed empty output bug if addresses is empty list
- Loading branch information
Showing
with
36 additions
and
5 deletions.
-
+9
−5
netjsonconfig/backends/openwrt/renderers.py
-
+27
−0
tests/openwrt/test_network.py
|
@@ -19,7 +19,7 @@ def _get_interfaces(self): |
|
|
interfaces = self.config.get('interfaces', []) |
|
|
# this line ensures interfaces are not entirely |
|
|
# ignored if they do not contain any address |
|
|
default_addresses = [{'proto': 'none'}] |
|
|
default_address = [{'proto': 'none'}] |
|
|
# results container |
|
|
uci_interfaces = [] |
|
|
for interface in interfaces: |
|
@@ -34,8 +34,12 @@ def _get_interfaces(self): |
|
|
if interface.get('type') == 'bridge': |
|
|
is_bridge = True |
|
|
bridge_members = ' '.join(interface['bridge_members']) |
|
|
# ensure address list is not never empty, even when 'addresses' is [] |
|
|
address_list = interface.get('addresses') |
|
|
if not address_list: |
|
|
address_list = default_address |
|
|
# address list defaults to empty list |
|
|
for address in interface.get('addresses', default_addresses): |
|
|
for address in address_list: |
|
|
# prepare new UCI interface directive |
|
|
uci_interface = deepcopy(interface) |
|
|
if network: |
|
@@ -46,11 +50,11 @@ def _get_interfaces(self): |
|
|
if uci_interface.get('disabled'): |
|
|
uci_interface['enabled'] = not interface['disabled'] |
|
|
del uci_interface['disabled'] |
|
|
if uci_interface.get('addresses'): |
|
|
if 'addresses' in uci_interface: |
|
|
del uci_interface['addresses'] |
|
|
if uci_interface.get('type'): |
|
|
if 'type' in uci_interface: |
|
|
del uci_interface['type'] |
|
|
if uci_interface.get('wireless'): |
|
|
if 'wireless' in uci_interface: |
|
|
del uci_interface['wireless'] |
|
|
# default values |
|
|
address_key = None |
|
|
|
@@ -874,3 +874,30 @@ def test_mac_address_format(self): |
|
|
# empty is valid (will be ignored) |
|
|
o.config['interfaces'][0]['mac'] = '' |
|
|
o.validate() |
|
|
|
|
|
def test_default_addresses(self): |
|
|
""" |
|
|
the following configuration dictionary caused empty output up to 0.4.0 |
|
|
""" |
|
|
o = OpenWrt({ |
|
|
"interfaces": [ |
|
|
{ |
|
|
"type": "bridge", |
|
|
"network": "lan", |
|
|
"addresses": [], |
|
|
"name": "br-lan", |
|
|
"bridge_members": [ |
|
|
"eth0", |
|
|
"eth1" |
|
|
] |
|
|
} |
|
|
] |
|
|
}) |
|
|
expected = self._tabs("""package network |
|
|
|
|
|
config interface 'lan' |
|
|
option ifname 'eth0 eth1' |
|
|
option proto 'none' |
|
|
option type 'bridge' |
|
|
""") |
|
|
self.assertEqual(o.render(), expected) |