~pieq/checkbox/fix-1484872-env-variables-forced-to-non-international

« back to all changes in this revision

Viewing changes to providers/plainbox-provider-checkbox/bin/dmitest

  • Committer: Zygmunt Krynicki
  • Date: 2014-12-19 12:11:52 UTC
  • mto: This revision was merged to the branch mainline in revision 3516.
  • Revision ID: zygmunt.krynicki@canonical.com-20141219121152-y9vtxajhrd6e1c3l
cep: merge CEPs in to trunk

This patch merges CEPs (aka Checkbox Enhancement Proposals) into trunk.
Those lived on separately for a while as lp:checkbox/cep but in
retrospective nobody knows about them and this should give them some
more exposure. In addition, the move allows new features to land a CEP
document along, making review of complex new features easier to make as
their specification can be seen alongside the patches that implement it.

Due to bazaar limitations in merging separate repositories together I've
discarded history entries (not that there were many) and just added
those files in directly.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
# desktop/laptop)
23
23
#
24
24
# By: Rod Smith
25
 
 
26
 
"""Script to test dmidecode output for sanity.
27
 
 
28
 
:param --dmifile:
29
 
    Input filename; optional. If specified, file is used instead of
30
 
    dmidecode output.
31
 
:param --test_versions:
32
 
    Include chassis, system, and base boad version numbers among tests.
33
 
:param --test_serials:
34
 
    Include system and base board serial numbers among tests.
35
 
:param cpu_check:
36
 
    Don't perform usual tests, except for CPU test.
37
 
:param desktop:
38
 
    SUT is a desktop or laptop
39
 
:param server:
40
 
    SUT is a server
41
 
"""
 
25
#
 
26
# Parameters:
 
27
#  * --dmifile {filename} -- Input filename; optional. If specified,
 
28
#    file is used instead of dmidecode output.
 
29
#  * --test_versions -- Include chassis, system, and base boad version
 
30
#    numbers among tests.
 
31
#  * --test_serials -- Include system and base board serial numbers among
 
32
#    tests.
 
33
#  * 'desktop' or 'server' -- Type of system being tested.
42
34
 
43
35
import re
44
36
import subprocess
46
38
 
47
39
from argparse import ArgumentParser
48
40
 
 
41
# Command to retrieve DMI information
 
42
COMMAND = "dmidecode"
 
43
 
49
44
 
50
45
def find_in_section(stream, section, label, strings, find_empty):
51
 
    """Search for a set of strings on a line in the output.
52
 
 
 
46
    """ Search for a set of strings on a labelled line in a section
 
47
        of the output.
53
48
    :param stream:
54
49
        input text stream (dmidecode output)
55
50
    :param section:
87
82
    return found
88
83
 
89
84
 
90
 
def standard_tests(args, stream):
91
 
    """
92
 
    Perform the standard set of tests.
93
 
 
94
 
    :param args:
95
 
        Arguments passed to script
96
 
    :param stream:
97
 
        Input stream containing dmidecode output
98
 
    :returns retval:
99
 
        Number of problems found
100
 
    """
 
85
def main():
 
86
    parser = ArgumentParser("dmitest")
 
87
    parser.add_argument('system_type',
 
88
                        help="System type ('server' or 'desktop').",
 
89
                        choices=['server', 'desktop'])
 
90
    parser.add_argument('--dmifile',
 
91
                        help="File to use in lieu of dmidecode.")
 
92
    parser.add_argument('--test_versions', action="store_true",
 
93
                        help="Set to check version information")
 
94
    parser.add_argument('--test_serials', action="store_true",
 
95
                        help="Set to check serial number information")
 
96
    args = parser.parse_args()
 
97
 
 
98
    try:
 
99
        if args.dmifile:
 
100
            print("Reading " + args.dmifile + " as DMI data")
 
101
            stream = subprocess.check_output(['cat', args.dmifile], universal_newlines=True).splitlines()
 
102
        else:
 
103
            stream = subprocess.check_output(COMMAND, universal_newlines=True).splitlines()
 
104
    except subprocess.CalledProcessError as err:
 
105
        print("Error running {}: {}".format(COMMAND, err))
 
106
        return 1
 
107
 
101
108
    retval = 0
 
109
 
102
110
    """
103
111
    NOTE: System type is encoded in both the "Chassis Information" and "Base
104
112
    Board Type" sections. The former is more reliable, so we do a whitelist
110
118
    shipped in those form factors, so we don't flag that combination as an
111
119
    error.
112
120
    """
113
 
    if args.test_type == 'server':
 
121
    if args.system_type == 'server':
114
122
        if not find_in_section(stream, 'Chassis Information', 'Type:',
115
123
                               ['server', 'rack mount', 'blade',
116
124
                                'expansion chassis', 'multi-system'], False):
117
125
            print("*** Incorrect or unknown server chassis type!")
118
 
            retval += 1
 
126
            retval = 1
119
127
        if find_in_section(stream, 'Base Board Information', 'Type:',
120
128
                           ['portable', 'notebook', 'space-saving',
121
129
                            'all in one'], False):
122
130
            print("*** Incorrect server base board type!")
123
 
            retval += 1
 
131
            retval = 1
124
132
    else:
125
133
        if not find_in_section(stream, 'Chassis Information', 'Type:',
126
134
                               ['notebook', 'portable', 'laptop', 'desktop',
127
135
                                'lunch box', 'space-saving', 'tower',
128
136
                                'all in one', 'hand held'], False):
129
137
            print("*** Incorrect or unknown desktop chassis type!")
130
 
            retval += 1
 
138
            retval = 1
131
139
        if find_in_section(stream, 'Base Board Information', 'Type:',
132
140
                           ['rack mount', 'server', 'multi-system',
133
141
                            'interconnect board'], False):
134
142
            print("*** Incorrect desktop base board type!")
135
 
            retval += 1
 
143
            retval = 1
 
144
 
136
145
    if find_in_section(stream, 'Chassis Information', 'Manufacturer:',
137
146
                       ['empty', 'chassis manufacture', 'null', 'insyde',
138
147
                        'to be filled by o\.e\.m\.', 'no enclosure',
139
148
                        '\.\.\.\.\.'], True):
140
149
        print("*** Invalid chassis manufacturer!")
141
 
        retval += 1
 
150
        retval = 1
 
151
 
142
152
    if find_in_section(stream, 'System Information', 'Manufacturer:',
143
153
                       ['system manufacture', 'insyde', 'standard',
144
154
                        'to be filled by o\.e\.m\.', 'no enclosure'], True):
145
155
        print("*** Invalid system manufacturer!")
146
 
        retval += 1
 
156
        retval = 1
 
157
 
147
158
    if find_in_section(stream, 'Base Board Information', 'Manufacturer:',
148
159
                       ['to be filled by o\.e\.m\.'], True):
149
160
        print("*** Invalid base board manufacturer!")
150
 
        retval += 1
 
161
        retval = 1
 
162
 
151
163
    if find_in_section(stream, 'System Information', 'Product Name:',
152
164
                       ['system product name', 'to be filled by o\.e\.m\.'],
153
165
                       False):
154
166
        print("*** Invalid system product name!")
155
 
        retval += 1
 
167
        retval = 1
 
168
 
156
169
    if find_in_section(stream, 'Base Board Information', 'Product Name:',
157
170
                       ['base board product name',
158
171
                        'to be filled by o\.e\.m\.'], False):
159
172
        print("*** Invalid base board product name!")
160
 
        retval += 1
161
 
    return retval
162
 
 
163
 
 
164
 
def version_tests(args, stream):
165
 
    """
166
 
    Perform the version tests.
167
 
 
168
 
    :param args:
169
 
        Arguments passed to script
170
 
    :param stream:
171
 
        Input stream containing dmidecode output
172
 
    :returns retval:
173
 
        Number of problems found
174
 
    """
175
 
    retval = 0
176
 
    if find_in_section(stream, 'Chassis Information', 'Version:',
177
 
                       ['to be filled by o\.e\.m\.', 'empty'],
178
 
                       False):
179
 
        print("*** Invalid chassis version!")
180
 
        retval += 1
181
 
    if find_in_section(stream, 'System Information', 'Version:',
182
 
                       ['to be filled by o\.e\.m\.', '\(none\)',
183
 
                        'null', 'system version', 'not applicable',
184
 
                        '\.\.\.\.\.'], False):
185
 
        print("*** Invalid system information version!")
186
 
        retval += 1
187
 
    if find_in_section(stream, 'Base Board Information', 'Version:',
188
 
                       ['base board version',
189
 
                        'empty', 'to be filled by o\.e\.m\.'], False):
190
 
        print("*** Invalid base board version!")
191
 
        retval += 1
192
 
    return retval
193
 
 
194
 
 
195
 
def serial_tests(args, stream):
196
 
    """
197
 
    Perform the serial number tests.
198
 
 
199
 
    :param args:
200
 
        Arguments passed to script
201
 
    :param stream:
202
 
        Input stream containing dmidecode output
203
 
    :returns retval:
204
 
        Number of problems found
205
 
    """
206
 
    retval = 0
207
 
    if find_in_section(stream, 'System Information', 'Serial Number:',
208
 
                       ['to be filled by o\.e\.m\.',
209
 
                        'system serial number', '\.\.\.\.\.'],
210
 
                       False):
211
 
        print("*** Invalid system information serial number!")
212
 
        retval += 1
213
 
    if find_in_section(stream, 'Base Board Information', 'Serial Number:',
214
 
                       ['n/a', 'base board serial number',
215
 
                        'to be filled by o\.e\.m\.', 'empty', '\.\.\.'],
216
 
                       False):
217
 
        print("*** Invalid base board serial number!")
218
 
        retval += 1
219
 
    return retval
220
 
 
221
 
 
222
 
def main():
223
 
    """Main function."""
224
 
    parser = ArgumentParser("dmitest")
225
 
    parser.add_argument('test_type',
226
 
                        help="Test type ('server', 'desktop' or 'cpu-check').",
227
 
                        choices=['server', 'desktop', 'cpu-check'])
228
 
    parser.add_argument('--dmifile',
229
 
                        help="File to use in lieu of dmidecode.")
230
 
    parser.add_argument('--test_versions', action="store_true",
231
 
                        help="Set to check version information")
232
 
    parser.add_argument('--test_serials', action="store_true",
233
 
                        help="Set to check serial number information")
234
 
    args = parser.parse_args()
235
 
 
236
 
    # Command to retrieve DMI information
237
 
    COMMAND = "dmidecode"
238
 
    try:
239
 
        if args.dmifile:
240
 
            print("Reading " + args.dmifile + " as DMI data")
241
 
            stream = subprocess.check_output(['cat', args.dmifile],
242
 
                                             universal_newlines=True).splitlines()
243
 
        else:
244
 
            stream = subprocess.check_output(COMMAND,
245
 
                                             universal_newlines=True).splitlines()
246
 
    except subprocess.CalledProcessError as err:
247
 
        print("Error running {}: {}".format(COMMAND, err))
248
 
        return 1
249
 
 
250
 
    retval = 0
251
 
    if args.test_type == 'server' or args.test_type == 'desktop':
252
 
        retval += standard_tests(args, stream)
 
173
        retval = 1
 
174
 
253
175
    if args.test_versions:
254
 
        retval += version_tests(args, stream)
 
176
 
 
177
        if find_in_section(stream, 'Chassis Information', 'Version:',
 
178
                           ['to be filled by o\.e\.m\.', 'empty'],
 
179
                           False):
 
180
            print("*** Invalid chassis version!")
 
181
            retval = 1
 
182
 
 
183
        if find_in_section(stream, 'System Information', 'Version:',
 
184
                           ['to be filled by o\.e\.m\.', '\(none\)',
 
185
                            'null', 'system version', 'not applicable',
 
186
                            '\.\.\.\.\.'], False):
 
187
            print("*** Invalid system information version!")
 
188
            retval = 1
 
189
 
 
190
        if find_in_section(stream, 'Base Board Information', 'Version:',
 
191
                           ['base board version',
 
192
                            'empty', 'to be filled by o\.e\.m\.'], False):
 
193
            print("*** Invalid base board version!")
 
194
            retval = 1
 
195
 
255
196
    if args.test_serials:
256
 
        retval += serial_tests(args, stream)
 
197
 
 
198
        if find_in_section(stream, 'System Information', 'Serial Number:',
 
199
                           ['to be filled by o\.e\.m\.',
 
200
                            'system serial number', '\.\.\.\.\.'],
 
201
                           False):
 
202
            print("*** Invalid system information serial number!")
 
203
            retval = 1
 
204
 
 
205
        if find_in_section(stream, 'Base Board Information', 'Serial Number:',
 
206
                           ['n/a', 'base board serial number',
 
207
                            'to be filled by o\.e\.m\.', 'empty', '\.\.\.'],
 
208
                           False):
 
209
            print("*** Invalid base board serial number!")
 
210
            retval = 1
 
211
 
257
212
    if find_in_section(stream, 'Processor Information', 'Version:',
258
213
                       ['sample'], False):
259
214
        print("*** Invalid processor information!")
260
 
        retval += 1
 
215
        retval = 1
261
216
 
262
217
    # In review of dmidecode data on 10/23/2014, no conspicuous problems
263
218
    # found in BIOS Information section's Vendor, Version, or Release Date
264
219
    # fields. Therefore, no tests based on these fields have been written.
265
220
 
266
 
    if retval > 0:
267
 
        if retval == 1:
268
 
            print("\nFailed 1 test (see above)")
269
 
        else:
270
 
            print("\nFailed {0} tests (see above)".format(retval))
 
221
    if retval:
 
222
        print("\nFailed one or more tests (see above)")
271
223
    else:
272
224
        print("\nPassed all tests")
273
225