remove fabric_type
Change-Id: I63a10b68764669383b407ba429c282a69a58e7cf
This commit is contained in:
parent
f165779c8c
commit
1319c5b35f
|
@ -24,13 +24,11 @@ class DeviceDB(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.device_db = {}
|
self.device_db = {}
|
||||||
|
|
||||||
def add_fabric(self, fabric, pf, hca_port, fabric_type,
|
def add_fabric(self, fabric, pf, hca_port, pf_mlx_dev):
|
||||||
pf_mlx_dev):
|
|
||||||
pf_details = {}
|
pf_details = {}
|
||||||
pf_details['vfs'] = {}
|
pf_details['vfs'] = {}
|
||||||
pf_details['pf_device_type'] = None
|
pf_details['pf_device_type'] = None
|
||||||
pf_details['hca_port'] = hca_port
|
pf_details['hca_port'] = hca_port
|
||||||
pf_details['fabric_type'] = fabric_type
|
|
||||||
pf_details['pf_mlx_dev'] = pf_mlx_dev
|
pf_details['pf_mlx_dev'] = pf_mlx_dev
|
||||||
if self.device_db.get(fabric) is None:
|
if self.device_db.get(fabric) is None:
|
||||||
self.device_db[fabric] = {pf: pf_details}
|
self.device_db[fabric] = {pf: pf_details}
|
||||||
|
|
|
@ -46,36 +46,24 @@ class eSwitchHandler(object):
|
||||||
self.add_fabrics(fabrics)
|
self.add_fabrics(fabrics)
|
||||||
|
|
||||||
def add_fabrics(self, fabrics):
|
def add_fabrics(self, fabrics):
|
||||||
res_fabrics = []
|
|
||||||
for fabric, pf in fabrics:
|
for fabric, pf in fabrics:
|
||||||
fabric_type = None
|
verify_vendor_pf = (
|
||||||
|
self.pci_utils.verify_vendor_pf(pf, constants.VENDOR))
|
||||||
if pf in ('autoib', 'autoeth'):
|
if (not verify_vendor_pf or
|
||||||
fabric_type = pf.strip('auto')
|
not self.pci_utils.is_sriov_pf(pf) or
|
||||||
pf = self.pci_utils.get_auto_pf(fabric_type)
|
not self.pci_utils.is_ifc_module(pf)):
|
||||||
else:
|
LOG.error(_LE("PF %s must have Mellanox Vendor ID"
|
||||||
fabric_type = self.pci_utils.get_interface_type(pf)
|
",SR-IOV and driver module "
|
||||||
verify_vendor_pf = (
|
"enabled. Terminating!") % pf)
|
||||||
self.pci_utils.verify_vendor_pf(pf, constants.VENDOR))
|
|
||||||
if (not verify_vendor_pf or
|
|
||||||
not self.pci_utils.is_sriov_pf(pf) or
|
|
||||||
not self.pci_utils.is_ifc_module(pf, fabric_type)):
|
|
||||||
LOG.error(_LE("PF %s must have Mellanox Vendor ID"
|
|
||||||
",SR-IOV and driver module "
|
|
||||||
"enabled. Terminating!") % pf)
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
if fabric_type:
|
|
||||||
if self.eswitches.get(fabric) is None:
|
|
||||||
self.eswitches[fabric] = []
|
|
||||||
vfs = self.pci_utils.get_vfs_info(pf)
|
|
||||||
self.eswitches[fabric].append(
|
|
||||||
eswitch_db.eSwitchDB(pf=pf, vfs=vfs))
|
|
||||||
self._add_fabric(fabric, pf, fabric_type)
|
|
||||||
res_fabrics.append((fabric, pf, fabric_type))
|
|
||||||
else:
|
|
||||||
LOG.info(_LI("No fabric type for PF:%s.Terminating!") % pf)
|
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
if self.eswitches.get(fabric) is None:
|
||||||
|
self.eswitches[fabric] = []
|
||||||
|
vfs = self.pci_utils.get_vfs_info(pf)
|
||||||
|
self.eswitches[fabric].append(
|
||||||
|
eswitch_db.eSwitchDB(pf=pf, vfs=vfs))
|
||||||
|
self._add_fabric(fabric, pf)
|
||||||
|
|
||||||
self.sync_devices()
|
self.sync_devices()
|
||||||
|
|
||||||
def sync_devices(self):
|
def sync_devices(self):
|
||||||
|
@ -88,8 +76,8 @@ class eSwitchHandler(object):
|
||||||
self._treat_removed_devices(removed_devs)
|
self._treat_removed_devices(removed_devs)
|
||||||
self.devices = set(devices)
|
self.devices = set(devices)
|
||||||
|
|
||||||
def _add_fabric(self, fabric, pf, fabric_type):
|
def _add_fabric(self, fabric, pf):
|
||||||
self.rm.add_fabric(fabric, pf, fabric_type)
|
self.rm.add_fabric(fabric, pf)
|
||||||
self._config_port_up(pf)
|
self._config_port_up(pf)
|
||||||
pf_fabric_details = self.rm.get_fabric_details(fabric, pf)
|
pf_fabric_details = self.rm.get_fabric_details(fabric, pf)
|
||||||
eswitches = self._get_eswitches_for_fabric(fabric)
|
eswitches = self._get_eswitches_for_fabric(fabric)
|
||||||
|
|
|
@ -32,10 +32,9 @@ class ResourceManager(object):
|
||||||
self.pci_utils = pci_utils.pciUtils()
|
self.pci_utils = pci_utils.pciUtils()
|
||||||
self.device_db = device_db.DeviceDB()
|
self.device_db = device_db.DeviceDB()
|
||||||
|
|
||||||
def add_fabric(self, fabric, pf, fabric_type):
|
def add_fabric(self, fabric, pf):
|
||||||
hca_port, pf_mlx_dev = self._get_pf_details(pf)
|
hca_port, pf_mlx_dev = self._get_pf_details(pf)
|
||||||
self.device_db.add_fabric(fabric, pf, hca_port, fabric_type,
|
self.device_db.add_fabric(fabric, pf, hca_port, pf_mlx_dev)
|
||||||
pf_mlx_dev)
|
|
||||||
vfs = self.discover_devices(pf)
|
vfs = self.discover_devices(pf)
|
||||||
LOG.info(_LI("PF %(pf)s, vfs = %(vf)s"), {'pf': pf, 'vf': vfs})
|
LOG.info(_LI("PF %(pf)s, vfs = %(vf)s"), {'pf': pf, 'vf': vfs})
|
||||||
self.device_db.set_fabric_devices(fabric, pf, vfs)
|
self.device_db.set_fabric_devices(fabric, pf, vfs)
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
import glob
|
import glob
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
|
||||||
|
|
||||||
import ethtool
|
import ethtool
|
||||||
from oslo_concurrency import processutils
|
from oslo_concurrency import processutils
|
||||||
|
@ -113,36 +112,12 @@ class pciUtils(object):
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def is_ifc_module(self, ifc, fabric_type):
|
def is_ifc_module(self, ifc):
|
||||||
modules = {'eth': 'mlx4_en', 'ib': 'ipoib'}
|
if 'ipoib' in ethtool.get_module(ifc):
|
||||||
if modules[fabric_type] in ethtool.get_module(ifc):
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def filter_ifcs_module(self, ifcs, fabric_type):
|
def filter_ifcs_module(self, ifcs):
|
||||||
return [ifc for ifc in ifcs if self.is_ifc_module(ifc, fabric_type)]
|
return [ifc for ifc in ifcs if self.is_ifc_module(ifc)]
|
||||||
|
|
||||||
def get_auto_pf(self, fabric_type):
|
|
||||||
def log_error_and_exit(err_msg):
|
|
||||||
LOG.error(err_msg)
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
mlnx_pfs = [ifc for ifc in ethtool.get_devices()
|
|
||||||
if self.verify_vendor_pf(ifc)]
|
|
||||||
if not mlnx_pfs:
|
|
||||||
log_error_and_exit("Didn't find any Mellanox devices.")
|
|
||||||
|
|
||||||
mlnx_pfs = [ifc for ifc in mlnx_pfs if self.is_sriov_pf(ifc)]
|
|
||||||
if not mlnx_pfs:
|
|
||||||
log_error_and_exit("Didn't find Mellanox NIC "
|
|
||||||
"with SR-IOV capabilities.")
|
|
||||||
mlnx_pfs = self.filter_ifcs_module(mlnx_pfs, fabric_type)
|
|
||||||
if not mlnx_pfs:
|
|
||||||
log_error_and_exit("Didn't find Mellanox NIC of type %s with "
|
|
||||||
"SR-IOV capabilites." % fabric_type)
|
|
||||||
if len(mlnx_pfs) != 1:
|
|
||||||
log_error_and_exit("Found multiple PFs %s. Configure Manually."
|
|
||||||
% mlnx_pfs)
|
|
||||||
return mlnx_pfs[0]
|
|
||||||
|
|
||||||
def get_pf_mlx_dev(self, pf):
|
def get_pf_mlx_dev(self, pf):
|
||||||
dev_path = (
|
dev_path = (
|
||||||
|
|
|
@ -41,53 +41,6 @@ class TestPciUtils(base.TestCase):
|
||||||
super(TestPciUtils, self).setUp()
|
super(TestPciUtils, self).setUp()
|
||||||
self.pci_utils = pci_utils.pciUtils()
|
self.pci_utils = pci_utils.pciUtils()
|
||||||
|
|
||||||
def _assert_get_auto_pf_error(self, log_msg):
|
|
||||||
with mock.patch.object(pci_utils, 'LOG') as LOG:
|
|
||||||
self.assertRaises(SystemExit,
|
|
||||||
self.pci_utils.get_auto_pf, 'fabtype')
|
|
||||||
LOG.error.assert_called_with(log_msg)
|
|
||||||
|
|
||||||
def _test_get_auto_pf(self, devices=None, is_vendor_pf=True,
|
|
||||||
is_sriov=True, valid_fabric_type=True):
|
|
||||||
devices = devices if devices else []
|
|
||||||
ifcs = devices if valid_fabric_type else []
|
|
||||||
return nested(
|
|
||||||
mock.patch('ethtool.get_devices', return_value=devices),
|
|
||||||
mock.patch.object(self.pci_utils, 'verify_vendor_pf',
|
|
||||||
return_value=is_vendor_pf),
|
|
||||||
mock.patch.object(self.pci_utils, 'is_sriov_pf',
|
|
||||||
return_value=is_sriov),
|
|
||||||
mock.patch.object(self.pci_utils, 'filter_ifcs_module',
|
|
||||||
return_value=ifcs),
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_get_auto_pf_no_mlnx_devices(self):
|
|
||||||
log_msg = "Didn't find any Mellanox devices."
|
|
||||||
with self._test_get_auto_pf():
|
|
||||||
self._assert_get_auto_pf_error(log_msg)
|
|
||||||
|
|
||||||
log_msg = "Didn't find any Mellanox devices."
|
|
||||||
with self._test_get_auto_pf(devices=['device-1'], is_vendor_pf=False):
|
|
||||||
self._assert_get_auto_pf_error(log_msg)
|
|
||||||
|
|
||||||
def test_get_auto_pf_no_mlnx_sriov_devices(self):
|
|
||||||
log_msg = "Didn't find Mellanox NIC with SR-IOV capabilities."
|
|
||||||
with self._test_get_auto_pf(devices=['device-1'], is_sriov=False):
|
|
||||||
self._assert_get_auto_pf_error(log_msg)
|
|
||||||
|
|
||||||
def test_get_auto_pf_wrong_fabric_type(self):
|
|
||||||
log_msg = ("Didn't find Mellanox NIC of type fabtype with "
|
|
||||||
"SR-IOV capabilites.")
|
|
||||||
with self._test_get_auto_pf(devices=['device-1'],
|
|
||||||
valid_fabric_type=False):
|
|
||||||
self._assert_get_auto_pf_error(log_msg)
|
|
||||||
|
|
||||||
def test_get_auto_pf_multiple_pfs(self):
|
|
||||||
devices = ['device-1', 'device-2']
|
|
||||||
log_msg = "Found multiple PFs %s. Configure Manually." % devices
|
|
||||||
with self._test_get_auto_pf(devices=devices):
|
|
||||||
self._assert_get_auto_pf_error(log_msg)
|
|
||||||
|
|
||||||
def test_get_vfs_info_not_found_device(self):
|
def test_get_vfs_info_not_found_device(self):
|
||||||
pf = "pf_that_does_not_exist"
|
pf = "pf_that_does_not_exist"
|
||||||
with mock.patch.object(pci_utils, 'LOG') as LOG:
|
with mock.patch.object(pci_utils, 'LOG') as LOG:
|
||||||
|
|
Loading…
Reference in New Issue