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
1diff --git a/plainbox/impl/exporter/xlsx.py b/plainbox/impl/exporter/xlsx.py
2index eb4253a..0a235f0 100644
3--- a/plainbox/impl/exporter/xlsx.py
4+++ b/plainbox/impl/exporter/xlsx.py
5@@ -230,7 +230,7 @@ class XLSXSessionStateExporter(SessionStateExporterBase):
6 hw_info['bios'] = result.pop()
7 resource = 'com.canonical.certification::cpuinfo'
8 if resource in data['resource_map']:
9- result = ['{} x {}'.format(i['model'], i['count'])
10+ result = ['{} x {}'.format(i.get('model'), i.get('count'))
11 for i in data["resource_map"][resource]]
12 if result:
13 hw_info['processors'] = result.pop()
14@@ -268,7 +268,8 @@ class XLSXSessionStateExporter(SessionStateExporterBase):
15 hw_info['vram'] = '{} MiB'.format(vram)
16 resource = 'com.canonical.certification::meminfo'
17 if resource in data['resource_map']:
18- result = ['{} GiB'.format(format(int(i['total']) / 1073741824,
19+ result = ['{} GiB'.format(format(int(
20+ i.get('total', 0)) / 1073741824,
21 '.1f')) for i in data["resource_map"][resource]]
22 if result:
23 hw_info['memory'] = result.pop()

Subscribers

People subscribed via source and target branches