From b6ec2066653319b60385de1d4117165eb88890a1 Mon Sep 17 00:00:00 2001 From: imarom Date: Wed, 25 Nov 2015 07:39:39 -0500 Subject: fixed a bug with default start command in the console also added clear events and more types of events --- .../client/trex_stateless_client.py | 30 ++++++++++++++++++++-- .../trex_control_plane/console/parsing_opts.py | 2 +- .../trex_control_plane/console/trex_console.py | 22 ++++++++++++++++ 3 files changed, 51 insertions(+), 3 deletions(-) (limited to 'scripts/automation') 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 1d0ca606..149d2855 100755 --- a/scripts/automation/trex_control_plane/client/trex_stateless_client.py +++ b/scripts/automation/trex_control_plane/client/trex_stateless_client.py @@ -410,26 +410,49 @@ class CTRexStatelessClient(object): ev = "[event] - " + show_event = False + + # port started if (type == 0): + port_id = int(data['port_id']) + ev += "Port {0} has started".format(port_id) + + # port stopped + elif (type == 1): port_id = int(data['port_id']) ev += "Port {0} has stopped".format(port_id) + # call the handler self.async_event_port_stopped(port_id) + - elif (type == 1): + # server stopped + elif (type == 2): ev += "Server has stopped" self.async_event_server_stopped() + show_event = True + + # port finished traffic + elif (type == 3): + port_id = int(data['port_id']) + ev += "Port {0} job done".format(port_id) + + # call the handler + self.async_event_port_stopped(port_id) + show_event = True else: # unknown event - ignore return - print format_text("\n" + ev, 'bold') + if show_event: + print format_text("\n" + ev, 'bold') ts = time.time() st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S') self.events.append("{0} - ".format(st) + format_text(ev, 'bold')) + def async_event_port_stopped (self, port_id): self.ports[port_id].async_event_port_stopped() @@ -439,6 +462,9 @@ class CTRexStatelessClient(object): def get_events (self): return self.events + def clear_events (self): + self.events = [] + ############# helper functions section ############## def validate_port_list(self, port_id_list): diff --git a/scripts/automation/trex_control_plane/console/parsing_opts.py b/scripts/automation/trex_control_plane/console/parsing_opts.py index d2484a83..0bcdce84 100755 --- a/scripts/automation/trex_control_plane/console/parsing_opts.py +++ b/scripts/automation/trex_control_plane/console/parsing_opts.py @@ -121,7 +121,7 @@ def is_valid_file(filename): OPTIONS_DB = {MULTIPLIER: ArgumentPack(['-m', '--multiplier'], {'help': match_multiplier_help, 'dest': "mult", - 'default': 1.0, + 'default': {'type':'raw', 'max':1}, 'type': match_multiplier}), diff --git a/scripts/automation/trex_control_plane/console/trex_console.py b/scripts/automation/trex_control_plane/console/trex_console.py index b164af4e..fc2c845a 100755 --- a/scripts/automation/trex_control_plane/console/trex_console.py +++ b/scripts/automation/trex_control_plane/console/trex_console.py @@ -334,12 +334,34 @@ class TRexConsole(TRexGeneralCmd): self.stateless_client.cmd_reset() + def help_events (self): + self.do_events("-h") + def do_events (self, line): '''shows events recieved from server\n''' + + x = parsing_opts.ArgumentPack(['-c','--clear'], + {'action' : "store_true", + 'default': False, + 'help': "clear the events log"}) + + parser = parsing_opts.gen_parser(self, + "events", + self.do_events.__doc__, + x) + + opts = parser.parse_args(line.split()) + if opts is None: + return + events = self.stateless_client.get_events() for ev in events: print ev + if opts.clear: + self.stateless_client.clear_events() + print format_text("\n\nEvent log was cleared\n\n") + # tui def do_tui (self, line): '''Shows a graphical console\n''' -- cgit 1.2.3-korg