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
=== modified file 'charmhelpers/contrib/network/ip.py'
--- charmhelpers/contrib/network/ip.py 2016-03-21 16:33:03 +0000
+++ charmhelpers/contrib/network/ip.py 2016-05-16 10:01:19 +0000
@@ -214,7 +214,16 @@
214214
215def get_iface_addr(iface='eth0', inet_type='AF_INET', inc_aliases=False,215def get_iface_addr(iface='eth0', inet_type='AF_INET', inc_aliases=False,
216 fatal=True, exc_list=None):216 fatal=True, exc_list=None):
217 """Return the assigned IP address for a given interface, if any."""217 """Return the assigned IP address for a given interface, if any.
218
219 :param iface: network interface on which address(es) are expected to
220 be found.
221 :param inet_type: inet address family
222 :param inc_aliases: include alias interfaces in search
223 :param fatal: if True, raise exception if address not found
224 :param exc_list: list of addresses to ignore
225 :return: list of ip addresses
226 """
218 # Extract nic if passed /dev/ethX227 # Extract nic if passed /dev/ethX
219 if '/' in iface:228 if '/' in iface:
220 iface = iface.split('/')[-1]229 iface = iface.split('/')[-1]
@@ -315,6 +324,14 @@
315 We currently only support scope global IPv6 addresses i.e. non-temporary324 We currently only support scope global IPv6 addresses i.e. non-temporary
316 addresses. If no global IPv6 address is found, return the first one found325 addresses. If no global IPv6 address is found, return the first one found
317 in the ipv6 address list.326 in the ipv6 address list.
327
328 :param iface: network interface on which ipv6 address(es) are expected to
329 be found.
330 :param inc_aliases: include alias interfaces in search
331 :param fatal: if True, raise exception if address not found
332 :param exc_list: list of addresses to ignore
333 :param dynamic_only: only recognise dynamic addresses
334 :return: list of ipv6 addresses
318 """335 """
319 addresses = get_iface_addr(iface=iface, inet_type='AF_INET6',336 addresses = get_iface_addr(iface=iface, inet_type='AF_INET6',
320 inc_aliases=inc_aliases, fatal=fatal,337 inc_aliases=inc_aliases, fatal=fatal,
@@ -336,7 +353,7 @@
336 cmd = ['ip', 'addr', 'show', iface]353 cmd = ['ip', 'addr', 'show', iface]
337 out = subprocess.check_output(cmd).decode('UTF-8')354 out = subprocess.check_output(cmd).decode('UTF-8')
338 if dynamic_only:355 if dynamic_only:
339 key = re.compile("inet6 (.+)/[0-9]+ scope global dynamic.*")356 key = re.compile("inet6 (.+)/[0-9]+ scope global.* dynamic.*")
340 else:357 else:
341 key = re.compile("inet6 (.+)/[0-9]+ scope global.*")358 key = re.compile("inet6 (.+)/[0-9]+ scope global.*")
342359
343360
=== modified file 'tests/contrib/network/test_ip.py'
--- tests/contrib/network/test_ip.py 2016-01-27 12:47:55 +0000
+++ tests/contrib/network/test_ip.py 2016-05-16 10:01:19 +0000
@@ -81,6 +81,19 @@
81 valid_lft forever preferred_lft forever81 valid_lft forever preferred_lft forever
82"""82"""
8383
84IP2_OUTPUT = b"""link/ether fa:16:3e:2a:cc:ce brd ff:ff:ff:ff:ff:ff
85 inet 10.5.16.93/16 brd 10.5.255.255 scope global eth0
86 valid_lft forever preferred_lft forever
87 inet6 2001:db8:1:0:d0cf:528c:23eb:6000/64 scope global
88 valid_lft forever preferred_lft forever
89 inet6 2001:db8:1:0:2918:3444:852:5b8a/64 scope global temporary dynamic
90 valid_lft 86400sec preferred_lft 14400sec
91 inet6 2001:db8:1:0:f816:3eff:fe2a:ccce/64 scope global mngtmpaddr dynamic
92 valid_lft 86400sec preferred_lft 14400sec
93 inet6 fe80::f816:3eff:fe2a:ccce/64 scope link
94 valid_lft forever preferred_lft forever
95"""
96
84IP_OUTPUT_NO_VALID = b"""link/ether fa:16:3e:2a:cc:ce brd ff:ff:ff:ff:ff:ff97IP_OUTPUT_NO_VALID = b"""link/ether fa:16:3e:2a:cc:ce brd ff:ff:ff:ff:ff:ff
85 inet 10.5.16.93/16 brd 10.5.255.255 scope global eth098 inet 10.5.16.93/16 brd 10.5.255.255 scope global eth0
86 valid_lft forever preferred_lft forever99 valid_lft forever preferred_lft forever
@@ -508,6 +521,22 @@
508 'fe80::f816:3eff:fe2a:ccce%eth0']521 'fe80::f816:3eff:fe2a:ccce%eth0']
509 self.assertEqual([scope_global_dyn_addr], net_ip.get_ipv6_addr())522 self.assertEqual([scope_global_dyn_addr], net_ip.get_ipv6_addr())
510523
524 @patch('charmhelpers.contrib.network.ip.get_iface_from_addr')
525 @patch('charmhelpers.contrib.network.ip.subprocess.check_output')
526 @patch('charmhelpers.contrib.network.ip.get_iface_addr')
527 def test_get_ipv6_global_dynamic_address_ip2(self, mock_get_iface_addr,
528 mock_check_out,
529 mock_get_iface_from_addr):
530 mock_get_iface_from_addr.return_value = 'eth0'
531 mock_check_out.return_value = IP2_OUTPUT
532 scope_global_addr = '2001:db8:1:0:d0cf:528c:23eb:6000'
533 scope_global_dyn_addr = '2001:db8:1:0:f816:3eff:fe2a:ccce'
534 mock_get_iface_addr.return_value = [scope_global_addr,
535 scope_global_dyn_addr,
536 '2001:db8:1:0:2918:3444:852:5b8a',
537 'fe80::f816:3eff:fe2a:ccce%eth0']
538 self.assertEqual([scope_global_dyn_addr], net_ip.get_ipv6_addr())
539
511 @patch('charmhelpers.contrib.network.ip.subprocess.check_output')540 @patch('charmhelpers.contrib.network.ip.subprocess.check_output')
512 @patch('charmhelpers.contrib.network.ip.get_iface_addr')541 @patch('charmhelpers.contrib.network.ip.get_iface_addr')
513 def test_get_ipv6_global_dynamic_address_invalid_address(self,542 def test_get_ipv6_global_dynamic_address_invalid_address(self,

Subscribers

People subscribed via source and target branches