Skip to content

Commit 9557323

Browse files
committed
Adding missing socket count functionality.
Signed-off-by: Rob Dobson <[email protected]>
1 parent f492712 commit 9557323

File tree

6 files changed

+91
-10
lines changed

6 files changed

+91
-10
lines changed

.pylint.rc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ load-plugins=
3838
# --enable=similarities". If you want to run only the classes checker, but have
3939
# no Warning level messages displayed, use"--disable=all --enable=classes
4040
# --disable=W"
41-
disable=I0011,W0511,W0110,W0141,W0603,W0142,C0103,C0111,R0801,W0614,W0401,R0903,R0904,C0301,W0231
41+
disable=I0011,W0511,W0110,W0141,W0603,W0142,C0103,C0111,R0801,W0614,W0401,R0903,R0904,C0301,W0231,W0703
4242

4343

4444
[REPORTS]

hwinfo/host/dmidecode.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ class DmidecodeParser(CommandParser):
1616
r'System\ Information\n(.)*\n(.)*\n(.)*\n(.)*\n\tUUID:\ (?P<system_uuid>.*)\n',
1717
# Chassis Info
1818
r'Chassis\ Information\n(.)*\n\tType:\ (?P<chassis_type>.*)\n',
19+
# Processor Info
20+
r'Processor\ Information\n\tSocket\ Designation:\ (?P<socket_designation>.*)\n',
1921
]
2022

2123

hwinfo/host/tests/data/dmidecode

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,62 @@ Processor Information
131131
Characteristics:
132132
64-bit capable
133133

134+
Handle 0x0401, DMI type 4, 40 bytes
135+
Processor Information
136+
Socket Designation: CPU2
137+
Type: Central Processor
138+
Family: Xeon
139+
Manufacturer: Intel
140+
ID: E5 06 01 00 FF FB EB BF
141+
Signature: Type 0, Family 6, Model 30, Stepping 5
142+
Flags:
143+
FPU (Floating-point unit on-chip)
144+
VME (Virtual mode extension)
145+
DE (Debugging extension)
146+
PSE (Page size extension)
147+
TSC (Time stamp counter)
148+
MSR (Model specific registers)
149+
PAE (Physical address extension)
150+
MCE (Machine check exception)
151+
CX8 (CMPXCHG8 instruction supported)
152+
APIC (On-chip APIC hardware supported)
153+
SEP (Fast system call)
154+
MTRR (Memory type range registers)
155+
PGE (Page global enable)
156+
MCA (Machine check architecture)
157+
CMOV (Conditional move instruction supported)
158+
PAT (Page attribute table)
159+
PSE-36 (36-bit page size extension)
160+
CLFSH (CLFLUSH instruction supported)
161+
DS (Debug store)
162+
ACPI (ACPI supported)
163+
MMX (MMX technology supported)
164+
FXSR (FXSAVE and FXSTOR instructions supported)
165+
SSE (Streaming SIMD extensions)
166+
SSE2 (Streaming SIMD extensions 2)
167+
SS (Self-snoop)
168+
HTT (Multi-threading)
169+
TM (Thermal monitor supported)
170+
PBE (Pending break enabled)
171+
Version: Intel(R) Xeon(R) CPU X3450 @ 2.67GHz
172+
Voltage: 1.2 V
173+
External Clock: 4800 MHz
174+
Max Speed: 3600 MHz
175+
Current Speed: 2666 MHz
176+
Status: Populated, Enabled
177+
Upgrade: Socket LGA1366
178+
L1 Cache Handle: 0x0700
179+
L2 Cache Handle: 0x0701
180+
L3 Cache Handle: 0x0702
181+
Serial Number: Not Specified
182+
Asset Tag: Not Specified
183+
Part Number: Not Specified
184+
Core Count: 4
185+
Core Enabled: 4
186+
Thread Count: 8
187+
Characteristics:
188+
64-bit capable
189+
134190
Handle 0x0700, DMI type 7, 19 bytes
135191
Cache Information
136192
Socket Designation: Not Specified

hwinfo/host/tests/test_dmidecode.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class DmidecodeParserTests(unittest.TestCase):
1818
'system_serial_number': 'GZ7BS4J',
1919
'system_uuid': '4C4C4544-005A-3710-8042-C7C04F53344A',
2020
'chassis_type': 'Rack Mount Chassis',
21+
'socket_designation': 'CPU1, CPU2',
2122
}
2223

2324

@@ -54,3 +55,6 @@ def test_dmidecode_system_uuid(self):
5455

5556
def test_dmidecode_chassis_type(self):
5657
return self._assert_equal('chassis_type')
58+
59+
def test_dmidecode_socket_designation_type(self):
60+
return self._assert_equal('socket_designation')

hwinfo/tools/inspector.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
import os
88
import sys
99
import tarfile
10-
import random
11-
import string
1210
import tempfile
1311
import shutil
1412

@@ -63,7 +61,6 @@ def find_in_tarball(tarball, filename):
6361

6462
def read_files_from_tarball(tarball, files):
6563
tar = tarfile.open(tarball)
66-
data = None
6764
tmpdir = tempfile.mkdtemp()
6865

6966

@@ -135,7 +132,7 @@ def get_cpuinfo_data(self):
135132
return self.exec_command(['cat /proc/cpuinfo'])
136133

137134
def get_os_data(self):
138-
return self.exec_command(['cat', '/etc/xensource-inventory'])
135+
return self.exec_command(['cat', '/etc/xensource-inventory'])
139136

140137
def get_os_info(self):
141138
rec = {}
@@ -155,11 +152,16 @@ def get_info(self):
155152
data = self.get_dmidecode_data()
156153
parser = dmidecode.DmidecodeParser(data)
157154
rec = parser.parse()
155+
print rec
156+
#Count sockets
157+
if 'socket_designation' in rec:
158+
rec['socket_count'] = len(rec['socket_designation'].split(','))
159+
158160
try:
159161
os_rec = self.get_os_info()
160162
for k, v in os_rec.iteritems():
161163
rec[k] = v
162-
except:
164+
except Exception:
163165
#Ignore failures. Only supports XS right now.
164166
pass
165167

hwinfo/util/__init__.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,23 @@
22

33
import re
44

5+
def combine_dicts(recs):
6+
"""Combine a list of recs, appending values to matching keys"""
7+
if not recs:
8+
return None
9+
10+
if len(recs) == 1:
11+
return recs.pop()
12+
13+
new_rec = {}
14+
for rec in recs:
15+
for k, v in rec.iteritems():
16+
if k in new_rec:
17+
new_rec[k] = "%s, %s" % (new_rec[k], v)
18+
else:
19+
new_rec[k] = v
20+
return new_rec
21+
522
class CommandParser(object):
623
"""Object for extending to parse command outputs"""
724

@@ -29,10 +46,10 @@ def set_seperator(self, seperator):
2946
def parse_item(self, item):
3047
rec = {}
3148
for regex in self.ITEM_REGEXS:
32-
match = re.search(regex, item)
33-
if match:
34-
rec = dict(rec.items() + match.groupdict().items())
35-
49+
matches = [m.groupdict() for m in re.finditer(regex, item)]
50+
mdicts = combine_dicts(matches)
51+
if mdicts:
52+
rec = dict(rec.items() + mdicts.items())
3653
return rec
3754

3855
def parse_items(self):

0 commit comments

Comments
 (0)