diff options
Diffstat (limited to 'scripts')
3 files changed, 42 insertions, 34 deletions
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 93b36f82..011c9426 100755 --- a/scripts/automation/trex_control_plane/client/trex_stateless_client.py +++ b/scripts/automation/trex_control_plane/client/trex_stateless_client.py @@ -50,15 +50,18 @@ class RC: def err (self): return all([x.data if not x.rc else "" for x in self.rc_list]) - def annotate (self, desc): - print format_text('\n{:<40}'.format(desc), 'bold'), + def annotate (self, desc = None): + if desc: + print format_text('\n{:<40}'.format(desc), 'bold'), if self.bad(): # print all the errors + print "" for x in self.rc_list: if not x.rc: print format_text("\n{0}".format(x.data), 'bold') + print "" print format_text("[FAILED]\n", 'red', 'bold') @@ -274,16 +277,15 @@ class CTRexStatelessClient(object): ############# helper functions section ############## - def validate_port_list(self, port_id): - if isinstance(port_id, list) or isinstance(port_id, set): - # check each item of the sequence - return all([self._is_ports_valid(port) - for port in port_id]) - elif (isinstance(port_id, int)) and (port_id >= 0) and (port_id <= self.get_port_count()): - return True - else: + def validate_port_list(self, port_id_list): + if not isinstance(port_id_list, list): + print type(port_id_list) return False + # check each item of the sequence + return all([ (port_id >= 0) and (port_id < self.get_port_count()) + for port_id in port_id_list ]) + # some preprocessing for port argument def __ports (self, port_id_list): @@ -355,6 +357,8 @@ class CTRexStatelessClient(object): def disconnect(self): self.connected = False self.comm_link.disconnect() + return RC_OK() + ########### cached queries (no server traffic) ########### @@ -384,6 +388,9 @@ class CTRexStatelessClient(object): def get_connection_port (self): return self.comm_link.port + def get_connection_ip (self): + return self.comm_link.server + def get_acquired_ports(self): return [port.port_id for port in self.ports if port.is_acquired()] @@ -543,10 +550,22 @@ class CTRexStatelessClient(object): ######################### Console (high level) API ######################### + def cmd_ping (self): + rc = self.ping() + rc.annotate("Pinging the server on '{0}' port '{1}': ".format(self.get_connection_ip(), self.get_connection_port())) + return rc + + def cmd_connect (self): + rc = self.connect() + rc.annotate() + return rc + + def cmd_disconnect (self): + rc = self.disconnect() + rc.annotate() + return rc + # reset - # acquire, stop, remove streams and clear stats - # - # def cmd_reset (self): @@ -631,7 +650,7 @@ class CTRexStatelessClient(object): return True - + ################################# # ------ private classes ------ # class CCommLink(object): """describes the connectivity of the stateless client method""" diff --git a/scripts/automation/trex_control_plane/console/parsing_opts.py b/scripts/automation/trex_control_plane/console/parsing_opts.py index 252d33bf..0e11df74 100755 --- a/scripts/automation/trex_control_plane/console/parsing_opts.py +++ b/scripts/automation/trex_control_plane/console/parsing_opts.py @@ -139,8 +139,8 @@ class CCmdArgParser(argparse.ArgumentParser): opts.ports = self.stateless_client.get_port_ids() for port in opts.ports: - if not self.stateless_client.validate_port_list(port): - self.error("port id {0} is not a valid port id\n".format(port)) + if not self.stateless_client.validate_port_list([port]): + self.error("port id '{0}' is not a valid port id\n".format(port)) return opts diff --git a/scripts/automation/trex_control_plane/console/trex_console.py b/scripts/automation/trex_control_plane/console/trex_console.py index 5ba82dcb..bd79479d 100755 --- a/scripts/automation/trex_control_plane/console/trex_console.py +++ b/scripts/automation/trex_control_plane/console/trex_console.py @@ -195,12 +195,8 @@ class TRexConsole(cmd.Cmd): def do_ping (self, line): '''Ping the server\n''' - rc = self.stateless_client.ping() - if rc.good(): - print format_text("[SUCCESS]\n", 'green', 'bold') - else: - print "\n*** " + rc.err() + "\n" - print format_text("[FAILED]\n", 'red', 'bold') + rc = self.stateless_client.cmd_ping() + if rc.bad(): return def do_test (self, line): @@ -230,25 +226,18 @@ class TRexConsole(cmd.Cmd): def do_connect (self, line): '''Connects to the server\n''' - rc = self.stateless_client.connect() - if rc.good(): - print format_text("[SUCCESS]\n", 'green', 'bold') - else: - print "\n*** " + rc.err() + "\n" - print format_text("[FAILED]\n", 'red', 'bold') + rc = self.stateless_client.cmd_connect() + if rc.bad(): return def do_disconnect (self, line): '''Disconnect from the server\n''' - if not self.stateless_client.is_connected(): - print "Not connected to server\n" + rc = self.stateless_client.cmd_disconnect() + if rc.bad(): return - self.stateless_client.disconnect() - print format_text("[SUCCESS]\n", 'green', 'bold') - ############### start @@ -332,7 +321,7 @@ class TRexConsole(cmd.Cmd): '''Shows a graphical console\n''' if not self.stateless_client.is_connected(): - print "Not connected to server\n" + print format_text("\nNot connected to server\n", 'bold') return self.do_verbose('off') |