Merge lp:~hazmat/pyjuju/increase-session-timeout into lp:pyjuju
- increase-session-timeout
- Merge into trunk
Status: | Merged |
---|---|
Merged at revision: | 614 |
Proposed branch: | lp:~hazmat/pyjuju/increase-session-timeout |
Merge into: | lp:pyjuju |
Diff against target: |
504 lines (+124/-84) 16 files modified
juju/agents/base.py (+3/-1) juju/lib/port.py (+13/-0) juju/lib/tests/test_port.py (+32/-0) juju/lib/tests/test_zk.py (+14/-8) juju/lib/zk.py (+17/-4) juju/providers/common/cloudinit.py (+19/-11) juju/providers/common/connect.py (+4/-2) juju/providers/common/tests/data/cloud_init_bootstrap (+5/-4) juju/providers/common/tests/data/cloud_init_bootstrap_testing (+3/-1) juju/providers/common/tests/data/cloud_init_bootstrap_zookeepers (+5/-4) juju/providers/local/__init__.py (+1/-1) juju/providers/local/tests/test_files.py (+2/-3) juju/state/sshclient.py (+4/-1) juju/state/tests/test_utils.py (+1/-30) juju/state/utils.py (+0/-12) test (+1/-2) |
To merge this branch: | bzr merge lp:~hazmat/pyjuju/increase-session-timeout |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Juju Engineering | Pending | ||
Review via email: mp+146169@code.launchpad.net |
Commit message
Description of the change
Increase zk session and ping times.
During scale testing work, one of the take aways was the default zookeeper
session time was too low, which caused issues for any transient communication
problems between the agents the zk. The managed client work landed subsequently
does recovery for this and for session expiration, but its better to avoid
the issue entirely by increasing the session time and increasing the heartbeat
time periodicity.
Kapil Thangavelu (hazmat) wrote : | # |
Benjamin Saller (bcsaller) wrote : | # |
LGTM, some minors below but they are optional.
https:/
File juju/lib/port.py (right):
https:/
juju/lib/port.py:5: """Get an open port on the machine.
There is a race between close and return, but the kernel shouldn't
re-allocate the same port number again for some reasonable window so
this should be ok.
https:/
File juju/lib/zk.py (right):
https:/
juju/lib/zk.py:57: use_deferred=True, min_session_
Should you use the constant above for min and define one for max and use
it as well?
https:/
File juju/providers/
https:/
juju/providers/
/etc/zookeeper/
It might make sense that these are defined in lib.zk rather than
calculated values here.
https:/
File juju/providers/
https:/
juju/providers/
SSHClient(
Should this be the default in SSHClient.__init__?
Kapil Thangavelu (hazmat) wrote : | # |
thanks for the review.
https:/
File juju/lib/port.py (right):
https:/
juju/lib/port.py:5: """Get an open port on the machine.
On 2013/02/01 17:12:20, bcsaller wrote:
> There is a race between close and return, but the kernel shouldn't
re-allocate
> the same port number again for some reasonable window so this should
be ok.
this is a refactor from elsewhere, the so reuse i believe helps with a
concurrent handout, in either case better than a hardcode.
https:/
File juju/lib/zk.py (right):
https:/
juju/lib/zk.py:57: use_deferred=True, min_session_
On 2013/02/01 17:12:20, bcsaller wrote:
> Should you use the constant above for min and define one for max and
use it as
> well?
makes sense, done.
https:/
File juju/providers/
https:/
juju/providers/
/etc/zookeeper/
On 2013/02/01 17:12:20, bcsaller wrote:
> It might make sense that these are defined in lib.zk rather than
calculated
> values here.
done.
https:/
File juju/providers/
https:/
juju/providers/
SSHClient(
On 2013/02/01 17:12:20, bcsaller wrote:
> Should this be the default in SSHClient.__init__?
sshclient doesn't define that, changed to use the lib.zk
CLIENT_SESSION_TIME
- 455. By Kapil Thangavelu
-
address review comments
Kapil Thangavelu (hazmat) wrote : | # |
Please take a look.
Benjamin Saller (bcsaller) wrote : | # |
Thanks for the changes, LGTM
Kapil Thangavelu (hazmat) wrote : | # |
*** Submitted:
Increase zk session and ping times.
During scale testing work, one of the take aways was the default
zookeeper
session time was too low, which caused issues for any transient
communication
problems between the agents the zk. The managed client work landed
subsequently
does recovery for this and for session expiration, but its better to
avoid
the issue entirely by increasing the session time and increasing the
heartbeat
time periodicity.
R=bcsaller
CC=
https:/
Preview Diff
1 | === modified file 'juju/agents/base.py' |
2 | --- juju/agents/base.py 2012-04-26 18:32:14 +0000 |
3 | +++ juju/agents/base.py 2013-02-01 17:52:19 +0000 |
4 | @@ -18,6 +18,7 @@ |
5 | from juju.control.options import setup_twistd_options |
6 | from juju.errors import NoConnection, JujuError |
7 | from juju.lib.zklog import ZookeeperHandler |
8 | +from juju.lib.zk import CLIENT_SESSION_TIMEOUT |
9 | from juju.state.environment import GlobalSettingsStateManager |
10 | |
11 | |
12 | @@ -204,7 +205,8 @@ |
13 | def connect(self): |
14 | """Return an authenticated connection to the juju zookeeper.""" |
15 | yield self._kill_existing_session() |
16 | - self.client = yield ManagedClient().connect( |
17 | + self.client = yield ManagedClient( |
18 | + session_timeout=CLIENT_SESSION_TIMEOUT).connect( |
19 | self.config["zookeeper_servers"]) |
20 | save_client_id( |
21 | self.config["session_file"], self.client.client_id) |
22 | |
23 | === added file 'juju/lib/port.py' |
24 | --- juju/lib/port.py 1970-01-01 00:00:00 +0000 |
25 | +++ juju/lib/port.py 2013-02-01 17:52:19 +0000 |
26 | @@ -0,0 +1,13 @@ |
27 | +import socket |
28 | + |
29 | + |
30 | +def get_open_port(host=""): |
31 | + """Get an open port on the machine. |
32 | + """ |
33 | + temp_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
34 | + temp_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) |
35 | + temp_sock.bind((host, 0)) |
36 | + port = temp_sock.getsockname()[1] |
37 | + temp_sock.close() |
38 | + del temp_sock |
39 | + return port |
40 | |
41 | === added file 'juju/lib/tests/test_port.py' |
42 | --- juju/lib/tests/test_port.py 1970-01-01 00:00:00 +0000 |
43 | +++ juju/lib/tests/test_port.py 2013-02-01 17:52:19 +0000 |
44 | @@ -0,0 +1,32 @@ |
45 | +import socket |
46 | +from unittest import TestCase |
47 | +from juju.lib.port import get_open_port |
48 | + |
49 | + |
50 | +class OpenPortTest(TestCase): |
51 | + |
52 | + def test_get_open_port(self): |
53 | + port = get_open_port() |
54 | + self.assertTrue(isinstance(port, int)) |
55 | + |
56 | + sock = socket.socket( |
57 | + socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP) |
58 | + |
59 | + # would raise an error if we got it wrong. |
60 | + sock.bind(("127.0.0.1", port)) |
61 | + sock.listen(1) |
62 | + sock.close() |
63 | + del sock |
64 | + |
65 | + def test_get_open_port_with_host(self): |
66 | + port = get_open_port("localhost") |
67 | + self.assertTrue(isinstance(port, int)) |
68 | + |
69 | + sock = socket.socket( |
70 | + socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP) |
71 | + |
72 | + # would raise an error if we got it wrong. |
73 | + sock.bind(("127.0.0.1", port)) |
74 | + sock.listen(1) |
75 | + sock.close() |
76 | + del sock |
77 | |
78 | === modified file 'juju/lib/tests/test_zk.py' |
79 | --- juju/lib/tests/test_zk.py 2011-09-16 00:36:31 +0000 |
80 | +++ juju/lib/tests/test_zk.py 2013-02-01 17:52:19 +0000 |
81 | @@ -7,6 +7,7 @@ |
82 | |
83 | from juju.lib.testing import TestCase |
84 | from juju.lib.zk import Zookeeper, check_zookeeper |
85 | +from juju.lib.port import get_open_port |
86 | |
87 | |
88 | sample_package_environment_conf = """\ |
89 | @@ -46,12 +47,11 @@ |
90 | self.makeFile("", path=os.path.join( |
91 | software_dir, "build", "zookeeper-3.4.0.jar")) |
92 | |
93 | - for p in [ |
94 | - "jline-0.9.94.jar", |
95 | - "netty-3.2.2.Final.jar", |
96 | - "log4j-1.2.15.jar", |
97 | - "slf4j-log4j12-1.6.1.jar", |
98 | - "slf4j-api-1.6.1.jar"]: |
99 | + for p in ["jline-0.9.94.jar", |
100 | + "netty-3.2.2.Final.jar", |
101 | + "log4j-1.2.15.jar", |
102 | + "slf4j-log4j12-1.6.1.jar", |
103 | + "slf4j-api-1.6.1.jar"]: |
104 | self.makeFile("", path=os.path.join(lib_dir, p)) |
105 | |
106 | instance = Zookeeper(data_dir, 12345, zk_location=software_dir) |
107 | @@ -96,16 +96,22 @@ |
108 | def test_managed_zookeeper(self): |
109 | zookeeper.set_debug_level(0) |
110 | |
111 | + port = get_open_port() |
112 | # Start zookeeper |
113 | data_dir = self.makeDir() |
114 | - instance = Zookeeper(data_dir, 12345) |
115 | + instance = Zookeeper( |
116 | + data_dir, |
117 | + port, |
118 | + min_session_timeout=80000, |
119 | + max_session_timeout=100000) |
120 | yield instance.start() |
121 | self.assertTrue(instance.running) |
122 | |
123 | # Connect a client |
124 | - client = ZookeeperClient("127.0.1.1:12345") |
125 | + client = ZookeeperClient("127.0.1.1:%d" % port) |
126 | yield client.connect() |
127 | stat = yield client.exists("/") |
128 | + self.assertEqual(client.session_timeout, 80000) |
129 | yield client.close() |
130 | self.assertTrue(stat) |
131 | |
132 | |
133 | === modified file 'juju/lib/zk.py' |
134 | --- juju/lib/zk.py 2012-06-26 16:36:32 +0000 |
135 | +++ juju/lib/zk.py 2013-02-01 17:52:19 +0000 |
136 | @@ -11,6 +11,9 @@ |
137 | |
138 | from twisted.internet.threads import deferToThread |
139 | |
140 | +CLIENT_SESSION_TIMEOUT = 30000 |
141 | +TICK_TIME = int(CLIENT_SESSION_TIMEOUT / 2) |
142 | +MAX_SESSION_TIMEOUT = CLIENT_SESSION_TIMEOUT * 2 |
143 | |
144 | zookeeper_script_template = """\ |
145 | #!/bin/bash |
146 | @@ -39,6 +42,8 @@ |
147 | dataDir=%s |
148 | clientPort=%s |
149 | maxClientCnxns=500 |
150 | +minSessionTimeout=%d |
151 | +maxSessionTimeout=%d |
152 | """ |
153 | |
154 | |
155 | @@ -51,7 +56,10 @@ |
156 | |
157 | def __init__(self, run_dir, port=None, host=None, |
158 | zk_location="system", user=None, group=None, |
159 | - use_deferred=True, fsync=True): |
160 | + use_deferred=True, |
161 | + min_session_timeout=CLIENT_SESSION_TIMEOUT, |
162 | + max_session_timeout=MAX_SESSION_TIMEOUT, |
163 | + fsync=True): |
164 | """ |
165 | :param run_dir: Directory to store all zookeeper instance related data. |
166 | :param port: The port zookeeper should run on. |
167 | @@ -72,6 +80,8 @@ |
168 | self._user = user |
169 | self._group = group |
170 | self._zk_location = zk_location |
171 | + self._min_session_time = min_session_timeout |
172 | + self._max_session_time = max_session_timeout |
173 | self._use_deferred = use_deferred |
174 | self.fsync = fsync |
175 | |
176 | @@ -198,9 +208,12 @@ |
177 | config.write(log4j_properties) |
178 | |
179 | with open(zk_vars["config_path"], "w") as config: |
180 | - conf = zookeeper_conf_template % (zk_vars["data_dir"], self._port) |
181 | - if self.fsync: |
182 | - conf += "\nfsync=no\n" |
183 | + conf = zookeeper_conf_template % ( |
184 | + zk_vars["data_dir"], self._port, |
185 | + self._min_session_time, |
186 | + self._max_session_time) |
187 | + if not self.fsync: |
188 | + conf += "\nforceSync=no\n" |
189 | config.write(conf) |
190 | if self._host: |
191 | config.write("\nclientPortAddress=%s" % self._host) |
192 | |
193 | === modified file 'juju/providers/common/cloudinit.py' |
194 | --- juju/providers/common/cloudinit.py 2013-01-22 15:29:50 +0000 |
195 | +++ juju/providers/common/cloudinit.py 2013-02-01 17:52:19 +0000 |
196 | @@ -5,6 +5,8 @@ |
197 | from juju.errors import CloudInitError |
198 | from juju.lib.upstart import UpstartService |
199 | from juju.lib import serializer |
200 | +from juju.lib.zk import ( |
201 | + CLIENT_SESSION_TIMEOUT, TICK_TIME, MAX_SESSION_TIMEOUT) |
202 | from juju.providers.common.utils import format_cloud_init |
203 | from juju.state.auth import make_identity |
204 | |
205 | @@ -38,6 +40,12 @@ |
206 | |
207 | def _zookeeper_scripts(instance_id, secret, constraints, provider_type): |
208 | return [ |
209 | + 'sed -i -e s/tickTime=2000/tickTime=%d/g /etc/zookeeper/conf/zoo.cfg' % ( |
210 | + TICK_TIME), |
211 | + 'echo "minSessionTimeout=%d" >> /etc/zookeeper/conf/zoo.cfg' % ( |
212 | + CLIENT_SESSION_TIMEOUT), |
213 | + 'echo "maxSessionTimeout=%d" >> /etc/zookeeper/conf/zoo.cfg' % ( |
214 | + MAX_SESSION_TIMEOUT), |
215 | "juju-admin initialize" |
216 | " --instance-id=%s" |
217 | " --admin-identity=%s" |
218 | @@ -66,20 +74,20 @@ |
219 | service.set_description( |
220 | "Juju unit agent for %s" % unit_name) |
221 | service.set_environ( |
222 | - {"JUJU_MACHINE_ID": str(machine_id), |
223 | - "JUJU_UNIT_NAME": unit_name, |
224 | - "JUJU_HOME": juju_home, |
225 | - "JUJU_ENV_UUID": env_id, |
226 | - "JUJU_ZOOKEEPER": zookeeper_hosts}) |
227 | + {"JUJU_MACHINE_ID": str(machine_id), |
228 | + "JUJU_UNIT_NAME": unit_name, |
229 | + "JUJU_HOME": juju_home, |
230 | + "JUJU_ENV_UUID": env_id, |
231 | + "JUJU_ZOOKEEPER": zookeeper_hosts}) |
232 | service.set_output_path( |
233 | "/var/log/juju/unit-%s-output.log" % unit_path_name) |
234 | service.set_command(" ".join( |
235 | - ["/usr/bin/python", |
236 | - "-m", "juju.agents.unit", |
237 | - "--nodaemon", |
238 | - "--logfile", "/var/log/juju/unit-%s.log" % unit_path_name, |
239 | - "--session-file", |
240 | - "/var/run/juju/unit-%s-agent.zksession" % unit_path_name])) |
241 | + ["/usr/bin/python", |
242 | + "-m", "juju.agents.unit", |
243 | + "--nodaemon", |
244 | + "--logfile", "/var/log/juju/unit-%s.log" % unit_path_name, |
245 | + "--session-file", |
246 | + "/var/run/juju/unit-%s-agent.zksession" % unit_path_name])) |
247 | return service.get_cloud_init_commands() |
248 | |
249 | |
250 | |
251 | === modified file 'juju/providers/common/connect.py' |
252 | --- juju/providers/common/connect.py 2011-12-08 20:17:19 +0000 |
253 | +++ juju/providers/common/connect.py 2013-02-01 17:52:19 +0000 |
254 | @@ -6,6 +6,7 @@ |
255 | |
256 | from juju.errors import EnvironmentNotFound, EnvironmentPending, NoConnection |
257 | from juju.lib.twistutils import sleep |
258 | +from juju.lib.zk import CLIENT_SESSION_TIMEOUT |
259 | from juju.state.sshclient import SSHClient |
260 | |
261 | from .utils import log |
262 | @@ -64,8 +65,9 @@ |
263 | chosen = random.choice(assigned) |
264 | log.debug("Connecting to environment using %s...", chosen.dns_name) |
265 | try: |
266 | - client = yield SSHClient().connect( |
267 | - chosen.dns_name + ":2181", timeout=30, share=share) |
268 | + client = yield SSHClient( |
269 | + session_timeout=CLIENT_SESSION_TIMEOUT).connect( |
270 | + chosen.dns_name + ":2181", timeout=30, share=share) |
271 | except (NoConnection, ConnectionTimeoutException) as e: |
272 | raise EnvironmentPending( |
273 | "Cannot connect to environment using %s " |
274 | |
275 | === modified file 'juju/providers/common/tests/data/cloud_init_bootstrap' |
276 | --- juju/providers/common/tests/data/cloud_init_bootstrap 2012-08-23 16:14:42 +0000 |
277 | +++ juju/providers/common/tests/data/cloud_init_bootstrap 2013-02-01 17:52:19 +0000 |
278 | @@ -6,7 +6,9 @@ |
279 | output: {all: '| tee -a /var/log/cloud-init-output.log'} |
280 | packages: [bzr, byobu, tmux, python-setuptools, python-twisted, python-txaws, python-zookeeper, |
281 | default-jre-headless, zookeeper, zookeeperd, juju] |
282 | -runcmd: [sudo mkdir -p /var/lib/juju, sudo mkdir -p /var/log/juju, 'juju-admin initialize |
283 | +runcmd: [sudo mkdir -p /var/lib/juju, sudo mkdir -p /var/log/juju, sed -i -e s/tickTime=2000/tickTime=15000/g |
284 | + /etc/zookeeper/conf/zoo.cfg, echo "minSessionTimeout=30000" >> /etc/zookeeper/conf/zoo.cfg, |
285 | + echo "maxSessionTimeout=60000" >> /etc/zookeeper/conf/zoo.cfg, 'juju-admin initialize |
286 | --instance-id=token --admin-identity=admin:19vlzY4Vc3q4Ew5OsCwKYqrq1HI= --constraints-data=e2NwdTogJzIwJywgcHJvdmlkZXItdHlwZTogZHVtbXksIHVidW50dS1zZXJpZXM6IGFzdG9uaXNoaW5nfQo= |
287 | --provider-type=dummy', 'cat >> /etc/init/juju-machine-agent.conf <<EOF |
288 | |
289 | @@ -33,8 +35,7 @@ |
290 | |
291 | EOF |
292 | |
293 | - ', /sbin/start juju-machine-agent, 'cat >> /etc/init/juju-provision-agent.conf |
294 | - <<EOF |
295 | +', /sbin/start juju-machine-agent, 'cat >> /etc/init/juju-provision-agent.conf <<EOF |
296 | |
297 | description "Juju provisioning agent" |
298 | |
299 | @@ -57,5 +58,5 @@ |
300 | |
301 | EOF |
302 | |
303 | - ', /sbin/start juju-provision-agent] |
304 | +', /sbin/start juju-provision-agent] |
305 | ssh_authorized_keys: [chubb] |
306 | |
307 | === modified file 'juju/providers/common/tests/data/cloud_init_bootstrap_testing' |
308 | --- juju/providers/common/tests/data/cloud_init_bootstrap_testing 2013-01-22 15:29:50 +0000 |
309 | +++ juju/providers/common/tests/data/cloud_init_bootstrap_testing 2013-02-01 17:52:19 +0000 |
310 | @@ -6,7 +6,9 @@ |
311 | output: {all: '| tee -a /var/log/cloud-init-output.log'} |
312 | packages: [bzr, byobu, tmux, python-setuptools, python-twisted, python-txaws, python-zookeeper, |
313 | default-jre-headless, zookeeper, zookeeperd, juju] |
314 | -runcmd: [sudo mkdir -p /var/lib/juju, sudo mkdir -p /var/log/juju, 'juju-admin initialize |
315 | +runcmd: [sudo mkdir -p /var/lib/juju, sudo mkdir -p /var/log/juju, sed -i -e s/tickTime=2000/tickTime=15000/g |
316 | + /etc/zookeeper/conf/zoo.cfg, echo "minSessionTimeout=30000" >> /etc/zookeeper/conf/zoo.cfg, |
317 | + echo "maxSessionTimeout=60000" >> /etc/zookeeper/conf/zoo.cfg, 'juju-admin initialize |
318 | --instance-id=token --admin-identity=admin:19vlzY4Vc3q4Ew5OsCwKYqrq1HI= --constraints-data=e2NwdTogJzIwJywgcHJvdmlkZXItdHlwZTogZHVtbXksIHVidW50dS1zZXJpZXM6IGFzdG9uaXNoaW5nfQo= |
319 | --provider-type=dummy', 'cat >> /etc/init/juju-machine-agent.conf <<EOF |
320 | |
321 | |
322 | === modified file 'juju/providers/common/tests/data/cloud_init_bootstrap_zookeepers' |
323 | --- juju/providers/common/tests/data/cloud_init_bootstrap_zookeepers 2012-08-23 16:14:42 +0000 |
324 | +++ juju/providers/common/tests/data/cloud_init_bootstrap_zookeepers 2013-02-01 17:52:19 +0000 |
325 | @@ -6,7 +6,9 @@ |
326 | output: {all: '| tee -a /var/log/cloud-init-output.log'} |
327 | packages: [bzr, byobu, tmux, python-setuptools, python-twisted, python-txaws, python-zookeeper, |
328 | default-jre-headless, zookeeper, zookeeperd, juju] |
329 | -runcmd: [sudo mkdir -p /var/lib/juju, sudo mkdir -p /var/log/juju, 'juju-admin initialize |
330 | +runcmd: [sudo mkdir -p /var/lib/juju, sudo mkdir -p /var/log/juju, sed -i -e s/tickTime=2000/tickTime=15000/g |
331 | + /etc/zookeeper/conf/zoo.cfg, echo "minSessionTimeout=30000" >> /etc/zookeeper/conf/zoo.cfg, |
332 | + echo "maxSessionTimeout=60000" >> /etc/zookeeper/conf/zoo.cfg, 'juju-admin initialize |
333 | --instance-id=token --admin-identity=admin:19vlzY4Vc3q4Ew5OsCwKYqrq1HI= --constraints-data=e2NwdTogJzIwJywgcHJvdmlkZXItdHlwZTogZHVtbXksIHVidW50dS1zZXJpZXM6IGFzdG9uaXNoaW5nfQo= |
334 | --provider-type=dummy', 'cat >> /etc/init/juju-machine-agent.conf <<EOF |
335 | |
336 | @@ -33,8 +35,7 @@ |
337 | |
338 | EOF |
339 | |
340 | - ', /sbin/start juju-machine-agent, 'cat >> /etc/init/juju-provision-agent.conf |
341 | - <<EOF |
342 | +', /sbin/start juju-machine-agent, 'cat >> /etc/init/juju-provision-agent.conf <<EOF |
343 | |
344 | description "Juju provisioning agent" |
345 | |
346 | @@ -57,5 +58,5 @@ |
347 | |
348 | EOF |
349 | |
350 | - ', /sbin/start juju-provision-agent] |
351 | +', /sbin/start juju-provision-agent] |
352 | ssh_authorized_keys: [chubb] |
353 | |
354 | === modified file 'juju/providers/local/__init__.py' |
355 | --- juju/providers/local/__init__.py 2012-09-28 06:32:46 +0000 |
356 | +++ juju/providers/local/__init__.py 2013-02-01 17:52:19 +0000 |
357 | @@ -8,6 +8,7 @@ |
358 | from juju.errors import ProviderError, EnvironmentNotFound |
359 | from juju.lib.lxc import LXCContainer, get_containers |
360 | from juju.lib.zk import Zookeeper |
361 | +from juju.lib.port import get_open_port |
362 | from juju.providers.common.base import MachineProviderBase |
363 | from juju.providers.common.connect import ZookeeperConnect |
364 | from juju.providers.common.utils import get_user_authorized_keys |
365 | @@ -20,7 +21,6 @@ |
366 | from juju.state.auth import make_identity |
367 | from juju.state.initialize import StateHierarchy |
368 | from juju.state.placement import LOCAL_POLICY |
369 | -from juju.state.utils import get_open_port |
370 | |
371 | |
372 | log = logging.getLogger("juju.local-dev") |
373 | |
374 | === modified file 'juju/providers/local/tests/test_files.py' |
375 | --- juju/providers/local/tests/test_files.py 2012-09-28 06:13:47 +0000 |
376 | +++ juju/providers/local/tests/test_files.py 2013-02-01 17:52:19 +0000 |
377 | @@ -1,7 +1,6 @@ |
378 | import os |
379 | import signal |
380 | -from StringIO import StringIO |
381 | -import subprocess |
382 | +from StringIO import StringIO |
383 | |
384 | from twisted.internet.defer import inlineCallbacks, succeed |
385 | from twisted.web.client import getPage |
386 | @@ -12,9 +11,9 @@ |
387 | from juju.lib.testing import TestCase |
388 | from juju.lib.service import TwistedDaemonService |
389 | from juju.lib.mocker import ANY |
390 | +from juju.lib.port import get_open_port |
391 | from juju.providers.local.files import ( |
392 | LocalStorage, StorageServer, SERVER_URL_KEY) |
393 | -from juju.state.utils import get_open_port |
394 | |
395 | |
396 | class WebFileStorageTest(TestCase): |
397 | |
398 | === modified file 'juju/state/sshclient.py' |
399 | --- juju/state/sshclient.py 2011-12-07 21:13:52 +0000 |
400 | +++ juju/state/sshclient.py 2013-02-01 17:52:19 +0000 |
401 | @@ -5,11 +5,14 @@ |
402 | from twisted.internet.defer import Deferred, inlineCallbacks, returnValue |
403 | from txzookeeper.client import ConnectionTimeoutException |
404 | |
405 | + |
406 | from juju.errors import NoConnection, InvalidHost, InvalidUser |
407 | +from juju.lib.port import get_open_port |
408 | from juju.state.security import SecurityPolicyConnection |
409 | from juju.state.sshforward import forward_port, ClientTunnelProtocol |
410 | |
411 | -from .utils import PortWatcher, get_open_port |
412 | +from .utils import PortWatcher |
413 | + |
414 | |
415 | SERVER_RE = re.compile("^(\S+):(\d+)$") |
416 | |
417 | |
418 | === modified file 'juju/state/tests/test_utils.py' |
419 | --- juju/state/tests/test_utils.py 2012-09-10 03:20:20 +0000 |
420 | +++ juju/state/tests/test_utils.py 2013-02-01 17:52:19 +0000 |
421 | @@ -14,7 +14,7 @@ |
422 | from juju.state.base import StateBase |
423 | from juju.state.errors import StateChanged, StateNotFound |
424 | from juju.state.utils import ( |
425 | - PortWatcher, remove_tree, dict_merge, get_open_port, |
426 | + PortWatcher, remove_tree, dict_merge, |
427 | YAMLState, YAMLStateNodeMixin, AddedItem, ModifiedItem, DeletedItem) |
428 | |
429 | |
430 | @@ -227,35 +227,6 @@ |
431 | dict(b=2, c=1)) |
432 | |
433 | |
434 | -class OpenPortTest(TestCase): |
435 | - |
436 | - def test_get_open_port(self): |
437 | - port = get_open_port() |
438 | - self.assertTrue(isinstance(port, int)) |
439 | - |
440 | - sock = socket.socket( |
441 | - socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP) |
442 | - |
443 | - # would raise an error if we got it wrong. |
444 | - sock.bind(("127.0.0.1", port)) |
445 | - sock.listen(1) |
446 | - sock.close() |
447 | - del sock |
448 | - |
449 | - def test_get_open_port_with_host(self): |
450 | - port = get_open_port("localhost") |
451 | - self.assertTrue(isinstance(port, int)) |
452 | - |
453 | - sock = socket.socket( |
454 | - socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP) |
455 | - |
456 | - # would raise an error if we got it wrong. |
457 | - sock.bind(("127.0.0.1", port)) |
458 | - sock.listen(1) |
459 | - sock.close() |
460 | - del sock |
461 | - |
462 | - |
463 | class ChangeItemsTest(TestCase): |
464 | """Tests the formatting of change items. |
465 | |
466 | |
467 | === modified file 'juju/state/utils.py' |
468 | --- juju/state/utils.py 2012-09-10 03:20:20 +0000 |
469 | +++ juju/state/utils.py 2013-02-01 17:52:19 +0000 |
470 | @@ -84,18 +84,6 @@ |
471 | yield client.delete(path) |
472 | |
473 | |
474 | -def get_open_port(host=""): |
475 | - """Get an open port on the machine. |
476 | - """ |
477 | - temp_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
478 | - temp_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) |
479 | - temp_sock.bind((host, 0)) |
480 | - port = temp_sock.getsockname()[1] |
481 | - temp_sock.close() |
482 | - del temp_sock |
483 | - return port |
484 | - |
485 | - |
486 | def dict_merge(d1, d2): |
487 | """Return a union of dicts if they have no conflicting values. |
488 | |
489 | |
490 | === modified file 'test' |
491 | --- test 2012-07-19 17:39:35 +0000 |
492 | +++ test 2013-02-01 17:52:19 +0000 |
493 | @@ -42,10 +42,9 @@ |
494 | print ("JUJU_TEST_TIMEOUT must be a number") |
495 | exit() |
496 | |
497 | - |
498 | with zookeeper_test_context( |
499 | os.environ["ZOOKEEPER_PATH"], |
500 | - os.environ.get("ZOOKEEPER_TEST_PORT", 28181)): |
501 | + os.environ.get("ZOOKEEPER_TEST_PORT", 28181)) as zk: |
502 | run() |
503 | |
504 | if __name__ == "__main__": |
Reviewers: mp+146169_ code.launchpad. net,
Message:
Please take a look.
Description:
Increase zk session and ping times.
During scale testing work, one of the take aways was the default
zookeeper
session time was too low, which caused issues for any transient
communication
problems between the agents the zk. The managed client work landed
subsequently
does recovery for this and for session expiration, but its better to
avoid
the issue entirely by increasing the session time and increasing the
heartbeat
time periodicity.
https:/ /code.launchpad .net/~hazmat/ juju/increase- session- timeout/ +merge/ 146169
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/7231079/
Affected files: tests/test_ port.py tests/test_ zk.py common/ cloudinit. py common/ connect. py common/ tests/data/ cloud_init_ bootstrap common/ tests/data/ cloud_init_ bootstrap_ testing common/ tests/data/ cloud_init_ bootstrap_ zookeepers local/_ _init__ .py local/tests/ test_files. py sshclient. py tests/test_ utils.py
A [revision details]
M juju/agents/base.py
A juju/lib/port.py
A juju/lib/
M juju/lib/
M juju/lib/zk.py
M juju/providers/
M juju/providers/
M juju/providers/
M juju/providers/
M juju/providers/
M juju/providers/
M juju/providers/
M juju/state/
M juju/state/
M juju/state/utils.py
M test