예제 #1
0
    def test_sriov_vf_with_dpdk_noop_output(self):
        def test_get_vf_devname(device, vfid):
            return device + '_' + str(vfid)

        def test_get_pci_address(ifname, noop):
            return '0000:79:10.2'

        self.stub_out('os_net_config.utils.get_vf_devname',
                      test_get_vf_devname)
        self.stub_out('os_net_config.utils.get_pci_address',
                      test_get_pci_address)
        ivs_yaml = os.path.join(SAMPLE_BASE, 'sriov_pf_ovs_dpdk.yaml')
        ivs_json = os.path.join(SAMPLE_BASE, 'sriov_pf_ovs_dpdk.json')
        stdout_yaml, stderr = self.run_cli('ARG0 --provider=ifcfg --noop '
                                           '--exit-on-validation-errors '
                                           '-c %s' % ivs_yaml)
        self.assertEqual('', stderr)
        contents = common.get_file_data(common.SRIOV_CONFIG_FILE)
        sriov_config_yaml = yaml.safe_load(contents)
        os.remove(common.SRIOV_CONFIG_FILE)
        stdout_json, stderr = self.run_cli('ARG0 --provider=ifcfg --noop '
                                           '--exit-on-validation-errors '
                                           '-c %s' % ivs_json)
        self.assertEqual('', stderr)
        contents = common.get_file_data(common.SRIOV_CONFIG_FILE)
        sriov_config_json = yaml.safe_load(contents)
        sanity_devices = [
            'DEVICE=p2p1', 'DEVICE=p2p1_5', 'DEVICE=br-vfs',
            'TYPE=OVSUserBridge', 'DEVICE=dpdk0', 'TYPE=OVSDPDKPort'
        ]
        for dev in sanity_devices:
            self.assertIn(dev, stdout_yaml)
        self.assertEqual(stdout_yaml, stdout_json)
        self.assertCountEqual(sriov_config_yaml, sriov_config_json)
예제 #2
0
 def test_update_sriov_vf_map_complete_new(self):
     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)
     contents = common.get_file_data(common.SRIOV_CONFIG_FILE)
     sriov_vf_map = yaml.safe_load(contents) if contents else []
     self.assertEqual(1, len(sriov_vf_map))
     test_sriov_vf_map = [{
         '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"
     }]
     self.assertListEqual(test_sriov_vf_map, sriov_vf_map)
예제 #3
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,
                       'min_tx_rate': 0, 'max_tx_rate': 00,
                       '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(common.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", max_tx_rate=40)
        vf_final = [{'device_type': 'vf', 'name': 'eth1_2',
                     'device': {'name': 'eth1', 'vfid': 2},
                     'vlan_id': 100, 'qos': 15,
                     'min_tx_rate': 0, 'max_tx_rate': 40,
                     'spoofcheck': 'off', 'trust': 'off',
                     'state': 'auto',
                     'macaddr': 'BB:BB:CC:DD:EE:FF',
                     'promisc': 'on',
                     '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)
예제 #4
0
    def test_udev_rule_for_sriov_vf(self):
        def get_numvfs_stub(pf_name):
            return 10
        self.stub_out('os_net_config.sriov_config.get_numvfs',
                      get_numvfs_stub)
        utils.update_sriov_pf_map('eth1', 10, False)
        utils.update_sriov_pf_map('eth2', 10, False)
        utils.update_sriov_vf_map('eth1', 2, 'eth1_2')
        contents = common.get_file_data(common.SRIOV_CONFIG_FILE)
        sriov_vf_map = yaml.safe_load(contents) if contents else []
        self.assertEqual(3, len(sriov_vf_map))

        test_sriov_vf_map = {'device': {'name': 'eth1', 'vfid': 2},
                             'device_type': 'vf', 'max_tx_rate': 0,
                             'min_tx_rate': 0, 'name': 'eth1_2'}
        udev_file = open(sriov_config._UDEV_LEGACY_RULE_FILE, "w")
        udev_file.write(udev_content)
        udev_file.close()

        # sriov_config.add_udev_rule_for_legacy_sriov_pf("eth1", 10)
        for dev in sriov_vf_map:
            if(dev.keys() == test_sriov_vf_map.keys()):
                self.assertEqual(test_sriov_vf_map, dev)

        expect = '# This file is autogenerated by os-net-config\n'\
                 'KERNEL=="eth2", RUN+="/bin/os-net-config-sriov -n %k:10"\n'
        utils.nicpart_udev_rules_check()
        f = open(sriov_config._UDEV_LEGACY_RULE_FILE, 'r')
        self.assertEqual(expect, f.read())
        f.close()
예제 #5
0
def add_udev_rule(udev_data, udev_file, pattern=None):
    logger.debug(f"adding udev rule to {udev_file}: {udev_data}")
    trigger_udev_rule = False
    udev_data = udev_data.strip()
    if not pattern:
        pattern = udev_data
    if not os.path.exists(udev_file):
        with open(udev_file, "w") as f:
            data = "# This file is autogenerated by os-net-config\n"\
                   f"{udev_data}\n"
            f.write(data)
    else:
        file_data = common.get_file_data(udev_file)
        udev_lines = file_data.splitlines()
        if pattern in file_data:
            if udev_data in udev_lines:
                return trigger_udev_rule
            with open(udev_file, "w") as f:
                for line in udev_lines:
                    if pattern in line:
                        f.write(udev_data + "\n")
                    else:
                        f.write(line + "\n")
        else:
            with open(udev_file, "a") as f:
                f.write(udev_data + "\n")

    reload_udev_rules()
    trigger_udev_rule = True
    return trigger_udev_rule
예제 #6
0
    def test_update_sriov_pf_map_exist_with_vdpa(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',
            'vdpa': False
        }]
        utils.write_yaml_config(common.SRIOV_CONFIG_FILE, pf_initial)

        utils.update_sriov_pf_map('eth1', 10, False, vdpa=True)
        pf_final = [{
            'device_type': 'pf',
            'link_mode': 'legacy',
            'name': 'eth1',
            'numvfs': 10,
            'promisc': 'on',
            'vdpa': True
        }]
        contents = common.get_file_data(common.SRIOV_CONFIG_FILE)

        pf_map = yaml.safe_load(contents) if contents else []
        self.assertEqual(1, len(pf_map))
        self.assertListEqual(pf_final, pf_map)
예제 #7
0
 def test_update_sriov_vf_map_minimal_new(self):
     utils.update_sriov_vf_map('eth1', 2, 'eth1_2')
     contents = common.get_file_data(common.SRIOV_CONFIG_FILE)
     sriov_vf_map = yaml.safe_load(contents) if contents else []
     self.assertEqual(1, len(sriov_vf_map))
     test_sriov_vf_map = [{'device_type': 'vf', 'name': 'eth1_2',
                           'min_tx_rate': 0, 'max_tx_rate': 0,
                           'device': {"name": "eth1", "vfid": 2}}]
     self.assertListEqual(test_sriov_vf_map, sriov_vf_map)
예제 #8
0
def _wait_for_uplink_rep_creation(pf_name):
    uplink_rep_phys_switch_id_path = f"/sys/class/net/{pf_name}/phys_switch_id"

    for i in range(MAX_RETRIES):
        if common.get_file_data(uplink_rep_phys_switch_id_path):
            logger.info(f"{pf_name} Uplink representor ready")
            break
        time.sleep(1)
    else:
        raise RuntimeError(f"{pf_name}: Timeout waiting uplink representor")
예제 #9
0
 def test_dhcp_ovs_bridge_network_apply(self):
     interface = objects.Interface('eth0')
     bridge = objects.OvsBridge('br0', use_dhcp=True, members=[interface])
     self.provider.add_interface(interface)
     self.provider.add_bridge(bridge)
     self.provider.apply()
     iface_data = common.get_file_data(self.temp_config_file.name)
     self.assertEqual((_OVS_BRIDGE_DHCP + _OVS_PORT_IFACE), iface_data)
     self.assertIn('eth0', self.ifup_interface_names)
     self.assertIn('br0', self.ifup_interface_names)
예제 #10
0
def get_vf_pcis_list(pf_name):
    vf_pcis_list = []
    pf_files = os.listdir(common.get_dev_path(pf_name, "_device"))
    for pf_file in pf_files:
        if pf_file.startswith("virtfn"):
            vf_info = common.get_file_data(common.get_dev_path(pf_name,
                                           f"{pf_file}/uevent"))
            vf_pcis_list.append(re.search(r'PCI_SLOT_NAME=(.*)',
                                          vf_info, re.MULTILINE).group(1))
    return vf_pcis_list
예제 #11
0
    def test__update_dpdk_map_new(self):
        utils._update_dpdk_map('eth1', '0000:03:00.0', '01:02:03:04:05:06',
                               'vfio-pci')
        contents = common.get_file_data(common.DPDK_MAPPING_FILE)

        dpdk_map = yaml.safe_load(contents) if contents else []
        self.assertEqual(1, len(dpdk_map))
        dpdk_test = [{'name': 'eth1', 'pci_address': '0000:03:00.0',
                      'mac_address': '01:02:03:04:05:06',
                      'driver': 'vfio-pci'}]
        self.assertListEqual(dpdk_test, dpdk_map)
예제 #12
0
 def test_update_sriov_pf_map_new_with_vdpa(self):
     def get_numvfs_stub(pf_name):
         return 0
     self.stub_out('os_net_config.sriov_config.get_numvfs',
                   get_numvfs_stub)
     utils.update_sriov_pf_map('eth1', 10, False, vdpa=True)
     contents = common.get_file_data(common.SRIOV_CONFIG_FILE)
     sriov_pf_map = yaml.safe_load(contents) if contents else []
     self.assertEqual(1, len(sriov_pf_map))
     test_sriov_pf_map = [{'device_type': 'pf', 'link_mode': 'legacy',
                           'name': 'eth1', 'numvfs': 10, 'vdpa': True}]
     self.assertListEqual(test_sriov_pf_map, sriov_pf_map)
예제 #13
0
    def test_update_vpp_mapping(self):
        tmpdir = tempfile.mkdtemp()
        vpp_exec_path = os.path.join(tmpdir, 'vpp-exec')
        utils._VPP_EXEC_FILE = vpp_exec_path

        def test_get_dpdk_map():
            return [{
                'name': 'eth1',
                'pci_address': '0000:00:09.0',
                'mac_address': '01:02:03:04:05:06',
                'driver': 'vfio-pci'
            }]

        self.stub_out('os_net_config.utils._get_dpdk_map', test_get_dpdk_map)

        def test_execute(name, *args, **kwargs):
            return None, None

        self.stub_out('oslo_concurrency.processutils.execute', test_execute)

        def test_get_vpp_interface(pci_dev, tries, timeout):
            return {'name': 'GigabitEthernet0/9/0', 'index': '1'}

        self.stub_out('os_net_config.utils._get_vpp_interface',
                      test_get_vpp_interface)

        int1 = objects.VppInterface('eth1', options="vlan-strip-offload off")
        int1.pci_dev = '0000:00:09.0'
        int1.hwaddr = '01:02:03:04:05:06'
        int2 = objects.VppInterface('eth2')
        int2.pci_dev = '0000:00:09.1'
        int2.hwaddr = '01:02:03:04:05:07'
        interfaces = [int1, int2]

        utils.update_vpp_mapping(interfaces, [])

        contents = common.get_file_data(common.DPDK_MAPPING_FILE)

        dpdk_test = [{
            'name': 'eth1',
            'pci_address': '0000:00:09.0',
            'mac_address': '01:02:03:04:05:06',
            'driver': 'vfio-pci'
        }, {
            'name': 'eth2',
            'pci_address': '0000:00:09.1',
            'mac_address': '01:02:03:04:05:07',
            'driver': 'vfio-pci'
        }]
        dpdk_map = yaml.safe_load(contents) if contents else []
        self.assertEqual(2, len(dpdk_map))
        self.assertListEqual(dpdk_test, dpdk_map)
예제 #14
0
    def test_apply_noactivate(self):
        route1 = objects.Route('192.168.1.1', '172.19.0.0/24')
        route2 = objects.Route('192.168.1.5',
                               '172.20.0.0/24',
                               route_options="metric 100")
        v4_addr = objects.Address('192.168.1.2/24')
        interface = objects.Interface('eth0',
                                      addresses=[v4_addr],
                                      routes=[route1, route2])
        self.provider.add_interface(interface)

        self.provider.apply(activate=False)
        iface_data = common.get_file_data(self.temp_config_file.name)
        self.assertEqual((_V4_IFACE_STATIC_IP + _RTS), iface_data)
        self.assertEqual([], self.ifup_interface_names)
예제 #15
0
def _ordered_nics(check_active):
    embedded_nics = []
    nics = []
    logger.info("Finding active nics")
    for name in glob.iglob(common.SYS_CLASS_NET + '/*'):
        nic = name[(len(common.SYS_CLASS_NET) + 1):]
        if _is_available_nic(nic, check_active):
            if _is_embedded_nic(nic):
                logger.info("%s is an embedded active nic" % nic)
                embedded_nics.append(nic)
            else:
                logger.info("%s is an active nic" % nic)
                nics.append(nic)
        else:
            logger.info("%s is not an active nic" % nic)

    # Adding nics which are bound to DPDK as it will not be found in '/sys'
    # after it is bound to DPDK driver.
    contents = common.get_file_data(common.DPDK_MAPPING_FILE)
    if contents:
        dpdk_map = yaml.safe_load(contents)
        for item in dpdk_map:
            # If the DPDK drivers are bound to a VF, the same needs
            # to be skipped for the NIC ordering
            nic = item['name']
            if common.is_vf(item['pci_address']):
                logger.info("%s is a VF, skipping it for NIC ordering" % nic)
            elif common.is_vf_by_name(nic, True):
                logger.info("%s is a VF, skipping it for NIC ordering" % nic)
            elif _is_embedded_nic(nic):
                logger.info("%s is an embedded DPDK bound nic" % nic)
                if nic not in embedded_nics:
                    embedded_nics.append(nic)
            else:
                logger.info("%s is an DPDK bound nic" % nic)
                if nic not in nics:
                    nics.append(nic)
    else:
        logger.info("No DPDK mapping available in path (%s)" %
                    common.DPDK_MAPPING_FILE)

    # NOTE: we could just natural sort all active devices,
    # but this ensures em, eno, and eth are ordered first
    # (more backwards compatible)
    active_nics = (sorted(embedded_nics, key=_natural_sort_key) +
                   sorted(nics, key=_natural_sort_key))
    logger.info("Active nics are %s" % active_nics)
    return active_nics
예제 #16
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)
예제 #17
0
def add_udev_rule_for_vf_representors(pf_name):
    logger.info(f"{pf_name}: adding udev rules for vf representators")
    phys_switch_id_path = common.get_dev_path(pf_name, "_phys_switch_id")
    phys_switch_id = common.get_file_data(phys_switch_id_path).strip()
    pf_pci = get_pf_pci(pf_name)
    pf_fun_num_match = PF_FUNC_RE.search(pf_pci)
    if not pf_fun_num_match:
        logger.error(f"{pf_name}: Failed to get function number "
                     "and so failed to create a udev rule for renaming "
                     "its vf-represent")
        return

    pf_fun_num = pf_fun_num_match.group(1)
    udev_data_line = 'SUBSYSTEM=="net", ACTION=="add", ATTR{phys_switch_id}'\
                     '=="%s", ATTR{phys_port_name}=="pf%svf*", '\
                     'IMPORT{program}="%s $attr{phys_port_name}", '\
                     'NAME="%s_$env{NUMBER}"' % (phys_switch_id,
                                                 pf_fun_num,
                                                 _REP_LINK_NAME_FILE,
                                                 pf_name)
    create_rep_link_name_script()
    return add_udev_rule(udev_data_line, _UDEV_RULE_FILE)
예제 #18
0
def _get_dpdk_map():
    contents = common.get_file_data(common.DPDK_MAPPING_FILE)
    dpdk_map = yaml.safe_load(contents) if contents else []
    return dpdk_map
예제 #19
0
def update_vpp_mapping(vpp_interfaces, vpp_bonds):
    """Verify VPP interface binding and update mapping file

    VppException will be raised if interfaces are not properly bound.

    :param vpp_interfaces: List of VPP interface objects
    :param vpp_bonds: List of VPP bond objects
    """
    cli_list = []

    for vpp_int in vpp_interfaces:
        # Try to get VPP interface name. In case VPP service is down
        # for some reason, we will restart VPP and try again. Currently
        # only trying one more time, can turn into a retry_counter if needed
        # in the future.
        for i in range(2):
            int_info = _get_vpp_interface(vpp_int.pci_dev, tries=12, timeout=5)
            if not int_info:
                restart_vpp(vpp_interfaces)
            else:
                vpp_int.vpp_name = int_info['name']
                vpp_int.vpp_idx = int_info['index']
                break
        else:
            raise VppException('Interface %s with pci address %s not '
                               'bound to vpp' %
                               (vpp_int.name, vpp_int.pci_dev))

        # Generate content of startup script for VPP
        if not vpp_bonds:
            cli_list.append('set interface state %s up' % int_info['name'])
            for address in vpp_int.addresses:
                cli_list.append(
                    'set interface ip address %s %s/%s\n' %
                    (int_info['name'], address.ip, address.prefixlen))

        logger.info('Updating mapping for vpp interface %s:'
                    'pci_dev: %s mac address: %s uio driver: %s' %
                    (vpp_int.name, vpp_int.pci_dev, vpp_int.hwaddr,
                     vpp_int.uio_driver))
        _update_dpdk_map(vpp_int.name, vpp_int.pci_dev, vpp_int.hwaddr,
                         vpp_int.uio_driver)

    for vpp_bond in vpp_bonds:
        bond_ids = [member.vpp_idx for member in vpp_bond.members]
        bond_info = _get_vpp_bond(bond_ids)
        if bond_info:
            cli_list.append('set interface state %s up' % bond_info['name'])
            for address in vpp_bond.addresses:
                cli_list.append(
                    'set interface ip address %s %s/%s' %
                    (bond_info['name'], address.ip, address.prefixlen))
        else:
            raise VppException('Bond %s not found in VPP.' % vpp_bond.name)

    vpp_start_cli = common.get_file_data(_VPP_EXEC_FILE)
    for cli_line in cli_list:
        if not re.search(r'^\s*%s\s*$' % cli_line, vpp_start_cli,
                         re.MULTILINE):
            vpp_start_cli += cli_line + '\n'

    if diff(_VPP_EXEC_FILE, vpp_start_cli):
        write_config(_VPP_EXEC_FILE, vpp_start_cli)
        restart_vpp(vpp_interfaces)

    # Enable VPP service to make the VPP interface configuration
    # persistent.
    processutils.execute('systemctl', 'enable', 'vpp')
예제 #20
0
def generate_vpp_config(vpp_config_path, vpp_interfaces, vpp_bonds):
    """Generate configuration content for VPP

    Generate interface related configuration content for VPP. Current
    configuration will be preserved, with interface related configurations
    updated or inserted. The config only affects 'dpdk' section of VPP config
    file, and only those lines affecting interfaces, specifically, lines
    containing the following:
    dpdk {
      ...
      dev <pci_dev> {<options>}
      uio-driver <uio_driver_name>
      ...
    }

    :param vpp_config_path: VPP Configuration file path
    :param vpp_interfaces: List of VPP interface objects
    :param vpp_bonds: List of VPP bond objects
    :return: updated VPP config content.
    """

    data = common.get_file_data(vpp_config_path)

    # Add interface config to 'dpdk' section
    for vpp_interface in vpp_interfaces:
        if vpp_interface.pci_dev:
            logger.info('vpp interface %s pci dev: %s' %
                        (vpp_interface.name, vpp_interface.pci_dev))

            if vpp_interface.options:
                int_cfg = '%s {%s}' % (vpp_interface.pci_dev,
                                       vpp_interface.options)
            else:
                int_cfg = vpp_interface.pci_dev

            # Make sure 'dpdk' section exists in the config
            if not re.search(r'^\s*dpdk\s*\{', data, re.MULTILINE):
                data += "\ndpdk {\n}\n"

            # Find existing config line for the device we are trying to
            # configure, the line should look like 'dev <pci_dev>  ...'
            # If such config line is found, we will replace the line with
            # appropriate configuration, otherwise, add a new config line
            # in 'dpdk' section of the config.
            m = re.search(
                r'^\s*dev\s+%s\s*(\{[^}]*\})?\s*$' % vpp_interface.pci_dev,
                data, re.IGNORECASE | re.MULTILINE)
            if m:
                data = re.sub(m.group(0),
                              '  dev %s\n' % int_cfg,
                              data,
                              flags=re.MULTILINE)
            else:
                data = re.sub(r'(^\s*dpdk\s*\{)',
                              r'\1\n  dev %s\n' % int_cfg,
                              data,
                              flags=re.MULTILINE)

            if vpp_interface.uio_driver:
                # Check if there is existing uio-driver configuration, if
                # found, the line will be replaced with the appropriate
                # configuration, otherwise, add a new line in 'dpdk' section.
                m = re.search(r'^\s*uio-driver.*$', data, re.MULTILINE)
                if m:
                    data = re.sub(r'^\s*uio-driver.*$',
                                  '  uio-driver %s' % vpp_interface.uio_driver,
                                  data,
                                  flags=re.MULTILINE)
                else:
                    data = re.sub(r'(^\s*dpdk\s*\{)',
                                  r'\1\n  uio-driver %s' %
                                  vpp_interface.uio_driver,
                                  data,
                                  flags=re.MULTILINE)
        else:
            raise VppException('Interface %s has no PCI address and is not'
                               ' found in mapping file' % vpp_interface.name)

    # Add bond config to 'dpdk' section
    for vpp_bond in vpp_bonds:
        slave_str = ''
        for member in vpp_bond.members:
            slave_str += ",slave=%s" % member.pci_dev
        if vpp_bond.bonding_options:
            options_str = ',' + vpp_bond.bonding_options.strip(' ,')
        else:
            options_str = ''

        if slave_str:
            m = re.search(r'^\s*vdev\s+%s.*$' % vpp_bond.name, data,
                          re.MULTILINE)
            if m:
                data = re.sub(
                    m.group(0),
                    r'  vdev %s%s%s' % (vpp_bond.name, slave_str, options_str),
                    data)
            else:
                data = re.sub(r'(^\s*dpdk\s*\{)',
                              r'\1\n  vdev %s%s%s' %
                              (vpp_bond.name, slave_str, options_str),
                              data,
                              flags=re.MULTILINE)

    # Add start up script for VPP to config. This script will be executed by
    # VPP on service start.
    if not re.search(r'^\s*unix\s*\{', data, re.MULTILINE):
        data += "\nunix {\n}\n"

    m = re.search(r'^\s*(exec|startup-config).*$', data,
                  re.IGNORECASE | re.MULTILINE)
    if m:
        data = re.sub(m.group(0), '  exec %s' % _VPP_EXEC_FILE, data)
    else:
        data = re.sub(r'(^\s*unix\s*\{)',
                      r'\1\n  exec %s' % _VPP_EXEC_FILE,
                      data,
                      flags=re.MULTILINE)
    # Make sure startup script exists to avoid VPP startup failure.
    open(_VPP_EXEC_FILE, 'a').close()

    return data
예제 #21
0
def diff(filename, data):
    file_data = common.get_file_data(filename)
    logger.debug("Diff file data:\n%s" % file_data)
    logger.debug("Diff data:\n%s" % data)
    # convert to string as JSON may have unicode in it
    return not file_data == data
예제 #22
0
def get_pf_device_id(pf_name):
    pf_device_path = common.get_dev_path(pf_name, "device")
    pf_device_id = common.get_file_data(pf_device_path).strip()
    return pf_device_id
예제 #23
0
def get_pf_pci(pf_name):
    pf_pci_path = common.get_dev_path(pf_name, "uevent")
    pf_info = common.get_file_data(pf_pci_path)
    pf_pci = re.search(r'PCI_SLOT_NAME=(.*)', pf_info, re.MULTILINE).group(1)
    return pf_pci