Merge "Allow configuration of inactive DPDK devices as well"
This commit is contained in:
		@@ -792,12 +792,6 @@ class TestUtils(base.TestCase):
 | 
				
			|||||||
        def test_get_stored_pci_address(ifname, noop):
 | 
					        def test_get_stored_pci_address(ifname, noop):
 | 
				
			||||||
            return "0000:00:07.0"
 | 
					            return "0000:00:07.0"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        def test_vf_by_name(ifname):
 | 
					 | 
				
			||||||
            return True
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        def test_not_vf_by_name(ifname):
 | 
					 | 
				
			||||||
            return False
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        self.stub_out('oslo_concurrency.processutils.execute', test_execute)
 | 
					        self.stub_out('oslo_concurrency.processutils.execute', test_execute)
 | 
				
			||||||
        self.stub_out('os_net_config.utils.get_stored_pci_address',
 | 
					        self.stub_out('os_net_config.utils.get_stored_pci_address',
 | 
				
			||||||
                      test_get_stored_pci_address)
 | 
					                      test_get_stored_pci_address)
 | 
				
			||||||
@@ -817,19 +811,16 @@ class TestUtils(base.TestCase):
 | 
				
			|||||||
        self.assertEqual(utils.get_dpdk_devargs(nic, False),
 | 
					        self.assertEqual(utils.get_dpdk_devargs(nic, False),
 | 
				
			||||||
                         '0000:00:19.0')
 | 
					                         '0000:00:19.0')
 | 
				
			||||||
        # Testing VFs of Mellanox Connect-X cards
 | 
					        # Testing VFs of Mellanox Connect-X cards
 | 
				
			||||||
        self.stub_out('os_net_config.utils._is_vf_by_name',
 | 
					        os.makedirs(os.path.join(nic_path, 'device', 'physfn'))
 | 
				
			||||||
                      test_vf_by_name)
 | 
					 | 
				
			||||||
        self.assertEqual(utils.get_dpdk_devargs(nic, False),
 | 
					        self.assertEqual(utils.get_dpdk_devargs(nic, False),
 | 
				
			||||||
                         '0000:00:19.0')
 | 
					                         '0000:00:19.0')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # Check if exception is raised, when the operstate is down
 | 
					        # Check if devargs is derived, when the operstate is down
 | 
				
			||||||
        # and not VF
 | 
					        os.rmdir(os.path.join(nic_path, 'device', 'physfn'))
 | 
				
			||||||
        with open(os.path.join(nic_path, 'operstate'), 'w') as f:
 | 
					        with open(os.path.join(nic_path, 'operstate'), 'w') as f:
 | 
				
			||||||
            f.write('down')
 | 
					            f.write('down')
 | 
				
			||||||
        self.stub_out('os_net_config.utils._is_vf_by_name',
 | 
					        self.assertEqual(utils.get_dpdk_devargs(nic, False),
 | 
				
			||||||
                      test_not_vf_by_name)
 | 
					                         '0000:00:19.0')
 | 
				
			||||||
        self.assertRaises(utils.InvalidInterfaceException,
 | 
					 | 
				
			||||||
                          utils.get_dpdk_devargs, nic, False)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # now testing the Mellanox CX3
 | 
					        # now testing the Mellanox CX3
 | 
				
			||||||
        with open(os.path.join(nic_path, 'device', 'device'), 'w') as f:
 | 
					        with open(os.path.join(nic_path, 'device', 'device'), 'w') as f:
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -323,7 +323,7 @@ def get_dpdk_devargs(ifname, noop):
 | 
				
			|||||||
    if not noop:
 | 
					    if not noop:
 | 
				
			||||||
        vendor_id = common.get_vendor_id(ifname)
 | 
					        vendor_id = common.get_vendor_id(ifname)
 | 
				
			||||||
        device_id = common.get_device_id(ifname)
 | 
					        device_id = common.get_device_id(ifname)
 | 
				
			||||||
        if vendor_id == "0x15b3":
 | 
					        if vendor_id == common.MLNX_VENDOR_ID:
 | 
				
			||||||
            logger.info("Getting devargs for Mellanox cards")
 | 
					            logger.info("Getting devargs for Mellanox cards")
 | 
				
			||||||
            if device_id == "0x1007":
 | 
					            if device_id == "0x1007":
 | 
				
			||||||
                # Some NICs (i.e. Mellanox ConnectX-3) have only one PCI
 | 
					                # Some NICs (i.e. Mellanox ConnectX-3) have only one PCI
 | 
				
			||||||
@@ -331,18 +331,12 @@ def get_dpdk_devargs(ifname, noop):
 | 
				
			|||||||
                # device won’t work. Instead, we should use
 | 
					                # device won’t work. Instead, we should use
 | 
				
			||||||
                # "class=eth,mac=<MAC>"
 | 
					                # "class=eth,mac=<MAC>"
 | 
				
			||||||
                dpdk_devargs = f"class=eth,mac={common.interface_mac(ifname)}"
 | 
					                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:
 | 
					            else:
 | 
				
			||||||
                msg = ("Unable to get devargs for interface %s" % ifname)
 | 
					                # Get the PCI address of the devices other than CX-3.
 | 
				
			||||||
                raise InvalidInterfaceException(msg)
 | 
					                # It includes the VFs as well. For all Other Mellanox devices
 | 
				
			||||||
 | 
					                # the PCI address 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)
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            logger.info("Getting stored PCI address as devarg")
 | 
					            logger.info("Getting stored PCI address as devarg")
 | 
				
			||||||
            dpdk_devargs = get_stored_pci_address(ifname, noop)
 | 
					            dpdk_devargs = get_stored_pci_address(ifname, noop)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user