diff options
author | 2015-10-26 08:18:30 +0200 | |
---|---|---|
committer | 2015-10-26 08:18:30 +0200 | |
commit | 82832d9d372ddbe8e18c30b988843703b7b8965d (patch) | |
tree | cd9868ba9de5d9aab18ca229d8347fc755f8ce6b /scripts/automation/trex_control_plane/server/trex_server.py | |
parent | ed13067343186b5dad0566962cd308445136f3b7 (diff) | |
parent | 44cfe8691c6d81872b0a0d9c1d15781cba24ddba (diff) |
Merge branch 'get_logs_and_version'
Diffstat (limited to 'scripts/automation/trex_control_plane/server/trex_server.py')
-rwxr-xr-x | scripts/automation/trex_control_plane/server/trex_server.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/scripts/automation/trex_control_plane/server/trex_server.py b/scripts/automation/trex_control_plane/server/trex_server.py index e48f8963..66a98d5f 100755 --- a/scripts/automation/trex_control_plane/server/trex_server.py +++ b/scripts/automation/trex_control_plane/server/trex_server.py @@ -59,6 +59,7 @@ class CTRexServer(object): self.__check_trex_path_validity() self.__check_files_path_validity() self.trex = CTRex() + self.trex_version = None self.trex_host = trex_host self.trex_daemon_port = trex_daemon_port self.trex_zmq_port = trex_zmq_port @@ -116,6 +117,9 @@ class CTRexServer(object): # set further functionality and peripherals to server instance try: self.server.register_function(self.add) + self.server.register_function(self.get_trex_log) + self.server.register_function(self.get_trex_daemon_log) + self.server.register_function(self.get_trex_version) self.server.register_function(self.connectivity_check) self.server.register_function(self.start_trex) self.server.register_function(self.stop_trex) @@ -140,6 +144,42 @@ class CTRexServer(object): self.server.shutdown() pass + # get files from Trex server and return their content (mainly for logs) + @staticmethod + def _pull_file(filepath): + try: + with open(filepath, 'rb') as f: + file_content = f.read() + return binascii.b2a_base64(file_content) + except Exception as e: + err_str = "Can't get requested file: {0}, possibly due to TRex that did not run".format(filepath) + logger.error('{0}, error: {1}'.format(err_str, e)) + return Fault(-33, err_str) + + # get Trex log /tmp/trex.txt + def get_trex_log(self): + logger.info("Processing get_trex_log() command.") + return self._pull_file('/tmp/trex.txt') + + # get daemon log /var/log/trex/trex_daemon_server.log + def get_trex_daemon_log (self): + logger.info("Processing get_trex_daemon_log() command.") + return self._pull_file('/var/log/trex/trex_daemon_server.log') + + # get Trex version from ./t-rex-64 --help (last 4 lines) + def get_trex_version (self): + try: + logger.info("Processing get_trex_version() command.") + if self.trex_version: + return self.trex_version + help_print = os.popen('cd {path}; ./t-rex-64 --help'.format(path=self.TREX_PATH), 'r').read() + self.trex_version = binascii.b2a_base64('\n'.join(help_print.split('\n')[-5:-1])) + return self.trex_version + except Exception as e: + err_str = "Can't get trex version, error: {0}".format(e) + logger.error(err_str) + return Fault(-33, err_str) + def stop_handler (self, signum, frame): logger.info("Daemon STOP request detected.") if self.is_running(): |