Example #1
0
    def show_vpp_settings(node, *additional_cmds):
        """Print default VPP settings. In case others are needed, can be
        accepted as next parameters (each setting one parameter), preferably
        in form of a string.

        :param node: VPP node.
        :param additional_cmds: Additional commands that the vpp should print
        settings for.
        :type node: dict
        :type additional_cmds: tuple
        """
        def_setting_tb_displayed = {
            'IPv6 FIB': 'ip6 fib',
            'IPv4 FIB': 'ip fib',
            'Interface IP': 'int addr',
            'Interfaces': 'int',
            'ARP': 'ip arp',
            'Errors': 'err'
        }

        if additional_cmds:
            for cmd in additional_cmds:
                def_setting_tb_displayed['Custom Setting: {}'.format(
                    cmd)] = cmd
        ssh = SSH()
        ssh.connect(node)
        for _, value in def_setting_tb_displayed.items():
            ssh.exec_command_sudo('vppctl sh {}'.format(value))
Example #2
0
    def linux_del_if_ipv6_addr(node, interface, addr, prefix):
        """Delete IPv6 address on linux host.

        :param node: Linux node.
        :param interface: Node interface.
        :param addr: IPv6 address.
        :param prefix: IPv6 address prefix.
        :type node: dict
        :type interface: str
        :type addr: str
        :type prefix: str
        """
        ssh = SSH()
        ssh.connect(node)

        cmd = "ifconfig {dev} inet6 del {ip}/{p}".format(dev=interface,
                                                         ip=addr,
                                                         p=prefix)
        (ret_code, _, _) = ssh.exec_command_sudo(cmd)
        if int(ret_code) != 0:
            raise Exception('TG ifconfig failed')

        cmd = "ifconfig {dev} down".format(dev=interface)
        (ret_code, _, _) = ssh.exec_command_sudo(cmd)
        if int(ret_code) != 0:
            raise Exception('TG ifconfig failed')
Example #3
0
    def stop_odl_client(node, path):
        """Stop ODL client service on the specified node.

        :param node: Node to start ODL client on.
        :param path: Path to ODL client.
        :type node: dict
        :type path: str
        :raises HoneycombError: If ODL client fails to stop.
        """

        ssh = SSH()
        ssh.connect(node)

        cmd = "{0}/*karaf*/bin/stop".format(path)

        ssh = SSH()
        ssh.connect(node)
        ret_code, _, _ = ssh.exec_command_sudo(cmd)
        if int(ret_code) != 0:
            logger.debug("ODL Client refused to shut down.")
            cmd = "pkill -f 'karaf'"
            (ret_code, _, _) = ssh.exec_command_sudo(cmd)
            if int(ret_code) != 0:
                raise HoneycombError('Node {0} failed to stop ODL.'.format(
                    node['host']))

        logger.info("ODL client service stopped.")
Example #4
0
    def tg_set_interface_driver(node, pci_addr, driver):
        """Set interface driver on the TG node.

        :param node: Node to set interface driver on (must be TG node).
        :param pci_addr: PCI address of the interface.
        :param driver: Driver name.
        :type node: dict
        :type pci_addr: str
        :type driver: str
        :raises RuntimeError: If unbinding from the current driver fails.
        :raises RuntimeError: If binding to the new driver fails.
        """
        old_driver = InterfaceUtil.tg_get_interface_driver(node, pci_addr)
        if old_driver == driver:
            return

        ssh = SSH()
        ssh.connect(node)

        # Unbind from current driver
        if old_driver is not None:
            cmd = 'sh -c "echo {0} > /sys/bus/pci/drivers/{1}/unbind"'\
                .format(pci_addr, old_driver)
            (ret_code, _, _) = ssh.exec_command_sudo(cmd)
            if int(ret_code) != 0:
                raise RuntimeError("'{0}' failed on '{1}'"
                                   .format(cmd, node['host']))

        # Bind to the new driver
        cmd = 'sh -c "echo {0} > /sys/bus/pci/drivers/{1}/bind"'\
            .format(pci_addr, driver)
        (ret_code, _, _) = ssh.exec_command_sudo(cmd)
        if int(ret_code) != 0:
            raise RuntimeError("'{0}' failed on '{1}'"
                               .format(cmd, node['host']))
Example #5
0
    def delete_kubernetes_resource_on_node(node,
                                           nspace,
                                           name=None,
                                           rtype=u"po,cm,deploy,rs,rc,svc"):
        """Delete Kubernetes resource on node.

        :param node: DUT node.
        :param nspace: Kubernetes namespace.
        :param rtype: Kubernetes resource type.
        :param name: Name of resource (Default: all).
        :type node: dict
        :type nspace: str
        :type rtype: str
        :type name: str
        :raises RuntimeError: If retrieving or deleting Kubernetes resource
            failed.
        """
        ssh = SSH()
        ssh.connect(node)

        name = f"{name}" if name else u"--all"
        nspace = f"-n {nspace}" if nspace else u""
        cmd = f"kubectl delete {nspace} {rtype} {name}"

        ret_code, _, _ = ssh.exec_command_sudo(cmd, timeout=120)
        if int(ret_code) != 0:
            raise RuntimeError(
                f"Failed to delete Kubernetes resources on {node[u'host']}.")

        cmd = f"kubectl get {nspace} pods --no-headers"
        for _ in range(MAX_RETRY):
            ret_code, stdout, stderr = ssh.exec_command_sudo(cmd)
            if int(ret_code) != 0:
                raise RuntimeError(f"Failed to retrieve Kubernetes resources "
                                   f"on {node[u'host']}.")
            if name == u"--all":
                ready = False
                for line in stderr.splitlines():
                    if u"No resources found." in line:
                        ready = True
                if ready:
                    break
            else:
                ready = False
                for line in stdout.splitlines():
                    try:
                        state = line.split()[1].split(u"/")
                        ready = bool(u"Running" in line
                                     and state == state[::-1])
                        if not ready:
                            break
                    except (ValueError, IndexError):
                        ready = False
                if ready:
                    break
            sleep(5)
        else:
            raise RuntimeError(
                f"Failed to delete Kubernetes resources on {node[u'host']}.")
Example #6
0
    def check_honeycomb_startup_state(*nodes):
        """Check state of Honeycomb service during startup on specified nodes.

        Reads html path from template file oper_vpp_version.url.

        Honeycomb nodes reply with connection refused or the following status
        codes depending on startup progress: codes 200, 401, 403, 404, 500, 503

        :param nodes: List of DUT nodes starting Honeycomb.
        :type nodes: list
        :return: True if all GETs returned code 200(OK).
        :rtype bool
        """
        path = HcUtil.read_path_from_url_file("oper_vpp_version")
        expected_status_codes = (HTTPCodes.UNAUTHORIZED, HTTPCodes.FORBIDDEN,
                                 HTTPCodes.NOT_FOUND,
                                 HTTPCodes.SERVICE_UNAVAILABLE,
                                 HTTPCodes.INTERNAL_SERVER_ERROR)

        for node in nodes:
            if node['type'] == NodeType.DUT:
                HoneycombSetup.print_ports(node)
                try:
                    status_code, _ = HTTPRequest.get(node,
                                                     path,
                                                     enable_logging=False)
                except HTTPRequestError:
                    ssh = SSH()
                    ssh.connect(node)
                    ret_code, _, _ = ssh.exec_command_sudo(
                        "tail -n 100 /var/log/syslog")
                    if ret_code != 0:
                        # It's probably Centos
                        ssh.exec_command_sudo("tail -n 100 /var/log/messages")
                    raise
                if status_code == HTTPCodes.OK:
                    logger.info(
                        "Honeycomb on node {0} is up and running".format(
                            node['host']))
                elif status_code in expected_status_codes:
                    if status_code == HTTPCodes.UNAUTHORIZED:
                        logger.info('Unauthorized. If this triggers keyword '
                                    'timeout, verify Honeycomb username and '
                                    'password.')
                    raise HoneycombError('Honeycomb on node {0} running but '
                                         'not yet ready.'.format(node['host']),
                                         enable_logging=False)
                else:
                    raise HoneycombError(
                        'Unexpected return code: {0}.'.format(status_code))

                status_code, _ = HcUtil.get_honeycomb_data(
                    node, "config_vpp_interfaces")
                if status_code != HTTPCodes.OK:
                    raise HoneycombError('Honeycomb on node {0} running but '
                                         'not yet ready.'.format(node['host']),
                                         enable_logging=False)
        return True
Example #7
0
    def archive_odl_log(node):
        """Copy ODL karaf log file from DUT node to VIRL for archiving.

        :param node: Honeycomb node.
        :type node: dict
        """

        ssh = SSH()
        ssh.connect(node)

        cmd = "cp /tmp/karaf.log /scratch/"
        ssh.exec_command_sudo(cmd, timeout=60)
Example #8
0
    def archive_honeycomb_log(node):
        """Copy honeycomb log file from DUT node to VIRL for archiving.

        :param node: Honeycomb node.
        :type node: dict
        """

        ssh = SSH()
        ssh.connect(node)

        cmd = "cp /var/log/honeycomb/honeycomb.log /scratch/"

        ssh.exec_command_sudo(cmd)
Example #9
0
    def clear_memif_socks(node, *socks):
        """Clear Memif sockets for the given node.

        :param node: Given node to clear Memif sockets on.
        :param socks: Memif sockets.
        :type node: dict
        :type socks: list
        """
        ssh = SSH()
        ssh.connect(node)

        for sock in socks:
            ssh.exec_command_sudo('rm -f {}'.format(sock))
    def describe_kubernetes_resource_on_node(node, nspace):
        """Describe all Kubernetes PODs in namespace on node.

        :param node: DUT node.
        :param nspace: Kubernetes namespace.
        :type node: dict
        :type nspace: str
        """
        ssh = SSH()
        ssh.connect(node)

        nspace = '-n {nspace}'.format(nspace=nspace) if nspace else ''

        cmd = 'kubectl describe {nspace} all'.format(nspace=nspace)
        ssh.exec_command_sudo(cmd)
Example #11
0
    def setup_odl_client(node, path):
        """Start ODL client on the specified node.

        Karaf should be located in the provided path, and VPP and Honeycomb
        should already be running, otherwise the start will fail.
        :param node: Node to start ODL client on.
        :param path: Path to ODL client on node.
        :type node: dict
        :type path: str
        :raises HoneycombError: If Honeycomb fails to start.
        """

        logger.console("\nStarting ODL client ...")
        ssh = SSH()
        ssh.connect(node)

        cmd = "{path}/*karaf*/bin/start clean".format(path=path)
        ret_code, _, _ = ssh.exec_command_sudo(cmd)

        if int(ret_code) != 0:
            raise HoneycombError('Node {0} failed to start ODL.'.format(
                node['host']))
        else:
            logger.info("Starting the ODL client on node {0} is "
                        "in progress ...".format(node['host']))
Example #12
0
    def start_honeycomb_on_duts(*nodes):
        """Start Honeycomb on specified DUT nodes.

        This keyword starts the Honeycomb service on specified DUTs.
        The keyword just starts the Honeycomb and does not check its startup
        state. Use the keyword "Check Honeycomb Startup State" to check if the
        Honeycomb is up and running.
        Honeycomb must be installed in "/opt" directory, otherwise the start
        will fail.
        :param nodes: List of nodes to start Honeycomb on.
        :type nodes: list
        :raises HoneycombError: If Honeycomb fails to start.
        """

        HoneycombSetup.print_environment(nodes)

        cmd = "sudo service honeycomb start"

        for node in nodes:
            if node['type'] == NodeType.DUT:
                logger.console(
                    "\n(re)Starting Honeycomb service on node {0}".format(
                        node["host"]))
                ssh = SSH()
                ssh.connect(node)
                (ret_code, _, _) = ssh.exec_command_sudo(cmd)
                if int(ret_code) != 0:
                    raise HoneycombError(
                        'Node {0} failed to start Honeycomb.'.format(
                            node['host']))
                else:
                    logger.info(
                        "Starting the Honeycomb service on node {0} is "
                        "in progress ...".format(node['host']))
Example #13
0
    def copy_odl_client(node, odl_name, src_path, dst_path):
        """Copy ODL Client from source path to destination path.

        :param node: Honeycomb node.
        :param odl_name: Name of ODL client version to use.
        :param src_path: Source Path where to find ODl client.
        :param dst_path: Destination path.
        :type node: dict
        :type odl_name: str
        :type src_path: str
        :type dst_path: str
        :raises HoneycombError: If the operation fails.
        """

        ssh = SSH()
        ssh.connect(node)

        cmd = "sudo rm -rf {dst}/*karaf_{odl_name} && " \
              "cp -r {src}/*karaf_{odl_name}* {dst}".format(
                  src=src_path, odl_name=odl_name, dst=dst_path)

        ret_code, _, _ = ssh.exec_command_sudo(cmd, timeout=180)
        if int(ret_code) != 0:
            raise HoneycombError(
                "Failed to copy ODL client on node {0}".format(node["host"]))
Example #14
0
    def copy_java_libraries(node):
        """Copy Java libraries installed by vpp-api-java package to honeycomb
        lib folder.

        This is a (temporary?) workaround for jvpp version mismatches.

        :param node: Honeycomb node
        :type node: dict
        """

        ssh = SSH()
        ssh.connect(node)
        (_, stdout,
         _) = ssh.exec_command_sudo("ls /usr/share/java | grep ^jvpp-*")

        files = stdout.split("\n")[:-1]
        for item in files:
            # example filenames:
            # jvpp-registry-17.04.jar
            # jvpp-core-17.04.jar

            parts = item.split("-")
            version = "{0}-SNAPSHOT".format(parts[2][:5])
            artifact_id = "{0}-{1}".format(parts[0], parts[1])

            directory = "{0}/lib/io/fd/vpp/{1}/{2}".format(
                Const.REMOTE_HC_DIR, artifact_id, version)
            cmd = "sudo mkdir -p {0}; " \
                  "sudo cp /usr/share/java/{1} {0}/{2}-{3}.jar".format(
                      directory, item, artifact_id, version)

            (ret_code, _, stderr) = ssh.exec_command(cmd)
            if ret_code != 0:
                raise HoneycombError("Failed to copy JVPP libraries on "
                                     "node {0}, {1}".format(node, stderr))
Example #15
0
    def print_ports(node):
        """Uses "sudo netstat -anp | grep java" to print port where a java
        application listens.

        :param node: Honeycomb node where we want to print the ports.
        :type node: dict
        """

        cmds = ("netstat -anp | grep java", "ps -ef | grep [h]oneycomb")

        logger.info("Checking node {} ...".format(node['host']))
        for cmd in cmds:
            logger.info("Command: {}".format(cmd))
            ssh = SSH()
            ssh.connect(node)
            ssh.exec_command_sudo(cmd)
Example #16
0
    def configure_restconf_binding_address(node):
        """Configure Honeycomb to accept restconf requests from all IP
        addresses. IP version is determined by node data.

         :param node: Information about a DUT node.
         :type node: dict
         :raises HoneycombError: If the configuration could not be changed.
         """

        find = "restconf-binding-address"
        try:
            IPv6Address(unicode(node["host"]))
            # if management IP of the node is in IPv6 format
            replace = '\\"restconf-binding-address\\": \\"0::0\\",'
        except (AttributeError, AddressValueError):
            replace = '\\"restconf-binding-address\\": \\"0.0.0.0\\",'

        argument = '"/{0}/c\\ {1}"'.format(find, replace)
        path = "{0}/config/restconf.json".format(Const.REMOTE_HC_DIR)
        command = "sed -i {0} {1}".format(argument, path)

        ssh = SSH()
        ssh.connect(node)
        (ret_code, _, stderr) = ssh.exec_command_sudo(command)
        if ret_code != 0:
            raise HoneycombError("Failed to modify configuration on "
                                 "node {0}, {1}".format(node, stderr))
Example #17
0
    def execute_script(self,
                       vat_name,
                       node,
                       timeout=120,
                       json_out=True,
                       copy_on_execute=False):
        """Execute VAT script on remote node, and store the result. There is an
        option to copy script from local host to remote host before execution.
        Path is defined automatically.

        :param vat_name: Name of the vat script file. Only the file name of
            the script is required, the resources path is prepended
            automatically.
        :param node: Node to execute the VAT script on.
        :param timeout: Seconds to allow the script to run.
        :param json_out: Require JSON output.
        :param copy_on_execute: If true, copy the file from local host to remote
            before executing.
        :type vat_name: str
        :type node: dict
        :type timeout: int
        :type json_out: bool
        :type copy_on_execute: bool
        :raises SSHException: If cannot open connection for VAT.
        :raises SSHTimeout: If VAT execution is timed out.
        :raises RuntimeError: If VAT script execution fails.
        """
        ssh = SSH()
        try:
            ssh.connect(node)
        except:
            raise SSHException(
                "Cannot open SSH connection to execute VAT "
                "command(s) from vat script {name}".format(name=vat_name))

        if copy_on_execute:
            ssh.scp(vat_name, vat_name)
            remote_file_path = vat_name
        else:
            remote_file_path = '{0}/{1}/{2}'.format(
                Constants.REMOTE_FW_DIR, Constants.RESOURCES_TPL_VAT, vat_name)

        cmd = "{vat_bin} {json} in {vat_path} script".format(
            vat_bin=Constants.VAT_BIN_NAME,
            json="json" if json_out is True else "",
            vat_path=remote_file_path)

        try:
            ret_code, stdout, stderr = ssh.exec_command_sudo(cmd=cmd,
                                                             timeout=timeout)
        except SSHTimeout:
            logger.error("VAT script execution timeout: {0}".format(cmd))
            raise
        except:
            raise RuntimeError("VAT script execution failed: {0}".format(cmd))

        self._ret_code = ret_code
        self._stdout = stdout
        self._stderr = stderr
        self._script_name = vat_name
Example #18
0
    def stop_honeycomb_on_duts(*nodes):
        """Stop the Honeycomb service on specified DUT nodes.

        This keyword stops the Honeycomb service on specified nodes. It just
        stops the Honeycomb and does not check its shutdown state. Use the
        keyword "Check Honeycomb Shutdown State" to check if Honeycomb has
        stopped.
        :param nodes: List of nodes to stop Honeycomb on.
        :type nodes: list
        :raises HoneycombError: If Honeycomb failed to stop.
        """

        cmd = "sudo service honeycomb stop"
        errors = []

        for node in nodes:
            if node['type'] == NodeType.DUT:
                logger.console(
                    "\nShutting down Honeycomb service on node {0}".format(
                        node["host"]))
                ssh = SSH()
                ssh.connect(node)
                (ret_code, _, _) = ssh.exec_command_sudo(cmd)
                if int(ret_code) != 0:
                    errors.append(node['host'])
                else:
                    logger.info(
                        "Stopping the Honeycomb service on node {0} is "
                        "in progress ...".format(node['host']))
        if errors:
            raise HoneycombError(
                'Node(s) {0} failed to stop Honeycomb.'.format(errors))
Example #19
0
    def cleanup_dpdk_environment(dut_node, dut_if1, dut_if2):
        """
        Cleanup the DPDK test environment on the DUT node.
        Unbind the NIC from the igb_uio and bind them to the kernel driver.

        :param dut_node: Will cleanup 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 cleanup the dpdk.
        """
        if dut_node['type'] == NodeType.DUT:
            pci_address1 = Topology.get_interface_pci_addr(dut_node, dut_if1)
            if1_driver = Topology.get_interface_driver(dut_node, dut_if1)
            pci_address2 = Topology.get_interface_pci_addr(dut_node, dut_if2)
            if2_driver = Topology.get_interface_driver(dut_node, dut_if2)

            ssh = SSH()
            ssh.connect(dut_node)

            cmd = '{fwdir}/tests/dpdk/dpdk_scripts/cleanup_dpdk.sh ' \
                  '{drv1} {pci1} {drv2} {pci2}'.\
                  format(fwdir=Constants.REMOTE_FW_DIR, drv1=if1_driver,
                         pci1=pci_address1, drv2=if2_driver, pci2=pci_address2)

            ret_code, _, _ = ssh.exec_command_sudo(cmd, timeout=600)
            if ret_code != 0:
                raise RuntimeError(
                    'Failed to cleanup the dpdk at node {name}'.format(
                        name=dut_node['host']))
Example #20
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']))
Example #21
0
    def vpp_ip_probe(node, interface, addr, if_type="key"):
        """Run ip probe on VPP node.

        :param node: VPP node.
        :param interface: Interface key or name.
        :param addr: IPv4/IPv6 address.
        :param if_type: Interface type
        :type node: dict
        :type interface: str
        :type addr: str
        :type if_type: str
        :raises ValueError: If the if_type is unknown.
        :raises Exception: If vpp probe fails.
        """
        ssh = SSH()
        ssh.connect(node)

        if if_type == "key":
            iface_name = Topology.get_interface_name(node, interface)
        elif if_type == "name":
            iface_name = interface
        else:
            raise ValueError("if_type unknown: {0}".format(if_type))

        cmd = "{c}".format(c=Constants.VAT_BIN_NAME)
        cmd_input = 'exec ip probe {dev} {ip}'.format(dev=iface_name, ip=addr)
        (ret_code, _, _) = ssh.exec_command_sudo(cmd, cmd_input)
        if int(ret_code) != 0:
            raise Exception('VPP ip probe {dev} {ip} failed on {h}'.format(
                dev=iface_name, ip=addr, h=node['host']))
Example #22
0
    def _lxc_cgroup(self, state_object, value=''):
        """Manage the control group associated with a container.

        :param state_object: Specify the state object name.
        :param value: Specify the value to assign to the state object. If empty,
        then action is GET, otherwise is action SET.
        :type state_object: str
        :type value: str
        :raises RuntimeError: If failed to get/set for state of a container.
        """

        ssh = SSH()
        ssh.connect(self._node)

        ret, _, _ = ssh.exec_command_sudo(
            'lxc-cgroup --name {0} {1} {2}'.format(self._container_name,
                                                   state_object, value))
        if int(ret) != 0:
            if value:
                raise RuntimeError(
                    'Failed to set {0} of LXC container {1}.'.format(
                        state_object, self._container_name))
            else:
                raise RuntimeError(
                    'Failed to get {0} of LXC container {1}.'.format(
                        state_object, self._container_name))
Example #23
0
    def install_odl_features(node, path, *features):
        """Install required features on a running ODL client.

        :param node: Honeycomb node.
        :param path: Path to ODL client on node.
        :param features: Optional, list of additional features to install.
        :type node: dict
        :type path: str
        :type features: list
        """

        ssh = SSH()
        ssh.connect(node)

        cmd = "{path}/*karaf*/bin/client -u karaf feature:install " \
              "odl-restconf-all " \
              "odl-netconf-connector-all " \
              "odl-netconf-topology".format(path=path)
        for feature in features:
            cmd += " {0}".format(feature)

        ret_code, _, _ = ssh.exec_command_sudo(cmd, timeout=250)

        if int(ret_code) != 0:
            raise HoneycombError("Feature install did not succeed.")
Example #24
0
    def set_vpp_scheduling_rr(node):
        """Set real-time scheduling attributes of VPP worker threads to
        SCHED_RR with priority 1.

        :param node: DUT node with running VPP.
        :type node: dict
        :raises RuntimeError: Failed to retrieve PID for VPP worker threads.
        """
        ssh = SSH()
        ssh.connect(node)

        cmd = u"cat /proc/`pidof vpp`/task/*/stat | grep -i vpp_wk" \
            u" | awk '{print $1}'"

        for _ in range(3):
            ret, out, _ = ssh.exec_command_sudo(cmd)
            if ret == 0:
                try:
                    if not out:
                        raise ValueError
                except ValueError:
                    print(u"Reading VPP worker thread PID failed.")
                else:
                    for pid in out.split(u"\n"):
                        if pid and pid[0] != u"#":
                            SchedUtils.set_proc_scheduling_rr(node, int(pid))
                    break
        else:
            raise RuntimeError(
                u"Failed to retrieve PID for VPP worker threads.")
Example #25
0
    def get_huge_page_total(node, huge_size):
        """Get total number of huge pages in system.

        :param node: Node in the topology.
        :param huge_size: Size of hugepages.
        :type node: dict
        :type huge_size: int

        :returns: Total number of huge pages in system.
        :rtype: int
        :raises RuntimeError: If reading failed for three times.
        """
        # TODO: add numa aware option
        ssh = SSH()
        ssh.connect(node)

        for _ in range(3):
            ret_code, stdout, _ = ssh.exec_command_sudo(
                'cat /sys/kernel/mm/hugepages/hugepages-{0}kB/nr_hugepages'.
                format(huge_size))
            if ret_code == 0:
                try:
                    huge_total = int(stdout)
                except ValueError:
                    logger.trace('Reading total huge pages information failed')
                else:
                    break
        else:
            raise RuntimeError('Getting total huge pages information failed.')
        return huge_total
Example #26
0
    def set_proc_scheduling_rr(node, pid, priority=1):
        """Set real-time scheduling of a process to SCHED_RR with priority for
        specified PID.

        :param node: Node where to apply scheduling changes.
        :param pid: Process ID.
        :param priority: Realtime priority in range 1-99. Default is 1.
        :type node: dict
        :type pid: int
        :type priority: int
        :raises ValueError: Parameters out of allowed ranges.
        :raises RuntimeError: Failed to set policy for PID.
        """
        ssh = SSH()
        ssh.connect(node)

        if pid < 1:
            raise ValueError(u"SCHED_RR: PID must be higher then 1.")

        if 1 <= priority <= 99:
            cmd = f"chrt -r -p {priority} {pid}"
            ret, _, _ = ssh.exec_command_sudo(cmd)
            if ret != 0:
                raise RuntimeError(
                    f"SCHED_RR: Failed to set policy for PID {pid}.")
        else:
            raise ValueError(u"SCHED_RR: Priority must be in range 1-99.")
Example #27
0
    def clear_persisted_honeycomb_config(*nodes):
        """Remove configuration data persisted from last Honeycomb session.
        Default configuration will be used instead.

        :param nodes: List of DUTs to execute on.
        :type nodes: list
        :raises HoneycombError: If persisted configuration could not be removed.
        """
        cmd = "rm -rf {}/*".format(Const.REMOTE_HC_PERSIST)
        for node in nodes:
            if node['type'] == NodeType.DUT:
                ssh = SSH()
                ssh.connect(node)
                (ret_code, _, stderr) = ssh.exec_command_sudo(cmd)
                if ret_code != 0:
                    if "No such file or directory" not in stderr:
                        raise HoneycombError(
                            'Could not clear persisted '
                            'configuration on node {0}, {1}'.format(
                                node['host'], stderr))
                    else:
                        logger.info("Persistence data was not present on node"
                                    " {0}".format(node['host']))
                else:
                    logger.info("Persistence files removed on node {0}".format(
                        node['host']))
Example #28
0
    def restart_honeycomb_on_dut(node):
        """Restart Honeycomb on specified DUT nodes.

        This keyword restarts the Honeycomb service on specified DUTs. Use the
        keyword "Check Honeycomb Startup State" to check if the Honeycomb is up
        and running.

        :param node: Node to restart Honeycomb on.
        :type node: dict
        :raises HoneycombError: If Honeycomb fails to start.
        """

        logger.console("\n(re)Starting Honeycomb service on node {0}".format(
            node["host"]))

        cmd = "sudo service honeycomb restart"

        ssh = SSH()
        ssh.connect(node)
        (ret_code, _, _) = ssh.exec_command_sudo(cmd)
        if int(ret_code) != 0:
            raise HoneycombError(
                'Node {0} failed to restart Honeycomb.'.format(node['host']))
        else:
            logger.info(
                "Honeycomb service restart is in progress on node {0}".format(
                    node['host']))
Example #29
0
    def get_huge_page_size(node):
        """Get default size of huge pages in system.

        :param node: Node in the topology.
        :type node: dict
        :returns: Default size of free huge pages in system.
        :rtype: int
        :raises RuntimeError: If reading failed for three times.
        """
        ssh = SSH()
        ssh.connect(node)

        for _ in range(3):
            ret_code, stdout, _ = ssh.exec_command_sudo(
                "grep Hugepagesize /proc/meminfo | awk '{ print $2 }'")
            if ret_code == 0:
                try:
                    huge_size = int(stdout)
                except ValueError:
                    logger.trace('Reading huge page size information failed')
                else:
                    break
        else:
            raise RuntimeError('Getting huge page size information failed.')
        return huge_size
Example #30
0
    def vpp_set_if_ipv6_addr(node, iface_key, addr, prefix):
        """Set IPv6 address on VPP.

        :param node: VPP node.
        :param iface_key: Node interface key.
        :param addr: IPv6 address.
        :param prefix: IPv6 address prefix.
        :type node: dict
        :type iface_key: str
        :type addr: str
        :type prefix: str
        """
        sw_if_index = Topology.get_interface_sw_index(node, iface_key)
        with VatTerminal(node) as vat:
            vat.vat_terminal_exec_cmd_from_template('add_ip_address.vat',
                                                    sw_if_index=sw_if_index,
                                                    address=addr,
                                                    prefix_length=prefix)
            vat.vat_terminal_exec_cmd_from_template('set_if_state.vat',
                                                    sw_if_index=sw_if_index,
                                                    state='admin-up')

        ssh = SSH()
        ssh.connect(node)
        cmd_input = 'exec show int'
        (ret_code, stdout,
         stderr) = ssh.exec_command_sudo(Constants.VAT_BIN_NAME, cmd_input)
        logger.debug('ret: {0}'.format(ret_code))
        logger.debug('stdout: {0}'.format(stdout))
        logger.debug('stderr: {0}'.format(stderr))