From 344e3045d8346b4b204692e591e1556fc2333f97 Mon Sep 17 00:00:00 2001 From: imarom Date: Wed, 27 Jul 2016 11:08:09 +0300 Subject: support for graceful shutdown --- .../trex_control_plane/stl/console/trex_console.py | 5 +++ .../trex_control_plane/stl/console/trex_tui.py | 6 ++- .../stl/trex_stl_lib/trex_stl_client.py | 47 ++++++++++++++++++++-- 3 files changed, 52 insertions(+), 6 deletions(-) (limited to 'scripts/automation/trex_control_plane') 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 7ad0cfa4..110457d6 100755 --- a/scripts/automation/trex_control_plane/stl/console/trex_console.py +++ b/scripts/automation/trex_control_plane/stl/console/trex_console.py @@ -279,6 +279,11 @@ class TRexConsole(TRexGeneralCmd): self.stateless_client.ping_line(line) + @verify_connected + def do_shutdown (self, line): + '''Sends the server a shutdown request\n''' + self.stateless_client.shutdown_line(line) + # set verbose on / off def do_verbose(self, line): '''Shows or set verbose mode\n''' 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 d3da738b..a69c4165 100644 --- a/scripts/automation/trex_control_plane/stl/console/trex_tui.py +++ b/scripts/automation/trex_control_plane/stl/console/trex_tui.py @@ -720,6 +720,7 @@ class AsyncKeysEngineConsole: self.ac = {'start' : client.start_line, 'stop' : client.stop_line, 'pause' : client.pause_line, + 'push' : client.push_line, 'resume' : client.resume_line, 'update' : client.update_line, 'connect' : client.connect_line, @@ -847,8 +848,9 @@ class AsyncKeysEngineConsole: # handle TAB for completing filenames def handle_tab_files (self, tokens): - # we support only start command with files - if tokens[0] != 'start': + + # only commands with files + if tokens[0] not in {'start', 'push'}: return # '-f' with no paramters - no partial and use current dir 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 a4f26f69..4e3d3092 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 @@ -1658,8 +1658,8 @@ class STLClient(object): """ - self.logger.pre_cmd( "Pinging the server on '{0}' port '{1}': ".format(self.connection_info['server'], - self.connection_info['sync_port'])) + self.logger.pre_cmd("Pinging the server on '{0}' port '{1}': ".format(self.connection_info['server'], + self.connection_info['sync_port'])) rc = self._transmit("ping", api_class = None) self.logger.post_cmd(rc) @@ -1667,6 +1667,30 @@ class STLClient(object): if not rc: raise STLError(rc) + @__api_check(True) + def server_shutdown (self, force = False): + """ + Sends the server a request for total shutdown + + :parameters: + force - shutdown server even if some ports are owned by another + user + + :raises: + + :exc:`STLError` + + """ + + self.logger.pre_cmd("Sending shutdown request for the server") + + rc = self._transmit("shutdown", params = {'force': force, 'user': self.username}) + + self.logger.post_cmd(rc) + + if not rc: + raise STLError(rc) + + @__api_check(True) def get_active_pgids(self): """ @@ -2107,7 +2131,7 @@ class STLClient(object): ports = ports if ports is not None else self.get_acquired_ports() ports = self._validate_port_list(ports) - validate_type('pcap_filename', pcap_filename, str) + validate_type('pcap_filename', pcap_filename, basestring) validate_type('ipg_usec', ipg_usec, (float, int, type(None))) validate_type('speedup', speedup, (float, int)) validate_type('count', count, int) @@ -2174,7 +2198,7 @@ class STLClient(object): ports = ports if ports is not None else self.get_acquired_ports() ports = self._validate_port_list(ports) - validate_type('pcap_filename', pcap_filename, str) + validate_type('pcap_filename', pcap_filename, basestring) validate_type('ipg_usec', ipg_usec, (float, int, type(None))) validate_type('speedup', speedup, (float, int)) validate_type('count', count, int) @@ -2444,6 +2468,21 @@ class STLClient(object): self.ping() return RC_OK() + @__console + def shutdown_line (self, line): + '''shutdown the server''' + parser = parsing_opts.gen_parser(self, + "shutdown", + self.shutdown_line.__doc__, + parsing_opts.FORCE) + + opts = parser.parse_args(line.split()) + if not opts: + return opts + + self.server_shutdown(force = opts.force) + return RC_OK() + @__console def connect_line (self, line): '''Connects to the TRex server and acquire ports''' -- cgit