Merge ~bladernr/plainbox-provider-checkbox:1655155 into plainbox-provider-checkbox:master

Proposed by Jeff Lane 
Status: Merged
Approved by: Sylvain Pineau
Approved revision: 353587cf1d12e20250e58b33b2b5f2e8aabaef56
Merged at revision: 62b3636c2b7848ae9558c81ad2179a4b118e708d
Proposed branch: ~bladernr/plainbox-provider-checkbox:1655155
Merge into: plainbox-provider-checkbox:master
Diff against target: 75 lines (+32/-7)
1 file modified
bin/dmitest (+32/-7)
Reviewer Review Type Date Requested Status
Sylvain Pineau (community) Approve
Review via email: mp+314487@code.launchpad.net

Description of the change

Fixes a problem where non-Unicode characters cause a traceback when attempting to decode (this triggers a traceback outside the try/except that check_output is in.

Now, the script attempts to get the output in one try/except, and then does the decoding elsewhere to catch that separately.

Also, it now tells you exactly which line in dmidecode output is responsible, and dumps the bytes representation of that line to output.

I also added a --show_dmi option for debugging things like this, so if you see bad things, you can re-run with --show_dmi and look for the places where the bad data lived.

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

Nice improvement, +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/bin/dmitest b/bin/dmitest
index 27cfc8e..9be70be 100755
--- a/bin/dmitest
+++ b/bin/dmitest
@@ -28,6 +28,8 @@
28:param --dmifile:28:param --dmifile:
29 Input filename; optional. If specified, file is used instead of29 Input filename; optional. If specified, file is used instead of
30 dmidecode output.30 dmidecode output.
31:param --show_dmi:
32 Print the DMI data used. For debugging purposes if errors are encountered.
31:param --test_versions:33:param --test_versions:
32 Include chassis, system, and base boad version numbers among tests.34 Include chassis, system, and base boad version numbers among tests.
33:param --test_serials:35:param --test_serials:
@@ -228,26 +230,45 @@ def main():
228 choices=['server', 'desktop', 'cpu-check'])230 choices=['server', 'desktop', 'cpu-check'])
229 parser.add_argument('--dmifile',231 parser.add_argument('--dmifile',
230 help="File to use in lieu of dmidecode.")232 help="File to use in lieu of dmidecode.")
233 parser.add_argument('--show_dmi', action="store_true",
234 help="Print DMI Data used for debugging purposes.")
231 parser.add_argument('--test_versions', action="store_true",235 parser.add_argument('--test_versions', action="store_true",
232 help="Set to check version information")236 help="Set to check version information")
233 parser.add_argument('--test_serials', action="store_true",237 parser.add_argument('--test_serials', action="store_true",
234 help="Set to check serial number information")238 help="Set to check serial number information")
235 args = parser.parse_args()239 args = parser.parse_args()
236240
241 bad_data = False
237 # Command to retrieve DMI information242 # Command to retrieve DMI information
238 COMMAND = "dmidecode"243 COMMAND = "dmidecode"
244 if args.dmifile:
245 COMMAND = ['cat', args.dmifile]
246 print("Reading " + args.dmifile + " as DMI data")
239 try:247 try:
240 if args.dmifile:248 dmi_out = subprocess.check_output(COMMAND).splitlines()
241 print("Reading " + args.dmifile + " as DMI data")
242 stream = subprocess.check_output(['cat', args.dmifile],
243 universal_newlines=True).splitlines()
244 else:
245 stream = subprocess.check_output(COMMAND,
246 universal_newlines=True).splitlines()
247 except subprocess.CalledProcessError as err:249 except subprocess.CalledProcessError as err:
248 print("Error running {}: {}".format(COMMAND, err))250 print("Error running {}: {}".format(COMMAND, err))
249 return 1251 return 1
250252
253 # Convert the bytes output separately, line by line, because it's possible
254 # that someone put non-encodable characters in DMI, which cases a
255 # UnicodeDecodeError that is non-helpful. LP: 1655155
256 stream = []
257 for line in dmi_out:
258 try:
259 stream.append(line.decode('utf-8'))
260 except UnicodeDecodeError as ude:
261 print("DATA ERROR: {}".format(ude))
262 print("\tLINE NUMBER {}: {}".format(dmi_out.index(line) + 1, line))
263 stream.append("ERROR: BAD DATA FOUND HERE")
264 bad_data = True
265
266 if args.show_dmi:
267 print("===== DMI Data Used: =====")
268 for line in stream:
269 print(line)
270 print("===== DMI Output Complete =====")
271
251 retval = 0272 retval = 0
252 if args.test_type == 'server' or args.test_type == 'desktop':273 if args.test_type == 'server' or args.test_type == 'desktop':
253 retval += standard_tests(args, stream)274 retval += standard_tests(args, stream)
@@ -272,6 +293,10 @@ def main():
272 else:293 else:
273 print("\nPassed all tests")294 print("\nPassed all tests")
274295
296 if bad_data:
297 print("\nBad Characters discovered in DMI output. Rerun with "
298 "the --show_dmi option to see more")
299
275 return retval300 return retval
276301
277302

Subscribers

People subscribed via source and target branches