diff --git a/networking_mlnx/eswitchd/db/device_db.py b/networking_mlnx/eswitchd/db/device_db.py index 1248800..0cd4598 100644 --- a/networking_mlnx/eswitchd/db/device_db.py +++ b/networking_mlnx/eswitchd/db/device_db.py @@ -24,13 +24,11 @@ class DeviceDB(object): def __init__(self): self.device_db = {} - def add_fabric(self, fabric, pf, hca_port, fabric_type, - pf_mlx_dev): + def add_fabric(self, fabric, pf, hca_port, pf_mlx_dev): pf_details = {} pf_details['vfs'] = {} pf_details['pf_device_type'] = None pf_details['hca_port'] = hca_port - pf_details['fabric_type'] = fabric_type pf_details['pf_mlx_dev'] = pf_mlx_dev if self.device_db.get(fabric) is None: self.device_db[fabric] = {pf: pf_details} diff --git a/networking_mlnx/eswitchd/eswitch_handler.py b/networking_mlnx/eswitchd/eswitch_handler.py index 21f70d5..a481174 100644 --- a/networking_mlnx/eswitchd/eswitch_handler.py +++ b/networking_mlnx/eswitchd/eswitch_handler.py @@ -46,36 +46,24 @@ class eSwitchHandler(object): self.add_fabrics(fabrics) def add_fabrics(self, fabrics): - res_fabrics = [] for fabric, pf in fabrics: - fabric_type = None - - if pf in ('autoib', 'autoeth'): - fabric_type = pf.strip('auto') - pf = self.pci_utils.get_auto_pf(fabric_type) - else: - fabric_type = self.pci_utils.get_interface_type(pf) - verify_vendor_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) + verify_vendor_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)): + LOG.error(_LE("PF %s must have Mellanox Vendor ID" + ",SR-IOV and driver module " + "enabled. Terminating!") % pf) 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() def sync_devices(self): @@ -88,8 +76,8 @@ class eSwitchHandler(object): self._treat_removed_devices(removed_devs) self.devices = set(devices) - def _add_fabric(self, fabric, pf, fabric_type): - self.rm.add_fabric(fabric, pf, fabric_type) + def _add_fabric(self, fabric, pf): + self.rm.add_fabric(fabric, pf) self._config_port_up(pf) pf_fabric_details = self.rm.get_fabric_details(fabric, pf) eswitches = self._get_eswitches_for_fabric(fabric) diff --git a/networking_mlnx/eswitchd/resource_mngr.py b/networking_mlnx/eswitchd/resource_mngr.py index 4ff77bd..da35ef8 100644 --- a/networking_mlnx/eswitchd/resource_mngr.py +++ b/networking_mlnx/eswitchd/resource_mngr.py @@ -32,10 +32,9 @@ class ResourceManager(object): self.pci_utils = pci_utils.pciUtils() 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) - self.device_db.add_fabric(fabric, pf, hca_port, fabric_type, - pf_mlx_dev) + self.device_db.add_fabric(fabric, pf, hca_port, pf_mlx_dev) vfs = self.discover_devices(pf) LOG.info(_LI("PF %(pf)s, vfs = %(vf)s"), {'pf': pf, 'vf': vfs}) self.device_db.set_fabric_devices(fabric, pf, vfs) diff --git a/networking_mlnx/eswitchd/utils/pci_utils.py b/networking_mlnx/eswitchd/utils/pci_utils.py index a7c420d..cd9fedf 100644 --- a/networking_mlnx/eswitchd/utils/pci_utils.py +++ b/networking_mlnx/eswitchd/utils/pci_utils.py @@ -15,7 +15,6 @@ import glob import os import re -import sys import ethtool from oslo_concurrency import processutils @@ -113,36 +112,12 @@ class pciUtils(object): else: return None - def is_ifc_module(self, ifc, fabric_type): - modules = {'eth': 'mlx4_en', 'ib': 'ipoib'} - if modules[fabric_type] in ethtool.get_module(ifc): + def is_ifc_module(self, ifc): + if 'ipoib' in ethtool.get_module(ifc): return True - def filter_ifcs_module(self, ifcs, fabric_type): - return [ifc for ifc in ifcs if self.is_ifc_module(ifc, fabric_type)] - - 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 filter_ifcs_module(self, ifcs): + return [ifc for ifc in ifcs if self.is_ifc_module(ifc)] def get_pf_mlx_dev(self, pf): dev_path = ( diff --git a/networking_mlnx/tests/unit/eswitchd/test_pci_utils.py b/networking_mlnx/tests/unit/eswitchd/test_pci_utils.py index 031d5ca..b82b57d 100644 --- a/networking_mlnx/tests/unit/eswitchd/test_pci_utils.py +++ b/networking_mlnx/tests/unit/eswitchd/test_pci_utils.py @@ -41,53 +41,6 @@ class TestPciUtils(base.TestCase): super(TestPciUtils, self).setUp() 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): pf = "pf_that_does_not_exist" with mock.patch.object(pci_utils, 'LOG') as LOG: