Merge lp:~codehelp/lava-dispatcher/multinode-pep8 into lp:lava-dispatcher/multinode

Proposed by Neil Williams
Status: Superseded
Proposed branch: lp:~codehelp/lava-dispatcher/multinode-pep8
Merge into: lp:lava-dispatcher/multinode
Diff against target: 692 lines (+123/-114)
8 files modified
lava/dispatcher/commands.py (+3/-2)
lava/dispatcher/group.py (+27/-22)
lava_dispatcher/actions/deploy.py (+9/-9)
lava_dispatcher/actions/launch_control.py (+10/-7)
lava_dispatcher/actions/lava_test_shell.py (+29/-25)
lava_dispatcher/device/master.py (+18/-20)
lava_dispatcher/device/target.py (+2/-3)
lava_dispatcher/lava_test_shell.py (+25/-26)
To merge this branch: bzr merge lp:~codehelp/lava-dispatcher/multinode-pep8
Reviewer Review Type Date Requested Status
Linaro Automation & Validation Pending
Review via email: mp+175256@code.launchpad.net

This proposal has been superseded by a proposal from 2013-07-18.

Description of the change

Remaining PEP8 changes to match tip.

To post a comment you must log in.

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lava/dispatcher/commands.py'
2--- lava/dispatcher/commands.py 2013-06-21 15:53:31 +0000
3+++ lava/dispatcher/commands.py 2013-07-17 11:38:38 +0000
4@@ -82,7 +82,7 @@
5 help="Test scenario file")
6 parser.add_argument(
7 "--target",
8- default = None,
9+ default=None,
10 help="Run the job on a specific target device"
11 )
12
13@@ -154,7 +154,8 @@
14 exit(0)
15 if self.args.target is None:
16 if 'target' not in json_jobdata:
17- logging.error("The job file does not specify a target device. You must specify one using the --target option.")
18+ logging.error("The job file does not specify a target device. "
19+ "You must specify one using the --target option.")
20 exit(1)
21 else:
22 json_jobdata['target'] = self.args.target
23
24=== modified file 'lava/dispatcher/group.py'
25--- lava/dispatcher/group.py 2013-07-05 11:48:41 +0000
26+++ lava/dispatcher/group.py 2013-07-17 11:38:38 +0000
27@@ -20,7 +20,6 @@
28 import json
29 import time
30 import socket
31-import copy
32
33
34 class GroupDispatcher(object):
35@@ -88,7 +87,6 @@
36 logging.error("Missing client_name in request: %s" % json_data)
37 return None
38 if json_data['group_name'] not in self.all_groups:
39- print json.dumps(json_data)
40 if "group_size" not in json_data or json_data["group_size"] == 0:
41 logging.error('%s asked for a new group %s without specifying the size of the group'
42 % (client_name, json_data['group_name']))
43@@ -151,7 +149,8 @@
44 self._badRequest()
45 return
46 logging.info("Sending messageID '%s' to %s in group %s: %s" %
47- (messageID, client_name, self.group['group'], json.dumps(self.group['messages'][client_name][messageID])))
48+ (messageID, client_name, self.group['group'],
49+ json.dumps(self.group['messages'][client_name][messageID])))
50 msg = {"response": "ack", "message": self.group['messages'][client_name][messageID]}
51 logging.info("Sending response to %s in group %s: %s" %
52 (client_name, self.group['group'], json.dumps(msg)))
53@@ -192,13 +191,15 @@
54 Global synchronization primitive. Sends a message and waits for the same
55 message from all of the other devices.
56 """
57- logging.debug("GroupDispatcher:lavaSync %s from %s in group %s" %(json.dumps(json_data), client_name, self.group['group']))
58+ logging.debug("GroupDispatcher:lavaSync %s from %s in group %s" %
59+ (json.dumps(json_data), client_name, self.group['group']))
60 messageID = self._getMessageID(json_data)
61 message = self._getMessage(json_data)
62 # FIXME: in _sendMessage, be sure to send the messageID if message is empty
63 if not message:
64 message = messageID
65- logging.info("LavaSync request for '%s' at stage '%s' in group '%s'" % (client_name, messageID, self.group['group']))
66+ logging.info("LavaSync request for '%s' at stage '%s' in group '%s'" %
67+ (client_name, messageID, self.group['group']))
68 self.group['syncs'].setdefault(messageID, {})
69 self.group['messages'].setdefault(client_name, {}).setdefault(messageID, {})
70 if len(self.group['syncs'][messageID]) >= self.group['count']:
71@@ -230,21 +231,13 @@
72 """
73 messageID = self._getMessageID(json_data)
74 if 'role' in json_data:
75- role_msg = {}
76+ logging.debug("setting message: %s for %s" % (self.group['messages'][client_name][messageID], client_name))
77 for client in self.group['roles'][json_data['role']]:
78 if client not in self.group['messages'] or messageID not in self.group['messages'][client]:
79 self._waitResponse()
80 return
81- # combine all messages for this messageID into a single message for the entire role.
82- role_msg[client] = copy.deepcopy(self.group['messages'][client][messageID])
83- msg = {}
84- # build a single structure with all of the data for all clients in the role
85- for client in self.group['roles'][json_data['role']]:
86- msg[client] = role_msg[client]
87- del self.group['messages'][client_name][messageID]
88- # now put all of the data in msg into the messageID for all clients with this role
89- for client in self.group['roles'][json_data['role']]:
90- self.group['messages'][client][messageID] = copy.deepcopy(msg)
91+ logging.debug("broadcasting: %s for %s" % (self.group['messages'][client][messageID], client))
92+ logging.debug("lavaWaitAll message: %s" % json.dumps(self.group['messages'][client_name][messageID]))
93 else:
94 for client in self.group['clients']:
95 if client not in self.group['messages'] or messageID not in self.group['messages'][client]:
96@@ -266,7 +259,7 @@
97 return
98 self._sendMessage(client_name, messageID)
99
100- def lavaSend(self, json_data):
101+ def lavaSend(self, json_data, client_name):
102 """
103 A message list won't be seen by the destination until the destination
104 calls lava_wait or lava_wait_all with the messageID
105@@ -274,14 +267,26 @@
106 """
107 message = self._getMessage(json_data)
108 messageID = self._getMessageID(json_data)
109- logging.info("lavaSend handler in GroupDispatcher received a messageID '%s' for group '%s'"
110- % (messageID, self.group['group']))
111+ logging.info("lavaSend handler in GroupDispatcher received a messageID '%s' for group '%s' from %s"
112+ % (messageID, self.group['group'], client_name))
113+ if client_name not in self.group['messages']:
114+ self.group['messages'][client_name] = {}
115+ # construct the message hash which stores the data from each client separately
116+ # but which gets returned as a complete hash upon request
117+ msg_hash = {}
118+ msg_hash.update({client_name: message})
119+ # always set this client data if the call is made to update the broadcast
120+ if messageID not in self.group['messages'][client_name]:
121+ self.group['messages'][client_name][messageID] = {}
122+ self.group['messages'][client_name][messageID].update(msg_hash)
123+ logging.debug("message %s for %s" % (json.dumps(self.group['messages'][client_name][messageID]), client_name))
124 for client in self.group['clients']:
125 if client not in self.group['messages']:
126 self.group['messages'][client] = {}
127 if messageID not in self.group['messages'][client]:
128- self.group['messages'][client][messageID] = []
129- self.group['messages'][client][messageID].append(message)
130+ self.group['messages'][client][messageID] = {}
131+ self.group['messages'][client][messageID].update(msg_hash)
132+ logging.debug("broadcast %s for %s" % (json.dumps(self.group['messages'][client][messageID]), client))
133 self._ackResponse()
134
135 def dataReceived(self, json_data):
136@@ -315,7 +320,7 @@
137 self.lavaWait(json_data, client_name)
138 elif request == 'lava_send':
139 logging.info("lava_send: %s" % json_data)
140- self.lavaSend(json_data)
141+ self.lavaSend(json_data, client_name)
142 elif request == "complete":
143 logging.info("dispatcher communication for '%s' in group '%s' is complete, closing." %
144 (client_name, self.group['group']))
145
146=== modified file 'lava_dispatcher/actions/deploy.py'
147--- lava_dispatcher/actions/deploy.py 2013-07-03 10:44:31 +0000
148+++ lava_dispatcher/actions/deploy.py 2013-07-17 11:38:38 +0000
149@@ -56,9 +56,9 @@
150 'rootfstype': {'type': 'string', 'optional': True},
151 'bootloader': {'type': 'string', 'optional': True, 'default': 'u_boot'},
152 'role': {'type': 'string', 'optional': True},
153- },
154+ },
155 'additionalProperties': False,
156- }
157+ }
158
159 @classmethod
160 def validate_parameters(cls, parameters):
161@@ -85,9 +85,9 @@
162 'system': {'type': 'string'},
163 'data': {'type': 'string'},
164 'rootfstype': {'type': 'string', 'optional': True, 'default': 'ext4'},
165- },
166+ },
167 'additionalProperties': False,
168- }
169+ }
170
171 def run(self, boot, system, data, rootfstype='ext4'):
172 self.client.deploy_linaro_android(boot, system, data, rootfstype)
173@@ -98,12 +98,12 @@
174 parameters_schema = {
175 'type': 'object',
176 'properties': {
177- 'type': {'type': 'string', 'enum':['ubuntu', 'oe', 'android', 'fedora']},
178- },
179+ 'type': {'type': 'string', 'enum': ['ubuntu', 'oe', 'android', 'fedora']},
180+ },
181 'additionalProperties': False,
182- }
183+ }
184
185- def run(self, type):
186+ def run(self, target_type):
187 device = self.client.target_device
188 device.boot_master_image()
189- device.deployment_data = device.target_map[type]
190+ device.deployment_data = device.target_map[target_type]
191
192=== modified file 'lava_dispatcher/actions/launch_control.py'
193--- lava_dispatcher/actions/launch_control.py 2013-06-24 16:47:11 +0000
194+++ lava_dispatcher/actions/launch_control.py 2013-07-17 11:38:38 +0000
195@@ -37,7 +37,9 @@
196
197
198 class GatherResultsError(Exception):
199- def __init__(self, msg, bundles=[]):
200+ def __init__(self, msg, bundles=None):
201+ if not bundles:
202+ bundles = []
203 super(GatherResultsError, self).__init__(msg)
204 self.bundles = bundles
205
206@@ -50,7 +52,8 @@
207 #Fix it: it's going to be deleted after transition
208 if server.endswith("dashboard/"):
209 server = ''.join([server, "xml-rpc/"])
210- logging.warn("Please use whole endpoint URL not just end with 'dashboard/', 'xml-rpc/' is added automatically now!!!")
211+ logging.warn("Please use whole endpoint URL not just end with 'dashboard/', "
212+ "'xml-rpc/' is added automatically now!!!")
213
214 parsed_server = urlparse.urlparse(server)
215 auth_backend = MemoryAuthBackend([])
216@@ -96,9 +99,9 @@
217 'stream': {'type': 'string'},
218 'result_disk': {'type': 'string', 'optional': True},
219 'token': {'type': 'string', 'optional': True},
220- },
221+ },
222 'additionalProperties': False,
223- }
224+ }
225
226 def _get_bundles(self, files):
227 bundles = []
228@@ -208,9 +211,9 @@
229 def combine_bundles(self, all_bundles):
230 if not all_bundles:
231 main_bundle = {
232- "test_runs": [],
233- "format": "Dashboard Bundle Format 1.6"
234- }
235+ "test_runs": [],
236+ "format": "Dashboard Bundle Format 1.6"
237+ }
238 else:
239 main_bundle = all_bundles.pop(0)
240 test_runs = main_bundle['test_runs']
241
242=== modified file 'lava_dispatcher/actions/lava_test_shell.py'
243--- lava_dispatcher/actions/lava_test_shell.py 2013-07-03 10:44:31 +0000
244+++ lava_dispatcher/actions/lava_test_shell.py 2013-07-17 11:38:38 +0000
245@@ -127,7 +127,6 @@
246 from lava_dispatcher import utils
247
248 from lava_dispatcher.actions import BaseAction
249-from lava_dispatcher.client.base import wait_for_prompt
250 from lava_dispatcher.device.target import Target
251 from lava_dispatcher.downloader import download_image
252
253@@ -166,6 +165,7 @@
254 # 755 file permissions
255 XMOD = stat.S_IRWXU | stat.S_IXGRP | stat.S_IRGRP | stat.S_IXOTH | stat.S_IROTH
256
257+
258 def _get_testdef_git_repo(testdef_repo, tmpdir, revision):
259 cwd = os.getcwd()
260 gitdir = os.path.join(tmpdir, 'gittestrepo')
261@@ -251,6 +251,8 @@
262
263 def load_from_repo(self, testdef_repo):
264 tmpdir = utils.mkdtemp(self.tmpbase)
265+ repo = None
266+ info = None
267 if 'git-repo' in testdef_repo:
268 repo = _get_testdef_git_repo(
269 testdef_repo['git-repo'], tmpdir, testdef_repo.get('revision'))
270@@ -263,6 +265,8 @@
271 name = testdef_repo['bzr-repo'].replace('lp:', '').split('/')[-1]
272 info = _bzr_info(testdef_repo['bzr-repo'], repo, name)
273
274+ if not repo or not info:
275+ logging.debug("Unable to identify specified repository. %s" % testdef_repo)
276 test = testdef_repo.get('testdef', 'lavatest.yaml')
277 with open(os.path.join(repo, test), 'r') as f:
278 logging.info('loading test definition ...')
279@@ -283,7 +287,7 @@
280 'branch_vcs': 'bzr',
281 'branch_revision': revno,
282 'branch_url': url,
283- }
284+ }
285 finally:
286 os.chdir(cwd)
287
288@@ -298,8 +302,8 @@
289 'project_name': name,
290 'branch_vcs': 'git',
291 'branch_revision': commit_id,
292- 'branch_url': url,
293- }
294+ 'branch_url': url
295+ }
296 finally:
297 os.chdir(cwd)
298
299@@ -354,7 +358,8 @@
300 # have non-reproducible behavior because it may rely on
301 # bzr whoami value, presence of ssh keys, etc.
302 subprocess.check_call(['bzr', 'branch', repo],
303- env={'BZR_HOME': '/dev/null', 'BZR_LOG': '/dev/null'})
304+ env={'BZR_HOME': '/dev/null',
305+ 'BZR_LOG': '/dev/null'})
306 name = repo.replace('lp:', '').split('/')[-1]
307 self._sw_sources.append(_bzr_info(repo, name, name))
308
309@@ -422,8 +427,8 @@
310 f.write('read\n')
311 steps = self.testdef['run'].get('steps', [])
312 if steps:
313- for cmd in steps:
314- f.write('%s\n' % cmd)
315+ for cmd in steps:
316+ f.write('%s\n' % cmd)
317 f.write('echo "<LAVA_SIGNAL_ENDRUN $TESTRUN_ID $UUID>"\n')
318 f.write('#wait for an ack from the dispatcher\n')
319 f.write('read\n')
320@@ -466,23 +471,23 @@
321 'testdef_repos': {'type': 'array',
322 'items': {'type': 'object',
323 'properties':
324- {'git-repo': {'type': 'string',
325- 'optional': True},
326- 'bzr-repo': {'type': 'string',
327- 'optional': True},
328- 'revision': {'type': 'string',
329- 'optional': True},
330- 'testdef': {'type': 'string',
331- 'optional': True}
332- },
333+ {'git-repo': {'type': 'string',
334+ 'optional': True},
335+ 'bzr-repo': {'type': 'string',
336+ 'optional': True},
337+ 'revision': {'type': 'string',
338+ 'optional': True},
339+ 'testdef': {'type': 'string',
340+ 'optional': True}
341+ },
342 'additionalProperties': False},
343 'optional': True
344 },
345 'timeout': {'type': 'integer', 'optional': True},
346 'role': {'type': 'string', 'optional': True},
347- },
348+ },
349 'additionalProperties': False,
350- }
351+ }
352
353 def run(self, testdef_urls=None, testdef_repos=None, timeout=-1):
354 target = self.client.target_device
355@@ -511,12 +516,12 @@
356
357 def _keep_running(self, runner, timeout, signal_director):
358 patterns = [
359- '<LAVA_TEST_RUNNER>: exiting',
360- pexpect.EOF,
361- pexpect.TIMEOUT,
362- '<LAVA_SIGNAL_(\S+) ([^>]+)>',
363- '<LAVA_MULTI_NODE> <LAVA_(\S+) ([^>]+)>',
364- ]
365+ '<LAVA_TEST_RUNNER>: exiting',
366+ pexpect.EOF,
367+ pexpect.TIMEOUT,
368+ '<LAVA_SIGNAL_(\S+) ([^>]+)>',
369+ '<LAVA_MULTI_NODE> <LAVA_(\S+) ([^>]+)>',
370+ ]
371
372 idx = runner._connection.expect(patterns, timeout=timeout)
373 if idx == 0:
374@@ -664,4 +669,3 @@
375 prefix='lava-test-shell', suffix='.bundle', dir=rdir)
376 with os.fdopen(fd, 'w') as f:
377 DocumentIO.dump(f, bundle)
378-
379
380=== modified file 'lava_dispatcher/device/master.py'
381--- lava_dispatcher/device/master.py 2013-07-02 14:37:47 +0000
382+++ lava_dispatcher/device/master.py 2013-07-17 11:38:38 +0000
383@@ -85,7 +85,7 @@
384 'oe': Target.oe_deployment_data,
385 'ubuntu': Target.ubuntu_deployment_data,
386 'fedora': Target.fedora_deployment_data,
387- }
388+ }
389
390 self.master_ip = None
391 self.device_version = None
392@@ -128,7 +128,7 @@
393 self._deploy_android_tarballs(master, boot, system, data)
394
395 if master.has_partition_with_label('userdata') and \
396- master.has_partition_with_label('sdcard'):
397+ master.has_partition_with_label('sdcard'):
398 _purge_linaro_android_sdcard(master)
399
400 self.deployment_data = Target.android_deployment_data
401@@ -245,8 +245,7 @@
402 def _format_testpartition(self, runner, fstype):
403 logging.info("Format testboot and testrootfs partitions")
404 runner.run('umount /dev/disk/by-label/testrootfs', failok=True)
405- runner.run('mkfs -t %s -q /dev/disk/by-label/testrootfs -L testrootfs'
406- % fstype, timeout=1800)
407+ runner.run('mkfs -t %s -q /dev/disk/by-label/testrootfs -L testrootfs' % fstype, timeout=1800)
408 runner.run('umount /dev/disk/by-label/testboot', failok=True)
409 runner.run('mkfs.vfat /dev/disk/by-label/testboot -n testboot')
410
411@@ -288,7 +287,7 @@
412 return
413 except (OperationFailed, pexpect.TIMEOUT):
414 logging.warning(("transfering %s failed. %d retry left."
415- % (tar_url, num_retry - 1)))
416+ % (tar_url, num_retry - 1)))
417
418 if num_retry > 1:
419 # send CTRL C in case wget still hasn't exited.
420@@ -299,7 +298,7 @@
421 sleep_time = 60
422 logging.info("Wait %d second before retry" % sleep_time)
423 time.sleep(sleep_time)
424- num_retry = num_retry - 1
425+ num_retry -= 1
426
427 raise RuntimeError('extracting %s on target failed' % tar_url)
428
429@@ -321,7 +320,7 @@
430 @contextlib.contextmanager
431 def file_system(self, partition, directory):
432 logging.info('attempting to access master filesystem %r:%s' %
433- (partition, directory))
434+ (partition, directory))
435
436 assert directory != '/', "cannot mount entire partition"
437
438@@ -336,7 +335,7 @@
439 parent_dir, target_name = os.path.split(targetdir)
440
441 runner.run('tar -czf /tmp/fs.tgz -C %s %s' %
442- (parent_dir, target_name))
443+ (parent_dir, target_name))
444 runner.run('cd /tmp') # need to be in same dir as fs.tgz
445 self.proc.sendline('python -m SimpleHTTPServer 0 2>/dev/null')
446 match_id = self.proc.expect([
447@@ -545,8 +544,8 @@
448
449 pattern1 = "<(\d?\d?\d?\.\d?\d?\d?\.\d?\d?\d?\.\d?\d?\d?)>"
450 cmd = ("ifconfig %s | grep 'inet addr' | awk -F: '{print $2}' |"
451- "awk '{print \"<\" $1 \">\"}'" %
452- self._client.config.default_network_interface)
453+ "awk '{print \"<\" $1 \">\"}'" %
454+ self._client.config.default_network_interface)
455 self.run(
456 cmd, [pattern1, pexpect.EOF, pexpect.TIMEOUT], timeout=5)
457 if self.match_id != 0:
458@@ -568,7 +567,7 @@
459 "| sed 's/[^0-9-]//g; s/^-\+//')"
460 "\"",
461 [pattern, pexpect.EOF, pexpect.TIMEOUT],
462- timeout = 5)
463+ timeout=5)
464
465 device_version = None
466 if self.match_id == 0:
467@@ -662,11 +661,10 @@
468 # delete use of cache partition
469 session.run('sed -i "/\/dev\/block\/%s%s%s/d" %s'
470 % (blkorg, partition_padding_string_org, cache_part_org, rc_filename))
471- session.run('sed -i "s/%s%s%s/%s%s%s/g" %s'
472- % (blkorg, partition_padding_string_org, data_part_org, blklava, partition_padding_string_lava, data_part_lava, rc_filename))
473- session.run('sed -i "s/%s%s%s/%s%s%s/g" %s'
474- % (blkorg, partition_padding_string_org, sys_part_org, blklava, partition_padding_string_lava, sys_part_lava, rc_filename))
475-
476+ session.run('sed -i "s/%s%s%s/%s%s%s/g" %s' % (blkorg, partition_padding_string_org, data_part_org, blklava,
477+ partition_padding_string_lava, data_part_lava, rc_filename))
478+ session.run('sed -i "s/%s%s%s/%s%s%s/g" %s' % (blkorg, partition_padding_string_org, sys_part_org, blklava,
479+ partition_padding_string_lava, sys_part_lava, rc_filename))
480
481
482 def _recreate_uInitrd(session, target):
483@@ -740,9 +738,9 @@
484 script_path = '%s/%s' % ('/mnt/lava', '/system/bin/disablesuspend.sh')
485 if not session.is_file_exist(script_path):
486 session.run("sh -c 'export http_proxy=%s'" %
487- target.context.config.lava_proxy)
488+ target.context.config.lava_proxy)
489 session.run('wget --no-check-certificate %s -O %s' %
490- (target.config.git_url_disablesuspend_sh, script_path))
491+ (target.config.git_url_disablesuspend_sh, script_path))
492 session.run('chmod +x %s' % script_path)
493 session.run('chown :2000 %s' % script_path)
494
495@@ -772,9 +770,9 @@
496 data_label = _android_data_label(session)
497 session.run('umount /dev/disk/by-label/%s' % data_label, failok=True)
498 session.run('mkfs.ext4 -q /dev/disk/by-label/%s -L %s' %
499- (data_label, data_label))
500+ (data_label, data_label))
501 session.run('udevadm trigger')
502 session.run('mkdir -p /mnt/lava/data')
503- session.run('mount /dev/disk/by-label/%s /mnt/lava/data' % (data_label))
504+ session.run('mount /dev/disk/by-label/%s /mnt/lava/data' % data_label)
505 session._client.target_extract(session, datatbz2, '/mnt/lava', timeout=600)
506 session.run('umount /mnt/lava/data')
507
508=== modified file 'lava_dispatcher/device/target.py'
509--- lava_dispatcher/device/target.py 2013-07-03 10:44:31 +0000
510+++ lava_dispatcher/device/target.py 2013-07-17 11:38:38 +0000
511@@ -24,8 +24,7 @@
512 import re
513
514 from lava_dispatcher.client.lmc_utils import (
515- image_partition_mounted,
516- )
517+ image_partition_mounted)
518 import lava_dispatcher.utils as utils
519
520
521@@ -49,7 +48,7 @@
522 'TESTER_PS1': ANDROID_TESTER_PS1,
523 'TESTER_PS1_PATTERN': ANDROID_TESTER_PS1,
524 'TESTER_PS1_INCLUDES_RC': False,
525- }
526+ }
527 ubuntu_deployment_data = {
528 'TESTER_PS1': "linaro-test [rc=$(echo \$?)]# ",
529 'TESTER_PS1_PATTERN': "linaro-test \[rc=(\d+)\]# ",
530
531=== modified file 'lava_dispatcher/lava_test_shell.py'
532--- lava_dispatcher/lava_test_shell.py 2013-04-08 04:57:50 +0000
533+++ lava_dispatcher/lava_test_shell.py 2013-07-17 11:38:38 +0000
534@@ -103,13 +103,12 @@
535
536
537 def _get_sw_context(build, pkgs, sw_sources):
538- ctx = {}
539- ctx['image'] = {'name': build}
540+ ctx = {'image': {'name': build}}
541
542 pkglist = []
543 pattern = re.compile(
544 ("^\s*package:\s*(?P<package_name>[^:]+?)\s*:"
545- "\s*(?P<version>[^\s].+)\s*$"), re.M)
546+ "\s*(?P<version>[^\s].+)\s*$"), re.M)
547 for line in pkgs.split('\n'):
548 match = pattern.search(line)
549 if match:
550@@ -121,9 +120,9 @@
551 return ctx
552
553
554-def _attachments_from_dir(dir):
555+def _attachments_from_dir(from_dir):
556 attachments = []
557- for filename, filepath in _directory_names_and_paths(dir, ignore_missing=True):
558+ for filename, filepath in _directory_names_and_paths(from_dir, ignore_missing=True):
559 if filename.endswith('.mimetype'):
560 continue
561 mime_type = _read_content(filepath + '.mimetype', ignore_missing=True).strip()
562@@ -136,48 +135,47 @@
563 return attachments
564
565
566-def _attributes_from_dir(dir):
567+def _attributes_from_dir(from_dir):
568 attributes = {}
569- for filename, filepath in _directory_names_and_paths(dir, ignore_missing=True):
570+ for filename, filepath in _directory_names_and_paths(from_dir, ignore_missing=True):
571 if os.path.isfile(filepath):
572 attributes[filename] = _read_content(filepath)
573 return attributes
574
575
576-def _result_to_dir(test_result, dir):
577+def _result_to_dir(test_result, res_dir):
578
579 def w(name, content):
580- with open(os.path.join(dir, name), 'w') as f:
581+ with open(os.path.join(res_dir, name), 'w') as f:
582 f.write(str(content) + '\n')
583
584 for name in 'result', 'measurement', 'units', 'message', 'timestamp', 'duration':
585 if name in test_result:
586 w(name, test_result[name])
587
588-
589- os.makedirs(os.path.join(dir, 'attachments'))
590+ os.makedirs(os.path.join(res_dir, 'attachments'))
591
592 for attachment in test_result.get('attachments', []):
593 path = 'attachments/' + attachment['pathname']
594 w(path, base64.b64decode(attachment['content']))
595 w(path + '.mimetype', attachment['mime_type'])
596
597- os.makedirs(os.path.join(dir, 'attributes'))
598+ os.makedirs(os.path.join(res_dir, 'attributes'))
599
600 for attrname, attrvalue in test_result.get('attributes', []).items():
601 path = 'attributes/' + attrname
602 w(path, attrvalue)
603
604
605-def _result_from_dir(dir, test_case_id=None):
606+def _result_from_dir(res_dir, test_case_id=None):
607 if not test_case_id:
608- test_case_id = os.path.basename(dir)
609+ test_case_id = os.path.basename(res_dir)
610 result = {
611 'test_case_id': test_case_id
612- }
613+ }
614
615 for fname in 'result', 'measurement', 'units', 'message', 'timestamp', 'duration':
616- fpath = os.path.join(dir, fname)
617+ fpath = os.path.join(res_dir, fname)
618 if os.path.isfile(fpath):
619 result[fname] = _read_content(fpath).strip()
620
621@@ -185,11 +183,11 @@
622 try:
623 result['measurement'] = decimal.Decimal(result['measurement'])
624 except decimal.InvalidOperation:
625- logging.warning("Invalid measurement for %s: %s" % (dir, result['measurement']))
626+ logging.warning("Invalid measurement for %s: %s" % (res_dir, result['measurement']))
627 del result['measurement']
628
629- result['attachments'] = _attachments_from_dir(os.path.join(dir, 'attachments'))
630- result['attributes'] = _attributes_from_dir(os.path.join(dir, 'attributes'))
631+ result['attachments'] = _attachments_from_dir(os.path.join(res_dir, 'attachments'))
632+ result['attributes'] = _attributes_from_dir(os.path.join(res_dir, 'attributes'))
633
634 return result
635
636@@ -214,6 +212,7 @@
637 def _get_test_results(test_run_dir, testdef, stdout):
638 results_from_log_file = []
639 fixupdict = {}
640+ pattern = None
641
642 if 'parse' in testdef:
643 if 'fixupdict' in testdef['parse']:
644@@ -227,6 +226,8 @@
645 'UNKNOWN': 'unknown'}
646 logging.warning("""Using a default pattern to parse the test result. This may lead to empty test result in certain cases.""")
647
648+ if not pattern:
649+ logging.debug("No pattern set")
650 for lineno, line in enumerate(stdout.split('\n'), 1):
651 match = pattern.match(line.strip())
652 if match:
653@@ -244,7 +245,7 @@
654 res['measurement'] = decimal.Decimal(res['measurement'])
655 except decimal.InvalidOperation:
656 logging.warning("Invalid measurement %s" % (
657- res['measurement']))
658+ res['measurement']))
659 del res['measurement']
660 results_from_log_file.append(res)
661
662@@ -277,10 +278,8 @@
663
664
665 def _get_run_attachments(test_run_dir, testdef, stdout):
666- attachments = []
667-
668- attachments.append(create_attachment('stdout.log', stdout))
669- attachments.append(create_attachment('testdef.yaml', testdef))
670+ attachments = [create_attachment('stdout.log', stdout),
671+ create_attachment('testdef.yaml', testdef)]
672 return_code = _read_content(os.path.join(test_run_dir, 'return_code'), ignore_missing=True)
673 if return_code:
674 attachments.append(create_attachment('return_code', return_code))
675@@ -301,7 +300,7 @@
676 'os': None,
677 'devices': None,
678 'environment': None
679- }
680+ }
681
682 metadata = _read_content(os.path.join(test_run_dir, 'testdef_metadata'))
683 if metadata is not '':
684@@ -339,7 +338,7 @@
685 'attachments': attachments,
686 'attributes': attributes,
687 'testdef_metadata': _get_run_testdef_metadata(test_run_dir)
688- }
689+ }
690
691
692 def _read_content(filepath, ignore_missing=False):

Subscribers

People subscribed via source and target branches

to status/vote changes: