Merge ~kissiel/checkbox-ng:fix-1853392-crash-on-reports into checkbox-ng:master

Proposed by Maciej Kisielewski
Status: Merged
Approved by: Maciej Kisielewski
Approved revision: 93f805847b40386580bdacd1cbe13d3d682ca04f
Merged at revision: 423dde258fec42263d8137e179f59202004fa690
Proposed branch: ~kissiel/checkbox-ng:fix-1853392-crash-on-reports
Merge into: checkbox-ng:master
Diff against target: 23 lines (+3/-2)
1 file modified
plainbox/impl/exporter/xlsx.py (+3/-2)
Reviewer Review Type Date Requested Status
Sylvain Pineau (community) Approve
Review via email: mp+379878@code.launchpad.net

Description of the change

xlsx: fix crash when resources were missing fields

Previously the xlsx exporter blindly accessed fields that may have not been there, due to - for instance - crash in the resource job or misformat of some information yielded by the resource job's binary. This patch uses .get()s on thosde dictionaries, so the worst case scenario is missing information in the report instead of a Checkbox crash.

Tested on good, broken, and sort-of-lacking resource jobs.

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

LGTM, thx

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/plainbox/impl/exporter/xlsx.py b/plainbox/impl/exporter/xlsx.py
index eb4253a..0a235f0 100644
--- a/plainbox/impl/exporter/xlsx.py
+++ b/plainbox/impl/exporter/xlsx.py
@@ -230,7 +230,7 @@ class XLSXSessionStateExporter(SessionStateExporterBase):
230 hw_info['bios'] = result.pop()230 hw_info['bios'] = result.pop()
231 resource = 'com.canonical.certification::cpuinfo'231 resource = 'com.canonical.certification::cpuinfo'
232 if resource in data['resource_map']:232 if resource in data['resource_map']:
233 result = ['{} x {}'.format(i['model'], i['count'])233 result = ['{} x {}'.format(i.get('model'), i.get('count'))
234 for i in data["resource_map"][resource]]234 for i in data["resource_map"][resource]]
235 if result:235 if result:
236 hw_info['processors'] = result.pop()236 hw_info['processors'] = result.pop()
@@ -268,7 +268,8 @@ class XLSXSessionStateExporter(SessionStateExporterBase):
268 hw_info['vram'] = '{} MiB'.format(vram)268 hw_info['vram'] = '{} MiB'.format(vram)
269 resource = 'com.canonical.certification::meminfo'269 resource = 'com.canonical.certification::meminfo'
270 if resource in data['resource_map']:270 if resource in data['resource_map']:
271 result = ['{} GiB'.format(format(int(i['total']) / 1073741824,271 result = ['{} GiB'.format(format(int(
272 i.get('total', 0)) / 1073741824,
272 '.1f')) for i in data["resource_map"][resource]]273 '.1f')) for i in data["resource_map"][resource]]
273 if result:274 if result:
274 hw_info['memory'] = result.pop()275 hw_info['memory'] = result.pop()

Subscribers

People subscribed via source and target branches