Skip to content

Commit 987dd40

Browse files
committed
test/infamy: support ipv6 addresses in iface.address_exist()
Signed-off-by: Joachim Wiberg <[email protected]>
1 parent 9226a4a commit 987dd40

File tree

1 file changed

+47
-14
lines changed

1 file changed

+47
-14
lines changed

test/infamy/iface.py

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,28 +37,61 @@ def exist(target, iface):
3737
"""Verify that the target interface exists"""
3838
return get_param(target, iface, "name") is not None
3939

40-
def address_exist(target, iface, address, prefix_length = 24, proto="dhcp"):
40+
41+
def address_exist(target, iface, address, prefix_length=None, proto="dhcp"):
4142
"""Check if 'address' is set on iface"""
43+
if not prefix_length:
44+
if ':' in address:
45+
prefix_length = 64
46+
else:
47+
prefix_length = 24
48+
4249
addrs = get_ipv4_address(target, iface)
43-
if not addrs:
44-
return False
45-
for addr in addrs:
46-
if addr['origin'] == proto and addr['ip'] == address and addr['prefix-length'] == prefix_length:
47-
return True
50+
if addrs:
51+
for addr in addrs:
52+
if addr['origin'] == proto and addr['ip'] == address and\
53+
addr['prefix-length'] == prefix_length:
54+
return True
55+
56+
addrs = get_ipv6_address(target, iface)
57+
if addrs:
58+
for addr in addrs:
59+
if addr['origin'] == proto and addr['ip'] == address and\
60+
addr['prefix-length'] == prefix_length:
61+
return True
62+
63+
return False
64+
4865

4966
def get_ipv4_address(target, iface):
50-
"""Fetch interface IPv4 addresses from (operational status)"""
51-
# The interface array is different in restconf/netconf, netconf has a keyed list but
52-
# restconf has a numbered list, i think i read that this was a bug in rousette, but
53-
# have not found it.
54-
interface=target.get_iface(iface)
67+
"""Fetch interface IPv4 addresses from operational"""
68+
# The interface array is different in restconf/netconf, netconf has
69+
# a keyed list but restconf has a numbered list, i think i read that
70+
# this was a bug in rousette, but have not found it.
71+
interface = target.get_iface(iface)
5572
if interface is None:
5673
raise "Interface not found"
5774

58-
ipv4 = interface.get("ipv4") or interface.get("ietf-ip:ipv4")
59-
if ipv4 is None or 'address' not in ipv4:
75+
ip = interface.get("ipv4") or interface.get("ietf-ip:ipv4")
76+
if ip is None or 'address' not in ip:
6077
return None
61-
return ipv4['address']
78+
return ip['address']
79+
80+
81+
def get_ipv6_address(target, iface):
82+
"""Fetch interface IPv6 addresses from operational"""
83+
# The interface array is different in restconf/netconf, netconf has
84+
# a keyed list but restconf has a numbered list, i think i read that
85+
# this was a bug in rousette, but have not found it.
86+
interface = target.get_iface(iface)
87+
if interface is None:
88+
raise "Interface not found"
89+
90+
ip = interface.get("ipv6") or interface.get("ietf-ip:ipv6")
91+
if ip is None or 'address' not in ip:
92+
return None
93+
return ip['address']
94+
6295

6396
def get_phys_address(target, iface):
6497
"""Fetch interface MAC address (operational status)"""

0 commit comments

Comments
 (0)