diff options
author | Yaroslav Brustinov <ybrustin@cisco.com> | 2017-01-12 16:24:03 +0200 |
---|---|---|
committer | Yaroslav Brustinov <ybrustin@cisco.com> | 2017-01-12 16:24:03 +0200 |
commit | 83861b490b5ce17212830a425d7c8cfd00090c40 (patch) | |
tree | 8a2ee522cf6740d015de8153a726af9937d683fd /scripts/automation/trex_control_plane/stl | |
parent | 6cdb4a984508a27a94df24ba9dabf050f3c319fd (diff) |
Add help message for --no-scapy-server flag
Python API: fix arp resolve console message
Python API: retry ZMQ send/recv only for push_pcap
Console: portattr fix for readonly mode
Change-Id: I69587987deb4edfbe192ee422ce6aad74b1ecaf3
Signed-off-by: Yaroslav Brustinov <ybrustin@cisco.com>
Diffstat (limited to 'scripts/automation/trex_control_plane/stl')
3 files changed, 34 insertions, 31 deletions
diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py index e20de3da..21ae42f1 100755 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py @@ -449,16 +449,16 @@ class CCommLink(object): if not self.virtual: return self.rpc_link.disconnect() - def transmit(self, method_name, params = None, api_class = 'core'): + def transmit(self, method_name, params = None, api_class = 'core', retry = 0): if self.virtual: self._prompt_virtual_tx_msg() _, msg = self.rpc_link.create_jsonrpc_v2(method_name, params, api_class) print(msg) return else: - return self.rpc_link.invoke_rpc_method(method_name, params, api_class) + return self.rpc_link.invoke_rpc_method(method_name, params, api_class, retry = retry) - def transmit_batch(self, batch_list): + def transmit_batch(self, batch_list, retry = 0): if self.virtual: self._prompt_virtual_tx_msg() print([msg @@ -469,7 +469,7 @@ class CCommLink(object): for command in batch_list: batch.add(command.method, command.params, command.api_class) # invoke the batch - return batch.invoke() + return batch.invoke(retry = retry) def _prompt_virtual_tx_msg(self): print("Transmitting virtually over tcp://{server}:{port}".format(server=self.server, @@ -2997,7 +2997,7 @@ class STLClient(object): :parameters: ports - for which ports to apply a unique sniffer (each port gets a unique file) - retires - how many times to retry on each port (intervals of 100 milliseconds) + retries - how many times to retry on each port (intervals of 100 milliseconds) verbose - log for each request the response :raises: + :exe:'STLError' @@ -3015,7 +3015,7 @@ class STLClient(object): self.logger.post_cmd(rc) if verbose: - for x in filter(bool, rc.data()): + for x in filter(bool, listify(rc.data())): self.logger.log(format_text("{0}".format(x), 'bold')) if not rc: @@ -3757,7 +3757,7 @@ class STLClient(object): parsing_opts.SUPPORTED, ) - opts = parser.parse_args(line.split(), default_ports = self.get_acquired_ports(), verify_acquired = True) + opts = parser.parse_args(line.split(), default_ports = self.get_acquired_ports()) if not opts: return opts @@ -3767,8 +3767,9 @@ class STLClient(object): opts.flow_ctrl = parsing_opts.FLOW_CTRL_DICT.get(opts.flow_ctrl) # if no attributes - fall back to printing the status - if not list(filter(lambda x:x is not None, [opts.prom, opts.link, opts.led, opts.flow_ctrl, opts.supp])): - self.show_stats_line("--ps --port {0}".format(' '.join(str(port) for port in opts.ports))) + if not list(filter(lambda opt:opt[0] not in ('all_ports', 'ports') and opt[1] is not None, opts._get_kwargs())): + ports = opts.ports if opts.ports else self.get_all_ports() + self.show_stats_line("--ps --port {0}".format(' '.join(str(port) for port in ports))) return if opts.supp: @@ -3781,11 +3782,13 @@ class STLClient(object): print(' Flow control: %s' % info['fc_supported']) print('') else: - self.set_port_attr(opts.ports, - opts.prom, - opts.link, - opts.led, - opts.flow_ctrl) + if not opts.ports: + raise STLError('No acquired ports!') + self.set_port_attr(opts.ports, + opts.prom, + opts.link, + opts.led, + opts.flow_ctrl) diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_jsonrpc_client.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_jsonrpc_client.py index 72c9317a..db216532 100644 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_jsonrpc_client.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_jsonrpc_client.py @@ -32,7 +32,7 @@ class BatchMessage(object): id, msg = self.rpc_client.create_jsonrpc_v2(method_name, params, api_class, encode = False) self.batch_list.append(msg) - def invoke(self, block = False, chunk_size = 500000): + def invoke(self, block = False, chunk_size = 500000, retry = 0): if not self.rpc_client.connected: return RC_ERR("Not connected to server") @@ -54,7 +54,7 @@ class BatchMessage(object): return response_batch else: batch_json = json.dumps(self.batch_list) - return self.rpc_client.send_msg(batch_json) + return self.rpc_client.send_msg(batch_json, retry = retry) # JSON RPC v2.0 client @@ -127,16 +127,16 @@ class JsonRpcClient(object): return id, msg - def invoke_rpc_method (self, method_name, params = None, api_class = 'core'): + def invoke_rpc_method (self, method_name, params = None, api_class = 'core', retry = 0): if not self.connected: return RC_ERR("Not connected to server") id, msg = self.create_jsonrpc_v2(method_name, params, api_class) - return self.send_msg(msg) + return self.send_msg(msg, retry = retry) - def send_msg (self, msg): + def send_msg (self, msg, retry = 0): # print before if self.logger.check_verbose(self.logger.VERBOSE_HIGH): self.verbose_msg("Sending Request To Server:\n\n" + self.pretty_json(msg) + "\n") @@ -145,9 +145,9 @@ class JsonRpcClient(object): buffer = msg.encode() if self.zipper.check_threshold(buffer): - response = self.send_raw_msg(self.zipper.compress(buffer)) + response = self.send_raw_msg(self.zipper.compress(buffer), retry = retry) else: - response = self.send_raw_msg(buffer) + response = self.send_raw_msg(buffer, retry = retry) if not response: return response @@ -175,16 +175,16 @@ class JsonRpcClient(object): # low level send of string message - def send_raw_msg (self, msg): + def send_raw_msg (self, msg, retry = 0): - tries = 0 + retry_left = retry while True: try: self.socket.send(msg) break except zmq.Again: - tries += 1 - if tries > 5: + retry_left -= 1 + if retry_left < 0: self.disconnect() return RC_ERR("*** [RPC] - Failed to send message to server") @@ -193,14 +193,14 @@ class JsonRpcClient(object): self.reconnect() raise e - tries = 0 + retry_left = retry while True: try: response = self.socket.recv() break except zmq.Again: - tries += 1 - if tries > 5: + retry_left -= 1 + if retry_left < 0: self.disconnect() return RC_ERR("*** [RPC] - Failed to get server response from {0}".format(self.transport)) diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_port.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_port.py index 8b6b2e2e..a9509ee9 100644 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_port.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_port.py @@ -264,7 +264,7 @@ class Port(object): def add_streams (self, streams_list): # listify - streams_list = streams_list if isinstance(streams_list, list) else [streams_list] + streams_list = listify(streams_list) lookup = {} @@ -338,7 +338,7 @@ class Port(object): def remove_streams (self, stream_id_list): # single element to list - stream_id_list = stream_id_list if isinstance(stream_id_list, list) else [stream_id_list] + stream_id_list = listify(stream_id_list) # verify existance if not all([stream_id in self.streams for stream_id in stream_id_list]): @@ -751,7 +751,7 @@ class Port(object): "slave_handler": slave_handler, "min_ipg_usec": min_ipg_usec if min_ipg_usec else 0} - rc = self.transmit("push_remote", params) + rc = self.transmit("push_remote", params, retry = 4) if rc.bad(): return self.err(rc.err()) |