Skip to content

Commit

Permalink
Merge 2b3a311 into 3d25204
Browse files Browse the repository at this point in the history
  • Loading branch information
yasharora102 committed Nov 25, 2018
2 parents 3d25204 + 2b3a311 commit 8fcaa90
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions netjsonconfig/backends/openwrt/converters/interfaces.py
Expand Up @@ -256,6 +256,10 @@ def __netjson_addresses(self, interface):
netmask = interface.pop('netmask', 32)
parsed_ip = self.__netjson_parse_ip(ipv4, netmask)
ipv4 = [parsed_ip] if parsed_ip else []
if not isinstance(ipv6, list):
netmask = interface.pop('netmask', 128)
parsed_ip = self.__netjson_parse_ip(ipv6, netmask)
ipv6 = [parsed_ip] if parsed_ip else []
if proto.startswith('dhcp'):
family = 'ipv4' if proto == 'dhcp' else 'ipv6'
addresses.append({'proto': 'dhcp', 'family': family})
Expand Down
27 changes: 27 additions & 0 deletions tests/openwrt/test_interfaces.py
Expand Up @@ -163,6 +163,22 @@ def test_parse_incorrect_ipaddr_netmask(self):
}
]
}
_eth0_64 = {
"interfaces": [
{
"name": "eth0",
"type": "ethernet",
"addresses": [
{
"address": "2aa1:4aaa:2aaa:1d::5",
"mask": 64,
"proto": "static",
"family": "ipv6"
}
]
}
]
}

def test_parse_missing_ipv4_mask(self):
native = self._tabs("""package network
Expand Down Expand Up @@ -197,6 +213,17 @@ def test_parse_missing_ipv4_mask_list(self):
o = OpenWrt(native=native)
self.assertEqual(o.config, self._eth0_32)

def test_parse_missing_ipv6_mask_list(self):
native = self._tabs("""package network
config interface 'eth0'
option ifname 'eth0'
option ip6addr '2aa1:4aaa:2aaa:1d::5/64'
option proto 'static'
""")
o = OpenWrt(native=native)
self.assertEqual(o.config, self._eth0_64)

def test_parse_ipv4_list(self):
native = self._tabs("""package network
Expand Down

0 comments on commit 8fcaa90

Please sign in to comment.