summaryrefslogtreecommitdiffstats
path: root/scripts/automation
diff options
context:
space:
mode:
authorimarom <imarom@cisco.com>2016-07-26 11:47:15 +0300
committerimarom <imarom@cisco.com>2016-07-26 11:47:15 +0300
commit90c64917b59e83556454d1338634473cdcd952a9 (patch)
tree1471d34521aafd039d2014e3f8ee4dedf9faaebb /scripts/automation
parente3b43560ff867c35ee726da9a98aed8acdc53b70 (diff)
some more TUI fixes
Diffstat (limited to 'scripts/automation')
-rwxr-xr-xscripts/automation/trex_control_plane/common/text_opts.py5
-rwxr-xr-xscripts/automation/trex_control_plane/stl/console/trex_console.py3
-rw-r--r--scripts/automation/trex_control_plane/stl/console/trex_tui.py45
-rw-r--r--scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_port.py14
-rw-r--r--scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_stats.py22
-rw-r--r--scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/text_opts.py5
6 files changed, 69 insertions, 25 deletions
diff --git a/scripts/automation/trex_control_plane/common/text_opts.py b/scripts/automation/trex_control_plane/common/text_opts.py
index ab0fd2f2..c9ab7ca8 100755
--- a/scripts/automation/trex_control_plane/common/text_opts.py
+++ b/scripts/automation/trex_control_plane/common/text_opts.py
@@ -27,7 +27,10 @@ class TextCodesStripper:
def strip (s):
return re.sub(TextCodesStripper.pattern, '', s)
-def format_num (size, suffix = "", compact = True, opts = ()):
+def format_num (size, suffix = "", compact = True, opts = None):
+ if opts is None:
+ opts = ()
+
txt = "NaN"
if type(size) == str:
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 41a04617..7ad0cfa4 100755
--- a/scripts/automation/trex_control_plane/stl/console/trex_console.py
+++ b/scripts/automation/trex_control_plane/stl/console/trex_console.py
@@ -573,7 +573,8 @@ class TRexConsole(TRexGeneralCmd):
try:
with self.stateless_client.logger.supress():
- self.tui.show(self.stateless_client, locked = opts.locked)
+ self.tui.show(self.stateless_client, self.save_console_history, locked = opts.locked)
+
except self.tui.ScreenSizeException as e:
print(format_text(str(e) + "\n", 'bold'))
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 81ba335c..d3da738b 100644
--- a/scripts/automation/trex_control_plane/stl/console/trex_tui.py
+++ b/scripts/automation/trex_control_plane/stl/console/trex_tui.py
@@ -24,6 +24,16 @@ class TUIQuit(Exception):
# for STL exceptions
from trex_stl_lib.api import *
+def ascii_split (s):
+ output = []
+
+ lines = s.split('\n')
+ for elem in lines:
+ if ansi_len(elem) > 0:
+ output.append(elem)
+
+ return output
+
class SimpleBar(object):
def __init__ (self, desc, pattern):
self.desc = desc
@@ -483,13 +493,13 @@ class TrexTUI():
#sys.stdout.write("\x1b[2J\x1b[H")
- def show (self, client, show_log = False, locked = False):
+ def show (self, client, save_console_history, show_log = False, locked = False):
rows, cols = os.popen('stty size', 'r').read().split()
if (int(rows) < TrexTUI.MIN_ROWS) or (int(cols) < TrexTUI.MIN_COLS):
raise self.ScreenSizeException(rows = rows, cols = cols)
- with AsyncKeys(client, locked) as async_keys:
+ with AsyncKeys(client, save_console_history, locked) as async_keys:
sys.stdout.write("\x1bc")
self.async_keys = async_keys
self.show_internal(show_log, locked)
@@ -597,8 +607,8 @@ class AsyncKeys:
STATUS_REDRAW_KEYS = 1
STATUS_REDRAW_ALL = 2
- def __init__ (self, client, locked = False):
- self.engine_console = AsyncKeysEngineConsole(self, client)
+ def __init__ (self, client, save_console_history, locked = False):
+ self.engine_console = AsyncKeysEngineConsole(self, client, save_console_history)
self.engine_legend = AsyncKeysEngineLegend(self)
self.locked = locked
@@ -700,11 +710,12 @@ class AsyncKeysEngineLegend:
# console engine
class AsyncKeysEngineConsole:
- def __init__ (self, async, client):
+ def __init__ (self, async, client, save_console_history):
self.async = async
self.lines = deque(maxlen = 100)
- self.generate_prompt = client.generate_prompt
+ self.generate_prompt = client.generate_prompt
+ self.save_console_history = save_console_history
self.ac = {'start' : client.start_line,
'stop' : client.stop_line,
@@ -929,6 +940,7 @@ class AsyncKeysEngineConsole:
self.lines.appendleft(empty_line)
self.line_index = 0
readline.add_history(cmd)
+ self.save_console_history()
# back to readonly
for line in self.lines:
@@ -939,15 +951,28 @@ class AsyncKeysEngineConsole:
if not func:
self.last_status = "unknown command: '{0}'".format(format_text(cmd.split()[0], 'bold'))
else:
+ # internal commands
if isinstance(func_rc, str):
self.last_status = func_rc
+
+ # RC response
else:
- self.last_status = format_text("[OK]", 'green') if func_rc else format_text(str(func_rc).replace('\n', ''), 'red')
- color = 'red'
+ # success
+ if func_rc:
+ self.last_status = format_text("[OK]", 'green')
+
+ # errors
+ else:
+ err_msgs = ascii_split(str(func_rc))
+ self.last_status = format_text(err_msgs[0], 'red')
+ if len(err_msgs) > 1:
+ self.last_status += " [{0} more errors messages]".format(len(err_msgs) - 1)
+ color = 'red'
# trim too long lines
- if ansi_len(self.last_status) > 100:
- self.last_status = format_text(self.last_status[:100] + "...", color, 'bold')
+ if ansi_len(self.last_status) > TrexTUI.MIN_COLS:
+ self.last_status = format_text(self.last_status[:TrexTUI.MIN_COLS] + "...", color, 'bold')
+
def draw (self):
sys.stdout.write("\nPress 'ESC' for navigation panel...\n")
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 be46e95f..d239fc57 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
@@ -68,7 +68,7 @@ class Port(object):
self.has_rx_streams = False
self.owner = ''
-
+ self.last_factor_type = None
# decorator to verify port is up
def up(func):
@@ -417,6 +417,9 @@ class Port(object):
self.state = last_state
return self.err(rc.err())
+ # save this for TUI
+ self.last_factor_type = mul['type']
+
return self.ok()
@@ -424,7 +427,7 @@ class Port(object):
# with force ignores the cached state and sends the command
@owned
def stop (self, force = False):
-
+
# if not is not active and not force - go back
if not self.is_active() and not force:
return self.ok()
@@ -437,10 +440,11 @@ class Port(object):
return self.err(rc.err())
self.state = self.STATE_STREAMS
+ self.last_factor_type = None
# timestamp for last tx
self.tx_stopped_ts = datetime.now()
-
+
return self.ok()
@@ -535,6 +539,9 @@ class Port(object):
if rc.bad():
return self.err(rc.err())
+ # save this for TUI
+ self.last_factor_type = mul['type']
+
return self.ok()
@owned
@@ -712,6 +719,7 @@ class Port(object):
# until thread is locked - order is important
self.tx_stopped_ts = datetime.now()
self.state = self.STATE_STREAMS
+ self.last_factor_type = None
# rest of the events are used for TUI / read only sessions
def async_event_port_stopped (self):
diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_stats.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_stats.py
index af4d6f69..1bf0a9a4 100644
--- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_stats.py
+++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_stats.py
@@ -776,12 +776,12 @@ class CTRexStats(object):
return value
- def get(self, field, format=False, suffix=""):
+ def get(self, field, format=False, suffix="", opts = None):
value = self._get(self.latest_stats, field)
if value == None:
return 'N/A'
- return value if not format else format_num(value, suffix)
+ return value if not format else format_num(value, suffix = suffix, opts = opts)
def get_rel(self, field, format=False, suffix=""):
@@ -1020,14 +1020,20 @@ class CPortStats(CTRexStats):
else:
state = format_text(state, 'bold')
+ # default rate format modifiers
+ rate_format = {'bpsl1': None, 'bps': None, 'pps': None, 'percentage': 'bold'}
+
# mark owned ports by color
if self._port_obj:
owner = self._port_obj.get_owner()
+ rate_format[self._port_obj.last_factor_type] = ('blue', 'bold')
if self._port_obj.is_acquired():
owner = format_text(owner, 'green')
+
else:
owner = ''
+
return {"owner": owner,
"state": "{0}".format(state),
"speed": self._port_obj.get_formatted_speed() if self._port_obj else '',
@@ -1038,21 +1044,19 @@ class CPortStats(CTRexStats):
"-----": " ",
"Tx bps L1": "{0} {1}".format(self.get_trend_gui("m_total_tx_bps_L1", show_value = False),
- self.get("m_total_tx_bps_L1", format = True, suffix = "bps")),
+ self.get("m_total_tx_bps_L1", format = True, suffix = "bps", opts = rate_format['bpsl1'])),
"Tx bps L2": "{0} {1}".format(self.get_trend_gui("m_total_tx_bps", show_value = False),
- self.get("m_total_tx_bps", format = True, suffix = "bps")),
+ self.get("m_total_tx_bps", format = True, suffix = "bps", opts = rate_format['bps'])),
- "Line Util.": "{0} {1}".format(self.get_trend_gui("m_percentage", show_value = False),
- format_text(
- self.get("m_percentage", format = True, suffix = "%") if self._port_obj else "",
- 'bold')) if self._port_obj else "",
+ "Line Util.": "{0} {1}".format(self.get_trend_gui("m_percentage", show_value = False) if self._port_obj else "",
+ self.get("m_percentage", format = True, suffix = "%", opts = rate_format['percentage']) if self._port_obj else ""),
"Rx bps": "{0} {1}".format(self.get_trend_gui("m_total_rx_bps", show_value = False),
self.get("m_total_rx_bps", format = True, suffix = "bps")),
"Tx pps": "{0} {1}".format(self.get_trend_gui("m_total_tx_pps", show_value = False),
- self.get("m_total_tx_pps", format = True, suffix = "pps")),
+ self.get("m_total_tx_pps", format = True, suffix = "pps", opts = rate_format['pps'])),
"Rx pps": "{0} {1}".format(self.get_trend_gui("m_total_rx_pps", show_value = False),
self.get("m_total_rx_pps", format = True, suffix = "pps")),
diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/text_opts.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/text_opts.py
index 26e64dae..bfb96950 100644
--- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/text_opts.py
+++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/text_opts.py
@@ -27,7 +27,10 @@ class TextCodesStripper:
def strip (s):
return re.sub(TextCodesStripper.pattern, '', s)
-def format_num (size, suffix = "", compact = True, opts = ()):
+def format_num (size, suffix = "", compact = True, opts = None):
+ if opts is None:
+ opts = ()
+
txt = "NaN"
if type(size) == str: