Merge lp:~bladernr/checkbox/1066118-modinfo-parser into lp:checkbox

Proposed by Jeff Lane 
Status: Merged
Approved by: Sylvain Pineau
Approved revision: 1789
Merged at revision: 1789
Proposed branch: lp:~bladernr/checkbox/1066118-modinfo-parser
Merge into: lp:checkbox
Diff against target: 57 lines (+22/-13)
2 files modified
checkbox/parsers/modinfo.py (+19/-12)
debian/changelog (+3/-1)
To merge this branch: bzr merge lp:~bladernr/checkbox/1066118-modinfo-parser
Reviewer Review Type Date Requested Status
Sylvain Pineau (community) Approve
Review via email: mp+130829@code.launchpad.net

Commit message

Added exception handling to address possible bad output from modinfo, by Jeff Lane

Description of the change

Fixes an issue where lines from modinfo that don't match the "key: value" format triggered a ValueError.
Most likely this is caused by blank lines appearing in the stream.

To post a comment you must log in.
Revision history for this message
Sylvain Pineau (sylvain-pineau) wrote :

Even if having access to the machine where the crash occurred would have helped, I was suspecting blank lines too. This fix works perfectly.

review: Approve
Revision history for this message
Marc Tardif (cr3) wrote :

You know what would've helped? unit tests :)

Revision history for this message
Jeff Lane  (bladernr) wrote :

Possibly, but modinfo returns very specific output. Unfortunately, without access to the failing machine this was impossible to recreate. Sylvain and I both guessed blank lines, but I have never seen modinfo return a blank line before, ever. My original suspicion was the empty "Depends" field in modinfo output, but that splits out into ('depends','') which is fine.

But your point is well taken, we do need more unit tests for these things :)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'checkbox/parsers/modinfo.py'
2--- checkbox/parsers/modinfo.py 2012-09-11 18:31:37 +0000
3+++ checkbox/parsers/modinfo.py 2012-10-22 14:44:00 +0000
4@@ -58,19 +58,26 @@
5 for line in stream.splitlines():
6 # At this point, stream should be the stdout from the modinfo
7 # command, in a list.
8- key, data = line.split(':', 1)
9- data = data.strip()
10- # First, we need to handle alias, parm, firmware, and depends
11- # because there can be multiple lines of output for these.
12- if key in ('alias', 'depend', 'firmware', 'parm',):
13- self._modinfo[key].append(data)
14- # Now handle unknown keys
15- elif key not in self._modinfo.keys():
16- self._modinfo[key] = ("WARNING: Unknown Key %s providing "
17+ try:
18+ key, data = line.split(':', 1)
19+ except ValueError:
20+ # Most likely this will be caused by a blank line in the
21+ # stream, so we just ignore it and move on.
22+ continue
23+ else:
24+ key = key.strip()
25+ data = data.strip()
26+ # First, we need to handle alias, parm, firmware, and depends
27+ # because there can be multiple lines of output for these.
28+ if key in ('alias', 'depend', 'firmware', 'parm',):
29+ self._modinfo[key].append(data)
30+ # Now handle unknown keys
31+ elif key not in self._modinfo.keys():
32+ self._modinfo[key] = ("WARNING: Unknown Key %s providing "
33 "data: %s") % (key, data)
34- # And finally known keys
35- else:
36- self._modinfo[key] = data
37+ # And finally known keys
38+ else:
39+ self._modinfo[key] = data
40
41 def get_all(self):
42 return self._modinfo
43
44=== modified file 'debian/changelog'
45--- debian/changelog 2012-10-19 20:20:53 +0000
46+++ debian/changelog 2012-10-22 14:44:00 +0000
47@@ -74,8 +74,10 @@
48 rather than fwts directly. Ensured all are calling with the proper
49 options. Fixed log name problems that caused log attachment jobs to not
50 work.
51+ * checkbox/parsers/modinfo.py - added exception handling to address possible
52+ bad output from modinfo causing a ValueError to occur. (LP: #1066118)
53
54- -- Jeff Lane <jeff@ubuntu.com> Thu, 18 Oct 2012 16:52:08 -0400
55+ -- Jeff Lane <jeff@ubuntu.com> Mon, 22 Oct 2012 10:35:36 -0400
56
57 checkbox (0.14.6) quantal; urgency=low
58

Subscribers

People subscribed via source and target branches