Merge lp:~hopem/charm-helpers/lp1581598 into lp:charm-helpers

Proposed by Edward Hope-Morley
Status: Merged
Merged at revision: 573
Proposed branch: lp:~hopem/charm-helpers/lp1581598
Merge into: lp:charm-helpers
Diff against target: 92 lines (+48/-2)
2 files modified
charmhelpers/contrib/network/ip.py (+19/-2)
tests/contrib/network/test_ip.py (+29/-0)
To merge this branch: bzr merge lp:~hopem/charm-helpers/lp1581598
Reviewer Review Type Date Requested Status
OpenStack Charmers Pending
charmers Pending
Review via email: mp+294674@code.launchpad.net
To post a comment you must log in.
lp:~hopem/charm-helpers/lp1581598 updated
574. By Edward Hope-Morley

add more docstring

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charmhelpers/contrib/network/ip.py'
2--- charmhelpers/contrib/network/ip.py 2016-03-21 16:33:03 +0000
3+++ charmhelpers/contrib/network/ip.py 2016-05-16 10:01:19 +0000
4@@ -214,7 +214,16 @@
5
6 def get_iface_addr(iface='eth0', inet_type='AF_INET', inc_aliases=False,
7 fatal=True, exc_list=None):
8- """Return the assigned IP address for a given interface, if any."""
9+ """Return the assigned IP address for a given interface, if any.
10+
11+ :param iface: network interface on which address(es) are expected to
12+ be found.
13+ :param inet_type: inet address family
14+ :param inc_aliases: include alias interfaces in search
15+ :param fatal: if True, raise exception if address not found
16+ :param exc_list: list of addresses to ignore
17+ :return: list of ip addresses
18+ """
19 # Extract nic if passed /dev/ethX
20 if '/' in iface:
21 iface = iface.split('/')[-1]
22@@ -315,6 +324,14 @@
23 We currently only support scope global IPv6 addresses i.e. non-temporary
24 addresses. If no global IPv6 address is found, return the first one found
25 in the ipv6 address list.
26+
27+ :param iface: network interface on which ipv6 address(es) are expected to
28+ be found.
29+ :param inc_aliases: include alias interfaces in search
30+ :param fatal: if True, raise exception if address not found
31+ :param exc_list: list of addresses to ignore
32+ :param dynamic_only: only recognise dynamic addresses
33+ :return: list of ipv6 addresses
34 """
35 addresses = get_iface_addr(iface=iface, inet_type='AF_INET6',
36 inc_aliases=inc_aliases, fatal=fatal,
37@@ -336,7 +353,7 @@
38 cmd = ['ip', 'addr', 'show', iface]
39 out = subprocess.check_output(cmd).decode('UTF-8')
40 if dynamic_only:
41- key = re.compile("inet6 (.+)/[0-9]+ scope global dynamic.*")
42+ key = re.compile("inet6 (.+)/[0-9]+ scope global.* dynamic.*")
43 else:
44 key = re.compile("inet6 (.+)/[0-9]+ scope global.*")
45
46
47=== modified file 'tests/contrib/network/test_ip.py'
48--- tests/contrib/network/test_ip.py 2016-01-27 12:47:55 +0000
49+++ tests/contrib/network/test_ip.py 2016-05-16 10:01:19 +0000
50@@ -81,6 +81,19 @@
51 valid_lft forever preferred_lft forever
52 """
53
54+IP2_OUTPUT = b"""link/ether fa:16:3e:2a:cc:ce brd ff:ff:ff:ff:ff:ff
55+ inet 10.5.16.93/16 brd 10.5.255.255 scope global eth0
56+ valid_lft forever preferred_lft forever
57+ inet6 2001:db8:1:0:d0cf:528c:23eb:6000/64 scope global
58+ valid_lft forever preferred_lft forever
59+ inet6 2001:db8:1:0:2918:3444:852:5b8a/64 scope global temporary dynamic
60+ valid_lft 86400sec preferred_lft 14400sec
61+ inet6 2001:db8:1:0:f816:3eff:fe2a:ccce/64 scope global mngtmpaddr dynamic
62+ valid_lft 86400sec preferred_lft 14400sec
63+ inet6 fe80::f816:3eff:fe2a:ccce/64 scope link
64+ valid_lft forever preferred_lft forever
65+"""
66+
67 IP_OUTPUT_NO_VALID = b"""link/ether fa:16:3e:2a:cc:ce brd ff:ff:ff:ff:ff:ff
68 inet 10.5.16.93/16 brd 10.5.255.255 scope global eth0
69 valid_lft forever preferred_lft forever
70@@ -508,6 +521,22 @@
71 'fe80::f816:3eff:fe2a:ccce%eth0']
72 self.assertEqual([scope_global_dyn_addr], net_ip.get_ipv6_addr())
73
74+ @patch('charmhelpers.contrib.network.ip.get_iface_from_addr')
75+ @patch('charmhelpers.contrib.network.ip.subprocess.check_output')
76+ @patch('charmhelpers.contrib.network.ip.get_iface_addr')
77+ def test_get_ipv6_global_dynamic_address_ip2(self, mock_get_iface_addr,
78+ mock_check_out,
79+ mock_get_iface_from_addr):
80+ mock_get_iface_from_addr.return_value = 'eth0'
81+ mock_check_out.return_value = IP2_OUTPUT
82+ scope_global_addr = '2001:db8:1:0:d0cf:528c:23eb:6000'
83+ scope_global_dyn_addr = '2001:db8:1:0:f816:3eff:fe2a:ccce'
84+ mock_get_iface_addr.return_value = [scope_global_addr,
85+ scope_global_dyn_addr,
86+ '2001:db8:1:0:2918:3444:852:5b8a',
87+ 'fe80::f816:3eff:fe2a:ccce%eth0']
88+ self.assertEqual([scope_global_dyn_addr], net_ip.get_ipv6_addr())
89+
90 @patch('charmhelpers.contrib.network.ip.subprocess.check_output')
91 @patch('charmhelpers.contrib.network.ip.get_iface_addr')
92 def test_get_ipv6_global_dynamic_address_invalid_address(self,

Subscribers

People subscribed via source and target branches