Merge lp:~javier.collado/utah/retry-timeout into lp:utah

Proposed by Javier Collado
Status: Merged
Merged at revision: 833
Proposed branch: lp:~javier.collado/utah/retry-timeout
Merge into: lp:utah
Diff against target: 264 lines (+34/-55)
9 files modified
utah/client/runner.py (+0/-3)
utah/config.py (+4/-1)
utah/exceptions.py (+1/-4)
utah/provisioning/baremetal/bamboofeeder.py (+2/-1)
utah/provisioning/baremetal/cobbler.py (+2/-2)
utah/provisioning/provisioning.py (+3/-17)
utah/provisioning/ssh.py (+3/-15)
utah/retry.py (+19/-9)
utah/url.py (+0/-3)
To merge this branch: bzr merge lp:~javier.collado/utah/retry-timeout
Reviewer Review Type Date Requested Status
Max Brustkern (community) Approve
Review via email: mp+153198@code.launchpad.net

Description of the change

This branch moves the different time.sleep calls in methods like `pingcheck`
and `sshcheck` to the `retry` function that is already wrapping them.

Before this change `retry` called the callable passed as argument as soon as a
retriable exception was caught and was the responsibiliy of the callable to
call `time.sleep` if needed. With this change, the `retry` takes care of that
and uses a default value from the configuration file so that callables only
need to take care of raising an exception when they fail.

To post a comment you must log in.
Revision history for this message
Max Brustkern (nuclearbob) wrote :

I see some merge conflicts. It seems weird that this and the rsyslog branch have been getting them lately. I wonder if there's been a change in launchpad that's causing this.

Revision history for this message
Max Brustkern (nuclearbob) wrote :

The actual changes look sound. I think at some point when we overhaul config, we can address the circular import problem.

Revision history for this message
Andy Doan (doanac) wrote :

these are real merge conflicts. minus those, i like the changes.

832. By Javier Collado

Merged changes to fix battery behavior with regard to logging

Source branch: lp:~javier.collado/utah/battery-measurements-logging

Revision history for this message
Javier Collado (javier.collado) wrote :

I've rebased the changes and the merge conflicts are not fixed.

I've run a test and everything worked fine, but I believe the code wasn't
really exercised because rsyslog implementation does a good work in monitoring
the reboot after the installation so the first ping command doesn't fail in VMs
as it used to do in the past.

Anyway, since I tested already before the rebasing, I don't expect any
problem.

Revision history for this message
Max Brustkern (nuclearbob) wrote :

Looks reasonable to me, if you're already tested.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'utah/client/runner.py'
2--- utah/client/runner.py 2013-03-11 09:17:54 +0000
3+++ utah/client/runner.py 2013-03-14 17:40:27 +0000
4@@ -31,7 +31,6 @@
5 import stat
6 import urllib
7 import jsonschema
8-import time
9
10 from utah.client.common import (
11 MASTER_RUNLIST,
12@@ -472,8 +471,6 @@
13 if (isinstance(vcs_handler, BzrHandler) and
14 result['returncode'] == 3 and
15 'Unable to handle http code 502' in result['stderr']):
16- # Separate every retry attempt with a timeout of 3 seconds
17- time.sleep(3)
18 raise UTAHException('Launchpad temporary error detected',
19 retry=True)
20 return result
21
22=== modified file 'utah/config.py'
23--- utah/config.py 2013-03-12 16:10:49 +0000
24+++ utah/config.py 2013-03-14 17:40:27 +0000
25@@ -186,7 +186,10 @@
26 'pattern': '.*NetworkManager',
27 'timeout': 180,
28 }
29- ]
30+ ],
31+
32+ # default timeout between retry attempts
33+ retry_timeout=3,
34 )
35
36 # These depend on the local user/path, and need to be filtered out
37
38=== modified file 'utah/exceptions.py'
39--- utah/exceptions.py 2012-12-03 14:02:18 +0000
40+++ utah/exceptions.py 2013-03-14 17:40:27 +0000
41@@ -24,8 +24,5 @@
42 Support retry argument, but default to False.
43 """
44 def __init__(self, *args, **kw):
45- try:
46- self.retry = kw.pop('retry')
47- except KeyError:
48- self.retry = False
49+ self.retry = kw.pop('retry', False)
50 super(UTAHException, self).__init__(*args, **kw)
51
52=== modified file 'utah/provisioning/baremetal/bamboofeeder.py'
53--- utah/provisioning/baremetal/bamboofeeder.py 2013-03-05 21:01:23 +0000
54+++ utah/provisioning/baremetal/bamboofeeder.py 2013-03-14 17:40:27 +0000
55@@ -275,7 +275,8 @@
56
57 self.rsyslog.wait_for_install(config.install_steps)
58 self.rsyslog.wait_for_booted(config.boot_steps)
59- retry(self.sshcheck, config.checktimeout, logmethod=self.logger.info)
60+ retry(self.sshcheck, logmethod=self.logger.info,
61+ retry_timeout=config.checktimeout)
62
63 self.provisioned = True
64 self.active = True
65
66=== modified file 'utah/provisioning/baremetal/cobbler.py'
67--- utah/provisioning/baremetal/cobbler.py 2013-03-05 21:01:23 +0000
68+++ utah/provisioning/baremetal/cobbler.py 2013-03-14 17:40:27 +0000
69@@ -21,7 +21,6 @@
70 import pipes
71 import subprocess
72 import tempfile
73-import time
74
75 from utah import config
76 from utah.provisioning.baremetal.exceptions import UTAHBMProvisioningException
77@@ -198,7 +197,8 @@
78 if self.installtype == 'desktop':
79 self._removenfs()
80
81- retry(self.sshcheck, config.checktimeout, logmethod=self.logger.info)
82+ retry(self.sshcheck, logmethod=self.logger.info,
83+ retry_timeout=config.checktimeout)
84
85 self.provisioned = True
86 self.active = True
87
88=== modified file 'utah/provisioning/provisioning.py'
89--- utah/provisioning/provisioning.py 2013-03-05 21:03:09 +0000
90+++ utah/provisioning/provisioning.py 2013-03-14 17:40:27 +0000
91@@ -28,7 +28,6 @@
92 import shutil
93 import subprocess
94 import sys
95-import time
96 import urllib
97 import uuid
98
99@@ -310,16 +309,9 @@
100 if not self.active:
101 self._start()
102
103- def pingcheck(self, timeout=config.checktimeout):
104+ def pingcheck(self):
105 """Check network connectivity using ping.
106
107- :param timeout: Amount of time in seconds to sleep after a failure
108- :type timeout: int
109- :raises: UTAHProvisioningException
110-
111- If there's a network connectivity failure, then sleep ``timeout``
112- seconds and raise a retriable exception.
113-
114 .. seealso:: :func:`utah.retry.retry`, :meth:`pingpoll`
115
116 """
117@@ -328,12 +320,6 @@
118 self._runargs(['ping', '-c1', '-w5', self.name])['returncode']
119 if returncode != 0:
120 err = 'Ping returned {0}'.format(returncode)
121-
122- if timeout > 0:
123- self.logger.info('Sleeping {timeout} seconds'
124- .format(timeout=timeout))
125- time.sleep(timeout)
126-
127 raise UTAHProvisioningException(err, retry=True)
128
129 def pingpoll(self,
130@@ -345,8 +331,8 @@
131 timeout = self.boottimeout
132 if logmethod is None:
133 logmethod = self.logger.debug
134- utah.timeout.timeout(timeout, retry, self.pingcheck, checktimeout,
135- logmethod=logmethod)
136+ utah.timeout.timeout(timeout, retry, self.pingcheck,
137+ logmethod=logmethod, retry_timeout=checktimeout)
138
139 def getutahdeb(self, deb):
140 """
141
142=== modified file 'utah/provisioning/ssh.py'
143--- utah/provisioning/ssh.py 2013-03-07 21:55:56 +0000
144+++ utah/provisioning/ssh.py 2013-03-14 17:40:27 +0000
145@@ -238,16 +238,9 @@
146
147 super(SSHMixin, self).destroy(*args, **kw)
148
149- def sshcheck(self, timeout=config.checktimeout):
150+ def sshcheck(self):
151 """Check if the machine is available via ssh.
152
153- :param timeout: Amount of time in seconds to sleep after a failure
154- :type timeout: int
155- :raises: UTAHProvisioningException
156-
157- If there's a network connectivity failure, then sleep ``timeout``
158- seconds and raise a retriable exception.
159-
160 .. seealso:: :func:`utah.retry.retry`, :meth:`sshpoll`
161
162 """
163@@ -257,11 +250,6 @@
164 username=config.user,
165 key_filename=config.sshprivatekey)
166 except socket.error as err:
167- if timeout > 0:
168- self.ssh_logger.info('Sleeping {timeout} seconds'
169- .format(timeout=timeout))
170- time.sleep(timeout)
171-
172 raise UTAHProvisioningException(str(err), retry=True)
173
174 def sshpoll(self, timeout=None,
175@@ -273,8 +261,8 @@
176 timeout = self.boottimeout
177 if logmethod is None:
178 logmethod = self.ssh_logger.debug
179- utah.timeout.timeout(timeout, retry, self.sshcheck, checktimeout,
180- logmethod=logmethod)
181+ utah.timeout.timeout(timeout, retry, self.sshcheck,
182+ logmethod=logmethod, retry_timeout=checktimeout)
183
184 def activecheck(self):
185 """
186
187=== modified file 'utah/retry.py'
188--- utah/retry.py 2013-02-06 10:53:54 +0000
189+++ utah/retry.py 2013-03-14 17:40:27 +0000
190@@ -17,6 +17,7 @@
191 Provide a retry loop that exits on success or an unretryable exception.
192 """
193 import sys
194+import time
195
196 from utah.exceptions import UTAHException
197 from utah.commandstr import commandstr
198@@ -36,18 +37,24 @@
199 Keyword arguments to be passed to the callable.
200
201 .. note::
202- If a keyword argument named ``logmethod`` is found, it will be
203- extracted (i.e. it won't be passed to the callable) and used to log
204- every retry attempt (using ``sys.stderr`` by default).
205+ There are a few keywords that are consumed by ``retry`` and not
206+ passed to the callable:
207+ * ``logmethod``: Preferred log method for every retry attempt
208+ (``sys.stderr`` by default)
209+ * ``retry_timeout``: Timeout in seconds between each retry
210+ attempt
211+
212 :returns: The value returned by the callable.
213
214 .. seealso:: :func:`utah.timeout.timeout`
215
216 """
217- try:
218- logmethod = kw.pop('logmethod')
219- except KeyError:
220- logmethod = sys.stderr.write
221+ # The following import is in the function body to avoid a cycle:
222+ # utah.config -> utah.url -> utah.retry -> utah.config
223+ from utah import config
224+
225+ logmethod = kw.pop('logmethod', sys.stderr.write)
226+ retry_timeout = kw.pop('retry_timeout', config.retry_timeout)
227 retval = False
228 while True:
229 try:
230@@ -57,8 +64,11 @@
231 try:
232 if err.retry:
233 if logmethod is not None:
234- logmethod('Caught ' + str(err) + ', retrying '
235- + commandstr(command, *args, **kw))
236+ logmethod('Caught {}, retrying {} in {} seconds'
237+ .format(err,
238+ commandstr(command, *args, **kw),
239+ retry_timeout))
240+ time.sleep(retry_timeout)
241 else:
242 raise AttributeError
243 except AttributeError:
244
245=== modified file 'utah/url.py'
246--- utah/url.py 2013-02-06 10:07:52 +0000
247+++ utah/url.py 2013-03-14 17:40:27 +0000
248@@ -24,7 +24,6 @@
249 import urllib2
250 import tempfile
251 import logging
252-import time
253 from urlparse import urlparse
254 from argparse import ArgumentTypeError
255
256@@ -226,8 +225,6 @@
257 try:
258 cmd.run(tmp_dir, url)
259 except bzrlib.errors.InvalidHttpResponse as exception:
260- # Separate every retry attempt with a timeout of 3 seconds
261- time.sleep(3)
262 raise UTAHException(exception.path, exception.msg, retry=True)
263
264 try:

Subscribers

People subscribed via source and target branches