def run_single_job_with_ui(self, job, ui): job_start_time = time.time() job_state = self.state.job_state_map[job.id] ui.considering_job(job, job_state) if job_state.can_start(): ui.about_to_start_running(job, job_state) self.metadata.running_job_name = job.id self.manager.checkpoint() ui.started_running(job, job_state) result_builder = self._run_single_job_with_ui_loop( job, job_state, ui) assert result_builder is not None result_builder.execution_duration = time.time() - job_start_time job_result = result_builder.get_result() self.metadata.running_job_name = None self.manager.checkpoint() ui.finished_running(job, job_state, job_result) else: result_builder = JobResultBuilder( outcome=IJobResult.OUTCOME_NOT_SUPPORTED, comments=job_state.get_readiness_description(), execution_duration=time.time() - job_start_time) job_result = result_builder.get_result() ui.job_cannot_start(job, job_state, job_result) self.state.update_job_result(job, job_result) ui.finished(job, job_state, job_result)
def _make_result_for(self, job): builder = JobResultBuilder(outcome='pass') if job.plugin == 'local': pass elif job.plugin == 'resource': pass else: builder.io_log = [(0, 'stdout', b'IO-LOG-STDOUT\n'), (1, 'stderr', b'IO-LOG-STDERR\n')] return builder.get_result()
def test_smoke_disk(self): builder = JobResultBuilder() builder.comments = 'it works' builder.execution_duration = 0.1 builder.io_log_filename = 'log' builder.outcome = 'pass' builder.return_code = 0 result = builder.get_result() self.assertEqual(result.comments, "it works") self.assertEqual(result.execution_duration, 0.1) self.assertEqual(result.io_log_filename, 'log') self.assertEqual(result.outcome, "pass") self.assertEqual(result.return_code, 0) # Sanity check: the builder we can re-create is identical builder2 = result.get_builder() self.assertEqual(builder, builder2)
def run_job(self, job, job_state, environ=None, ui=None): """ Only one resouce object is created from this runner. Exception: 'graphics_card' resource job creates two objects to simulate hybrid graphics. """ if job.plugin != 'resource': return super().run_job(job, job_state, environ, ui) builder = JobResultBuilder() if job.partial_id == 'graphics_card': builder.io_log = [(0, 'stdout', b'a: b\n'), (1, 'stdout', b'\n'), (2, 'stdout', b'a: c\n')] else: builder.io_log = [(0, 'stdout', b'a: b\n')] builder.outcome = 'pass' builder.return_code = 0 return builder.get_result()
def test_smoke_memory(self): builder = JobResultBuilder() builder.comments = 'it works' builder.execution_duration = 0.1 builder.io_log = [(0, 'stdout', b'ok\n')] builder.outcome = 'pass' builder.return_code = 0 result = builder.get_result() self.assertEqual(result.comments, "it works") self.assertEqual(result.execution_duration, 0.1) self.assertEqual( result.io_log, (IOLogRecord(delay=0, stream_name='stdout', data=b'ok\n'), )) self.assertEqual(result.outcome, "pass") self.assertEqual(result.return_code, 0) # Sanity check: the builder we can re-create is identical builder2 = result.get_builder() self.assertEqual(builder, builder2)
def run_single_job_with_ui(self, job, ui): job_start_time = time.time() job_state = self.state.job_state_map[job.id] ui.considering_job(job, job_state) if job_state.can_start(): ui.about_to_start_running(job, job_state) self.metadata.running_job_name = job.id self.manager.checkpoint() ui.started_running(job, job_state) result_builder = self._run_single_job_with_ui_loop( job, job_state, ui) assert result_builder is not None result_builder.execution_duration = time.time() - job_start_time job_result = result_builder.get_result() self.metadata.running_job_name = None self.manager.checkpoint() ui.finished_running(job, job_state, job_result) else: # Set the outcome of jobs that cannot start to # OUTCOME_NOT_SUPPORTED _except_ if any of the inhibitors point to # a job with an OUTCOME_SKIP outcome, if that is the case mirror # that outcome. This makes 'skip' stronger than 'not-supported' outcome = IJobResult.OUTCOME_NOT_SUPPORTED for inhibitor in job_state.readiness_inhibitor_list: if (inhibitor.cause == InhibitionCause.FAILED_RESOURCE and 'fail-on-resource' in job.get_flag_set()): outcome = IJobResult.OUTCOME_FAIL break elif inhibitor.cause != InhibitionCause.FAILED_DEP: continue related_job_state = self.state.job_state_map[ inhibitor.related_job.id] if related_job_state.result.outcome == IJobResult.OUTCOME_SKIP: outcome = IJobResult.OUTCOME_SKIP result_builder = JobResultBuilder( outcome=outcome, comments=job_state.get_readiness_description(), execution_duration=time.time() - job_start_time) job_result = result_builder.get_result() ui.job_cannot_start(job, job_state, job_result) self.state.update_job_result(job, job_result) ui.finished(job, job_state, job_result)
def test_io_log_clash(self): builder = JobResultBuilder() builder.io_log = [(0, 'stout', b'hi')] builder.io_log_filename = 'log' with self.assertRaises(ValueError): builder.get_result()
def _run_single_job_with_ui_loop(self, job, ui): print(self.C.header(job.tr_summary(), fill='-')) print(_("ID: {0}").format(job.id)) print( _("Category: {0}").format( self.sa.get_job_state(job.id).effective_category_id)) comments = "" while True: if job.plugin in ('user-interact', 'user-interact-verify', 'user-verify', 'manual'): job_state = self.sa.get_job_state(job.id) if (not self.is_interactive and job.plugin in ('user-interact', 'user-interact-verify', 'manual')): result_builder = JobResultBuilder( outcome=IJobResult.OUTCOME_SKIP, comments=_("Trying to run interactive job in a silent" " session")) return result_builder if job_state.can_start(): ui.notify_about_purpose(job) if (self.is_interactive and job.plugin in ('user-interact', 'user-interact-verify', 'manual')): if job_state.can_start(): ui.notify_about_steps(job) if job.plugin == 'manual': cmd = 'run' else: if job_state.can_start(): cmd = ui.wait_for_interaction_prompt(job) else: # 'running' the job will make it marked as skipped # because of the failed dependency cmd = 'run' if cmd == 'run' or cmd is None: result_builder = self.sa.run_job(job.id, ui, False) elif cmd == 'comment': new_comment = input( self.C.BLUE( _('Please enter your comments:') + '\n')) if new_comment: comments += new_comment + '\n' continue elif cmd == 'skip': result_builder = JobResultBuilder( outcome=IJobResult.OUTCOME_SKIP, comments=_("Explicitly skipped before" " execution")) if comments != "": result_builder.comments = comments break elif cmd == 'quit': raise SystemExit() else: result_builder = self.sa.run_job(job.id, ui, False) else: if 'noreturn' in job.get_flag_set(): ui.noreturn_job() result_builder = self.sa.run_job(job.id, ui, False) if (self.is_interactive and result_builder.outcome == IJobResult.OUTCOME_UNDECIDED): try: if comments != "": result_builder.comments = comments ui.notify_about_verification(job) self._interaction_callback(job, result_builder) except ReRunJob: self.sa.use_job_result(job.id, result_builder.get_result()) continue break return result_builder