Skip to content

Commit f27a864

Browse files
committed
[openwrt] Fixed empty name bug introduced in 2a6cfb2
Fixed a bug that was introduced in 0.6.0 alpha (2a6cfb2)
1 parent ad02e97 commit f27a864

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

netjsonconfig/backends/openwrt/converters.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ def to_intermediate(self):
7878
result = []
7979
for interface in get_copy(self.netjson, 'interfaces'):
8080
i = 1
81-
# determine uci logical interface name
82-
uci_name = logical_name(interface.get('network', interface['name']))
81+
uci_name = self.__get_uci_name(interface)
8382
address_list = self.__get_addresses(interface)
8483
interface = self.__get_interface(interface, uci_name)
8584
# create one or more "config interface" UCI blocks
@@ -101,6 +100,13 @@ def to_intermediate(self):
101100
i += 1
102101
return (('network', result),)
103102

103+
def __get_uci_name(self, interface):
104+
"""
105+
determines uci logical interface name
106+
"""
107+
name = interface.get('network') or interface['name']
108+
return logical_name(name)
109+
104110
def __get_addresses(self, interface):
105111
"""
106112
converts NetJSON address to

tests/openwrt/test_network.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,3 +1225,21 @@ def test_interface_disabled_bug(self):
12251225
})
12261226
self.assertNotIn("disabled '0'", o.render())
12271227
self.assertIn("enabled '1'", o.render())
1228+
1229+
def test_empty_network(self):
1230+
o = OpenWrt({
1231+
"interfaces": [
1232+
{
1233+
"name": "eth0",
1234+
"type": "ethernet",
1235+
"network": ""
1236+
}
1237+
]
1238+
})
1239+
expected = self._tabs("""package network
1240+
1241+
config interface 'eth0'
1242+
option ifname 'eth0'
1243+
option proto 'none'
1244+
""")
1245+
self.assertEqual(o.render(), expected)

0 commit comments

Comments
 (0)