Merge lp:~gnuoy/python-jujuclient/ipv6 into lp:python-jujuclient

Proposed by Liam Young
Status: Merged
Merged at revision: 56
Proposed branch: lp:~gnuoy/python-jujuclient/ipv6
Merge into: lp:python-jujuclient
Diff against target: 64 lines (+33/-1)
2 files modified
jujuclient.py (+11/-1)
test_jujuclient.py (+22/-0)
To merge this branch: bzr merge lp:~gnuoy/python-jujuclient/ipv6
Reviewer Review Type Date Requested Status
Kapil Thangavelu Approve
Martin Packman (community) Approve
Review via email: mp+258770@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Martin Packman (gz) wrote :

Needs unit test. I'd add a new port-splitting function used here that can be validated with some ipv4 and ipv6 inputs.

review: Needs Fixing
lp:~gnuoy/python-jujuclient/ipv6 updated
57. By Liam Young

Add unit tests and move host port splitting into its own function

Revision history for this message
Martin Packman (gz) wrote :

Looks good. Python style nits inline.

review: Approve
Revision history for this message
Kapil Thangavelu (hazmat) wrote :

lgtm, with martin's style nits addressed.

review: Approve
lp:~gnuoy/python-jujuclient/ipv6 updated
58. By Liam Young

Tipdyup after mp feedback

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'jujuclient.py'
2--- jujuclient.py 2015-02-27 12:03:22 +0000
3+++ jujuclient.py 2015-05-11 14:34:07 +0000
4@@ -19,6 +19,7 @@
5 import logging
6 import os
7 import pprint
8+import re
9 import shutil
10 import signal
11 import socket
12@@ -218,9 +219,18 @@
13 data = yaml.safe_load(fh.read())
14 return jhome, data
15
16+ @staticmethod
17+ def split_host_port(server):
18+ m = re.match('(.*):(.*)', server)
19+ if not m:
20+ raise ValueError("Not an ipaddr/port {!r}".format(server))
21+ address = m.group(1).strip("[]")
22+ port = m.group(2)
23+ return address, port
24+
25 def is_server_available(self, server):
26 """ Given address/port, return true/false if it's up """
27- address, port = server.split(":")
28+ address, port = Connector.split_host_port(server)
29 try:
30 socket.create_connection((address, port), 3)
31 return True
32
33=== modified file 'test_jujuclient.py'
34--- test_jujuclient.py 2015-01-27 22:32:46 +0000
35+++ test_jujuclient.py 2015-05-11 14:34:07 +0000
36@@ -60,6 +60,28 @@
37 self.assertFalse(
38 Connector().is_server_available("foo.example.com:7070"))
39
40+ def test_split_host_port_dns(self):
41+ self.assertEqual(
42+ Connector.split_host_port('foo.example.com:7070'),
43+ ('foo.example.com', '7070')
44+ )
45+
46+ def test_is_server_available_ipv4(self):
47+ self.assertEqual(
48+ Connector.split_host_port('10.0.0.10:7070'),
49+ ('10.0.0.10', '7070')
50+ )
51+
52+ def test_is_server_available_ipv6(self):
53+ self.assertEqual(
54+ Connector.split_host_port('[2001:db8::1]:7070'),
55+ ('2001:db8::1', '7070')
56+ )
57+
58+ def test_is_server_available_invalid_input(self):
59+ self.assertRaises(
60+ ValueError, Connector.split_host_port, 'I am not an ip/port combo'
61+ )
62
63 class KeyManagerTest(unittest.TestCase):
64 def setUp(self):

Subscribers

People subscribed via source and target branches

to all changes: