Merge ~bladernr/plainbox-provider-checkbox:1680217-improve-dmitest-output into plainbox-provider-checkbox:master

Proposed by Jeff Lane 
Status: Merged
Approved by: Sylvain Pineau
Approved revision: 6100a8cb8642dbed4ab29a57bef2af421ff17816
Merged at revision: a51e01d1161ca63c407246ff109827a53667dc49
Proposed branch: ~bladernr/plainbox-provider-checkbox:1680217-improve-dmitest-output
Merge into: plainbox-provider-checkbox:master
Diff against target: 238 lines (+77/-42)
1 file modified
bin/dmitest (+77/-42)
Reviewer Review Type Date Requested Status
Maciej Kisielewski Approve
Review via email: mp+322062@code.launchpad.net

Description of the change

Modifies output of dmitest to be more readable. See linked bug for before/after samples.

To post a comment you must log in.
Revision history for this message
Maciej Kisielewski (kissiel) wrote :

The code looks good.
I hope that nothing is using those changed functions directly, as the introduced arg is not optional.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/bin/dmitest b/bin/dmitest
2index 9be70be..d75aa37 100755
3--- a/bin/dmitest
4+++ b/bin/dmitest
5@@ -49,7 +49,7 @@ import sys
6 from argparse import ArgumentParser
7
8
9-def find_in_section(stream, section, label, strings, find_empty):
10+def find_in_section(stream, dmi_data, section, label, strings, find_empty):
11 """Search for a set of strings on a line in the output.
12
13 :param stream:
14@@ -75,8 +75,8 @@ def find_in_section(stream, section, label, strings, find_empty):
15 if line == section:
16 start_looking = True
17 if start_looking and re.search(label, line):
18- print("\n" + section)
19- print(line.strip())
20+ line_items = line.strip().split(':')
21+ dmi_data[section][line_items[0]] = line_items[1]
22 empty = len(line.strip()) == len(label)
23 if empty and find_empty:
24 found = True
25@@ -89,7 +89,7 @@ def find_in_section(stream, section, label, strings, find_empty):
26 return found
27
28
29-def standard_tests(args, stream):
30+def standard_tests(args, stream, dmi_data):
31 """
32 Perform the standard set of tests.
33
34@@ -113,58 +113,73 @@ def standard_tests(args, stream):
35 error.
36 """
37 if args.test_type == 'server':
38- if not find_in_section(stream, 'Chassis Information', 'Type:',
39+ if not find_in_section(stream, dmi_data, 'Chassis Information',
40+ 'Type:',
41 ['server', 'rack mount', 'blade', 'other',
42 'expansion chassis', 'multi-system', 'tower'],
43 False):
44- print("*** Incorrect or unknown server chassis type!")
45+ dmi_data['Chassis Information']['Type'] += \
46+ " *** Incorrect or unknown server chassis type!"
47 retval += 1
48- if find_in_section(stream, 'Base Board Information', 'Type:',
49+ if find_in_section(stream, dmi_data, 'Base Board Information', 'Type:',
50 ['portable', 'notebook', 'space-saving',
51 'all in one'], False):
52- print("*** Incorrect server base board type!")
53+ dmi_data['Base Board Information']['Type'] += \
54+ " *** Incorrect server base board type!"
55 retval += 1
56 else:
57- if not find_in_section(stream, 'Chassis Information', 'Type:',
58+ if not find_in_section(stream, dmi_data, 'Chassis Information',
59+ 'Type:',
60 ['notebook', 'portable', 'laptop', 'desktop',
61 'lunch box', 'space-saving', 'tower',
62 'all in one', 'hand held'], False):
63- print("*** Incorrect or unknown desktop chassis type!")
64+ dmi_data['Chassis Information']['Type'] += \
65+ " *** Incorrect or unknown desktop chassis type!"
66 retval += 1
67- if find_in_section(stream, 'Base Board Information', 'Type:',
68+ if find_in_section(stream, dmi_data, 'Base Board Information', 'Type:',
69 ['rack mount', 'server', 'multi-system',
70 'interconnect board'], False):
71- print("*** Incorrect desktop base board type!")
72+ dmi_data['Base Board Information']['Type'] += \
73+ " *** Incorrect desktop base board type!"
74 retval += 1
75- if find_in_section(stream, 'Chassis Information', 'Manufacturer:',
76+ if find_in_section(stream, dmi_data, 'Chassis Information',
77+ 'Manufacturer:',
78 ['empty', 'chassis manufacture', 'null', 'insyde',
79 'to be filled by o\.e\.m\.', 'no enclosure',
80 '\.\.\.\.\.'], True):
81- print("*** Invalid chassis manufacturer!")
82+ dmi_data['Chassis Information']['Manufacturer'] += \
83+ " *** Invalid chassis manufacturer!"
84 retval += 1
85- if find_in_section(stream, 'System Information', 'Manufacturer:',
86+ if find_in_section(stream, dmi_data, 'System Information', 'Manufacturer:',
87 ['system manufacture', 'insyde', 'standard',
88 'to be filled by o\.e\.m\.', 'no enclosure'], True):
89- print("*** Invalid system manufacturer!")
90+ dmi_data['System Information']['Manufacturer'] += \
91+ " *** Invalid system manufacturer!"
92 retval += 1
93- if find_in_section(stream, 'Base Board Information', 'Manufacturer:',
94+ if find_in_section(stream, dmi_data, 'Base Board Information',
95+ 'Manufacturer:',
96 ['to be filled by o\.e\.m\.'], True):
97- print("*** Invalid base board manufacturer!")
98+ dmi_data['Base Board Information']['Manufacturer'] += \
99+ " *** Invalid base board manufacturer!"
100 retval += 1
101- if find_in_section(stream, 'System Information', 'Product Name:',
102+ if find_in_section(stream, dmi_data, 'System Information',
103+ 'Product Name:',
104 ['system product name', 'to be filled by o\.e\.m\.'],
105 False):
106- print("*** Invalid system product name!")
107+ dmi_data['System Information']['Product Name'] += \
108+ " *** Invalid system product name!"
109 retval += 1
110- if find_in_section(stream, 'Base Board Information', 'Product Name:',
111+ if find_in_section(stream, dmi_data, 'Base Board Information',
112+ 'Product Name:',
113 ['base board product name',
114 'to be filled by o\.e\.m\.'], False):
115- print("*** Invalid base board product name!")
116+ dmi_data['Base Board Information']['Product Name'] += \
117+ " *** Invalid base board product name!"
118 retval += 1
119 return retval
120
121
122-def version_tests(args, stream):
123+def version_tests(args, stream, dmi_data):
124 """
125 Perform the version tests.
126
127@@ -176,26 +191,29 @@ def version_tests(args, stream):
128 Number of problems found
129 """
130 retval = 0
131- if find_in_section(stream, 'Chassis Information', 'Version:',
132- ['to be filled by o\.e\.m\.', 'empty'],
133+ if find_in_section(stream, dmi_data, 'Chassis Information', 'Version:',
134+ ['to be filled by o\.e\.m\.', 'empty', 'x\.x'],
135 False):
136- print("*** Invalid chassis version!")
137+ dmi_data['Chassis Information']['Version'] += \
138+ " *** Invalid chassis version!"
139 retval += 1
140- if find_in_section(stream, 'System Information', 'Version:',
141+ if find_in_section(stream, dmi_data, 'System Information', 'Version:',
142 ['to be filled by o\.e\.m\.', '\(none\)',
143 'null', 'system version', 'not applicable',
144 '\.\.\.\.\.'], False):
145- print("*** Invalid system information version!")
146+ dmi_data['System Information']['Version'] += \
147+ " *** Invalid system information version!"
148 retval += 1
149- if find_in_section(stream, 'Base Board Information', 'Version:',
150- ['base board version',
151+ if find_in_section(stream, dmi_data, 'Base Board Information', 'Version:',
152+ ['base board version', 'x\.x',
153 'empty', 'to be filled by o\.e\.m\.'], False):
154- print("*** Invalid base board version!")
155+ dmi_data['Base Board Information']['Version'] += \
156+ " *** Invalid base board version!"
157 retval += 1
158 return retval
159
160
161-def serial_tests(args, stream):
162+def serial_tests(args, stream, dmi_data):
163 """
164 Perform the serial number tests.
165
166@@ -207,17 +225,22 @@ def serial_tests(args, stream):
167 Number of problems found
168 """
169 retval = 0
170- if find_in_section(stream, 'System Information', 'Serial Number:',
171+ if find_in_section(stream, dmi_data, 'System Information',
172+ 'Serial Number:',
173 ['to be filled by o\.e\.m\.',
174 'system serial number', '\.\.\.\.\.'],
175 False):
176- print("*** Invalid system information serial number!")
177+ dmi_data['System Information']['Serial Number'] += \
178+ " *** Invalid system information serial number!"
179 retval += 1
180- if find_in_section(stream, 'Base Board Information', 'Serial Number:',
181+ if find_in_section(stream, dmi_data, 'Base Board Information',
182+ 'Serial Number:',
183 ['n/a', 'base board serial number',
184- 'to be filled by o\.e\.m\.', 'empty', '\.\.\.'],
185+ 'to be filled by o\.e\.m\.',
186+ 'empty', '\.\.\.'],
187 False):
188- print("*** Invalid base board serial number!")
189+ dmi_data['Base Board Information']['Serial Number'] += \
190+ " *** Invalid base board serial number!"
191 retval += 1
192 return retval
193
194@@ -239,6 +262,11 @@ def main():
195 args = parser.parse_args()
196
197 bad_data = False
198+ dmi_data = {'System Information': {},
199+ 'Base Board Information': {},
200+ 'Chassis Information': {},
201+ 'Processor Information': {}}
202+
203 # Command to retrieve DMI information
204 COMMAND = "dmidecode"
205 if args.dmifile:
206@@ -271,20 +299,27 @@ def main():
207
208 retval = 0
209 if args.test_type == 'server' or args.test_type == 'desktop':
210- retval += standard_tests(args, stream)
211+ retval += standard_tests(args, stream, dmi_data)
212 if args.test_versions:
213- retval += version_tests(args, stream)
214+ retval += version_tests(args, stream, dmi_data)
215 if args.test_serials:
216- retval += serial_tests(args, stream)
217- if find_in_section(stream, 'Processor Information', 'Version:',
218+ retval += serial_tests(args, stream, dmi_data)
219+ if find_in_section(stream, dmi_data, 'Processor Information', 'Version:',
220 ['sample', 'Genuine Intel\(R\) CPU 0000'], False):
221- print("*** Invalid processor information!")
222+ dmi_data['Processor Information']['Version'] += \
223+ " *** Invalid processor information!"
224 retval += 1
225
226 # In review of dmidecode data on 10/23/2014, no conspicuous problems
227 # found in BIOS Information section's Vendor, Version, or Release Date
228 # fields. Therefore, no tests based on these fields have been written.
229
230+ for section in sorted(dmi_data.keys()):
231+ print('{}:'.format(section))
232+ for item in sorted(dmi_data[section].keys()):
233+ print('\t{}: {}'.format(item, dmi_data[section][item]))
234+ print('\n')
235+
236 if retval > 0:
237 if retval == 1:
238 print("\nFailed 1 test (see above)")

Subscribers

People subscribed via source and target branches