Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions hwinfo/pci/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ def get_pci_id(self):
self.lookup_value('pci_subdevice_id'),
)

def get_pci_class(self):
return self.lookup_value('pci_device_class')

def is_subdevice(self):
return self.lookup_value('pci_subvendor_id') and self.lookup_value('pci_subdevice_id')

Expand All @@ -65,3 +68,17 @@ def get_info(self):
return "%s %s (%s %s)" % (self.get_subvendor_name(), self.get_subdevice_name(), self.get_vendor_name(), self.get_device_name())
else:
return "%s %s" % (self.get_vendor_name(), self.get_device_name())

def get_rec(self):
rec = {}
rec['vendor_name'] = self.get_vendor_name()
rec['device_name'] = self.get_device_name()
rec['vendor_id'] = self.get_vendor_id()
rec['device_id'] = self.get_device_id()
rec['class'] = self.get_pci_class()
rec['subvendor_name'] = self.get_subvendor_name()
rec['subdevice_name'] = self.get_subdevice_name()
rec['subvendor_id'] = self.get_subvendor_id()
rec['subdevice_id'] = self.get_subdevice_id()

return rec
14 changes: 7 additions & 7 deletions hwinfo/pci/lspci.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class LspciVVParser(CommandParser):
"""Parser object for the output of lspci -vv"""

ITEM_REGEXS = [
r'(?P<pci_device_bus_id>([0-9][0-9]:[0-9][0-9]\.[0-9]))\ (?P<pci_device_type>[\w\ ]*):\ (?P<pci_device_string>(.*))\n',
r'(?P<pci_device_bus_id>([0-9][0-9]:[0-9][0-9]\.[0-9]))\ (?P<pci_device_class_name>[\w\ ]*):\ (?P<pci_device_string>(.*))\n',
r'Product\ Name:\ (?P<pci_device_vpd_product_name>(.)*)\n',
r'Subsystem:\ (?P<pci_device_sub_string>(.)*)\n',
]
Expand All @@ -18,7 +18,7 @@ class LspciVVParser(CommandParser):

MUST_HAVE_FIELDS = [
'pci_device_bus_id',
'pci_device_type',
'pci_device_class_name',
'pci_device_string',
]

Expand All @@ -27,7 +27,7 @@ class LspciNParser(CommandParser):

#ff:0d.1 0880: 8086:0ee3 (rev 04)
ITEM_REGEXS = [
r'(?P<pci_device_bus_id>([0-9a-f][0-9a-f]:[0-9a-f][0-9a-f]\.[0-9a-f]))\ (?P<pci_device_type_id>[0-9a-f]{4}):\ (?P<pci_vendor_id>[0-9a-f]{4}):(?P<pci_device_id>[0-9a-f]{4})',
r'(?P<pci_device_bus_id>([0-9a-f][0-9a-f]:[0-9a-f][0-9a-f]\.[0-9a-f]))\ (?P<pci_device_class>[0-9a-f]{4}):\ (?P<pci_vendor_id>[0-9a-f]{4}):(?P<pci_device_id>[0-9a-f]{4})',
]

ITEM_SEPERATOR = "\n"
Expand All @@ -36,11 +36,11 @@ class LspciNParser(CommandParser):
'pci_device_bus_id',
'pci_device_id',
'pci_vendor_id',
'pci_device_type_id',
'pci_device_class',
]


LABEL_REGEX = r'[\w+\ \.\-\/]+'
LABEL_REGEX = r'[\w+\ \.\-\/\[\]\(\)]+'
CODE_REGEX = r'[0-9a-fA-F]{4}'

class LspciNNMMParser(CommandParser):
Expand All @@ -49,9 +49,9 @@ class LspciNNMMParser(CommandParser):
#02:00.1 "Ethernet controller [0200]" "Broadcom Corporation [14e4]" "NetXtreme II BCM5716 Gigabit Ethernet [163b]" -r20 "Dell [1028]" "Device [02a3]"

ITEM_REGEXS = [
r'(?P<pci_device_bus_id>([0-9a-fA-F]{2}:[0-9a-fA-F]{2}\.[0-9a-fA-F]))\ "(?P<pci_device_type_name>' + LABEL_REGEX + r')\ \[(?P<pci_device_type_id>' + CODE_REGEX + r')\]"' \
r'(?P<pci_device_bus_id>([0-9a-fA-F]{2}:[0-9a-fA-F]{2}\.[0-9a-fA-F]))\ "(?P<pci_device_class_name>' + LABEL_REGEX + r')\ \[(?P<pci_device_class>' + CODE_REGEX + r')\]"' \
+ r'\ "(?P<pci_vendor_name>' + LABEL_REGEX + r')\ \[(?P<pci_vendor_id>' + CODE_REGEX + r')\]"\ "(?P<pci_device_name>' + LABEL_REGEX + r')\ \[(?P<pci_device_id>' + CODE_REGEX + r')\]"' \
+ r'\ .*\ "((?P<pci_subvendor_name>' + LABEL_REGEX + r')\ \[(?P<pci_subvendor_id>' + CODE_REGEX + r')\])*"\ "((?P<pci_subdevice_name>' + LABEL_REGEX + r')\ \[(?P<pci_subdevice_id>' + CODE_REGEX + r')\])*',
+ r'\ .*\"((?P<pci_subvendor_name>' + LABEL_REGEX + r')\ \[(?P<pci_subvendor_id>' + CODE_REGEX + r')\])*"\ "((?P<pci_subdevice_name>' + LABEL_REGEX + r')\ \[(?P<pci_subdevice_id>' + CODE_REGEX + r')\])*',
]

ITEM_SEPERATOR = "\n"
88 changes: 72 additions & 16 deletions hwinfo/pci/tests/test_lspci.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class TestSingleDeviceVVParse(unittest.TestCase):

DEVICE_REC = {
'pci_device_string': 'Broadcom Corporation NetXtreme II BCM5716 Gigabit Ethernet (rev 20)',
'pci_device_type': 'Ethernet controller',
'pci_device_class': '0200',
'pci_device_class_name': 'Ethernet controller',
'pci_device_bus_id': '02:00.0',
'pci_device_sub_string': 'Dell Device 0488',
'pci_device_vpd_product_name': 'Broadcom NetXtreme II Ethernet Controller',
Expand All @@ -36,9 +37,9 @@ def test_pci_device_bus_id(self):
rec = self.parser.parse_items().pop()
self._assert_rec_key(rec, 'pci_device_bus_id')

def test_pci_device_type(self):
def test_pci_device_class_name(self):
rec = self.parser.parse_items().pop()
self._assert_rec_key(rec, 'pci_device_type')
self._assert_rec_key(rec, 'pci_device_class_name')

def test_pci_device_sub_string(self):
rec = self.parser.parse_items().pop()
Expand Down Expand Up @@ -70,7 +71,7 @@ class TestSingleDeviceNParse(unittest.TestCase):
'pci_device_bus_id': 'ff:10.5',
'pci_vendor_id': '8086',
'pci_device_id': '0eb5',
'pci_device_type_id': '0880',
'pci_device_class': '0880',
}

def setUp(self):
Expand All @@ -89,8 +90,8 @@ def test_pci_vendor_id(self):
def test_pci_device_id(self):
self._assert_rec_key('pci_device_id')

def test_pci_device_type_id(self):
self._assert_rec_key('pci_device_type_id')
def test_pci_device_class(self):
self._assert_rec_key('pci_device_class')

class TestMultiDeviceNParse(unittest.TestCase):

Expand All @@ -113,8 +114,8 @@ class TestSingleDeviceNNMMParse(unittest.TestCase):

DEVICE_REC = {
'pci_device_bus_id': '02:00.0',
'pci_device_type_id': '0200',
'pci_device_type_name': 'Ethernet controller',
'pci_device_class': '0200',
'pci_device_class_name': 'Ethernet controller',
'pci_vendor_name': 'Broadcom Corporation',
'pci_vendor_id': '14e4',
'pci_device_id': '163b',
Expand All @@ -135,11 +136,11 @@ def _assert_rec_key(self, key):
def test_pci_device_bus_id(self):
self._assert_rec_key('pci_device_bus_id')

def test_pci_device_type_id(self):
self._assert_rec_key('pci_device_type_id')
def test_pci_device_class(self):
self._assert_rec_key('pci_device_class')

def test_pci_device_type_name(self):
self._assert_rec_key('pci_device_type_name')
def test_pci_device_class_name(self):
self._assert_rec_key('pci_device_class_name')

def test_pci_vendor_name(self):
self._assert_rec_key('pci_vendor_name')
Expand Down Expand Up @@ -168,8 +169,8 @@ class LsiDeviceParse(TestSingleDeviceNNMMParse):

DEVICE_REC = {
'pci_device_bus_id': '03:00.0',
'pci_device_type_id': '0100',
'pci_device_type_name': 'SCSI storage controller',
'pci_device_class': '0100',
'pci_device_class_name': 'SCSI storage controller',
'pci_vendor_name': 'LSI Logic / Symbios Logic',
'pci_vendor_id': '1000',
'pci_device_id': '0058',
Expand All @@ -187,8 +188,8 @@ class IntelUSBControllerDeviceParse(TestSingleDeviceNNMMParse):

DEVICE_REC = {
'pci_device_bus_id': '00:1d.0',
'pci_device_type_id': '0c03',
'pci_device_type_name': 'USB controller',
'pci_device_class': '0c03',
'pci_device_class_name': 'USB controller',
'pci_vendor_name': 'Intel Corporation',
'pci_vendor_id': '8086',
'pci_device_id': '3b34',
Expand All @@ -199,6 +200,61 @@ class IntelUSBControllerDeviceParse(TestSingleDeviceNNMMParse):
'pci_subdevice_id': '02a3',
}

class EmulexNicDeviceParse(TestSingleDeviceNNMMParse):

SAMPLE_DATA = '0c:00.0 "Ethernet controller [0200]" "Emulex Corporation [19a2]" "OneConnect 10Gb NIC (be3) [0710]" -r02 "Emulex Corporation [10df]" "Device [e70b]"'

DEVICE_REC = {
'pci_device_bus_id': '0c:00.0',
'pci_device_class': '0200',
'pci_device_class_name': 'Ethernet controller',
'pci_vendor_name': 'Emulex Corporation',
'pci_vendor_id': '19a2',
'pci_device_id': '0710',
'pci_device_name': 'OneConnect 10Gb NIC (be3)',
'pci_subvendor_name': 'Emulex Corporation',
'pci_subvendor_id': '10df',
'pci_subdevice_name': 'Device',
'pci_subdevice_id': 'e70b',
}

class LsiSASDeviceParse(TestSingleDeviceNNMMParse):

SAMPLE_DATA = '06:00.0 "Serial Attached SCSI controller [0107]" "LSI Logic / Symbios Logic [1000]" "SAS2004 PCI-Express Fusion-MPT SAS-2 [Spitfire] [0070]" -r03 "IBM [1014]" "Device [03f8]"'

DEVICE_REC = {
'pci_device_bus_id': '06:00.0',
'pci_device_class': '0107',
'pci_device_class_name': 'Serial Attached SCSI controller',
'pci_vendor_name': 'LSI Logic / Symbios Logic',
'pci_vendor_id': '1000',
'pci_device_id': '0070',
'pci_device_name': 'SAS2004 PCI-Express Fusion-MPT SAS-2 [Spitfire]',
'pci_subvendor_name': 'IBM',
'pci_subvendor_id': '1014',
'pci_subdevice_name': 'Device',
'pci_subdevice_id': '03f8',
}

class BroadcomNetDeviceParse(TestSingleDeviceNNMMParse):

SAMPLE_DATA = '01:00.0 "Ethernet controller [0200]" "Broadcom Corporation [14e4]" "NetXtreme BCM5720 Gigabit Ethernet PCIe [165f]" "Dell [1028]" "Device [1f5b]"'

DEVICE_REC = {
'pci_device_bus_id': '01:00.0',
'pci_device_class': '0200',
'pci_device_class_name': 'Ethernet controller',
'pci_vendor_name': 'Broadcom Corporation',
'pci_vendor_id': '14e4',
'pci_device_id': '165f',
'pci_device_name': 'NetXtreme BCM5720 Gigabit Ethernet PCIe',
'pci_subvendor_name': 'Dell',
'pci_subvendor_id': '1028',
'pci_subdevice_name': 'Device',
'pci_subdevice_id': '1f5b',
}


class TestMultiDeviceNNMMParse(unittest.TestCase):

SAMPLE_FILE = '%s/lspci-nnmm' % DATA_DIR
Expand Down
8 changes: 6 additions & 2 deletions hwinfo/pci/tests/test_pci.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ class TestPCIDeviceObject(unittest.TestCase):

DEVICE_REC = {
'pci_device_bus_id': '02:00.0',
'pci_device_type_id': '0200',
'pci_device_type_name': 'Ethernet controller',
'pci_device_class': '0200',
'pci_device_class_name': 'Ethernet controller',
'pci_vendor_name': 'Broadcom Corporation',
'pci_vendor_id': '14e4',
'pci_device_id': '163b',
Expand Down Expand Up @@ -64,3 +64,7 @@ def test_is_subdevice(self):
def test_get_device_info(self):
info = self.device.get_info()
self.assertEqual(info, 'Dell [Device 02a3] (Broadcom Corporation NetXtreme II BCM5716 Gigabit Ethernet)')

def test_get_device_class(self):
pci_class = self.device.get_pci_class()
self.assertEqual(pci_class, '0200')
Empty file added hwinfo/tools/__init__.py
Empty file.
Loading