diff options
Diffstat (limited to 'scripts/automation')
3 files changed, 89 insertions, 65 deletions
diff --git a/scripts/automation/trex_control_plane/stl/console/trex_console.py b/scripts/automation/trex_control_plane/stl/console/trex_console.py index 02a99893..7fd34e6e 100755 --- a/scripts/automation/trex_control_plane/stl/console/trex_console.py +++ b/scripts/automation/trex_control_plane/stl/console/trex_console.py @@ -459,7 +459,6 @@ class TRexConsole(TRexGeneralCmd): self.stateless_client.start_line(line) - def help_start(self): @@ -590,7 +589,7 @@ class TRexConsole(TRexGeneralCmd): with self.stateless_client.logger.supress(): - self.tui.show(self) + self.tui.show(self.stateless_client) def help_tui (self): diff --git a/scripts/automation/trex_control_plane/stl/console/trex_tui.py b/scripts/automation/trex_control_plane/stl/console/trex_tui.py index 1d7892bb..f60ee170 100644 --- a/scripts/automation/trex_control_plane/stl/console/trex_tui.py +++ b/scripts/automation/trex_control_plane/stl/console/trex_tui.py @@ -378,17 +378,16 @@ class TrexTUIPanelManager(): else: return False - #msg = "" self.generate_legend() return True - if msg == None: - return False - else: - if msg: - self.log.add_event(msg) - return True + #if msg == None: + # return False + #else: + # if msg: + # self.log.add_event(msg) + # return True # actions @@ -438,17 +437,7 @@ class TrexTUI(): self.stateless_client = stateless_client self.pm = TrexTUIPanelManager(self) - - - - def handle_key_input (self): - # try to read a single key - ch = os.read(sys.stdin.fileno(), 1).decode() - if ch: - return (self.pm.handle_key(ch), True) - else: - return (True, False) - + def clear_screen (self): #os.system('clear') @@ -456,8 +445,8 @@ class TrexTUI(): sys.stdout.write("\x1b[2J\x1b[H") - def show (self, cmd, show_log = False): - with AsyncKeys(cmd) as async_keys: + def show (self, client, show_log = False): + with AsyncKeys(client) as async_keys: self.async_keys = async_keys self.show_internal(show_log) @@ -476,7 +465,7 @@ class TrexTUI(): status = self.async_keys.tick(self.pm) self.draw_screen(status) - if not status: + if status == AsyncKeys.STATUS_NONE: time.sleep(0.001) # regular state @@ -561,8 +550,8 @@ class AsyncKeys: STATUS_REDRAW_KEYS = 1 STATUS_REDRAW_ALL = 2 - def __init__ (self, cmd): - self.engine_console = AsyncKeysEngineConsole(self, cmd) + def __init__ (self, client): + self.engine_console = AsyncKeysEngineConsole(self, client) self.engine_legend = AsyncKeysEngineLegend(self) self.engine = self.engine_console @@ -644,21 +633,29 @@ class AsyncKeysEngineLegend: # console engine class AsyncKeysEngineConsole: - def __init__ (self, async, cmd): + def __init__ (self, async, client): self.async = async - self.cmd = cmd + self.client = client self.lines = deque(maxlen = 100) - # fetch readline history + self.ac = {'start' : client.start_line, + 'stop' : client.stop_line, + 'pause' : client.pause_line, + 'resume': client.resume_line, + 'update': client.update_line, + 'quit' : None, + 'exit' : None} + + # fetch readline history and add relevants for i in range(0, readline.get_current_history_length()): - self.lines.appendleft(CmdLine(readline.get_history_item(i))) + cmd = readline.get_history_item(i) + if cmd and cmd.split()[0] in self.ac: + self.lines.appendleft(CmdLine(cmd)) # new line self.lines.appendleft(CmdLine('')) self.line_index = 0 - - self.ac = ['start', 'stop', 'pause', 'resume', 'update', 'quit', 'exit'] - + self.last_status = '' def get_type (self): return self.async.MODE_CONSOLE @@ -727,6 +724,12 @@ class AsyncKeysEngineConsole: return AsyncKeys.STATUS_REDRAW_KEYS + def split_cmd (self, cmd): + s = cmd.split(' ', 1) + op = s[0] + param = s[1] if len(s) == 2 else '' + return op, param + def handle_cmd (self): cmd = self.lines[self.line_index].get().strip() @@ -736,7 +739,11 @@ class AsyncKeysEngineConsole: if cmd in ['quit', 'exit', 'q']: raise TUIQuit() - self.cmd.onecmd(cmd) + op, param = self.split_cmd(cmd) + + func = self.ac.get(op) + if func: + func_rc = func(param) # take out the empty line empty_line = self.lines.popleft() @@ -754,10 +761,16 @@ class AsyncKeysEngineConsole: line.invalidate() assert(self.lines[0].modified == False) + if not func: + self.last_status = "unknown command: '{0}'".format(cmd.split()[0]) + else: + self.last_status = format_text("[OK]", 'green') if func_rc else format_text(str(func_rc).replace('\n', ''), 'red') + def draw (self): sys.stdout.write("\nPress 'ESC' for navigation panel...\n") - sys.stdout.write("\n" + "tui>" + self.lines[self.line_index].get()) + sys.stdout.write("status: {0}\n".format(format_text(self.last_status, 'red'))) + sys.stdout.write("\ntui>" + self.lines[self.line_index].get()) # a readline alike command line - can be modified during edit 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 575d4025..153985ae 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 @@ -2428,13 +2428,14 @@ class STLClient(object): rc = f(*args) except STLError as e: client.logger.log("Log:\n" + format_text(e.brief() + "\n", 'bold')) - return + return RC_ERR(e.brief()) # if got true - print time if rc: delta = time.time() - time1 client.logger.log(format_time(delta) + "\n") + return rc return wrap @@ -2587,14 +2588,14 @@ class STLClient(object): opts = parser.parse_args(line.split(), default_ports = self.get_acquired_ports(), verify_acquired = True) if opts is None: - return + return RC_ERR("invalid arguments for 'start'") active_ports = list_intersect(self.get_active_ports(), opts.ports) if active_ports: if not opts.force: msg = "Port(s) {0} are active - please stop them or add '--force'\n".format(active_ports) self.logger.log(format_text(msg, 'bold')) - return + return RC_ERR(msg) else: self.stop(active_ports) @@ -2612,8 +2613,10 @@ class STLClient(object): else: # must be exact if len(opts.ports) != len(opts.tunables): - self.logger.log('tunables section count must be 1 or exactly as the number of ports: got {0}'.format(len(opts.tunables))) - return + msg = 'tunables section count must be 1 or exactly as the number of ports: got {0}'.format(len(opts.tunables)) + self.logger.log(msg) + return RC_ERR(msg) + tunables = opts.tunables @@ -2633,9 +2636,10 @@ class STLClient(object): self.add_streams(profile.get_streams(), ports = port) except STLError as e: - self.logger.log(format_text("\nError while loading profile '{0}'\n".format(opts.file[0]), 'bold')) + msg = format_text("\nError while loading profile '{0}'\n".format(opts.file[0]), 'bold') + self.logger.log(msg) self.logger.log(e.brief() + "\n") - return + return RC_ERR(msg) if opts.dry: @@ -2647,8 +2651,7 @@ class STLClient(object): opts.duration, opts.total) - # true means print time - return True + return RC_OK() @@ -2662,23 +2665,25 @@ class STLClient(object): opts = parser.parse_args(line.split(), default_ports = self.get_active_ports(), verify_acquired = True) if opts is None: - return + return RC_ERR("invalid arguments for 'stop'") # find the relevant ports ports = list_intersect(opts.ports, self.get_active_ports()) if not ports: if not opts.ports: - self.logger.log('stop - no active ports') + msg = 'stop - no active ports' else: - self.logger.log('stop - no active traffic on ports {0}'.format(opts.ports)) - return + msg = 'stop - no active traffic on ports {0}'.format(opts.ports) + + self.logger.log(msg) + return RC_ERR(msg) # call API self.stop(ports) # true means print time - return True + return RC_OK() @__console @@ -2694,22 +2699,24 @@ class STLClient(object): opts = parser.parse_args(line.split(), default_ports = self.get_active_ports(), verify_acquired = True) if opts is None: - return + return RC_ERR("invalid arguments for 'update'") # find the relevant ports ports = list_intersect(opts.ports, self.get_active_ports()) if not ports: if not opts.ports: - self.logger.log('update - no active ports') + msg = 'update - no active ports' else: - self.logger.log('update - no active traffic on ports {0}'.format(opts.ports)) - return + msg = 'update - no active traffic on ports {0}'.format(opts.ports) + + self.logger.log(msg) + return RC_ERR(msg) self.update(ports, opts.mult, opts.total, opts.force) # true means print time - return True + return RC_OK() @__console @@ -2722,26 +2729,29 @@ class STLClient(object): opts = parser.parse_args(line.split(), default_ports = self.get_transmitting_ports(), verify_acquired = True) if opts is None: - return + return RC_ERR("invalid arguments for 'pause'") # check for already paused case if opts.ports and is_sub_list(opts.ports, self.get_paused_ports()): - self.logger.log('pause - all of port(s) {0} are already paused'.format(opts.ports)) - return + msg = 'pause - all of port(s) {0} are already paused'.format(opts.ports) + self.logger.log(msg) + return RC_ERR(msg) # find the relevant ports ports = list_intersect(opts.ports, self.get_transmitting_ports()) if not ports: if not opts.ports: - self.logger.log('pause - no transmitting ports') + msg = 'pause - no transmitting ports' else: - self.logger.log('pause - none of ports {0} are transmitting'.format(opts.ports)) - return + msg = 'pause - none of ports {0} are transmitting'.format(opts.ports) + + self.logger.log(msg) + return RC_ERR(msg) self.pause(ports) # true means print time - return True + return RC_OK() @__console @@ -2754,22 +2764,24 @@ class STLClient(object): opts = parser.parse_args(line.split(), default_ports = self.get_paused_ports(), verify_acquired = True) if opts is None: - return + return RC_ERR("invalid arguments for 'resume'") # find the relevant ports ports = list_intersect(opts.ports, self.get_paused_ports()) if not ports: if not opts.ports: - self.logger.log('resume - no paused ports') + msg = 'resume - no paused ports' else: - self.logger.log('resume - none of ports {0} are paused'.format(opts.ports)) - return + msg = 'resume - none of ports {0} are paused'.format(opts.ports) + + self.logger.log(msg) + return RC_ERR(msg) self.resume(ports) # true means print time - return True + return RC_OK() @__console |