+
+ def get_log_files(self):
+ """Get the log files produced by the command launched
+ on the remote machine, and put it in the log directory of the user,
+ so they can be accessible from
+ """
+ # Do not get the files if the command is not finished
+ if not self.has_finished():
+ msg = _("Trying to get log files whereas the job is not finished.")
+ self.logger.write(src.printcolors.printcWarning(msg))
+ return
+
+ # First get the file that contains the list of log files to get
+ tmp_file_path = src.get_tmp_filename(self.config, "list_log_files.txt")
+ remote_path = os.path.join(self.machine.sat_path, "list_log_files.txt")
+ self.machine.sftp.get(
+ remote_path,
+ tmp_file_path)
+
+ # Read the file and get the result of the command and all the log files
+ # to get
+ fstream_tmp = open(tmp_file_path, "r")
+ file_lines = fstream_tmp.readlines()
+ file_lines = [line.replace("\n", "") for line in file_lines]
+ fstream_tmp.close()
+ os.remove(tmp_file_path)
+
+ try :
+ # The first line is the result of the command (0 success or 1 fail)
+ self.res_job = file_lines[0]
+ except Exception as e:
+ self.err += _("Unable to get status from remote file %s: %s" %
+ (remote_path, str(e)))
+
+ for i, job_path_remote in enumerate(file_lines[1:]):
+ try:
+ # For each command, there is two files to get :
+ # 1- The xml file describing the command and giving the
+ # internal traces.
+ # 2- The txt file containing the system command traces (like
+ # traces produced by the "make" command)
+ # 3- In case of the test command, there is another file to get :
+ # the xml board that contain the test results
+ dirname = os.path.basename(os.path.dirname(job_path_remote))
+ if dirname != 'OUT' and dirname != 'TEST':
+ # Case 1-
+ local_path = os.path.join(os.path.dirname(
+ self.logger.logFilePath),
+ os.path.basename(job_path_remote))
+ if i==0: # The first is the job command
+ self.logger.add_link(os.path.basename(job_path_remote),
+ "job",
+ self.res_job,
+ self.command)
+ elif dirname == 'OUT':
+ # Case 2-
+ local_path = os.path.join(os.path.dirname(
+ self.logger.logFilePath),
+ 'OUT',
+ os.path.basename(job_path_remote))
+ elif dirname == 'TEST':
+ # Case 3-
+ local_path = os.path.join(os.path.dirname(
+ self.logger.logFilePath),
+ 'TEST',
+ os.path.basename(job_path_remote))
+
+ # Get the file
+ if not os.path.exists(local_path):
+ self.machine.sftp.get(job_path_remote, local_path)
+ self.remote_log_files.append(local_path)
+ except Exception as e:
+ self.err += _("Unable to get %s log file from remote: %s" %
+ (str(job_path_remote),
+ str(e)))
+
+ def has_failed(self):
+ '''Returns True if the job has failed.
+ A job is considered as failed if the machine could not be reached,
+ if the remote command failed,
+ or if the job finished with a time out.
+
+ :return: True if the job has failed
+ :rtype: bool
+ '''
+ if not self.has_finished():
+ return False
+ if not self.machine.successfully_connected(self.logger):
+ return True
+ if self.is_timeout():
+ return True
+ if self.res_job == "1":
+ return True
+ return False