Exemplo n.º 1
0
def setup_node(args):
    """Run all set-up methods for a node.

    This method is used as map_async parameter. It receives tuple with all
    parameters as passed to map_async function.

    :param args: All parameters needed to setup one node.
    :type args: tuple
    :returns: True - success, False - error
    :rtype: bool
    :raises RuntimeError: If node setup failed.
    """
    tarball, remote_tarball, node = args

    # if unset, arch defaults to x86_64
    Topology.get_node_arch(node)

    try:
        if node['type'] == NodeType.DUT:
            copy_tarball_to_node(tarball, node)
            extract_tarball_at_node(remote_tarball, node)
            install_dmm_test(node)
    except RuntimeError as exc:
        logger.error("Node setup failed, error:'{0}'".format(exc.message))
        return False
    else:
        logger.console('Setup of node {0} done'.format(node['host']))
        return True
Exemplo n.º 2
0
    def initialize_dpdk_environment(dut_node, dut_if1, dut_if2):
        """
        Initialize the DPDK test environment on the dut_node.
        Load the module uio and igb_uio, then bind the test NIC to the igb_uio.

        :param dut_node: Will init the DPDK on this node.
        :param dut_if1: DUT interface name.
        :param dut_if2: DUT interface name.
        :type dut_node: dict
        :type dut_if1: str
        :type dut_if2: str
        :raises RuntimeError: If it fails to bind the interfaces to igb_uio.
        """
        if dut_node['type'] == NodeType.DUT:
            pci_address1 = Topology.get_interface_pci_addr(dut_node, dut_if1)
            pci_address2 = Topology.get_interface_pci_addr(dut_node, dut_if2)

            ssh = SSH()
            ssh.connect(dut_node)

            arch = Topology.get_node_arch(dut_node)
            cmd = '{fwdir}/tests/dpdk/dpdk_scripts/init_dpdk.sh '\
                  '{pci1} {pci2} {arch}'.format(fwdir=Constants.REMOTE_FW_DIR,
                                                pci1=pci_address1,
                                                pci2=pci_address2,
                                                arch=arch)

            ret_code, _, _ = ssh.exec_command_sudo(cmd, timeout=600)
            if ret_code != 0:
                raise RuntimeError('Failed to bind the interfaces to igb_uio '
                                   'at node {name}'.\
                                    format(name=dut_node['host']))
Exemplo n.º 3
0
    def create_kernelvm_config_testpmd_mac(self, **kwargs):
        """Create QEMU testpmd-mac command line.

        :param kwargs: Key-value pairs to construct command line parameters.
        :type kwargs: dict
        """
        testpmd_path = ('{path}/{arch}-native-linuxapp-gcc/app'.
                        format(path=Constants.QEMU_VM_DPDK,
                               arch=Topology.get_node_arch(self._node)))
        testpmd_cmd = DpdkUtil.get_testpmd_cmdline(
            eal_corelist='0-{smp}'.format(smp=self._opt.get('smp') - 1),
            eal_driver=False,
            eal_in_memory=True,
            pmd_num_mbufs=16384,
            pmd_fwd_mode='mac',
            pmd_eth_peer_0='0,{mac}'.format(mac=kwargs['vif1_mac']),
            pmd_eth_peer_1='1,{mac}'.format(mac=kwargs['vif2_mac']),
            pmd_rxq=kwargs['queues'],
            pmd_txq=kwargs['queues'],
            pmd_tx_offloads=False,
            pmd_disable_hw_vlan=False,
            pmd_max_pkt_len=9200 if kwargs['jumbo_frames'] else None,
            pmd_nb_cores=str(self._opt.get('smp') - 1))

        self._opt['vnf_bin'] = ('{testpmd_path}/{testpmd_cmd}'.
                                format(testpmd_path=testpmd_path,
                                       testpmd_cmd=testpmd_cmd))
Exemplo n.º 4
0
def install_dmm_test(node):
    """Prepare the DMM test envrionment.
    Raise errors when failed.

    :param node: Dictionary created from topology.
    :type node: dict
    :returns: nothing.
    :raises RuntimeError: If install dmm failed.
    """

    arch = Topology.get_node_arch(node)
    logger.console('Install the DMM on {0} ({1})'.format(node['host'], arch))

    ssh = SSH()
    ssh.connect(node)
    (ret_code, _, stderr) = ssh.exec_command(
        'cd {0}/{1} && ./install_prereq.sh {2} 2>&1 | tee '
        'log_install_prereq.txt'
        .format(con.REMOTE_FW_DIR, con.DMM_SCRIPTS, arch), timeout=600)

    if ret_code != 0:
        logger.error('Install the DMM error: {0}'.format(stderr))
        raise RuntimeError('Install prereq failed')
    else:
        logger.console('Install prereq on {0} success!'.format(node['host']))
Exemplo n.º 5
0
    def acquire(self, force=True):
        """Pull an image or a repository from a registry.

        :param force: Destroy a container if exists.
        :type force: bool
        :raises RuntimeError: If pulling a container failed.
        """
        if self.is_container_present():
            if force:
                self.destroy()
            else:
                return

        if not self.container.image:
            img = Constants.DOCKER_SUT_IMAGE_UBUNTU_ARM \
                if Topology.get_node_arch(self.container.node) == u"aarch64" \
                else Constants.DOCKER_SUT_IMAGE_UBUNTU
            setattr(self.container, u"image", img)

        cmd = f"docker pull {self.container.image}"

        ret, _, _ = self.container.ssh.exec_command_sudo(cmd, timeout=1800)
        if int(ret) != 0:
            raise RuntimeError(
                f"Failed to create container {self.container.name}."
            )

        if self.container.cpuset_cpus:
            self._configure_cgroup(u"docker")
Exemplo n.º 6
0
    def start_the_l2fwd_test(dut_node, cpu_cores, nb_cores, queue_nums,
                             jumbo_frames):
        """
        Execute the l2fwd on the dut_node.

        :param dut_node: Will execute the l2fwd on this node.
        :param cpu_cores: The DPDK run cores.
        :param nb_cores: The cores number for the forwarding.
        :param queue_nums: The queues number for the NIC.
        :param jumbo_frames: Are jumbo frames used or not.
        :type dut_node: dict
        :type cpu_cores: str
        :type nb_cores: str
        :type queue_nums: str
        :type jumbo_frames: str
        :raises RuntimeError: If the script "run_l2fwd.sh" fails.
        """
        if dut_node['type'] == NodeType.DUT:
            ssh = SSH()
            ssh.connect(dut_node)

            arch = Topology.get_node_arch(dut_node)
            cmd = '{fwdir}/tests/dpdk/dpdk_scripts/run_l2fwd.sh {cpu_cores} ' \
                  '{nb_cores} {queues} {jumbo} {arch}'.\
                  format(fwdir=Constants.REMOTE_FW_DIR, cpu_cores=cpu_cores,
                         nb_cores=nb_cores, queues=queue_nums,
                         jumbo=jumbo_frames, arch=arch)

            ret_code, _, _ = ssh.exec_command_sudo(cmd, timeout=600)
            if ret_code != 0:
                raise RuntimeError('Failed to execute l2fwd test at node '
                                   '{name}'.format(name=dut_node['host']))
Exemplo n.º 7
0
    def acquire(self, force=True):
        """Acquire a privileged system object where configuration is stored.

        :param force: If a container exists, destroy it and create a new
            container.
        :type force: bool
        :raises RuntimeError: If creating the container or writing the container
            config fails.
        """
        if self.is_container_present():
            if force:
                self.destroy()
            else:
                return

        target_arch = u"arm64" \
            if Topology.get_node_arch(self.container.node) == u"aarch64" \
            else u"amd64"

        image = self.container.image if self.container.image \
            else f"-d ubuntu -r bionic -a {target_arch}"

        cmd = f"lxc-create -t download --name {self.container.name} " \
            f"-- {image} --no-validate"

        ret, _, _ = self.container.ssh.exec_command_sudo(cmd, timeout=1800)
        if int(ret) != 0:
            raise RuntimeError(u"Failed to create container.")

        self._configure_cgroup(u"lxc")
Exemplo n.º 8
0
    def build_qemu(node, force_install=False, apply_patch=False):
        """Build QEMU from sources.

        :param node: Node to build QEMU on.
        :param force_install: If True, then remove previous build.
        :param apply_patch: If True, then apply patches from qemu_patches dir.
        :type node: dict
        :type force_install: bool
        :type apply_patch: bool
        :raises RuntimeError: If building QEMU failed.
        """
        ssh = SSH()
        ssh.connect(node)

        directory = ' --directory={0}'.format(Constants.QEMU_INSTALL_DIR)
        if apply_patch:
            directory += '-patch'
        else:
            directory += '-base'
        version = ' --version={0}'.format(Constants.QEMU_INSTALL_VERSION)
        force = ' --force' if force_install else ''
        patch = ' --patch' if apply_patch else ''
        arch = Topology.get_node_arch(node)
        target_list = ' --target-list={0}-softmmu'.format(arch)

        (ret_code, stdout, stderr) = \
            ssh.exec_command(
                "sudo -E sh -c '{0}/{1}/qemu_build.sh{2}{3}{4}{5}{6}'"\
                .format(Constants.REMOTE_FW_DIR, Constants.RESOURCES_LIB_SH,
                        version, directory, force, patch, target_list), 1000)

        if int(ret_code) != 0:
            logger.debug('QEMU build failed {0}'.format(stdout + stderr))
            raise RuntimeError('QEMU build failed on {0}'.format(node['host']))
Exemplo n.º 9
0
    def qemu_set_node(self, node):
        """Set node to run QEMU on.

        :param node: Node to run QEMU on.
        :type node: dict
        """
        self._node = node
        self._ssh = SSH()
        self._ssh.connect(node)
        self._vm_info['host'] = node['host']

        arch = Topology.get_node_arch(node)
        self._qemu_bin = 'qemu-system-{arch}'.format(arch=arch)
Exemplo n.º 10
0
    def qemu_version(self, version=None):
        """Return Qemu version or compare if version is higher than parameter.

        :param version: Version to compare.
        :type version: str
        :returns: Qemu version or Boolean if version is higher than parameter.
        :rtype: str or bool
        """
        command = ('{bin_path}/qemu-system-{arch} --version'.format(
            bin_path=Constants.QEMU_BIN_PATH,
            arch=Topology.get_node_arch(self._node)))
        try:
            stdout, _ = exec_cmd_no_error(self._node, command, sudo=True)
            ver = match(r'QEMU emulator version ([\d.]*)', stdout).group(1)
            return StrictVersion(ver) > StrictVersion(version) \
                if version else ver
        except RuntimeError:
            self.qemu_kill_all()
            raise
Exemplo n.º 11
0
    def install_dpdk_test(node):
        """
        Prepare the DPDK test environment

        :param node: Dictionary created from topology
        :type node: dict
        :returns: nothing
        :raises RuntimeError: If command returns nonzero return code.
        """
        arch = Topology.get_node_arch(node)

        ssh = SSH()
        ssh.connect(node)

        ret_code, _, _ = ssh.exec_command(
            '{fwdir}/tests/dpdk/dpdk_scripts/install_dpdk.sh {arch}'.
            format(fwdir=Constants.REMOTE_FW_DIR, arch=arch), timeout=600)

        if ret_code != 0:
            raise RuntimeError('Install the DPDK failed')
Exemplo n.º 12
0
    def patch_l3fwd(node, patch):
        """
        Patch l3fwd application and recompile.

        :param node: Dictionary created from topology.
        :param patch: Patch to apply.
        :type node: dict
        :type patch: str
        :raises RuntimeError: Patching of l3fwd failed.
        """
        arch = Topology.get_node_arch(node)

        ssh = SSH()
        ssh.connect(node)

        ret_code, _, _ = ssh.exec_command(
            '{fwdir}/tests/dpdk/dpdk_scripts/patch_l3fwd.sh {arch} '
            '{fwdir}/tests/dpdk/dpdk_scripts/{patch}'.format(
                fwdir=Constants.REMOTE_FW_DIR, arch=arch, patch=patch),
            timeout=600)

        if ret_code != 0:
            raise RuntimeError('Patch of l3fwd failed.')
Exemplo n.º 13
0
    def qemu_start(self):
        """Start QEMU and wait until VM boot.

        :returns: VM node info.
        :rtype: dict
        """
        cmd_opts = OptionString()
        cmd_opts.add('{bin_path}/qemu-system-{arch}'.format(
            bin_path=Constants.QEMU_BIN_PATH,
            arch=Topology.get_node_arch(self._node)))
        cmd_opts.extend(self._params)
        message = ('QEMU: Start failed on {host}!'.
                   format(host=self._node['host']))
        try:
            DUTSetup.check_huge_page(
                self._node, '/dev/hugepages', self._opt.get('mem'))

            exec_cmd_no_error(
                self._node, cmd_opts, timeout=300, sudo=True, message=message)
            self._wait_until_vm_boot()
        except RuntimeError:
            self.qemu_kill_all()
            raise
        return self._vm_info
Exemplo n.º 14
0
    def build_qemu(node, force_install=False, apply_patch=False):
        """Build QEMU from sources.

        :param node: Node to build QEMU on.
        :param force_install: If True, then remove previous build.
        :param apply_patch: If True, then apply patches from qemu_patches dir.
        :type node: dict
        :type force_install: bool
        :type apply_patch: bool
        :raises RuntimeError: If building QEMU failed.
        """
        ssh = SSH()
        ssh.connect(node)

        directory = (' --directory={install_dir}{patch}'.
                     format(install_dir=Constants.QEMU_INSTALL_DIR,
                            patch='-patch' if apply_patch else '-base'))
        version = (' --version={install_version}'.
                   format(install_version=Constants.QEMU_INSTALL_VERSION))
        force = ' --force' if force_install else ''
        patch = ' --patch' if apply_patch else ''
        arch = Topology.get_node_arch(node)
        target_list = (' --target-list={arch}-softmmu'.
                       format(arch=arch))

        ret_code, _, _ = ssh.exec_command(
            "sudo -E sh -c '{fw_dir}/{lib_sh}/qemu_build.sh{version}{directory}"
            "{force}{patch}{target_list}'".
            format(fw_dir=Constants.REMOTE_FW_DIR,
                   lib_sh=Constants.RESOURCES_LIB_SH,
                   version=version, directory=directory, force=force,
                   patch=patch, target_list=target_list), 1000)

        if int(ret_code) != 0:
            raise RuntimeError('QEMU build failed on {host}'.
                               format(host=node['host']))
Exemplo n.º 15
0
    def __init__(self,
                 node,
                 qemu_id=1,
                 smp=1,
                 mem=512,
                 vnf=None,
                 img=Constants.QEMU_VM_IMAGE):
        """Initialize QemuUtil class.

        :param node: Node to run QEMU on.
        :param qemu_id: QEMU identifier.
        :param smp: Number of virtual SMP units (cores).
        :param mem: Amount of memory.
        :param vnf: Network function workload.
        :param img: QEMU disk image or kernel image path.
        :type node: dict
        :type qemu_id: int
        :type smp: int
        :type mem: int
        :type vnf: str
        :type img: str
        """
        self._nic_id = 0
        self._node = node
        self._arch = Topology.get_node_arch(self._node)
        self._opt = dict()

        # Architecture specific options
        if self._arch == u"aarch64":
            dpdk_target = u"arm64-armv8a"
            self._opt[u"machine_args"] = \
                u"virt,accel=kvm,usb=off,mem-merge=off,gic-version=3"
            self._opt[u"console"] = u"ttyAMA0"
        else:
            dpdk_target = u"x86_64-native"
            self._opt[u"machine_args"] = u"pc,accel=kvm,usb=off,mem-merge=off"
            self._opt[u"console"] = u"ttyS0"
        self._testpmd_path = f"{Constants.QEMU_VM_DPDK}/" \
            f"{dpdk_target}-linux-gcc/app"
        self._vm_info = {
            u"host": node[u"host"],
            u"type": NodeType.VM,
            u"port": 10021 + qemu_id,
            u"serial": 4555 + qemu_id,
            u"username": '******',
            u"password": '******',
            u"interfaces": {},
        }
        if node[u"port"] != 22:
            self._vm_info[u"host_port"] = node[u"port"]
            self._vm_info[u"host_username"] = node[u"username"]
            self._vm_info[u"host_password"] = node[u"password"]
        # Input Options.
        self._opt[u"qemu_id"] = qemu_id
        self._opt[u"mem"] = int(mem)
        self._opt[u"smp"] = int(smp)
        self._opt[u"img"] = img
        self._opt[u"vnf"] = vnf
        # Temporary files.
        self._temp = dict()
        self._temp[u"log"] = f"/tmp/serial_{qemu_id}.log"
        self._temp[u"pidfile"] = f"/run/qemu_{qemu_id}.pid"
        if img == Constants.QEMU_VM_IMAGE:
            self._temp[u"qmp"] = f"/run/qmp_{qemu_id}.sock"
            self._temp[u"qga"] = f"/run/qga_{qemu_id}.sock"
        elif img == Constants.QEMU_VM_KERNEL:
            self._opt[u"img"], _ = exec_cmd_no_error(
                node,
                f"ls -1 {Constants.QEMU_VM_KERNEL}* | tail -1",
                message=u"Qemu Kernel VM image not found!")
            self._temp[u"ini"] = f"/etc/vm_init_{qemu_id}.conf"
            self._opt[u"initrd"], _ = exec_cmd_no_error(
                node,
                f"ls -1 {Constants.QEMU_VM_KERNEL_INITRD}* | tail -1",
                message=u"Qemu Kernel initrd image not found!")
        else:
            raise RuntimeError(f"QEMU: Unknown VM image option: {img}")
        # Computed parameters for QEMU command line.
        self._params = OptionString(prefix=u"-")