예제 #1
0
    def dispatch(self, liveaction_db):
        action_db = get_action_by_ref(liveaction_db.action)
        if not action_db:
            raise Exception('Action %s not found in DB.' %
                            (liveaction_db.action))

        runnertype_db = get_runnertype_by_name(action_db.runner_type['name'])

        extra = {
            'liveaction_db': liveaction_db,
            'runnertype_db': runnertype_db
        }
        LOG.info('Dispatching Action to a runner', extra=extra)

        # Get runner instance.
        runner = get_runner(runnertype_db.runner_module)
        LOG.debug('Runner instance for RunnerType "%s" is: %s',
                  runnertype_db.name, runner)

        # Invoke pre_run, run, post_run cycle.
        liveaction_db = self._do_run(runner, runnertype_db, action_db,
                                     liveaction_db)

        extra = {'result': liveaction_db.result}
        LOG.debug('Runner do_run result', extra=extra)

        extra = {'liveaction_db': liveaction_db}
        LOG.audit('Liveaction completed', extra=extra)

        return liveaction_db.result
예제 #2
0
파일: base.py 프로젝트: rgaertner/st2
    def dispatch(self, liveaction_db):
        action_db = get_action_by_ref(liveaction_db.action)
        if not action_db:
            raise Exception('Action %s not found in dB.' %
                            liveaction_db.action)
        runnertype_db = get_runnertype_by_name(action_db.runner_type['name'])
        runner_type = runnertype_db.name

        LOG.info('Dispatching Action to runner \n%s',
                 json.dumps(liveaction_db.to_serializable_dict(), indent=4))
        LOG.debug('    liverunner_type: %s', runner_type)
        LOG.debug('    RunnerType: %s', runnertype_db)

        # Get runner instance.
        runner = get_runner(runnertype_db.runner_module)
        LOG.debug('Runner instance for RunnerType "%s" is: %s',
                  runnertype_db.name, runner)

        # Invoke pre_run, run, post_run cycle.
        liveaction_db = self._do_run(runner, runnertype_db, action_db,
                                     liveaction_db)
        LOG.debug('runner do_run result: %s', liveaction_db.result)

        liveaction_serializable = liveaction_db.to_serializable_dict()

        extra = {'liveaction_db': liveaction_db}
        LOG.audit('liveaction complete.', extra=extra)
        LOG.info(
            'result :\n%s.',
            json.dumps(liveaction_serializable.get('result', None), indent=4))

        return liveaction_db.result
예제 #3
0
    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.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
예제 #4
0
파일: base.py 프로젝트: BlazeMediaGroup/st2
    def dispatch(self, liveaction_db):
        action_db = get_action_by_ref(liveaction_db.action)
        if not action_db:
            raise Exception('Action %s not found in dB.' % liveaction_db.action)
        runnertype_db = get_runnertype_by_name(action_db.runner_type['name'])
        runner_type = runnertype_db.name

        LOG.info('Dispatching Action to runner \n%s',
                 json.dumps(liveaction_db.to_serializable_dict(), indent=4))
        LOG.debug('    liverunner_type: %s', runner_type)
        LOG.debug('    RunnerType: %s', runnertype_db)

        # Get runner instance.
        runner = get_runner(runnertype_db.runner_module)
        LOG.debug('Runner instance for RunnerType "%s" is: %s', runnertype_db.name, runner)

        # Invoke pre_run, run, post_run cycle.
        liveaction_db = self._do_run(runner, runnertype_db, action_db, liveaction_db)
        LOG.debug('runner do_run result: %s', liveaction_db.result)

        liveaction_serializable = liveaction_db.to_serializable_dict()

        extra = {'liveaction_db': liveaction_db}
        LOG.audit('liveaction complete.', extra=extra)
        LOG.info('result :\n%s.', json.dumps(liveaction_serializable.get('result', None), indent=4))

        return liveaction_db.result
예제 #5
0
파일: base.py 프로젝트: Bala96/st2
    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
예제 #6
0
 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.')
예제 #7
0
 def test_get_runner_module_fail(self):
     runnertype_db = RunnerTypeDB(runner_module="absent.module")
     runner = None
     try:
         runner = get_runner(runnertype_db.runner_module)
     except ActionRunnerCreateError:
         pass
     self.assertFalse(runner, "TestRunner must be valid.")
예제 #8
0
    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)
예제 #9
0
    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)
예제 #10
0
파일: base.py 프로젝트: beryah/st2
    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.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)

        return runner
예제 #11
0
    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.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)

        return runner
예제 #12
0
파일: base.py 프로젝트: AlexeyDeyneko/st2
    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)
예제 #13
0
파일: base.py 프로젝트: timff/st2
    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)
예제 #14
0
파일: base.py 프로젝트: joshgre/st2
    def dispatch(self, liveaction_db):
        action_db = get_action_by_ref(liveaction_db.action)
        if not action_db:
            raise Exception('Action %s not found in DB.' % (liveaction_db.action))

        runnertype_db = get_runnertype_by_name(action_db.runner_type['name'])

        extra = {'liveaction_db': liveaction_db, 'runnertype_db': runnertype_db}
        LOG.info('Dispatching Action to a runner', extra=extra)

        # Get runner instance.
        runner = get_runner(runnertype_db.runner_module)
        LOG.debug('Runner instance for RunnerType "%s" is: %s', runnertype_db.name, runner)

        # Invoke pre_run, run, post_run cycle.
        liveaction_db = self._do_run(runner, runnertype_db, action_db, liveaction_db)

        extra = {'result': liveaction_db.result}
        LOG.debug('Runner do_run result', extra=extra)

        extra = {'liveaction_db': liveaction_db}
        LOG.audit('Liveaction completed', extra=extra)

        return liveaction_db.result
예제 #15
0
 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.')