def update_sriov_pf_map(ifname, numvfs, noop, promisc=None, link_mode='legacy'): if not noop: cur_numvfs = sriov_config.get_numvfs(ifname) if cur_numvfs > 0 and cur_numvfs != numvfs: msg = ("Can't change the numvfs for %s" % ifname) raise sriov_config.SRIOVNumvfsException(msg) sriov_map = _get_sriov_map() for item in sriov_map: if item['device_type'] == 'pf' and item['name'] == ifname: item['numvfs'] = numvfs if promisc is not None: item['promisc'] = promisc item['link_mode'] = link_mode break else: new_item = {} new_item['device_type'] = 'pf' new_item['name'] = ifname new_item['numvfs'] = numvfs if promisc is not None: new_item['promisc'] = promisc new_item['link_mode'] = link_mode sriov_map.append(new_item) write_yaml_config(sriov_config._SRIOV_CONFIG_FILE, sriov_map)
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'))
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'))
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'))
def test_numvfs_preconfigured(self): """Test the numvfs config while its already configured""" os.makedirs(sriov_config._SYS_CLASS_NET + "/p2p1/device") f = open(sriov_config._SYS_CLASS_NET + "/p2p1/device/sriov_numvfs", "w+") f.write("10") f.close() self.assertEqual(None, sriov_config.main(['ARG0', '-n', 'p2p1:15'])) self.assertEqual(10, sriov_config.get_numvfs('p2p1'))
def test_numvfs_invalid_params(self): """Test the numvfs config with invalid arguments""" os.makedirs(sriov_config._SYS_CLASS_NET + "/p2p1/device") f = open(sriov_config._SYS_CLASS_NET + "/p2p1/device/sriov_numvfs", "w+") f.write("0") f.close() self.assertEqual(1, sriov_config.main(['ARG0', '-n', 'p2p1:15a'])) self.assertEqual(0, sriov_config.get_numvfs('p2p1'))
def test_numvfs_preconfigured(self): """Test the numvfs config while its already configured""" self._write_numvfs('p2p1', 10) self.assertEqual(None, sriov_config.main(['ARG0', '-n', 'p2p1:15'])) self.assertEqual(10, sriov_config.get_numvfs('p2p1'))
def test_numvfs_invalid_params(self): """Test the numvfs config with invalid arguments""" self._write_numvfs('p2p1') self.assertEqual(1, sriov_config.main(['ARG0', '-n', 'p2p1:15a'])) self.assertEqual(0, sriov_config.get_numvfs('p2p1'))
def test_numvfs_config(self): """Test the numvfs config with valid arguments""" self._write_numvfs('p2p1') self.assertEqual(None, sriov_config.main(['ARG0', '-n', 'p2p1:15'])) self.assertEqual(15, sriov_config.get_numvfs('p2p1'))
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'))