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
=== modified file 'checkbox/parsers/modinfo.py'
--- checkbox/parsers/modinfo.py 2012-09-11 18:31:37 +0000
+++ checkbox/parsers/modinfo.py 2012-10-22 14:44:00 +0000
@@ -58,19 +58,26 @@
58 for line in stream.splitlines():58 for line in stream.splitlines():
59 # At this point, stream should be the stdout from the modinfo59 # At this point, stream should be the stdout from the modinfo
60 # command, in a list.60 # command, in a list.
61 key, data = line.split(':', 1)61 try:
62 data = data.strip()62 key, data = line.split(':', 1)
63 # First, we need to handle alias, parm, firmware, and depends63 except ValueError:
64 # because there can be multiple lines of output for these.64 # Most likely this will be caused by a blank line in the
65 if key in ('alias', 'depend', 'firmware', 'parm',):65 # stream, so we just ignore it and move on.
66 self._modinfo[key].append(data)66 continue
67 # Now handle unknown keys67 else:
68 elif key not in self._modinfo.keys():68 key = key.strip()
69 self._modinfo[key] = ("WARNING: Unknown Key %s providing "69 data = data.strip()
70 # First, we need to handle alias, parm, firmware, and depends
71 # because there can be multiple lines of output for these.
72 if key in ('alias', 'depend', 'firmware', 'parm',):
73 self._modinfo[key].append(data)
74 # Now handle unknown keys
75 elif key not in self._modinfo.keys():
76 self._modinfo[key] = ("WARNING: Unknown Key %s providing "
70 "data: %s") % (key, data)77 "data: %s") % (key, data)
71 # And finally known keys78 # And finally known keys
72 else:79 else:
73 self._modinfo[key] = data80 self._modinfo[key] = data
7481
75 def get_all(self):82 def get_all(self):
76 return self._modinfo83 return self._modinfo
7784
=== modified file 'debian/changelog'
--- debian/changelog 2012-10-19 20:20:53 +0000
+++ debian/changelog 2012-10-22 14:44:00 +0000
@@ -74,8 +74,10 @@
74 rather than fwts directly. Ensured all are calling with the proper74 rather than fwts directly. Ensured all are calling with the proper
75 options. Fixed log name problems that caused log attachment jobs to not75 options. Fixed log name problems that caused log attachment jobs to not
76 work.76 work.
77 * checkbox/parsers/modinfo.py - added exception handling to address possible
78 bad output from modinfo causing a ValueError to occur. (LP: #1066118)
7779
78 -- Jeff Lane <jeff@ubuntu.com> Thu, 18 Oct 2012 16:52:08 -040080 -- Jeff Lane <jeff@ubuntu.com> Mon, 22 Oct 2012 10:35:36 -0400
7981
80checkbox (0.14.6) quantal; urgency=low82checkbox (0.14.6) quantal; urgency=low
8183

Subscribers

People subscribed via source and target branches