~pieq/checkbox/fix-1576570-stress-test-progress-log

« back to all changes in this revision

Viewing changes to checkbox-support/checkbox_support/lib/dmi.py

  • Committer: Sylvain Pineau
  • Date: 2014-01-07 13:39:38 UTC
  • mto: This revision was merged to the branch mainline in revision 2588.
  • Revision ID: sylvain.pineau@canonical.com-20140107133938-46v5ehofwa9whl1e
checkbox-support: Copy required modules from checkbox-old/checkbox

and their corresponding tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# This file is part of Checkbox.
 
3
#
 
4
# Copyright 2008 Canonical Ltd.
 
5
#
 
6
# Checkbox is free software: you can redistribute it and/or modify
 
7
# it under the terms of the GNU General Public License version 3,
 
8
# as published by the Free Software Foundation.
 
9
 
 
10
#
 
11
# Checkbox is distributed in the hope that it will be useful,
 
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
# GNU General Public License for more details.
 
15
#
 
16
# You should have received a copy of the GNU General Public License
 
17
# along with Checkbox.  If not, see <http://www.gnu.org/licenses/>.
 
18
#
 
19
import os
 
20
 
 
21
from checkbox.lib.conversion import string_to_type
 
22
 
 
23
# See also 3.3.4.1 of the "System Management BIOS Reference Specification,
 
24
# Version 2.6.1" (Preliminary Standard) document, available from
 
25
# http://www.dmtf.org/standards/smbios.
 
26
class Dmi:
 
27
    chassis = (
 
28
        ("Undefined",             "unknown"),  # 0x00
 
29
        ("Other",                 "unknown"),
 
30
        ("Unknown",               "unknown"),
 
31
        ("Desktop",               "desktop"),
 
32
        ("Low Profile Desktop",   "desktop"),
 
33
        ("Pizza Box",             "server"),
 
34
        ("Mini Tower",            "desktop"),
 
35
        ("Tower",                 "desktop"),
 
36
        ("Portable",              "laptop"),
 
37
        ("Laptop",                "laptop"),
 
38
        ("Notebook",              "laptop"),
 
39
        ("Hand Held",             "handheld"),
 
40
        ("Docking Station",       "laptop"),
 
41
        ("All In One",            "unknown"),
 
42
        ("Sub Notebook",          "laptop"),
 
43
        ("Space-saving",          "desktop"),
 
44
        ("Lunch Box",             "unknown"),
 
45
        ("Main Server Chassis",   "server"),
 
46
        ("Expansion Chassis",     "unknown"),
 
47
        ("Sub Chassis",           "unknown"),
 
48
        ("Bus Expansion Chassis", "unknown"),
 
49
        ("Peripheral Chassis",    "unknown"),
 
50
        ("RAID Chassis",          "unknown"),
 
51
        ("Rack Mount Chassis",    "unknown"),
 
52
        ("Sealed-case PC",        "unknown"),
 
53
        ("Multi-system",          "unknown"),
 
54
        ("CompactPCI",            "unknonw"),
 
55
        ("AdvancedTCA",           "unknown"),
 
56
        ("Blade",                 "server"),
 
57
        ("Blade Enclosure",       "unknown"))
 
58
 
 
59
    chassis_names = tuple(c[0] for c in chassis)
 
60
    chassis_types = tuple(c[1] for c in chassis)
 
61
    chassis_name_to_type = dict(chassis)
 
62
 
 
63
    type_names = (
 
64
        "BIOS",  # 0x00
 
65
        "System",
 
66
        "Base Board",
 
67
        "Chassis",
 
68
        "Processor",
 
69
        "Memory Controller",
 
70
        "Memory Module",
 
71
        "Cache",
 
72
        "Port Connector",
 
73
        "System Slots",
 
74
        "On Board Devices",
 
75
        "OEM Strings",
 
76
        "System Configuration Options",
 
77
        "BIOS Language",
 
78
        "Group Associations",
 
79
        "System Event Log",
 
80
        "Physical Memory Array",
 
81
        "Memory Device",
 
82
        "32-bit Memory Error",
 
83
        "Memory Array Mapped Address",
 
84
        "Memory Device Mapped Address",
 
85
        "Built-in Pointing Device",
 
86
        "Portable Battery",
 
87
        "System Reset",
 
88
        "Hardware Security",
 
89
        "System Power Controls",
 
90
        "Voltage Probe",
 
91
        "Cooling Device",
 
92
        "Temperature Probe",
 
93
        "Electrical Current Probe",
 
94
        "Out-of-band Remote Access",
 
95
        "Boot Integrity Services",
 
96
        "System Boot",
 
97
        "64-bit Memory Error",
 
98
        "Management Device",
 
99
        "Management Device Component",
 
100
        "Management Device Threshold Data",
 
101
        "Memory Channel",
 
102
        "IPMI Device",
 
103
        "Power Supply",
 
104
        )
 
105
 
 
106
 
 
107
class DmiDevice:
 
108
 
 
109
    bus = "dmi"
 
110
    driver = None
 
111
    product_id = None
 
112
    vendor_id = None
 
113
 
 
114
    _product_blacklist = (
 
115
        "<BAD INDEX>",
 
116
        "N/A",
 
117
        "Not Available",
 
118
        "INVALID",
 
119
        "OEM",
 
120
        "Product Name",
 
121
        "System Product Name",
 
122
        "To be filled by O.E.M.",
 
123
        "To Be Filled By O.E.M.",
 
124
        "To Be Filled By O.E.M. by More String",
 
125
        "Unknown",
 
126
        "Uknown",
 
127
        "Unknow",
 
128
        "xxxxxxxxxxxxxx",
 
129
        )
 
130
    _vendor_blacklist = (
 
131
        "<BAD INDEX>",
 
132
        "Not Available",
 
133
        "OEM",
 
134
        "OEM Manufacturer",
 
135
        "System manufacturer",
 
136
        "System Manufacturer",
 
137
        "System Name",
 
138
        "To be filled by O.E.M.",
 
139
        "To Be Filled By O.E.M.",
 
140
        "To Be Filled By O.E.M. by More String",
 
141
        "Unknow",  # XXX This is correct mispelling
 
142
        "Unknown",
 
143
        )
 
144
    _serial_blacklist = (
 
145
       "0",
 
146
       "00000000",
 
147
       "00 00 00 00 00 00 00 00",
 
148
       "0123456789",
 
149
       "Base Board Serial Number",
 
150
       "Chassis Serial Number",
 
151
       "N/A",
 
152
       "None",
 
153
       "Not Applicable",
 
154
       "Not Available",
 
155
       "Not Specified",
 
156
       "OEM",
 
157
       "System Serial Number",
 
158
       )
 
159
    _version_blacklist = (
 
160
        "-1",
 
161
        "<BAD INDEX>",
 
162
        "N/A",
 
163
        "None",
 
164
        "Not Applicable",
 
165
        "Not Available",
 
166
        "Not Specified",
 
167
        "OEM",
 
168
        "System Version",
 
169
        "Unknown",
 
170
        "x.x",
 
171
        )
 
172
 
 
173
    def __init__(self, attributes, category):
 
174
        self._attributes = attributes
 
175
        self.category = category
 
176
 
 
177
    @property
 
178
    def path(self):
 
179
        path = "/devices/virtual/dmi/id"
 
180
        return os.path.join(path, self.category.lower())
 
181
 
 
182
    @property
 
183
    def product(self):
 
184
        if self.category == "CHASSIS":
 
185
            type_string = self._attributes.get("chassis_type", "0")
 
186
            try:
 
187
                type_index = int(type_string)
 
188
                return Dmi.chassis_names[type_index]
 
189
            except ValueError:
 
190
                return type_string
 
191
 
 
192
        for name in "name", "version":
 
193
            attribute = "%s_%s" % (self.category.lower(), name)
 
194
            product = self._attributes.get(attribute)
 
195
            if product and product not in self._product_blacklist:
 
196
                return product
 
197
 
 
198
        return None
 
199
 
 
200
    @property
 
201
    def vendor(self):
 
202
        for name in "manufacturer", "vendor":
 
203
            attribute = "%s_%s" % (self.category.lower(), name)
 
204
            vendor = self._attributes.get(attribute)
 
205
            if vendor and vendor not in self._vendor_blacklist:
 
206
                return vendor
 
207
 
 
208
        return None
 
209
 
 
210
    @property
 
211
    def serial(self):
 
212
        attribute = "%s_serial" % self.category.lower()
 
213
        serial = self._attributes.get(attribute)
 
214
        if serial and serial not in self._serial_blacklist:
 
215
            return serial
 
216
 
 
217
        return None
 
218
 
 
219
    @property
 
220
    def version(self):
 
221
        attribute = "%s_version" % self.category.lower()
 
222
        version = self._attributes.get(attribute)
 
223
        if version and version not in self._version_blacklist:
 
224
            return version
 
225
 
 
226
        return None
 
227
 
 
228
    @property
 
229
    def size(self):
 
230
        attribute = "%s_size" % self.category.lower()
 
231
        size = self._attributes.get(attribute)
 
232
 
 
233
        if size:
 
234
            size = string_to_type(size)
 
235
 
 
236
        return size
 
237
 
 
238
    @property
 
239
    def form(self):
 
240
        attribute = "%s_form" % self.category.lower()
 
241
        return self._attributes.get(attribute)