def get_dpdk_devargs(ifname, noop): if not noop: vendor_id = common.get_vendor_id(ifname) device_id = common.get_device_id(ifname) if vendor_id == "0x15b3": logger.info("Getting devargs for Mellanox cards") if device_id == "0x1007": # Some NICs (i.e. Mellanox ConnectX-3) have only one PCI # address associated with multiple ports. Using a PCI # device won’t work. Instead, we should use # "class=eth,mac=<MAC>" dpdk_devargs = f"class=eth,mac={common.interface_mac(ifname)}" elif is_active_nic(ifname): # Other Mellanox devices are active and they are not stored # in dpdk_mapping.yaml file, so we need to get their pci # address with ethtool. dpdk_devargs = get_pci_address(ifname, noop) elif common.is_vf_by_name(ifname): # For Mellanox devices the VFs bound with DPDK shall # be treated the same as VFs of other devices dpdk_devargs = get_pci_address(ifname, noop) else: msg = ("Unable to get devargs for interface %s" % ifname) raise InvalidInterfaceException(msg) else: logger.info("Getting stored PCI address as devarg") dpdk_devargs = get_stored_pci_address(ifname, noop) logger.debug("Devargs found: %s" % (dpdk_devargs)) return dpdk_devargs
def bind_dpdk_interfaces(ifname, driver, noop): if common.is_mellanox_interface(ifname) and 'vfio-pci' in driver: msg = ("For Mellanox NIC %s, the default driver vfio-pci " "needs to be overridden" % ifname) raise common.OvsDpdkBindException(msg) iface_driver = get_interface_driver(ifname) if iface_driver == driver: logger.info("Driver (%s) is already bound to the device (%s)" % (driver, ifname)) return pci_address = get_pci_address(ifname, noop) if not noop: if pci_address: # modbprobe of the driver has to be done before binding. # for reboots, puppet will add the modprobe to /etc/rc.modules if 'vfio-pci' in driver: try: processutils.execute('modprobe', 'vfio-pci') except processutils.ProcessExecutionError: msg = "Failed to modprobe vfio-pci module" raise common.OvsDpdkBindException(msg) mac_address = common.interface_mac(ifname) vendor_id = common.get_vendor_id(ifname) err = common.set_driverctl_override(pci_address, driver) if not err: _update_dpdk_map(ifname, pci_address, mac_address, driver) # Not like other nics, beacause mellanox nics keep the # interface after binding it to dpdk, so we are adding # ethtool command with 10 attempts after binding the driver # just to make sure that the interface is initialized # successfully in order not to fail in each of this cases: # - get_dpdk_devargs() in case of OvsDpdkPort and # OvsDpdkBond. # - bind_dpdk_interface() in case of OvsDpdkBond. if vendor_id == common.MLNX_VENDOR_ID: processutils.execute('ethtool', '-i', ifname, attempts=10) else: # Check if the pci address is already fetched and stored. # If the pci address could not be fetched from dpdk_mapping.yaml # raise OvsDpdkBindException, since the interface is neither # available nor bound with dpdk. if not get_stored_pci_address(ifname, noop): msg = "Interface %s cannot be found" % ifname raise common.OvsDpdkBindException(msg) else: logger.info('Interface %(name)s bound to DPDK driver %(driver)s ' 'using driverctl command' % { 'name': ifname, 'driver': driver })
def test_get_vendor_id_exception(self): mocked_open = mock.mock_open() mocked_open.side_effect = IOError with mock.patch('os_net_config.common.open', mocked_open, create=True): vendor = common.get_vendor_id('nic2') self.assertEqual(None, vendor)
def test_get_vendor_id_success(self): mocked_open = mock.mock_open(read_data='0x15b3\n') with mock.patch('os_net_config.common.open', mocked_open, create=True): vendor = common.get_vendor_id('nic2') self.assertEqual('0x15b3', vendor)