Esempio n. 1
0
    def start(self, ports=None, *args, **kwargs):
        # pylint: disable=keyword-arg-before-vararg
        # NOTE(ralonsoh): defining keyworded arguments before variable
        # positional arguments is a bug. This function definition doesn't work
        # in Python 2, although it works in Python 3. Reference:
        # https://www.python.org/dev/peps/pep-3102/
        cmd = "sudo fuser -n tcp {0.SYNC_PORT} {0.ASYNC_PORT} -k > /dev/null 2>&1"
        self.ssh_helper.execute(cmd.format(self))

        self.ssh_helper.execute("sudo pkill -9 rex > /dev/null 2>&1")

        # We MUST default to 1 because TRex won't work on single-queue devices with
        # more than one core per port
        # We really should be trying to find the number of queues in the driver,
        # but there doesn't seem to be a way to do this
        # TRex Error: the number of cores should be 1 when the driver
        # support only one tx queue and one rx queue. Please use -c 1
        threads_per_port = try_int(self.scenario_helper.options.get("queues_per_port"), 1)

        trex_path = self.ssh_helper.join_bin_path("trex", "scripts")
        path = get_nsb_option("trex_path", trex_path)

        cmd = "./t-rex-64 --no-scapy-server -i -c {} --cfg '{}'".format(threads_per_port,
                                                                        self.CONF_FILE)

        if self.scenario_helper.options.get("trex_server_debug"):
            # if there are errors we want to see them
            redir = ""
        else:
            redir = ">/dev/null"
        # we have to sudo cd because the path might be owned by root
        trex_cmd = """sudo bash -c "cd '{}' ; {}" {}""".format(path, cmd, redir)
        LOG.debug(trex_cmd)
        self.ssh_helper.execute(trex_cmd)
    def start(self, ports=None, *args, **kwargs):
        cmd = "sudo fuser -n tcp {0.SYNC_PORT} {0.ASYNC_PORT} -k > /dev/null 2>&1"
        self.ssh_helper.execute(cmd.format(self))

        self.ssh_helper.execute("sudo pkill -9 rex > /dev/null 2>&1")

        # We MUST default to 1 because TRex won't work on single-queue devices with
        # more than one core per port
        # We really should be trying to find the number of queues in the driver,
        # but there doesn't seem to be a way to do this
        # TRex Error: the number of cores should be 1 when the driver
        # support only one tx queue and one rx queue. Please use -c 1
        threads_per_port = try_int(
            self.scenario_helper.options.get("queues_per_port"), 1)

        trex_path = self.ssh_helper.join_bin_path("trex", "scripts")
        path = get_nsb_option("trex_path", trex_path)

        cmd = "./t-rex-64 --no-scapy-server -i -c {} --cfg '{}'".format(
            threads_per_port, self.CONF_FILE)

        if self.scenario_helper.options.get("trex_server_debug"):
            # if there are errors we want to see them
            redir = ""
        else:
            redir = ">/dev/null"
        # we have to sudo cd because the path might be owned by root
        trex_cmd = """sudo bash -c "cd '{}' ; {}" {}""".format(
            path, cmd, redir)
        LOG.debug(trex_cmd)
        self.ssh_helper.execute(trex_cmd)
Esempio n. 3
0
 def getitem(obj, name):
     # if integer then list index
     name = try_int(name)
     try:
         return obj[name]
     except (KeyError, TypeError, IndexError):
         return default
Esempio n. 4
0
 def port_stats(self, ports):
     """get counter values from a specific port"""
     tot_result = [0] * 12
     for port in ports:
         self.put_command("port_stats {}\n".format(port))
         ret = [try_int(s, 0) for s in self.get_data().split(",")]
         tot_result = [sum(x) for x in zip(tot_result, ret)]
     return tot_result
Esempio n. 5
0
 def getitem(obj, name):
     # try string then convert to int
     try:
         return obj[name]
     except (KeyError, TypeError, IndexError):
         name = try_int(name)
         try:
             return obj[name]
         except (KeyError, TypeError, IndexError):
             return default
Esempio n. 6
0
    def __new__(cls, *args):
        try:
            matches = cls.CORE_RE.search(str(args[0]))
            if matches:
                args = matches.groups()

            return super(CoreSocketTuple, cls).__new__(cls, int(args[0]), try_int(args[1], 0),
                                                       'h' if args[2] else '')

        except (AttributeError, TypeError, IndexError, ValueError):
            raise ValueError('Invalid core spec {}'.format(args))
Esempio n. 7
0
    def __init__(self,
                 user,
                 host,
                 port=None,
                 pkey=None,
                 key_filename=None,
                 password=None,
                 name=None):
        """Initialize SSH client.

        :param user: ssh username
        :param host: hostname or ip address of remote ssh server
        :param port: remote ssh port
        :param pkey: RSA or DSS private key string or file object
        :param key_filename: private key filename
        :param password: password
        """
        self.name = name
        if name:
            self.log = logging.getLogger(__name__ + '.' + self.name)
        else:
            self.log = logging.getLogger(__name__)

        self.wait_timeout = self.DEFAULT_WAIT_TIMEOUT
        self.user = user
        self.host = host
        # everybody wants to debug this in the caller, do it here instead
        self.log.debug("user:%s host:%s", user, host)

        # we may get text port from YAML, convert to int
        self.port = try_int(port, self.SSH_PORT)
        self.pkey = self._get_pkey(pkey) if pkey else None
        self.password = password
        self.key_filename = key_filename
        self._client = False
        # paramiko loglevel debug will output ssh protocl debug
        # we don't ever really want that unless we are debugging paramiko
        # ssh issues
        if os.environ.get("PARAMIKO_DEBUG", "").lower() == "true":
            logging.getLogger("paramiko").setLevel(logging.DEBUG)
        else:
            logging.getLogger("paramiko").setLevel(logging.WARN)