summaryrefslogtreecommitdiffstats
path: root/scripts/automation
diff options
context:
space:
mode:
authorimarom <imarom@cisco.com>2015-12-14 11:03:53 -0500
committerimarom <imarom@cisco.com>2015-12-14 11:05:07 -0500
commitd71dbce9695f348b2e52e00c9efd53cb89c62aa5 (patch)
treebb4727b416dac5f482545ce0e5ba9686db91b8ea /scripts/automation
parent3f94a09f66657970636a532aac9411ad6a5290ad (diff)
bugs fixes
1. ignore your own force acquire of ports 2. TUI fixes
Diffstat (limited to 'scripts/automation')
-rw-r--r--scripts/automation/trex_control_plane/client/trex_port.py4
-rwxr-xr-xscripts/automation/trex_control_plane/client/trex_stateless_client.py37
-rwxr-xr-xscripts/automation/trex_control_plane/console/trex_console.py28
-rw-r--r--scripts/automation/trex_control_plane/console/trex_tui.py2
4 files changed, 57 insertions, 14 deletions
diff --git a/scripts/automation/trex_control_plane/client/trex_port.py b/scripts/automation/trex_control_plane/client/trex_port.py
index 4f82e86a..0934313f 100644
--- a/scripts/automation/trex_control_plane/client/trex_port.py
+++ b/scripts/automation/trex_control_plane/client/trex_port.py
@@ -18,7 +18,7 @@ class Port(object):
STATE_PAUSE: "PAUSE"}
- def __init__ (self, port_id, speed, driver, user, comm_link):
+ def __init__ (self, port_id, speed, driver, user, comm_link, session_id):
self.port_id = port_id
self.state = self.STATE_IDLE
self.handler = None
@@ -30,6 +30,7 @@ class Port(object):
self.speed = speed
self.streams = {}
self.profile = None
+ self.session_id = session_id
self.port_stats = trex_stats.CPortStats(self)
@@ -47,6 +48,7 @@ class Port(object):
def acquire(self, force = False):
params = {"port_id": self.port_id,
"user": self.user,
+ "session_id": self.session_id,
"force": force}
command = RpcCmdData("acquire", params)
diff --git a/scripts/automation/trex_control_plane/client/trex_stateless_client.py b/scripts/automation/trex_control_plane/client/trex_stateless_client.py
index 899805cf..0d52359d 100755
--- a/scripts/automation/trex_control_plane/client/trex_stateless_client.py
+++ b/scripts/automation/trex_control_plane/client/trex_stateless_client.py
@@ -46,11 +46,11 @@ class CTRexStatelessClient(object):
"""docstring for CTRexStatelessClient"""
# verbose levels
- VERBOSE_SILENCE = 0
+ VERBOSE_QUIET = 0
VERBOSE_REGULAR = 1
VERBOSE_HIGH = 2
- def __init__(self, username, server="localhost", sync_port = 5050, async_port = 4500, virtual=False):
+ def __init__(self, username, server="localhost", sync_port = 5050, async_port = 4500, quiet = False, virtual = False):
super(CTRexStatelessClient, self).__init__()
self.user = username
@@ -58,7 +58,10 @@ class CTRexStatelessClient(object):
self.comm_link = CTRexStatelessClient.CCommLink(server, sync_port, virtual, self.prn_func)
# default verbose level
- self.verbose = self.VERBOSE_REGULAR
+ if not quiet:
+ self.verbose = self.VERBOSE_REGULAR
+ else:
+ self.verbose = self.VERBOSE_QUIET
self.ports = {}
self._connection_info = {"server": server,
@@ -79,7 +82,7 @@ class CTRexStatelessClient(object):
self.events = []
-
+ self.session_id = random.getrandbits(32)
self.read_only = False
self.connected = False
@@ -90,9 +93,15 @@ class CTRexStatelessClient(object):
return self.ports.get(port_id, None)
- def get_server (self):
+ # connection server ip
+ def get_server_ip (self):
return self.comm_link.get_server()
+ # connection server port
+ def get_server_port (self):
+ return self.comm_link.get_port()
+
+
################# events handler ######################
def add_event_log (self, msg, ev_type, show = False):
@@ -107,7 +116,7 @@ class CTRexStatelessClient(object):
if show:
self.prn_func(format_text("\n{:^8} - {:}".format(prefix, format_text(msg, 'bold'))))
-
+
def handle_async_stats_update(self, dump_data):
global_stats = {}
@@ -185,8 +194,16 @@ class CTRexStatelessClient(object):
# port was stolen...
elif (type == 5):
+ session_id = data['session_id']
+
+ # false alarm, its us
+ if session_id == self.session_id:
+ return
+
port_id = int(data['port_id'])
- ev = "Port {0} was forcely taken".format(port_id)
+ who = data['who']
+
+ ev = "Port {0} was forcely taken by '{1}'".format(port_id, who)
# call the handler
self.async_event_port_forced_acquired(port_id)
@@ -335,7 +352,7 @@ class CTRexStatelessClient(object):
speed = self.system_info['ports'][port_id]['speed']
driver = self.system_info['ports'][port_id]['driver']
- self.ports[port_id] = Port(port_id, speed, driver, self.user, self.comm_link)
+ self.ports[port_id] = Port(port_id, speed, driver, self.user, self.comm_link, self.session_id)
# sync the ports
@@ -689,6 +706,7 @@ class CTRexStatelessClient(object):
# reset
def cmd_reset(self):
+ #self.release(self.get_acquired_ports())
rc = self.acquire(force = True)
rc.annotate("Force acquiring all ports:")
@@ -1176,6 +1194,9 @@ class CTRexStatelessClient(object):
def get_server (self):
return self.server
+ def get_port (self):
+ return self.port
+
def set_verbose(self, mode):
self.verbose = mode
return self.rpc_link.set_verbose(mode)
diff --git a/scripts/automation/trex_control_plane/console/trex_console.py b/scripts/automation/trex_control_plane/console/trex_console.py
index 325ba514..fe6dfe12 100755
--- a/scripts/automation/trex_control_plane/console/trex_console.py
+++ b/scripts/automation/trex_control_plane/console/trex_console.py
@@ -172,7 +172,7 @@ class TRexConsole(TRexGeneralCmd):
def get_console_identifier(self):
return "{context}_{server}".format(context=self.__class__.__name__,
- server=self.stateless_client.get_server())
+ server=self.stateless_client.get_server_ip())
def register_main_console_methods(self):
main_names = set(self.trex_console.get_names()).difference(set(dir(self.__class__)))
@@ -450,6 +450,7 @@ class TRexConsole(TRexGeneralCmd):
self.stateless_client.clear_events()
print format_text("\n\nEvent log was cleared\n\n")
+
# tui
@verify_connected
def do_tui (self, line):
@@ -465,15 +466,26 @@ class TRexConsole(TRexGeneralCmd):
return
if opts.xterm:
- subprocess.Popen(['xterm', '-geometry', '105x40', '-e', './trex-console', '-t'])
+ exe = ''
+ if os.path.isfile('/usr/bin/wmctrl'):
+ exe += '/usr/bin/wmctrl -r trex_tui -b add,above;'
+
+ exe += './trex-console -t -q -s {0} -p {1}'.format(self.stateless_client.get_server_ip(), self.stateless_client.get_server_port())
+
+ cmd = ['xterm', '-geometry', '105x40', '-title', 'trex_tui', '-e', exe]
+ subprocess.Popen(cmd)
+
return
save_verbose = self.stateless_client.get_verbose()
- self.stateless_client.set_verbose(self.stateless_client.VERBOSE_SILENCE)
+ self.stateless_client.set_verbose(self.stateless_client.VERBOSE_QUIET)
self.tui.show()
self.stateless_client.set_verbose(save_verbose)
+ def help_tui (self):
+ do_tui("-h")
+
# quit function
def do_quit(self, line):
'''Exit the client\n'''
@@ -568,6 +580,11 @@ def setParserOptions():
action="store_true", help="Starts with TUI mode",
default = False)
+
+ parser.add_argument("-q", "--quiet", dest="quiet",
+ action="store_true", help="Starts with all outputs suppressed",
+ default = False)
+
return parser
@@ -576,9 +593,10 @@ def main():
options = parser.parse_args()
# Stateless client connection
- stateless_client = CTRexStatelessClient(options.user, options.server, options.port, options.pub)
+ stateless_client = CTRexStatelessClient(options.user, options.server, options.port, options.pub, options.quiet)
- print "\nlogged as {0}".format(format_text(options.user, 'bold'))
+ if not options.quiet:
+ print "\nlogged as {0}".format(format_text(options.user, 'bold'))
# TUI or no acquire will give us READ ONLY mode
if options.tui or not options.acquire:
diff --git a/scripts/automation/trex_control_plane/console/trex_tui.py b/scripts/automation/trex_control_plane/console/trex_tui.py
index 3a89097f..c8cdaa16 100644
--- a/scripts/automation/trex_control_plane/console/trex_tui.py
+++ b/scripts/automation/trex_control_plane/console/trex_tui.py
@@ -393,6 +393,7 @@ class TrexTUI():
def clear_screen (self):
os.system('clear')
+ #sys.stderr.write("\x1b[2J\x1b[H")
@@ -465,3 +466,4 @@ class TrexTUI():
def get_state (self):
return self.state
+