def _get_runner(self, runnertype_db, action_db, liveaction_db): runner = get_runner(runnertype_db.runner_module) resolved_entry_point = self._get_entry_point_abs_path( action_db.pack, action_db.entry_point) runner.runner_type_db = runnertype_db runner.container_service = RunnerContainerService() runner.action = action_db runner.action_name = action_db.name runner.liveaction = liveaction_db runner.liveaction_id = str(liveaction_db.id) runner.execution = ActionExecution.get( liveaction__id=runner.liveaction_id) runner.execution_id = str(runner.execution.id) runner.entry_point = resolved_entry_point runner.context = getattr(liveaction_db, 'context', dict()) runner.callback = getattr(liveaction_db, 'callback', dict()) runner.libs_dir_path = self._get_action_libs_abs_path( action_db.pack, action_db.entry_point) # For re-run, get the ActionExecutionDB in which the re-run is based on. rerun_ref_id = runner.context.get('re-run', {}).get('ref') runner.rerun_ex_ref = ActionExecution.get( id=rerun_ref_id) if rerun_ref_id else None return runner
def test_get_runner_module_fail(self): runnertype_db = RunnerTypeDB(name='dummy', runner_module='absent.module') runner = None try: runner = get_runner(runnertype_db.runner_module) except ActionRunnerCreateError: pass self.assertFalse(runner, 'TestRunner must be valid.')
def test_pre_run_runner_is_disabled(self): runnertype_db = RunnerContainerTest.runnertype_db runner = get_runner(runnertype_db.runner_module) runner.runner_type_db = runnertype_db runner.runner_type_db.enabled = False expected_msg = 'Runner "test-runner-1" has been disabled by the administrator' self.assertRaisesRegexp(ValueError, expected_msg, runner.pre_run)
def _invoke_post_run(self, actionexec_db, action_db): LOG.info('Invoking post run for action execution %s. Action=%s; Runner=%s', actionexec_db.id, action_db.name, action_db.runner_type['name']) # Get an instance of the action runner. runnertype_db = get_runnertype_by_name(action_db.runner_type['name']) runner = get_runner(runnertype_db.runner_module) # Configure the action runner. runner.container_service = RunnerContainerService() runner.action = action_db runner.action_name = action_db.name runner.action_execution_id = str(actionexec_db.id) runner.entry_point = RunnerContainerService.get_entry_point_abs_path( pack=action_db.pack, entry_point=action_db.entry_point) runner.context = getattr(actionexec_db, 'context', dict()) runner.callback = getattr(actionexec_db, 'callback', dict()) runner.libs_dir_path = RunnerContainerService.get_action_libs_abs_path( pack=action_db.pack, entry_point=action_db.entry_point) # Invoke the post_run method. runner.post_run(actionexec_db.status, actionexec_db.result)
def _get_runner(self, runnertype_db, action_db, liveaction_db): runner = get_runner(runnertype_db.runner_module) resolved_entry_point = self._get_entry_point_abs_path(action_db.pack, action_db.entry_point) runner.runner_type_db = runnertype_db runner.container_service = RunnerContainerService() runner.action = action_db runner.action_name = action_db.name runner.liveaction = liveaction_db runner.liveaction_id = str(liveaction_db.id) runner.execution = ActionExecution.get(liveaction__id=runner.liveaction_id) runner.execution_id = str(runner.execution.id) runner.entry_point = resolved_entry_point runner.context = getattr(liveaction_db, "context", dict()) runner.callback = getattr(liveaction_db, "callback", dict()) runner.libs_dir_path = self._get_action_libs_abs_path(action_db.pack, action_db.entry_point) # For re-run, get the ActionExecutionDB in which the re-run is based on. rerun_ref_id = runner.context.get("re-run", {}).get("ref") runner.rerun_ex_ref = ActionExecution.get(id=rerun_ref_id) if rerun_ref_id else None return runner
def test_get_runner_module(self): runnertype_db = RunnerContainerTest.runnertype_db runner = get_runner(runnertype_db.runner_module) self.assertTrue(runner is not None, 'TestRunner must be valid.')