Merge lp:~james-page/charm-helpers/is-ip-ipv6 into lp:charm-helpers

Proposed by James Page
Status: Merged
Merged at revision: 579
Proposed branch: lp:~james-page/charm-helpers/is-ip-ipv6
Merge into: lp:charm-helpers
Diff against target: 29 lines (+4/-3)
2 files modified
charmhelpers/contrib/network/ip.py (+3/-3)
tests/contrib/network/test_ip.py (+1/-0)
To merge this branch: bzr merge lp:~james-page/charm-helpers/is-ip-ipv6
Reviewer Review Type Date Requested Status
Liam Young (community) Approve
Review via email: mp+295920@code.launchpad.net

Description of the change

Ensure is_ip detects both IPv4 and IPv6 addresses.

To post a comment you must log in.
Revision history for this message
Liam Young (gnuoy) wrote :

LGTM

review: Approve

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-05-16 10:00:56 +0000
3+++ charmhelpers/contrib/network/ip.py 2016-05-27 09:23:36 +0000
4@@ -405,10 +405,10 @@
5 Returns True if address is a valid IP address.
6 """
7 try:
8- # Test to see if already an IPv4 address
9- socket.inet_aton(address)
10+ # Test to see if already an IPv4/IPv6 address
11+ address = netaddr.IPAddress(address)
12 return True
13- except socket.error:
14+ except netaddr.AddrFormatError:
15 return False
16
17
18
19=== modified file 'tests/contrib/network/test_ip.py'
20--- tests/contrib/network/test_ip.py 2016-05-13 17:30:00 +0000
21+++ tests/contrib/network/test_ip.py 2016-05-27 09:23:36 +0000
22@@ -590,6 +590,7 @@
23
24 def test_is_ip(self):
25 self.assertTrue(net_ip.is_ip('10.0.0.1'))
26+ self.assertTrue(net_ip.is_ip('2001:db8:1:0:2918:3444:852:5b8a'))
27 self.assertFalse(net_ip.is_ip('www.ubuntu.com'))
28
29 @patch('charmhelpers.contrib.network.ip.apt_install')

Subscribers

People subscribed via source and target branches