From d42a2a5567958ea052aac0ab0dc291876f97f4e2 Mon Sep 17 00:00:00 2001 From: Yaroslav Brustinov Date: Thu, 21 Apr 2016 11:14:52 +0300 Subject: regression: fix functional filters test path stateful API: add get_files, get_files_list --- .../stf/trex_stf_lib/trex_client.py | 53 +++++++++++++++++++++- 1 file changed, 51 insertions(+), 2 deletions(-) (limited to 'scripts/automation/trex_control_plane/stf') diff --git a/scripts/automation/trex_control_plane/stf/trex_stf_lib/trex_client.py b/scripts/automation/trex_control_plane/stf/trex_stf_lib/trex_client.py index 4fd1e4c7..412f52d4 100755 --- a/scripts/automation/trex_control_plane/stf/trex_stf_lib/trex_client.py +++ b/scripts/automation/trex_control_plane/stf/trex_stf_lib/trex_client.py @@ -725,7 +725,56 @@ class CTRexClient(object): raise finally: self.prompt_verbose_data() - + + def get_files_list (self, path): + """ + Gets a tuple (dirs, files) with lists of dirs and files from given path. + Path is limited to /tmp/trex_files or TRex directory (can be used relative path) + + :return: + Tuple: list of dirs and list of files in given path + + :raises: + + :exc:`trex_exceptions.TRexRequestDenied`, in case TRex is reserved for another user than the one trying to cancel the reservation. + + ProtocolError, in case of error in JSON-RPC protocol. + + """ + + try: + return self.server.get_files_list(path) + except AppError as err: + self._handle_AppError_exception(err.args[0]) + except ProtocolError: + raise + finally: + self.prompt_verbose_data() + + def get_file(self, filepath): + """ + Gets a file from /tmp/trex_files or TRex server directory. + + :parameters: + filepath : str + a path to a file at server. + it can be either relative to TRex server or absolute path starting with /tmp/trex_files + + :return: + Content of the file + + :raises: + + :exc:`trex_exceptions.TRexRequestDenied`, in case TRex is reserved for another user than the one trying to cancel the reservation. + + ProtocolError, in case of error in JSON-RPC protocol. + """ + + try: + return binascii.a2b_base64(self.server.get_file(filepath)) + except AppError as err: + self._handle_AppError_exception(err.args[0]) + except ProtocolError: + raise + finally: + self.prompt_verbose_data() + def push_files (self, filepaths): """ Pushes a file (or a list of files) to store locally on server. @@ -761,7 +810,7 @@ class CTRexClient(object): filename = os.path.basename(filepath) with open(filepath, 'rb') as f: file_content = f.read() - self.server.push_file(filename, binascii.b2a_base64(file_content)) + self.server.push_file(filename, binascii.b2a_base64(file_content).decode()) finally: self.prompt_verbose_data() return True -- cgit 1.2.3-korg