Ejemplo n.º 1
0
    def test_update_sriov_vf_map_exist_complete(self):
        vf_initial = [{'device_type': 'vf', 'name': 'eth1_2',
                       'device': {'name': 'eth1', 'vfid': 2},
                       'vlan_id': 10, 'qos': 5,
                       'spoofcheck': 'on', 'trust': 'on',
                       'state': 'enable',
                       'macaddr': 'AA:BB:CC:DD:EE:FF',
                       'promisc': 'off',
                       'pci_address': "0000:80:00.1"}]
        utils.write_yaml_config(sriov_config._SRIOV_CONFIG_FILE, vf_initial)

        utils.update_sriov_vf_map('eth1', 2, 'eth1_2', vlan_id=100, qos=15,
                                  spoofcheck="off", trust="off", state="auto",
                                  macaddr="BB:BB:CC:DD:EE:FF", promisc="on",
                                  pci_address="0000:80:00.1")
        vf_final = [{'device_type': 'vf', 'name': 'eth1_2',
                     'device': {'name': 'eth1', 'vfid': 2},
                     'vlan_id': 100, 'qos': 15,
                     'spoofcheck': 'off', 'trust': 'off',
                     'state': 'auto',
                     'macaddr': 'BB:BB:CC:DD:EE:FF',
                     'promisc': 'on',
                     'pci_address': '0000:80:00.1'}]
        contents = utils.get_file_data(sriov_config._SRIOV_CONFIG_FILE)

        vf_map = yaml.safe_load(contents) if contents else []
        self.assertEqual(1, len(vf_map))
        self.assertListEqual(vf_final, vf_map)
Ejemplo n.º 2
0
    def test_configure_sriov_vf(self):
        """Test configuration of SR-IOV VF settings"""

        vf_config = [{"device_type": "vf", "device": {"name": "p2p1",
                      "vfid": 1}, "promisc": "on", "vlan_id": 101,
                      "qos": 5, "macaddr": "AA:BB:CC:DD:EE:FF",
                      "spoofcheck": "on", "state": "auto", "trust": "on",
                      "min_tx_rate": 0, "max_tx_rate": 100,
                      "name": "p2p1_1"}]
        exp_cmds = ["ip link set dev p2p1 vf 1 mac AA:BB:CC:DD:EE:FF",
                    "ip link set dev p2p1 vf 1 vlan 101 qos 5",
                    "ip link set dev p2p1 vf 1 min_tx_rate 0",
                    "ip link set dev p2p1 vf 1 max_tx_rate 100",
                    "ip link set dev p2p1_1 promisc on",
                    "ip link set dev p2p1 vf 1 spoofchk on",
                    "ip link set dev p2p1 vf 1 state auto",
                    "ip link set dev p2p1 vf 1 trust on"]
        run_cmd = []

        def run_ip_config_cmd_stub(*args, **kwargs):
            run_cmd.append(' '.join(args))
        self.stub_out('os_net_config.sriov_config.run_ip_config_cmd',
                      run_ip_config_cmd_stub)

        utils.write_yaml_config(common.SRIOV_CONFIG_FILE, vf_config)
        sriov_config.configure_sriov_vf()

        for cmd in exp_cmds:
            self.assertIn(cmd, run_cmd)
Ejemplo n.º 3
0
    def test_update_sriov_pf_map_exist_with_promisc(self):
        def get_numvfs_stub(pf_name):
            return 10

        self.stub_out('os_net_config.sriov_config.get_numvfs', get_numvfs_stub)
        pf_initial = [{
            'device_type': 'pf',
            'link_mode': 'legacy',
            'name': 'eth1',
            'numvfs': 10,
            'promisc': 'on'
        }]
        utils.write_yaml_config(sriov_config._SRIOV_CONFIG_FILE, pf_initial)

        utils.update_sriov_pf_map('eth1', 10, False, promisc='off')
        pf_final = [{
            'device_type': 'pf',
            'link_mode': 'legacy',
            'name': 'eth1',
            'numvfs': 10,
            'promisc': 'off'
        }]
        contents = utils.get_file_data(sriov_config._SRIOV_CONFIG_FILE)

        pf_map = yaml.safe_load(contents) if contents else []
        self.assertEqual(1, len(pf_map))
        self.assertListEqual(pf_final, pf_map)
Ejemplo n.º 4
0
    def test_update_sriov_vf_map_exist_complete(self):
        vf_initial = [{'device_type': 'vf', 'name': 'eth1_2',
                       'device': {'name': 'eth1', 'vfid': 2},
                       'vlan_id': 10, 'qos': 5,
                       'spoofcheck': 'on', 'trust': 'on',
                       'state': 'enable',
                       'macaddr': 'AA:BB:CC:DD:EE:FF',
                       'promisc': 'off',
                       'pci_address': "0000:80:00.1"}]
        utils.write_yaml_config(sriov_config._SRIOV_CONFIG_FILE, vf_initial)

        utils.update_sriov_vf_map('eth1', 2, 'eth1_2', vlan_id=100, qos=15,
                                  spoofcheck="off", trust="off", state="auto",
                                  macaddr="BB:BB:CC:DD:EE:FF", promisc="on",
                                  pci_address="0000:80:00.1")
        vf_final = [{'device_type': 'vf', 'name': 'eth1_2',
                     'device': {'name': 'eth1', 'vfid': 2},
                     'vlan_id': 100, 'qos': 15,
                     'spoofcheck': 'off', 'trust': 'off',
                     'state': 'auto',
                     'macaddr': 'BB:BB:CC:DD:EE:FF',
                     'promisc': 'on',
                     'pci_address': '0000:80:00.1'}]
        contents = utils.get_file_data(sriov_config._SRIOV_CONFIG_FILE)

        vf_map = yaml.safe_load(contents) if contents else []
        self.assertEqual(1, len(vf_map))
        self.assertListEqual(vf_final, vf_map)
Ejemplo n.º 5
0
 def test_update_sriov_pf_map_exist(self):
     def get_numvfs_stub(pf_name):
         return 10
     self.stub_out('os_net_config.sriov_config.get_numvfs',
                   get_numvfs_stub)
     pf_initial = [{'device_type': 'pf', 'link_mode': 'legacy',
                    'name': 'eth1', 'numvfs': 10}]
     utils.write_yaml_config(sriov_config._SRIOV_CONFIG_FILE, pf_initial)
     self.assertRaises(sriov_config.SRIOVNumvfsException,
                       utils.update_sriov_pf_map, 'eth1', 20, False)
    def test_bind_vfs(self):
        """Test SR-IOV VFs binding"""
        vfs_driver = "mlx5_core"
        sriov_bind_pcis_map = {vfs_driver: ['0000:03:00.2', '0000:03:00.3']}
        os.makedirs(sriov_bind_config._PCI_DRIVER_BIND_FILE_PATH %
                    {"driver": vfs_driver})

        utils.write_yaml_config(sriov_bind_config._SRIOV_BIND_CONFIG_FILE,
                                sriov_bind_pcis_map)
        sriov_bind_config.bind_vfs()
Ejemplo n.º 7
0
    def test_update_sriov_pf_map_exist(self):
        pf_initial = [{'name': 'eth1', 'numvfs': 10}]
        utils.write_yaml_config(utils._SRIOV_PF_CONFIG_FILE, pf_initial)

        utils.update_sriov_pf_map('eth1', 20, False)
        pf_final = [{'name': 'eth1', 'numvfs': 20}]
        contents = utils.get_file_data(utils._SRIOV_PF_CONFIG_FILE)

        pf_map = yaml.load(contents) if contents else []
        self.assertEqual(1, len(pf_map))
        self.assertListEqual(pf_final, pf_map)
Ejemplo n.º 8
0
    def test_update_dpdk_map_exist(self):
        dpdk_test = [{'name': 'eth1', 'pci_address': '0000:03:00.0',
                      'mac_address': '01:02:03:04:05:06',
                      'driver': 'vfio-pci'}]
        utils.write_yaml_config(utils._DPDK_MAPPING_FILE, dpdk_test)

        utils._update_dpdk_map('eth1', '0000:03:00.0', '01:02:03:04:05:06',
                               'vfio-pci')
        contents = utils.get_file_data(utils._DPDK_MAPPING_FILE)

        dpdk_map = yaml.load(contents) if contents else []
        self.assertEqual(1, len(dpdk_map))
        self.assertListEqual(dpdk_test, dpdk_map)
Ejemplo n.º 9
0
    def test_update_dpdk_map_exist(self):
        dpdk_test = [{'name': 'eth1', 'pci_address': '0000:03:00.0',
                      'mac_address': '01:02:03:04:05:06',
                      'driver': 'vfio-pci'}]
        utils.write_yaml_config(utils._DPDK_MAPPING_FILE, dpdk_test)

        utils._update_dpdk_map('eth1', '0000:03:00.0', '01:02:03:04:05:06',
                               'vfio-pci')
        contents = utils.get_file_data(utils._DPDK_MAPPING_FILE)

        dpdk_map = yaml.safe_load(contents) if contents else []
        self.assertEqual(1, len(dpdk_map))
        self.assertListEqual(dpdk_test, dpdk_map)
Ejemplo n.º 10
0
    def test_update_sriov_pf_map_exist_with_promisc(self):
        pf_initial = [{'device_type': 'pf', 'link_mode': 'legacy',
                       'name': 'eth1', 'numvfs': 10, 'promisc': 'on'}]
        utils.write_yaml_config(sriov_config._SRIOV_CONFIG_FILE, pf_initial)

        utils.update_sriov_pf_map('eth1', 20, False)
        pf_final = [{'device_type': 'pf', 'link_mode': 'legacy',
                     'name': 'eth1', 'numvfs': 20, 'promisc': 'on'}]
        contents = utils.get_file_data(sriov_config._SRIOV_CONFIG_FILE)

        pf_map = yaml.safe_load(contents) if contents else []
        self.assertEqual(1, len(pf_map))
        self.assertListEqual(pf_final, pf_map)
Ejemplo n.º 11
0
    def test_configure_sriov_pf_non_nicpart(self):
        """Test the udev rules created for legacy mode of SR-IOV PF

        In this case, the nic partitioned VF(s) are not attached
        """

        self.setUp_pf_stubs()

        exp_udev_content = '# This file is autogenerated by os-net-config\n'\
            'KERNEL=="p2p1", RUN+="/bin/os-net-config-sriov -n %k:10"\n'\
            'KERNEL=="p2p2", RUN+="/bin/os-net-config-sriov -n %k:12"\n'
        exp_actions = [
            'udev_monitor_setup',
            'udev_monitor_start',
            'reload_udev_rules',
            'set_numvfs',
            'get_numvfs',
            '_wait_for_vf_creation',
            'get_numvfs',
            'reload_udev_rules',
            'set_numvfs',
            'get_numvfs',
            '_wait_for_vf_creation',
            'get_numvfs',
            'udev_monitor_stop',
        ]

        pf_config = [{"device_type": "pf", "name": "p2p1", "numvfs": 10,
                      "promisc": "on", "link_mode": "legacy"},
                     {"device_type": "pf", "name": "p2p2", "numvfs": 12,
                      "promisc": "off", "link_mode": "legacy"},
                     {"device": {"name": "eno3", "vfid": 1},
                      "device_type": "vf", "name": "eno3v0", "max_tx_rate": 0,
                      "min_tx_rate": 0, "pci_address": "0000:18:0e.1",
                      "trust": "on", "spoofcheck": "off"}]

        for ifname in ['p2p1', 'p2p2']:
            self._write_numvfs(ifname)

        self._action_order = []
        utils.write_yaml_config(common.SRIOV_CONFIG_FILE, pf_config)
        sriov_config.configure_sriov_pf()
        self.assertEqual(exp_actions, self._action_order)
        f = open(sriov_config._UDEV_LEGACY_RULE_FILE, 'r')
        self.assertEqual(exp_udev_content, f.read())
        self.assertEqual(10, sriov_config.get_numvfs('p2p1'))
        self.assertEqual(12, sriov_config.get_numvfs('p2p2'))
Ejemplo n.º 12
0
    def test_configure_vdpa_pf(self):
        """Test the vdpa PF

        """

        self.setUp_pf_stubs(common.MLNX_VENDOR_ID)

        exp_actions = [
            'udev_monitor_setup',
            'udev_monitor_start',
            'get_vdpa_vhost_devices',
            'configure_switchdev',
            'set_numvfs',
            'get_numvfs',
            '_wait_for_vf_creation',
            'get_numvfs',
            'reload_udev_rules',
            'reload_udev_rules',
            'reload_udev_rules',
            'reload_udev_rules',
            'configure_switchdev',
            'set_numvfs',
            'get_numvfs',
            '_wait_for_vf_creation',
            'get_numvfs',
            'reload_udev_rules',
            'reload_udev_rules',
            'reload_udev_rules',
            'trigger_udev_rules',
            'udev_monitor_stop',
        ]

        pf_config = [{"device_type": "pf", "name": "p2p1", "numvfs": 10,
                      "vdpa": True, "link_mode": "switchdev"},
                     {"device_type": "pf", "name": "p2p2", "numvfs": 12,
                      "vdpa": True, "link_mode": "switchdev"}]

        for ifname in ['p2p1', 'p2p2']:
            self._write_numvfs(ifname)

        self._action_order = []
        utils.write_yaml_config(common.SRIOV_CONFIG_FILE, pf_config)
        sriov_config.configure_sriov_pf()
        self.assertEqual(exp_actions, self._action_order)
        self.assertEqual(10, sriov_config.get_numvfs('p2p1'))
        self.assertEqual(12, sriov_config.get_numvfs('p2p2'))
Ejemplo n.º 13
0
    def test_update_sriov_vf_map_exist(self):
        vf_initial = [{
            'device_type': 'vf',
            'name': 'eth1_2',
            'device': {
                "name": "eth1",
                "vfid": 2
            }
        }]
        utils.write_yaml_config(common.SRIOV_CONFIG_FILE, vf_initial)

        utils.update_sriov_vf_map('eth1',
                                  2,
                                  'eth1_2',
                                  vlan_id=10,
                                  qos=5,
                                  spoofcheck="on",
                                  trust="on",
                                  state="enable",
                                  macaddr="AA:BB:CC:DD:EE:FF",
                                  promisc="off",
                                  pci_address="0000:80:00.1",
                                  max_tx_rate=10)
        vf_final = [{
            'device_type': 'vf',
            'name': 'eth1_2',
            'device': {
                'name': 'eth1',
                'vfid': 2
            },
            'vlan_id': 10,
            'qos': 5,
            'min_tx_rate': 0,
            'max_tx_rate': 10,
            'spoofcheck': 'on',
            'trust': 'on',
            'state': 'enable',
            'macaddr': 'AA:BB:CC:DD:EE:FF',
            'promisc': 'off',
            'pci_address': '0000:80:00.1'
        }]
        contents = common.get_file_data(common.SRIOV_CONFIG_FILE)

        vf_map = yaml.safe_load(contents) if contents else []
        self.assertEqual(1, len(vf_map))
        self.assertListEqual(vf_final, vf_map)
Ejemplo n.º 14
0
    def test_update_dpdk_map_value_change(self):
        dpdk_test = [{'name': 'eth1', 'pci_address': '0000:03:00.0',
                      'driver': 'vfio-pci'}]
        utils.write_yaml_config(common.DPDK_MAPPING_FILE, dpdk_test)

        dpdk_test = [{'name': 'eth1', 'pci_address': '0000:03:00.0',
                      'mac_address': '01:02:03:04:05:06',
                      'driver': 'vfio-pci'}]
        utils._update_dpdk_map('eth1', '0000:03:00.0', '01:02:03:04:05:06',
                               'vfio-pci')
        try:
            contents = common.get_file_data(common.DPDK_MAPPING_FILE)
        except IOError:
            pass

        dpdk_map = yaml.safe_load(contents) if contents else []
        self.assertEqual(1, len(dpdk_map))
        self.assertListEqual(dpdk_test, dpdk_map)
Ejemplo n.º 15
0
    def test_configure_sriov_pf(self):
        """Test the numvfs setting for SR-IOV PF

        Test the udev rules created for legacy mode of SR-IOV PF
        """

        self.setUp_pf_stubs()

        exp_udev_content = '# This file is autogenerated by os-net-config\n'\
            'KERNEL=="p2p1", RUN+="/bin/os-net-config-sriov -n %k:10"\n'\
            'KERNEL=="p2p2", RUN+="/bin/os-net-config-sriov -n %k:12"\n'
        exp_actions = [
            'udev_monitor_setup',
            'udev_monitor_start',
            'reload_udev_rules',
            'set_numvfs',
            'get_numvfs',
            '_wait_for_vf_creation',
            'get_numvfs',
            'reload_udev_rules',
            'set_numvfs',
            'get_numvfs',
            '_wait_for_vf_creation',
            'get_numvfs',
            'udev_monitor_stop',
        ]

        pf_config = [{"device_type": "pf", "name": "p2p1", "numvfs": 10,
                      "promisc": "on", "link_mode": "legacy"},
                     {"device_type": "pf", "name": "p2p2", "numvfs": 12,
                      "promisc": "off", "link_mode": "legacy"}]

        for ifname in ['p2p1', 'p2p2']:
            self._write_numvfs(ifname)

        self._action_order = []
        utils.write_yaml_config(common.SRIOV_CONFIG_FILE, pf_config)
        sriov_config.configure_sriov_pf()
        self.assertEqual(exp_actions, self._action_order)
        f = open(sriov_config._UDEV_LEGACY_RULE_FILE, 'r')
        self.assertEqual(exp_udev_content, f.read())
        self.assertEqual(10, sriov_config.get_numvfs('p2p1'))
        self.assertEqual(12, sriov_config.get_numvfs('p2p2'))
Ejemplo n.º 16
0
    def test_update_sriov_pf_map_exist(self):
        pf_initial = [{
            'device_type': 'pf',
            'link_mode': 'legacy',
            'name': 'eth1',
            'numvfs': 10
        }]
        utils.write_yaml_config(sriov_config._SRIOV_CONFIG_FILE, pf_initial)

        utils.update_sriov_pf_map('eth1', 20, False)
        pf_final = [{
            'device_type': 'pf',
            'link_mode': 'legacy',
            'name': 'eth1',
            'numvfs': 20
        }]
        contents = utils.get_file_data(sriov_config._SRIOV_CONFIG_FILE)

        pf_map = yaml.safe_load(contents) if contents else []
        self.assertEqual(1, len(pf_map))
        self.assertListEqual(pf_final, pf_map)
Ejemplo n.º 17
0
    def test_configure_sriov_pf(self):
        """Test the numvfs setting for SR-IOV PF

        Test the udev rules created for legacy mode of SR-IOV PF
        """

        exp_udev_content = '# This file is autogenerated by os-net-config\n'\
            'KERNEL=="p2p1", RUN+="/bin/os-net-config-sriov -n %k:10"\n'\
            'KERNEL=="p2p2", RUN+="/bin/os-net-config-sriov -n %k:12"\n'

        run_cmd = []

        def run_ip_config_cmd_stub(*args, **kwargs):
            run_cmd.append(' '.join(args))
        self.stub_out('os_net_config.sriov_config.run_ip_config_cmd',
                      run_ip_config_cmd_stub)

        def udev_monitor_setup_stub():
            return
        self.stub_out('os_net_config.sriov_config.udev_monitor_setup',
                      udev_monitor_setup_stub)

        def udev_monitor_start_stub(observer):
            return
        self.stub_out('os_net_config.sriov_config.udev_monitor_start',
                      udev_monitor_start_stub)

        def udev_monitor_stop_stub(observer):
            return
        self.stub_out('os_net_config.sriov_config.udev_monitor_stop',
                      udev_monitor_stop_stub)

        def cleanup_puppet_config_stub():
            return
        self.stub_out('os_net_config.sriov_config.cleanup_puppet_config',
                      cleanup_puppet_config_stub)

        def trigger_udev_rules_stub():
            return
        self.stub_out('os_net_config.sriov_config.trigger_udev_rules',
                      trigger_udev_rules_stub)

        def reload_udev_rules_stub():
            return
        self.stub_out('os_net_config.sriov_config.reload_udev_rules',
                      reload_udev_rules_stub)

        def _wait_for_vf_creation_stub(pf_name, numvfs):
            numvfs_pair = {"p2p1": 10, "p2p2": 12}
            self.assertEqual(numvfs_pair[pf_name], numvfs)
        self.stub_out('os_net_config.sriov_config._wait_for_vf_creation',
                      _wait_for_vf_creation_stub)

        def get_vendor_id_stub(ifname):
            return "0x8086"
        self.stub_out('os_net_config.sriov_config.get_vendor_id',
                      get_vendor_id_stub)

        pf_config = [{"device_type": "pf", "name": "p2p1", "numvfs": 10,
                      "promisc": "on", "link_mode": "legacy"},
                     {"device_type": "pf", "name": "p2p2", "numvfs": 12,
                      "promisc": "off", "link_mode": "legacy"}]

        os.makedirs(sriov_config._SYS_CLASS_NET + "/p2p1/device")
        os.makedirs(sriov_config._SYS_CLASS_NET + "/p2p2/device")
        f = open(sriov_config._SYS_CLASS_NET + "/p2p1/device/sriov_numvfs",
                 "w+")
        f.write("0")
        f.close()

        f = open(sriov_config._SYS_CLASS_NET + "/p2p2/device/sriov_numvfs",
                 "w+")
        f.write("0")
        f.close()

        utils.write_yaml_config(sriov_config._SRIOV_CONFIG_FILE, pf_config)
        sriov_config.configure_logger(debug=True)
        sriov_config.configure_sriov_pf()

        f = open(sriov_config._UDEV_LEGACY_RULE_FILE, 'r')
        self.assertEqual(exp_udev_content, f.read())
        self.assertEqual(10, sriov_config.get_numvfs('p2p1'))
        self.assertEqual(12, sriov_config.get_numvfs('p2p2'))