summaryrefslogtreecommitdiffstats
path: root/scripts/automation
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/automation')
-rw-r--r--scripts/automation/trex_control_plane/client_utils/jsonrpc_client.py35
-rwxr-xr-xscripts/automation/trex_control_plane/common/trex_exceptions.py14
-rw-r--r--scripts/automation/trex_control_plane/console/trex_status.py2
-rw-r--r--scripts/automation/trex_control_plane/examples/interactive_stateless.py128
4 files changed, 40 insertions, 139 deletions
diff --git a/scripts/automation/trex_control_plane/client_utils/jsonrpc_client.py b/scripts/automation/trex_control_plane/client_utils/jsonrpc_client.py
index 89ac9127..c6b22218 100644
--- a/scripts/automation/trex_control_plane/client_utils/jsonrpc_client.py
+++ b/scripts/automation/trex_control_plane/client_utils/jsonrpc_client.py
@@ -4,8 +4,20 @@ import outer_packages
import zmq
import json
import general_utils
+import re
from time import sleep
+class bcolors:
+ BLUE = '\033[94m'
+ GREEN = '\033[32m'
+ YELLOW = '\033[93m'
+ RED = '\033[31m'
+ MAGENTA = '\033[35m'
+ ENDC = '\033[0m'
+ BOLD = '\033[1m'
+ UNDERLINE = '\033[4m'
+
+
class JsonRpcClient(object):
def __init__ (self, default_server, default_port):
@@ -24,8 +36,25 @@ class JsonRpcClient(object):
return rc
- def pretty_json (self, json_str):
- return json.dumps(json.loads(json_str), indent = 4, separators=(',', ': '), sort_keys = True)
+ def pretty_json (self, json_str, use_colors = True):
+ pretty_str = json.dumps(json.loads(json_str), indent = 4, separators=(',', ': '), sort_keys = True)
+
+ if not use_colors:
+ return pretty_str
+
+ try:
+ # int numbers
+ pretty_str = re.sub(r'([ ]*:[ ]+)(\-?[1-9][0-9]*[^.])',r'\1{0}\2{1}'.format(bcolors.BLUE, bcolors.ENDC), pretty_str)
+ # float
+ pretty_str = re.sub(r'([ ]*:[ ]+)(\-?[1-9][0-9]*\.[0-9]+)',r'\1{0}\2{1}'.format(bcolors.MAGENTA, bcolors.ENDC), pretty_str)
+ # strings
+
+ pretty_str = re.sub(r'([ ]*:[ ]+)("[^"]*")',r'\1{0}\2{1}'.format(bcolors.RED, bcolors.ENDC), pretty_str)
+ pretty_str = re.sub(r"('[^']*')", r'{0}\1{1}'.format(bcolors.MAGENTA, bcolors.RED), pretty_str)
+ except :
+ pass
+
+ return pretty_str
def verbose_msg (self, msg):
if not self.verbose:
@@ -115,7 +144,7 @@ class JsonRpcClient(object):
return self.invoke_rpc_method("get_status")
def query_rpc_server(self):
- return self.invoke_rpc_method("get_reg_cmds")
+ return self.invoke_rpc_method("get_supported_cmds")
def set_verbose(self, mode):
diff --git a/scripts/automation/trex_control_plane/common/trex_exceptions.py b/scripts/automation/trex_control_plane/common/trex_exceptions.py
index a2a64e19..1353fd00 100755
--- a/scripts/automation/trex_control_plane/common/trex_exceptions.py
+++ b/scripts/automation/trex_control_plane/common/trex_exceptions.py
@@ -17,13 +17,13 @@ class RPCError(Exception):
self.data = remote_data
self.args = (code, self.msg, remote_data)
- def __str__(self):
- return self.__repr__()
- def __repr__(self):
- if self.args[2] is not None:
- return u"[errcode:%r] %r. Extended data: %r" % (self.args[0], self.args[1], self.args[2])
- else:
- return u"[errcode:%r] %r" % (self.args[0], self.args[1])
+ def __str__(self):
+ return self.__repr__()
+ def __repr__(self):
+ if self.args[2] is not None:
+ return u"[errcode:%r] %r. Extended data: %r" % (self.args[0], self.args[1], self.args[2])
+ else:
+ return u"[errcode:%r] %r" % (self.args[0], self.args[1])
class TRexException(RPCError):
"""
diff --git a/scripts/automation/trex_control_plane/console/trex_status.py b/scripts/automation/trex_control_plane/console/trex_status.py
index 8ee669b5..54853ea3 100644
--- a/scripts/automation/trex_control_plane/console/trex_status.py
+++ b/scripts/automation/trex_control_plane/console/trex_status.py
@@ -126,7 +126,7 @@ class TrexStatus():
self.max_x = self.stdscr.getmaxyx()[1]
# create cls panel
- self.main_panel = TrexStatusPanel(int(self.max_y * 0.8), self.max_x / 2, 0,0, "Trex Activity:")
+ self.main_panel = TrexStatusPanel(int(self.max_y * 0.8), self.max_x / 2, 0,0, "Trex Ports:")
self.general_panel = TrexStatusPanel(int(self.max_y * 0.6), self.max_x / 2, 0, self.max_x /2, "General Statistics:")
diff --git a/scripts/automation/trex_control_plane/examples/interactive_stateless.py b/scripts/automation/trex_control_plane/examples/interactive_stateless.py
deleted file mode 100644
index 7c25b4ef..00000000
--- a/scripts/automation/trex_control_plane/examples/interactive_stateless.py
+++ /dev/null
@@ -1,128 +0,0 @@
-#!/router/bin/python
-
-import trex_root_path
-from client.trex_stateless_client import *
-from common.trex_exceptions import *
-import cmd
-from termstyle import termstyle
-# import termstyle
-import os
-from argparse import ArgumentParser
-import socket
-import errno
-import ast
-import json
-
-
-class InteractiveStatelessTRex(cmd.Cmd):
-
- intro = termstyle.green("\nInteractive shell to play with Cisco's TRex stateless API.\
- \nType help to view available pre-defined scenarios\n(c) All rights reserved.\n")
- prompt = '> '
-
- def __init__(self, trex_host, trex_port, virtual, verbose):
- cmd.Cmd.__init__(self)
-
- self.verbose = verbose
- self.virtual = virtual
- self.trex = CTRexStatelessClient(trex_host, trex_port, self.virtual)
- self.DEFAULT_RUN_PARAMS = dict(m=1.5,
- nc=True,
- p=True,
- d=100,
- f='avl/sfr_delay_10_1g.yaml',
- l=1000)
- self.run_params = dict(self.DEFAULT_RUN_PARAMS)
-
- def do_transmit(self, line):
- """Transmits a request over using a given link to server.\
- \nuse: transmit [method_name] [method_params]"""
- if line == "":
- print "\nUsage: [method name] [param dict as string]\n"
- print "Example: rpc test_add {'x': 12, 'y': 17}\n"
- return
-
- args = line.split(' ', 1) # args will have max length of 2
- method_name = args[0]
- params = None
- bad_parse = False
-
- try:
- params = ast.literal_eval(args[1])
- if not isinstance(params, dict):
- bad_parse = True
- except ValueError as e1:
- bad_parse = True
- except SyntaxError as e2:
- bad_parse = True
-
- if bad_parse:
- print "\nValue should be a valid dict: '{0}'".format(args[1])
- print "\nUsage: [method name] [param dict as string]\n"
- print "Example: rpc test_add {'x': 12, 'y': 17}\n"
- return
-
- response = self.trex.transmit(method_name, params)
- if not self.virtual:
- # expect response
- rc, msg = response
- if rc:
- print "\nServer Response:\n\n" + json.dumps(msg) + "\n"
- else:
- print "\n*** " + msg + "\n"
-
-
-
-
-
- def do_push_files(self, filepaths):
- """Pushes a custom file to be stored locally on T-Rex server.\
- \nPush multiple files by specifying their path separated by ' ' (space)."""
- try:
- filepaths = filepaths.split(' ')
- print termstyle.green("*** Starting pushing files ({trex_files}) to T-Rex. ***".format(
- trex_files=', '.join(filepaths))
- )
- ret_val = self.trex.push_files(filepaths)
- if ret_val:
- print termstyle.green("*** End of T-Rex push_files method (success) ***")
- else:
- print termstyle.magenta("*** End of T-Rex push_files method (failed) ***")
-
- except IOError as inst:
- print termstyle.magenta(inst)
-
-if __name__ == "__main__":
- parser = ArgumentParser(description=termstyle.cyan('Run TRex client stateless API demos and scenarios.'),
- usage="client_interactive_example [options]")
-
- parser.add_argument('-v', '--version', action='version', version='%(prog)s 1.0 \t (C) Cisco Systems Inc.\n')
-
- parser.add_argument("-t", "--trex-host", required = True, dest="trex_host",
- action="store", help="Specify the hostname or ip to connect with T-Rex server.",
- metavar="HOST" )
- parser.add_argument("-p", "--trex-port", type=int, default = 5050, metavar="PORT", dest="trex_port",
- help="Select port on which the T-Rex server listens. Default port is 5050.", action="store")
- # parser.add_argument("-m", "--maxhist", type=int, default = 100, metavar="SIZE", dest="hist_size",
- # help="Specify maximum history size saved at client side. Default size is 100.", action="store")
- parser.add_argument("--virtual", dest="virtual",
- action="store_true",
- help="Switch ON virtual option at TRex client. Default is: OFF.",
- default=False)
- parser.add_argument("--verbose", dest="verbose",
- action="store_true",
- help="Switch ON verbose option at TRex client. Default is: OFF.",
- default=False)
- args = parser.parse_args()
-
- try:
- InteractiveStatelessTRex(**vars(args)).cmdloop()
-
- except KeyboardInterrupt:
- print termstyle.cyan('Bye Bye!')
- exit(-1)
- except socket.error, e:
- if e.errno == errno.ECONNREFUSED:
- raise socket.error(errno.ECONNREFUSED,
- "Connection from T-Rex server was terminated. \
- Please make sure the server is up.")