Merge lp:~nick-schutt/lava-dispatcher/nick-1130814 into lp:lava-dispatcher
- nick-1130814
- Merge into trunk
Proposed by
Nicholas Schutt
Status: | Merged |
---|---|
Merged at revision: | 568 |
Proposed branch: | lp:~nick-schutt/lava-dispatcher/nick-1130814 |
Merge into: | lp:lava-dispatcher |
Diff against target: |
440 lines (+67/-62) 9 files modified
lava_dispatcher/actions/lava_android_test.py (+4/-5) lava_dispatcher/client/lmc_utils.py (+7/-7) lava_dispatcher/context.py (+24/-1) lava_dispatcher/device/fastmodel.py (+5/-10) lava_dispatcher/device/master.py (+3/-3) lava_dispatcher/device/nexus.py (+6/-13) lava_dispatcher/device/qemu.py (+1/-5) lava_dispatcher/device/sdmux.py (+9/-11) lava_dispatcher/utils.py (+8/-7) |
To merge this branch: | bzr merge lp:~nick-schutt/lava-dispatcher/nick-1130814 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Linaro Validation Team | Pending | ||
Review via email: mp+152326@code.launchpad.net |
Commit message
Description of the change
Ignore the number in the branch name; it's for bug #1127288
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'lava_dispatcher/actions/lava_android_test.py' |
2 | --- lava_dispatcher/actions/lava_android_test.py 2012-11-22 02:14:51 +0000 |
3 | +++ lava_dispatcher/actions/lava_android_test.py 2013-03-08 06:44:20 +0000 |
4 | @@ -20,7 +20,6 @@ |
5 | # along with this program; if not, see <http://www.gnu.org/licenses>. |
6 | |
7 | import os |
8 | -import subprocess |
9 | import logging |
10 | from lava_dispatcher.actions import BaseAction |
11 | from lava_dispatcher.errors import OperationFailed, TimeoutError |
12 | @@ -69,7 +68,7 @@ |
13 | t = DrainConsoleOutput(proc=session._connection, timeout=timeout) |
14 | t.start() |
15 | logging.info("Execute command on host: %s" % (' '.join(cmds))) |
16 | - rc = subprocess.call(cmds) |
17 | + rc = self.context.run_command(cmds) |
18 | t.join() |
19 | if rc == 124: |
20 | raise TimeoutError( |
21 | @@ -132,7 +131,7 @@ |
22 | cmds.insert(0, 'timeout') |
23 | cmds.insert(1, '%ss' % timeout) |
24 | logging.info("Execute command on host: %s" % (' '.join(cmds))) |
25 | - rc = subprocess.call(cmds) |
26 | + rc = self.context.run_command(cmds) |
27 | if rc == 124: |
28 | raise TimeoutError( |
29 | "The test (%s) on device(%s) times out." % ( |
30 | @@ -180,7 +179,7 @@ |
31 | cmds.insert(1, '%ss' % timeout) |
32 | |
33 | logging.info("Execute command on host: %s" % (' '.join(cmds))) |
34 | - rc = subprocess.call(cmds) |
35 | + rc = self.context.run_command(cmds) |
36 | if rc == 124: |
37 | raise TimeoutError( |
38 | "Failed to run monkeyrunner test url[%s] " |
39 | @@ -219,7 +218,7 @@ |
40 | cmds.insert(0, 'timeout') |
41 | cmds.insert(1, '%ss' % timeout) |
42 | logging.info("Execute command on host: %s" % (' '.join(cmds))) |
43 | - rc = subprocess.call(cmds) |
44 | + rc = self.context.run_commands(cmds) |
45 | if rc == 124: |
46 | raise OperationFailed( |
47 | "The installation of test case(%s)" |
48 | |
49 | === modified file 'lava_dispatcher/client/lmc_utils.py' |
50 | --- lava_dispatcher/client/lmc_utils.py 2012-11-20 13:34:19 +0000 |
51 | +++ lava_dispatcher/client/lmc_utils.py 2013-03-08 06:44:20 +0000 |
52 | @@ -50,24 +50,24 @@ |
53 | logging.info("Executing the linaro-media-create command") |
54 | logging.info(cmd) |
55 | |
56 | - _run_linaro_media_create(cmd) |
57 | + _run_linaro_media_create(client.context, cmd) |
58 | return image_file |
59 | |
60 | -def generate_fastmodel_image(hwpack, rootfs, odir, bootloader='u_boot', size="2000M"): |
61 | +def generate_fastmodel_image(context, hwpack, rootfs, odir, bootloader='u_boot', size="2000M"): |
62 | cmd = ("flock /var/lock/lava-lmc.lck sudo linaro-media-create " |
63 | "--dev fastmodel --output-directory %s --image-size %s " |
64 | "--hwpack %s --binary %s --hwpack-force-yes --bootloader %s" % |
65 | (odir, size, hwpack, rootfs, bootloader) ) |
66 | logging.info("Generating fastmodel image with: %s" % cmd) |
67 | - _run_linaro_media_create(cmd) |
68 | + _run_linaro_media_create(context, cmd) |
69 | |
70 | -def generate_android_image(device, boot, data, system, ofile, size="2000M"): |
71 | +def generate_android_image(context, device, boot, data, system, ofile, size="2000M"): |
72 | cmd = ("flock /var/lock/lava-lmc.lck linaro-android-media-create " |
73 | "--dev %s --image_file %s --image_size %s " |
74 | "--boot %s --userdata %s --system %s" % |
75 | (device, ofile, size, boot, data, system) ) |
76 | logging.info("Generating android image with: %s" % cmd) |
77 | - _run_linaro_media_create(cmd) |
78 | + _run_linaro_media_create(context, cmd) |
79 | |
80 | def get_partition_offset(image, partno): |
81 | cmd = 'parted %s -m -s unit b print' % image |
82 | @@ -97,10 +97,10 @@ |
83 | logging_system('sudo umount ' + mntdir) |
84 | logging_system('rm -rf ' + mntdir) |
85 | |
86 | -def _run_linaro_media_create(cmd): |
87 | +def _run_linaro_media_create(context, cmd): |
88 | """Run linaro-media-create and accept licenses thrown up in the process. |
89 | """ |
90 | - proc = pexpect.spawn(cmd, logfile=sys.stdout) |
91 | + proc = context.spawn(cmd) |
92 | |
93 | # This code is a bit out of control. It describes a state machine. Each |
94 | # state has a name, a mapping patterns to wait for -> state to move to, a |
95 | |
96 | === modified file 'lava_dispatcher/context.py' |
97 | --- lava_dispatcher/context.py 2013-01-23 23:10:37 +0000 |
98 | +++ lava_dispatcher/context.py 2013-03-08 06:44:20 +0000 |
99 | @@ -21,13 +21,17 @@ |
100 | import atexit |
101 | import logging |
102 | import os |
103 | +import subprocess |
104 | import sys |
105 | import tempfile |
106 | |
107 | from lava_dispatcher.config import get_device_config |
108 | from lava_dispatcher.client.targetdevice import TargetBasedClient |
109 | from lava_dispatcher.test_data import LavaTestData |
110 | -from lava_dispatcher.utils import rmtree |
111 | +from lava_dispatcher.utils import ( |
112 | + logging_spawn, |
113 | + rmtree, |
114 | + ) |
115 | |
116 | |
117 | def _write_and_flush(fobj, data): |
118 | @@ -116,3 +120,22 @@ |
119 | |
120 | def get_device_version(self): |
121 | return self.client.target_device.get_device_version() |
122 | + |
123 | + def spawn(self, command, timeout=30): |
124 | + proc = logging_spawn(command, timeout) |
125 | + proc.logfile_read = self.logfile_read |
126 | + return proc |
127 | + |
128 | + def run_command(self, command, failok=True): |
129 | + """run command 'command' with output going to output-dir if specified""" |
130 | + if isinstance(command, (str, unicode)): |
131 | + command = ['sh', '-c', command] |
132 | + output_txt = self.client.context.output.output_txt |
133 | + output_args = {'stdout': output_txt, 'stderr': subprocess.STDOUT} |
134 | + logging.debug("Executing on host : '%r'" % command) |
135 | + if failok: |
136 | + rc = subprocess.call(command, **output_args) |
137 | + else: |
138 | + rc = subprocess.check_call(command, **output_args) |
139 | + return rc |
140 | + |
141 | |
142 | === modified file 'lava_dispatcher/device/fastmodel.py' |
143 | --- lava_dispatcher/device/fastmodel.py 2013-02-18 02:11:39 +0000 |
144 | +++ lava_dispatcher/device/fastmodel.py 2013-03-08 06:44:20 +0000 |
145 | @@ -25,8 +25,6 @@ |
146 | import os |
147 | import shutil |
148 | import stat |
149 | -import threading |
150 | -import re |
151 | import subprocess |
152 | |
153 | import lava_dispatcher.device.boot_options as boot_options |
154 | @@ -107,7 +105,7 @@ |
155 | self._sd_image = '%s/android.img' % os.path.dirname(self._system) |
156 | |
157 | generate_android_image( |
158 | - 'vexpress-a9', self._boot, self._data, self._system, self._sd_image |
159 | + self.context, 'vexpress-a9', self._boot, self._data, self._system, self._sd_image |
160 | ) |
161 | |
162 | self._copy_axf(self.config.boot_part, '') |
163 | @@ -119,7 +117,7 @@ |
164 | rootfs = download_image(rootfs, self.context, decompress=False) |
165 | odir = os.path.dirname(rootfs) |
166 | |
167 | - generate_fastmodel_image(hwpack, rootfs, odir, bootloader) |
168 | + generate_fastmodel_image(self.context, hwpack, rootfs, odir, bootloader) |
169 | self._sd_image = '%s/sd.img' % odir |
170 | self._axf = None |
171 | for f in self.config.simulator_axf_files: |
172 | @@ -203,10 +201,7 @@ |
173 | # the simulator proc only has stdout/stderr about the simulator |
174 | # we hook up into a telnet port which emulates a serial console |
175 | logging.info('launching fastmodel with command %r' % sim_cmd) |
176 | - self._sim_proc = logging_spawn( |
177 | - sim_cmd, |
178 | - logfile=self.context.logfile_read, |
179 | - timeout=1200) |
180 | + self._sim_proc = self.context.spawn(sim_cmd, timeout=1200) |
181 | self._sim_proc.expect(self.PORT_PATTERN, timeout=300) |
182 | self._serial_port = self._sim_proc.match.groups()[0] |
183 | logging.info('serial console port on: %s' % self._serial_port) |
184 | @@ -221,9 +216,9 @@ |
185 | logging.info('simulator is started connecting to serial port') |
186 | self.proc = logging_spawn( |
187 | 'telnet localhost %s' % self._serial_port, |
188 | - logfile=self._create_rtsm_ostream( |
189 | - self.context.logfile_read), |
190 | timeout=1200) |
191 | + self.proc.logfile_read = self._create_rtsm_ostream( |
192 | + self.proc.logfile_read) |
193 | return self.proc |
194 | |
195 | def get_test_data_attachments(self): |
196 | |
197 | === modified file 'lava_dispatcher/device/master.py' |
198 | --- lava_dispatcher/device/master.py 2013-01-30 18:45:16 +0000 |
199 | +++ lava_dispatcher/device/master.py 2013-03-08 06:44:20 +0000 |
200 | @@ -82,9 +82,9 @@ |
201 | self.device_version = None |
202 | |
203 | if config.pre_connect_command: |
204 | - logging_system(config.pre_connect_command) |
205 | + self.context.run_command(config.pre_connect_command) |
206 | |
207 | - self.proc = connect_to_serial(config, self.context.logfile_read) |
208 | + self.proc = connect_to_serial(self.context) |
209 | |
210 | def get_device_version(self): |
211 | return self.device_version |
212 | @@ -397,7 +397,7 @@ |
213 | logging.info("Perform hard reset on the system") |
214 | self.master_ip = None |
215 | if self.config.hard_reset_command != "": |
216 | - logging_system(self.config.hard_reset_command) |
217 | + self.context.run_command(self.config.hard_reset_command) |
218 | else: |
219 | self.proc.send("~$") |
220 | self.proc.sendline("hardreset") |
221 | |
222 | === modified file 'lava_dispatcher/device/nexus.py' |
223 | --- lava_dispatcher/device/nexus.py 2013-02-04 13:31:34 +0000 |
224 | +++ lava_dispatcher/device/nexus.py 2013-03-08 06:44:20 +0000 |
225 | @@ -19,7 +19,6 @@ |
226 | # with this program; if not, see <http://www.gnu.org/licenses>. |
227 | |
228 | import subprocess |
229 | -import pexpect |
230 | from time import sleep |
231 | import logging |
232 | import contextlib |
233 | @@ -31,8 +30,6 @@ |
234 | download_image |
235 | ) |
236 | from lava_dispatcher.utils import ( |
237 | - logging_system, |
238 | - logging_spawn, |
239 | mkdtemp |
240 | ) |
241 | from lava_dispatcher.errors import ( |
242 | @@ -40,13 +37,9 @@ |
243 | ) |
244 | |
245 | |
246 | -def _call(cmd, ignore_failure, timeout): |
247 | +def _call(context, cmd, ignore_failure, timeout): |
248 | cmd = 'timeout ' + str(timeout) + 's ' + cmd |
249 | - logging.debug("Running on the host: %s", cmd) |
250 | - if ignore_failure: |
251 | - subprocess.call(cmd, shell=True) |
252 | - else: |
253 | - subprocess.check_call(cmd, shell=True) |
254 | + context.run_command(cmd, failok=ignore_failure) |
255 | |
256 | |
257 | class FastBoot(object): |
258 | @@ -57,7 +50,7 @@ |
259 | def __call__(self, args, ignore_failure=False, timeout=600): |
260 | command = self.device.config.fastboot_command + ' ' + args |
261 | command = "flock /var/lock/lava-fastboot.lck " + command |
262 | - _call(command, ignore_failure, timeout) |
263 | + _call(self.device.context, command, ignore_failure, timeout) |
264 | |
265 | def enter(self): |
266 | if self.on(): |
267 | @@ -71,7 +64,7 @@ |
268 | # probably hung. |
269 | if self.device.config.hard_reset_command: |
270 | logging.debug("Will hard reset the device") |
271 | - logging_system(self.device.config.hard_reset_command) |
272 | + self.context.run_command(self.device.config.hard_reset_command) |
273 | else: |
274 | logging.critical( |
275 | "Hard reset command not configured. " |
276 | @@ -187,9 +180,9 @@ |
277 | def _adb(self, args, ignore_failure=False, spawn=False, timeout=600): |
278 | cmd = self.config.adb_command + ' ' + args |
279 | if spawn: |
280 | - return logging_spawn(cmd, timeout=60) |
281 | + return self.context.spawn(cmd, timeout=60) |
282 | else: |
283 | - _call(cmd, ignore_failure, timeout) |
284 | + _call(self.context, cmd, ignore_failure, timeout) |
285 | |
286 | def _get_image(self, url): |
287 | sdir = self.working_dir |
288 | |
289 | === modified file 'lava_dispatcher/device/qemu.py' |
290 | --- lava_dispatcher/device/qemu.py 2013-01-16 23:27:28 +0000 |
291 | +++ lava_dispatcher/device/qemu.py 2013-03-08 06:44:20 +0000 |
292 | @@ -36,7 +36,6 @@ |
293 | from lava_dispatcher.utils import ( |
294 | ensure_directory, |
295 | extract_targz, |
296 | - logging_spawn, |
297 | ) |
298 | |
299 | |
300 | @@ -79,10 +78,7 @@ |
301 | self.config.qemu_drive_interface, |
302 | self._sd_image) |
303 | logging.info('launching qemu with command %r' % qemu_cmd) |
304 | - proc = logging_spawn( |
305 | - qemu_cmd, |
306 | - logfile=self.context.logfile_read, |
307 | - timeout=1200) |
308 | + proc = self.context.spawn(qemu_cmd, timeout=1200) |
309 | return proc |
310 | |
311 | def get_device_version(self): |
312 | |
313 | === modified file 'lava_dispatcher/device/sdmux.py' |
314 | --- lava_dispatcher/device/sdmux.py 2013-01-28 23:59:47 +0000 |
315 | +++ lava_dispatcher/device/sdmux.py 2013-03-08 06:44:20 +0000 |
316 | @@ -42,7 +42,6 @@ |
317 | connect_to_serial, |
318 | ensure_directory, |
319 | extract_targz, |
320 | - logging_system, |
321 | ) |
322 | |
323 | |
324 | @@ -87,7 +86,7 @@ |
325 | raise CriticalError('Device config requires "power_off_cmd"') |
326 | |
327 | if config.pre_connect_command: |
328 | - logging_system(config.pre_connect_command) |
329 | + self.context.run_command(config.pre_connect_command) |
330 | |
331 | def deploy_linaro(self, hwpack=None, rootfs=None): |
332 | img = generate_image(self, hwpack, rootfs, self.scratch_dir) |
333 | @@ -115,7 +114,7 @@ |
334 | |
335 | img = os.path.join(scratch, 'android.img') |
336 | device_type = self.config.lmc_dev_arg |
337 | - generate_android_image(device_type, boot, data, system, img) |
338 | + generate_android_image(self.context, device_type, boot, data, system, img) |
339 | self._customize_android(img) |
340 | self._write_image(img) |
341 | |
342 | @@ -170,7 +169,7 @@ |
343 | raise CriticalError('Unable to access sdmux device') |
344 | finally: |
345 | logging.info('powering off sdmux') |
346 | - subprocess.check_call([muxscript, '-d', muxid, 'off']) |
347 | + self.context.run_command([muxscript, '-d', muxid, 'off'], failok=False) |
348 | |
349 | @contextlib.contextmanager |
350 | def file_system(self, partition, directory): |
351 | @@ -185,7 +184,7 @@ |
352 | with self.mux_device() as device: |
353 | device = '%s%s' % (device, partition) |
354 | try: |
355 | - subprocess.check_call(['mount', device, mntdir]) |
356 | + self.context.run_command(['mount', device, mntdir], failok=False) |
357 | if directory[0] == '/': |
358 | directory = directory[1:] |
359 | path = os.path.join(mntdir, directory) |
360 | @@ -203,11 +202,11 @@ |
361 | logging.info('unmounting sdmux') |
362 | try: |
363 | _flush_files(mntdir) |
364 | - subprocess.check_call(['umount', device]) |
365 | + self.context.run_command(['umount', device], failok=False) |
366 | except subprocess.CalledProcessError: |
367 | logging.exception('umount failed, re-try in 10 seconds') |
368 | time.sleep(10) |
369 | - if subprocess.call(['umount', device]) != 0: |
370 | + if self.context.run_command(['umount', device]) != 0: |
371 | logging.error( |
372 | 'Unable to unmount sdmux device %s', device) |
373 | |
374 | @@ -219,14 +218,13 @@ |
375 | |
376 | def power_off(self, proc): |
377 | super(SDMuxTarget, self).power_off(proc) |
378 | - logging_system(self.config.power_off_cmd) |
379 | + self.context.run_command(self.config.power_off_cmd) |
380 | |
381 | def power_on(self): |
382 | - self.proc = connect_to_serial( |
383 | - self.config, self.context.logfile_read) |
384 | + self.proc = connect_to_serial(self.context) |
385 | |
386 | logging.info('powering on') |
387 | - logging_system(self.config.power_on_cmd) |
388 | + self.context.run_command(self.config.power_on_cmd) |
389 | |
390 | return self.proc |
391 | |
392 | |
393 | === modified file 'lava_dispatcher/utils.py' |
394 | --- lava_dispatcher/utils.py 2013-01-16 23:27:28 +0000 |
395 | +++ lava_dispatcher/utils.py 2013-03-08 06:44:20 +0000 |
396 | @@ -169,9 +169,9 @@ |
397 | |
398 | class logging_spawn(pexpect.spawn): |
399 | |
400 | - def __init__(self, command, timeout=30, logfile=None): |
401 | + def __init__(self, command, timeout=30): |
402 | pexpect.spawn.__init__( |
403 | - self, command, timeout=timeout, logfile=logfile) |
404 | + self, command, timeout=timeout) |
405 | |
406 | # serial can be slow, races do funny things, so increase delay |
407 | self.delaybeforesend = 0.05 |
408 | @@ -214,7 +214,7 @@ |
409 | timeout=1, lava_no_logging=1) |
410 | |
411 | |
412 | -def connect_to_serial(device_config, logfile_read): |
413 | +def connect_to_serial(context): |
414 | """ |
415 | Attempts to connect to a serial console server like conmux or cyclades |
416 | """ |
417 | @@ -237,8 +237,9 @@ |
418 | results.append(result) |
419 | |
420 | while retry_count < retry_limit: |
421 | - proc = logging_spawn(device_config.connection_command, timeout=1200) |
422 | - proc.logfile_read = logfile_read |
423 | + proc = context.spawn( |
424 | + context.client.config.connection_command, |
425 | + timeout=1200) |
426 | logging.info('Attempting to connect to device') |
427 | match = proc.expect(patterns, timeout=10) |
428 | result = results[match] |
429 | @@ -252,9 +253,9 @@ |
430 | atexit.register(proc.close, True) |
431 | return proc |
432 | elif result == 'reset-port': |
433 | - reset_cmd = device_config.reset_port_command |
434 | + reset_cmd = context.client.config.reset_port_command |
435 | if reset_cmd: |
436 | - logging_system(reset_cmd) |
437 | + context.run_command(reset_cmd) |
438 | else: |
439 | raise CriticalError('no reset_port command configured') |
440 | proc.close(True) |