Exemple #1
0
 def get_output_log_result(self, run_dir):
     """
     Get the result of the Jules by looking at the log
     :param run_dir: the run directory to get the file from
     :return: log file parser
     """
     file_path = os.path.join(run_dir, FILENAME_OUTPUT_LOG)
     if not os.path.exists(file_path):
         raise ServiceException(ERROR_MESSAGE_NO_LOG_FILE)
     f = open(file_path, 'r')
     log_file_parser = LogFileParser(f)
     log_file_parser.parse()
     return log_file_parser
    def test_GIVEN_job_is_not_in_list_and_log_has_success_in_WHEN_get_job_status_THEN_job_status_complete(self):

        bsub_id = 10
        bjobs_list = {}
        self.job_service.exists_run_dir = Mock(return_value=True)
        self.job_service.get_bsub_id = Mock(return_value=bsub_id)
        result = LogFileParser(None)
        result.status = constants.MODEL_RUN_STATUS_COMPLETED
        self.job_service.get_output_log_result = Mock(return_value=result)

        self.job_status.check(self.job_service, bjobs_list)

        assert_that(self.job_status.status, is_(constants.MODEL_RUN_STATUS_COMPLETED), "Job status")
    def test_GIVEN_job_is_not_in_list_and_log_has_failed_in_WHEN_get_job_status_THEN_job_status_faield(self):

        expected_error_msg = "error"
        bsub_id = 10
        bjobs_list = {}
        self.job_service.exists_run_dir = Mock(return_value=True)
        self.job_service.get_bsub_id = Mock(return_value=bsub_id)
        result = LogFileParser(None)
        result.status = constants.MODEL_RUN_STATUS_FAILED
        result.error_message = expected_error_msg
        self.job_service.get_output_log_result = Mock(return_value=result)

        self.job_status.check(self.job_service, bjobs_list)

        assert_that(self.job_status.status, is_(constants.MODEL_RUN_STATUS_FAILED), "Job status")
        assert_that(self.job_status.error_message, is_(expected_error_msg), "Error message")
    def test_GIVEN_job_is_not_in_list_and_log_has_success_and_time_and_storage_in_WHEN_get_job_status_THEN_json_contains_storage_and_start_end_times(self):

        bsub_id = 10
        expected_storage = 1234

        bjobs_list = {}
        self.job_service.exists_run_dir = Mock(return_value=True)
        self.job_service.get_bsub_id = Mock(return_value=bsub_id)
        result = LogFileParser(None)
        result.status = constants.MODEL_RUN_STATUS_COMPLETED
        result.storage_in_mb = expected_storage
        result.start_time = datetime(2012, 01, 10, 11, 12, 13, tzinfo=pytz.utc)
        result.end_time = datetime(2013, 02, 11, 12, 1, 14, tzinfo=pytz.utc)
        self.job_service.get_output_log_result = Mock(return_value=result)

        self.job_status.check(self.job_service, bjobs_list)

        assert_that(self.job_status.start_time, is_(result.start_time), "start time")
        assert_that(self.job_status.end_time, is_(result.end_time), "start time")
        assert_that(self.job_status.storage_in_mb, is_(result.storage_in_mb), "start time")