提交 e0f97ef0 编写于 作者: A Abdul Haleem

get_slot_from_sysfs: accomodate more type of slot names in pci utils

This patche takes care of Slot format for ibm and openpower machines
* S0001
* Slot1
* SLOT1
* Backplane USB
* U78CB.001.WZS07CU-P1-C9-T1 (should return U78CB.001.WZS07CU-P1-C9)
* Onboard USB

Respective unit test has also been added test_utils_pci.py
Signed-off-by: NAbdul Haleem <abdhalee@linux.vnet.ibm.com>
Signed-off-by: NNarasimhan V <sim@linux.vnet.ibm.com>
上级 77058ab9
......@@ -182,8 +182,12 @@ def get_slot_from_sysfs(full_pci_address):
if not os.path.isfile("/proc/device-tree/%s/ibm,loc-code" % devspec):
return
slot = genio.read_file("/proc/device-tree/%s/ibm,loc-code" % devspec)
slot = re.match(r'((\w+)[.])+(\w+)-P(\d+)-C(\d+)|Slot(\d+)', slot).group()
return slot
slot_ibm = re.match(r'((\w+)[.])+(\w+)-[P(\d+)-]*C(\d+)', slot)
slot_openpower = re.match(r'(\w+)[\s]*(\w+)(\d*)', slot)
if slot_ibm:
return slot_ibm.group()
else:
return slot_openpower.group()
def get_slot_list():
......
import unittest
try:
from unittest import mock
except ImportError:
import mock
from avocado.utils import pci
class UtilsPciTest(unittest.TestCase):
def test_get_slot_from_sysfs(self):
pcid = '0002:01:00.1'
file_values = ['S0001', 'S0001[', 'Slot2', 'SLOT1', 'Backplane USB', 'U78CB.001.WZS07CU-P1-C9-T1', 'PLX Slot1', 'Onboard USB', 'U78D5.001.CSS130E-P1-P2-P2-C1-T1']
expected_values = ['S0001', 'S0001', 'Slot2', 'SLOT1', 'Backplane USB', 'U78CB.001.WZS07CU-P1-C9', 'PLX Slot1', 'Onboard USB', 'U78D5.001.CSS130E-P1-P2-P2-C1']
for value, exp in zip(file_values, expected_values):
with mock.patch('os.path.isfile', return_value=True):
with mock.patch('avocado.utils.genio.read_file',
return_value=value):
self.assertEqual(pci.get_slot_from_sysfs(pcid), exp)
if __name__ == '__main__':
unittest.main()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册