示例#1
0
    def run_cli_cmd_on_all_sockets(node, cli_cmd, log=True):
        """Run a CLI command as cli_inband, on all sockets in topology file.

        :param node: Node to run command on.
        :param cli_cmd: The CLI command to be run on the node.
        :param log: If True, the response is logged.
        :type node: dict
        :type cli_cmd: str
        :type log: bool
        """
        sockets = Topology.get_node_sockets(node, socket_type=SocketType.PAPI)
        if sockets:
            for socket in sockets.values():
                PapiSocketExecutor.run_cli_cmd(
                    node, cli_cmd, log=log, remote_vpp_socket=socket
                )
示例#2
0
    def disconnect_all_sockets_by_node(cls, node):
        """Disconnect all socket connected client instance.

        Noop if not connected.

        Also remove the local sockets by deleting the temporary directory.
        Put disconnected client instances to the reuse list.
        The added attributes are not cleaned up,
        as their values will get overwritten on next connect.

        Call this method just before killing/restarting remote VPP instance.
        """
        sockets = Topology.get_node_sockets(node, socket_type=SocketType.PAPI)
        if sockets:
            for socket in sockets.values():
                # TODO: Remove sockets from topology.
                PapiSocketExecutor.disconnect_by_node_and_socket(node, socket)
        # Always attempt to disconnect the default socket.
        return cls.disconnect_by_node_and_socket(node)
示例#3
0
    def vpp_show_runtime(node, log_zeros=False):
        """Run "show runtime" CLI command.

        :param node: Node to run command on.
        :param log_zeros: Log also items with zero values.
        :type node: dict
        :type log_zeros: bool
        """
        args = dict(path=u"^/sys/node")
        sockets = Topology.get_node_sockets(node, socket_type=SocketType.STATS)
        if sockets:
            for socket in sockets.values():
                with PapiExecutor(node) as papi_exec:
                    stats = papi_exec.add(u"vpp-stats", **args).\
                        get_stats(socket=socket)[0]

                names = stats[u"/sys/node/names"]

                if not names:
                    return

                runtime = list()
                runtime_nz = list()

                for name in names:
                    runtime.append({u"name": name})

                for idx, runtime_item in enumerate(runtime):

                    calls_th = []
                    for thread in stats[u"/sys/node/calls"]:
                        calls_th.append(thread[idx])
                    runtime_item[u"calls"] = calls_th

                    vectors_th = []
                    for thread in stats[u"/sys/node/vectors"]:
                        vectors_th.append(thread[idx])
                    runtime_item[u"vectors"] = vectors_th

                    suspends_th = []
                    for thread in stats[u"/sys/node/suspends"]:
                        suspends_th.append(thread[idx])
                    runtime_item[u"suspends"] = suspends_th

                    clocks_th = []
                    for thread in stats[u"/sys/node/clocks"]:
                        clocks_th.append(thread[idx])
                    runtime_item[u"clocks"] = clocks_th

                    if (sum(calls_th) or sum(vectors_th) or sum(suspends_th)
                            or sum(clocks_th)):
                        runtime_nz.append(runtime_item)

                if log_zeros:
                    logger.info(
                        f"stats runtime ({node[u'host']} - {socket}):\n"
                        f"{pformat(runtime)}")
                else:
                    logger.info(
                        f"stats runtime ({node[u'host']} - {socket}):\n"
                        f"{pformat(runtime_nz)}")
        # Run also the CLI command, the above sometimes misses some info.
        PapiSocketExecutor.run_cli_cmd_on_all_sockets(node, u"show runtime")