コード例 #1
0
    def test_get_dpdk_devargs_mlnx(self):
        def test_execute(name, dummy1, dummy2=None, dummy3=None):
            if 'ethtool' in name:
                out = _PCI_OUTPUT
                return out, None

        def test_get_stored_pci_address(ifname, noop):
            return "0000:00:07.0"

        self.stub_out('oslo_concurrency.processutils.execute', test_execute)
        self.stub_out('os_net_config.utils.get_stored_pci_address',
                      test_get_stored_pci_address)
        tmpdir = tempfile.mkdtemp()
        self.stub_out('os_net_config.utils._SYS_CLASS_NET', tmpdir)
        nic = 'p4p1'
        nic_path = os.path.join(tmpdir, nic)
        os.makedirs(nic_path)
        os.makedirs(os.path.join(nic_path, 'device'))
        # Testing standard Mellanox Connect-X cards
        with open(os.path.join(nic_path, 'operstate'), 'w') as f:
            f.write('up')
        with open(os.path.join(nic_path, 'address'), 'w') as f:
            f.write('00:0f:21:69:39:14')
        with open(os.path.join(nic_path, 'device', 'vendor'), 'w') as f:
            f.write('0x15b3')
        self.assertEqual(utils.get_dpdk_devargs(nic, False), '0000:00:19.0')
        # now testing the Mellanox CX3
        with open(os.path.join(nic_path, 'device', 'device'), 'w') as f:
            f.write('0x1007')
        self.assertEqual(utils.get_dpdk_devargs(nic, False),
                         'class=eth,mac=00:0f:21:69:39:14')
        with open(os.path.join(nic_path, 'device', 'vendor'), 'w') as f:
            f.write('0x15b4')
        self.assertEqual(utils.get_dpdk_devargs(nic, False), '0000:00:07.0')
        shutil.rmtree(tmpdir)
コード例 #2
0
ファイル: test_utils.py プロジェクト: openstack/os-net-config
    def test_get_dpdk_devargs_mlnx(self):
        def test_execute(name, dummy1, dummy2=None, dummy3=None):
            if 'ethtool' in name:
                out = _PCI_OUTPUT
                return out, None

        def test_get_stored_pci_address(ifname, noop):
            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('os_net_config.utils.get_stored_pci_address',
                      test_get_stored_pci_address)
        tmpdir = tempfile.mkdtemp()
        self.stub_out('os_net_config.common.SYS_CLASS_NET', tmpdir)
        nic = 'p4p1'
        nic_path = os.path.join(tmpdir, nic)
        os.makedirs(nic_path)
        os.makedirs(os.path.join(nic_path, 'device'))
        # Testing standard Mellanox Connect-X cards
        with open(os.path.join(nic_path, 'operstate'), 'w') as f:
            f.write('up')
        with open(os.path.join(nic_path, 'address'), 'w') as f:
            f.write('00:0f:21:69:39:14')
        with open(os.path.join(nic_path, 'device', 'vendor'), 'w') as f:
            f.write('0x15b3')
        self.assertEqual(utils.get_dpdk_devargs(nic, False),
                         '0000:00:19.0')
        # Testing VFs of Mellanox Connect-X cards
        self.stub_out('os_net_config.utils._is_vf_by_name',
                      test_vf_by_name)
        self.assertEqual(utils.get_dpdk_devargs(nic, False),
                         '0000:00:19.0')

        # Check if exception is raised, when the operstate is down
        # and not VF
        with open(os.path.join(nic_path, 'operstate'), 'w') as f:
            f.write('down')
        self.stub_out('os_net_config.utils._is_vf_by_name',
                      test_not_vf_by_name)
        self.assertRaises(utils.InvalidInterfaceException,
                          utils.get_dpdk_devargs, nic, False)

        # now testing the Mellanox CX3
        with open(os.path.join(nic_path, 'device', 'device'), 'w') as f:
            f.write('0x1007')
        self.assertEqual(utils.get_dpdk_devargs(nic, False),
                         'class=eth,mac=00:0f:21:69:39:14')
        with open(os.path.join(nic_path, 'device', 'vendor'), 'w') as f:
            f.write('0x15b4')
        self.assertEqual(utils.get_dpdk_devargs(nic, False),
                         '0000:00:07.0')
        shutil.rmtree(tmpdir)