• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python base.get_runner_container函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中st2actions.container.base.get_runner_container函数的典型用法代码示例。如果您正苦于以下问题:Python get_runner_container函数的具体用法?Python get_runner_container怎么用?Python get_runner_container使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_runner_container函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_created_temporary_auth_token_is_correctly_scoped_to_user_who_ran_the_action

    def test_created_temporary_auth_token_is_correctly_scoped_to_user_who_ran_the_action(self):
        params = {
            'actionstr': 'bar',
            'mock_status': action_constants.LIVEACTION_STATUS_SUCCEEDED
        }

        global global_runner
        global_runner = None

        def mock_get_runner(*args, **kwargs):
            global global_runner
            runner = original_get_runner(*args, **kwargs)
            global_runner = runner
            return runner

        # user joe_1

        runner_container = get_runner_container()
        original_get_runner = runner_container._get_runner

        liveaction_db = self._get_failingaction_exec_db_model(params)
        liveaction_db = LiveAction.add_or_update(liveaction_db)
        liveaction_db.context = {'user': 'user_joe_1'}
        executions.create_execution_object(liveaction_db)

        runner_container._get_runner = mock_get_runner

        self.assertEqual(getattr(global_runner, 'auth_token', None), None)
        runner_container.dispatch(liveaction_db)
        self.assertEqual(global_runner.auth_token.user, 'user_joe_1')
        self.assertEqual(global_runner.auth_token.metadata['service'], 'actions_container')

        runner_container._get_runner = original_get_runner

        # user mark_1
        global_runner = None
        runner_container = get_runner_container()
        original_get_runner = runner_container._get_runner

        liveaction_db = self._get_failingaction_exec_db_model(params)
        liveaction_db = LiveAction.add_or_update(liveaction_db)
        liveaction_db.context = {'user': 'user_mark_2'}
        executions.create_execution_object(liveaction_db)
        original_get_runner = runner_container._get_runner

        runner_container._get_runner = mock_get_runner

        self.assertEqual(getattr(global_runner, 'auth_token', None), None)
        runner_container.dispatch(liveaction_db)
        self.assertEqual(global_runner.auth_token.user, 'user_mark_2')
        self.assertEqual(global_runner.auth_token.metadata['service'], 'actions_container')
开发者ID:lyandut,项目名称:st2,代码行数:51,代码来源:test_runner_container.py


示例2: test_state_db_created_for_polling_async_actions

    def test_state_db_created_for_polling_async_actions(self):
        runner_container = get_runner_container()

        params = {
            'actionstr': 'foo',
            'actionint': 20,
            'async_test': True
        }

        liveaction_db = self._get_liveaction_model(
            RunnerContainerTest.polling_async_action_db,
            params
        )

        liveaction_db = LiveAction.add_or_update(liveaction_db)
        executions.create_execution_object(liveaction_db)

        # Assert that execution ran without exceptions.
        runner_container.dispatch(liveaction_db)
        states = ActionExecutionState.get_all()
        found = [state for state in states if state.execution_id == liveaction_db.id]

        self.assertTrue(len(found) > 0, 'There should be a state db object.')
        self.assertTrue(len(found) == 1, 'There should only be one state db object.')
        self.assertTrue(found[0].query_context is not None)
        self.assertTrue(found[0].query_module is not None)
开发者ID:lyandut,项目名称:st2,代码行数:26,代码来源:test_runner_container.py


示例3: _mark_inquiry_complete

    def _mark_inquiry_complete(self, inquiry_id, result):
        """Mark Inquiry as completed

        This function updates the local LiveAction and Execution with a successful
        status as well as call the "post_run" function for the Inquirer runner so that
        the appropriate callback function is executed

        :param inquiry: The Inquiry for which the response is given
        :param requester_user: The user providing the response

        :rtype: bool - True if requester_user is able to respond. False if not.
        """

        # Update inquiry's execution result with a successful status and the validated response
        liveaction_db = action_utils.update_liveaction_status(
            status=action_constants.LIVEACTION_STATUS_SUCCEEDED,
            runner_info=system_info.get_process_info(),
            result=result,
            liveaction_id=inquiry_id)
        executions.update_execution(liveaction_db)

        # Call Inquiry runner's post_run to trigger callback to workflow
        runner_container = get_runner_container()
        action_db = get_action_by_ref(liveaction_db.action)
        runnertype_db = get_runnertype_by_name(action_db.runner_type['name'])
        runner = runner_container._get_runner(runnertype_db, action_db, liveaction_db)
        runner.post_run(status=action_constants.LIVEACTION_STATUS_SUCCEEDED, result=result)

        return liveaction_db
开发者ID:lyandut,项目名称:st2,代码行数:29,代码来源:inquiries.py


示例4: respond

def respond(inquiry, response, requester=None):
    # Set requester to system user is not provided.
    if not requester:
        requester = cfg.CONF.system_user.user

    # Retrieve the liveaction from the database.
    liveaction_db = lv_db_access.LiveAction.get_by_id(inquiry.liveaction.get('id'))

    # Resume the parent workflow first. If the action execution for the inquiry is updated first,
    # it triggers handling of the action execution completion which will interact with the paused
    # parent workflow. The resuming logic that is executed here will then race with the completion
    # of the inquiry action execution, which will randomly result in the parent workflow stuck in
    # paused state.
    if liveaction_db.context.get('parent'):
        LOG.debug('Resuming workflow parent(s) for inquiry "%s".' % str(inquiry.id))

        # For action execution under Action Chain and Mistral workflows, request the entire
        # workflow to resume. Orquesta handles resume differently and so does not require root
        # to resume. Orquesta allows for specifc branches to resume while other is paused. When
        # there is no other paused branches, the conductor will resume the rest of the workflow.
        resume_target = (
            action_service.get_parent_liveaction(liveaction_db)
            if workflow_service.is_action_execution_under_workflow_context(liveaction_db)
            else action_service.get_root_liveaction(liveaction_db)
        )

        if resume_target.status in action_constants.LIVEACTION_PAUSE_STATES:
            action_service.request_resume(resume_target, requester)

    # Succeed the liveaction and update result with the inquiry response.
    LOG.debug('Updating response for inquiry "%s".' % str(inquiry.id))

    result = copy.deepcopy(inquiry.result)
    result['response'] = response

    liveaction_db = action_utils.update_liveaction_status(
        status=action_constants.LIVEACTION_STATUS_SUCCEEDED,
        end_timestamp=date_utils.get_datetime_utc_now(),
        runner_info=sys_info_utils.get_process_info(),
        result=result,
        liveaction_id=str(liveaction_db.id)
    )

    # Sync the liveaction with the corresponding action execution.
    execution_service.update_execution(liveaction_db)

    # Invoke inquiry post run to trigger a callback to parent workflow.
    LOG.debug('Invoking post run for inquiry "%s".' % str(inquiry.id))
    runner_container = container.get_runner_container()
    action_db = action_utils.get_action_by_ref(liveaction_db.action)
    runnertype_db = action_utils.get_runnertype_by_name(action_db.runner_type['name'])
    runner = runner_container._get_runner(runnertype_db, action_db, liveaction_db)
    runner.post_run(status=action_constants.LIVEACTION_STATUS_SUCCEEDED, result=result)

    return liveaction_db
开发者ID:nzlosh,项目名称:st2,代码行数:55,代码来源:inquiry.py


示例5: test_dispatch_runner_failure

 def test_dispatch_runner_failure(self):
     runner_container = get_runner_container()
     params = {"actionstr": "bar"}
     liveaction_db = self._get_failingaction_exec_db_model(params)
     liveaction_db = LiveAction.add_or_update(liveaction_db)
     executions.create_execution_object(liveaction_db)
     runner_container.dispatch(liveaction_db)
     # pickup updated liveaction_db
     liveaction_db = LiveAction.get_by_id(liveaction_db.id)
     self.assertTrue("message" in liveaction_db.result)
     self.assertTrue("traceback" in liveaction_db.result)
开发者ID:emptywee,项目名称:st2,代码行数:11,代码来源:test_runner_container.py


示例6: test_dispatch_runner_failure

 def test_dispatch_runner_failure(self):
     runner_container = get_runner_container()
     params = {
         'actionstr': 'bar'
     }
     actionexec_db = self._get_failingaction_exec_db_model(params)
     actionexec_db = ActionExecution.add_or_update(actionexec_db)
     self.assertTrue(runner_container.dispatch(actionexec_db))
     # pickup updated actionexec_db
     actionexec_db = ActionExecution.get_by_id(actionexec_db.id)
     self.assertTrue('message' in actionexec_db.result)
     self.assertTrue('traceback' in actionexec_db.result)
开发者ID:bjoernbessert,项目名称:st2,代码行数:12,代码来源:test_runner_container.py


示例7: test_dispatch_override_default_action_params

 def test_dispatch_override_default_action_params(self):
     runner_container = get_runner_container()
     params = {"actionstr": "foo", "actionint": 20}
     liveaction_db = self._get_action_exec_db_model(RunnerContainerTest.action_db, params)
     liveaction_db = LiveAction.add_or_update(liveaction_db)
     executions.create_execution_object(liveaction_db)
     # Assert that execution ran successfully.
     runner_container.dispatch(liveaction_db)
     liveaction_db = LiveAction.get_by_id(liveaction_db.id)
     result = liveaction_db.result
     self.assertTrue(result.get("action_params").get("actionint") == 20)
     self.assertTrue(result.get("action_params").get("actionstr") == "foo")
开发者ID:emptywee,项目名称:st2,代码行数:12,代码来源:test_runner_container.py


示例8: test_dispatch_non_utf8_result

    def test_dispatch_non_utf8_result(self):
        runner_container = get_runner_container()
        params = {"cmd": "python -c 'print \"\\x82\"'"}
        liveaction_db = self._get_liveaction_model(RunnerContainerTest.local_action_db, params)
        liveaction_db = LiveAction.add_or_update(liveaction_db)
        executions.create_execution_object(liveaction_db)

        try:
            runner_container.dispatch(liveaction_db)
            self.fail("Mongo won't handle non UTF-8 strings. Should have failed.")
        except InvalidStringData:
            pass
开发者ID:rlugojr,项目名称:st2,代码行数:12,代码来源:test_runner_container.py


示例9: test_dispatch

 def test_dispatch(self):
     runner_container = get_runner_container()
     params = {
         'actionstr': 'bar'
     }
     actionexec_db = self._get_action_exec_db_model(params)
     actionexec_db = ActionExecution.add_or_update(actionexec_db)
     # Assert that execution ran successfully.
     self.assertTrue(runner_container.dispatch(actionexec_db))
     actionexec_db = ActionExecution.get_by_id(actionexec_db.id)
     result = actionexec_db.result
     self.assertTrue(result.get('action_params').get('actionint') == 10)
     self.assertTrue(result.get('action_params').get('actionstr') == 'bar')
开发者ID:bjoernbessert,项目名称:st2,代码行数:13,代码来源:test_runner_container.py


示例10: test_dispatch_override_default_action_params

    def test_dispatch_override_default_action_params(self):
        runner_container = get_runner_container()
        params = {
            'actionstr': 'foo',
            'actionint': 20
        }
        actionexec_db = self._get_action_exec_db_model(params)
        actionexec_db = ActionExecution.add_or_update(actionexec_db)

        # Assert that execution ran successfully.
        result = runner_container.dispatch(actionexec_db)
        self.assertTrue(result)
        actionexec_db = ActionExecution.get_by_id(actionexec_db.id)
        result = actionexec_db.result
        self.assertTrue(result.get('action_params').get('actionint') == 20)
        self.assertTrue(result.get('action_params').get('actionstr') == 'foo')
开发者ID:bjoernbessert,项目名称:st2,代码行数:16,代码来源:test_runner_container.py


示例11: test_dispatch_unsupported_status

    def test_dispatch_unsupported_status(self):
        runner_container = get_runner_container()
        params = {'actionstr': 'bar'}
        liveaction_db = self._get_liveaction_model(RunnerContainerTest.action_db, params)
        liveaction_db = LiveAction.add_or_update(liveaction_db)
        executions.create_execution_object(liveaction_db)

        # Manually set the liveaction_db to some unsupported status.
        liveaction_db.status = action_constants.LIVEACTION_STATUS_CANCELED

        # Assert exception is raised on dispatch.
        self.assertRaises(
            ActionRunnerDispatchError,
            runner_container.dispatch,
            liveaction_db
        )
开发者ID:lyandut,项目名称:st2,代码行数:16,代码来源:test_runner_container.py


示例12: test_dispatch

    def test_dispatch(self):
        runner_container = get_runner_container()
        params = {"actionstr": "bar"}
        liveaction_db = self._get_action_exec_db_model(RunnerContainerTest.action_db, params)
        liveaction_db = LiveAction.add_or_update(liveaction_db)
        executions.create_execution_object(liveaction_db)
        # Assert that execution ran successfully.
        runner_container.dispatch(liveaction_db)
        liveaction_db = LiveAction.get_by_id(liveaction_db.id)
        result = liveaction_db.result
        self.assertTrue(result.get("action_params").get("actionint") == 10)
        self.assertTrue(result.get("action_params").get("actionstr") == "bar")

        # Assert that context is written correctly.
        context = {"user": "stanley", "third_party_system": {"ref_id": "1234"}}

        self.assertDictEqual(liveaction_db.context, context)
开发者ID:emptywee,项目名称:st2,代码行数:17,代码来源:test_runner_container.py


示例13: test_state_db_creation_async_actions

    def test_state_db_creation_async_actions(self):
        runner_container = get_runner_container()
        params = {"actionstr": "foo", "actionint": 20, "async_test": True}
        liveaction_db = self._get_action_exec_db_model(RunnerContainerTest.async_action_db, params)
        liveaction_db = LiveAction.add_or_update(liveaction_db)
        executions.create_execution_object(liveaction_db)
        # Assert that execution ran without exceptions.
        runner_container.dispatch(liveaction_db)
        states = ActionExecutionState.get_all()

        found = None
        for state in states:
            if state.execution_id == liveaction_db.id:
                found = state
        self.assertTrue(found is not None, "There should be a state db object.")
        self.assertTrue(found.query_context is not None)
        self.assertTrue(found.query_module is not None)
开发者ID:emptywee,项目名称:st2,代码行数:17,代码来源:test_runner_container.py


示例14: test_dispatch

    def test_dispatch(self):
        runner_container = get_runner_container()
        params = {
            'actionstr': 'bar'
        }
        liveaction_db = self._get_action_exec_db_model(RunnerContainerTest.action_db, params)
        liveaction_db = LiveAction.add_or_update(liveaction_db)
        executions.create_execution_object(liveaction_db)
        # Assert that execution ran successfully.
        runner_container.dispatch(liveaction_db)
        liveaction_db = LiveAction.get_by_id(liveaction_db.id)
        result = liveaction_db.result
        self.assertTrue(result.get('action_params').get('actionint') == 10)
        self.assertTrue(result.get('action_params').get('actionstr') == 'bar')

        # Assert that context is written correctly.
        context = {
            'user': 'stanley',
            'third_party_system': {
                'ref_id': '1234'
            }
        }

        self.assertDictEqual(liveaction_db.context, context)
开发者ID:BlazeMediaGroup,项目名称:st2,代码行数:24,代码来源:test_runner_container.py


示例15: test_post_run_is_always_called_after_run

    def test_post_run_is_always_called_after_run(self):
        # 1. post_run should be called on success, failure, etc.
        runner_container = get_runner_container()
        params = {
            'actionstr': 'bar',
            'mock_status': action_constants.LIVEACTION_STATUS_SUCCEEDED
        }
        liveaction_db = self._get_failingaction_exec_db_model(params)
        liveaction_db = LiveAction.add_or_update(liveaction_db)
        executions.create_execution_object(liveaction_db)

        global global_runner
        global_runner = None
        original_get_runner = runner_container._get_runner

        def mock_get_runner(*args, **kwargs):
            global global_runner
            runner = original_get_runner(*args, **kwargs)
            global_runner = runner
            return runner
        runner_container._get_runner = mock_get_runner

        # Note: We can't assert here that post_run hasn't been called yet because runner instance
        # is only instantiated later inside dispatch method
        runner_container.dispatch(liveaction_db)
        self.assertTrue(global_runner.post_run_called)

        # 2. Verify post_run is called if run() throws
        runner_container = get_runner_container()
        params = {
            'actionstr': 'bar',
            'raise': True
        }
        liveaction_db = self._get_failingaction_exec_db_model(params)
        liveaction_db = LiveAction.add_or_update(liveaction_db)
        executions.create_execution_object(liveaction_db)

        global_runner = None
        original_get_runner = runner_container._get_runner

        def mock_get_runner(*args, **kwargs):
            global global_runner
            runner = original_get_runner(*args, **kwargs)
            global_runner = runner
            return runner
        runner_container._get_runner = mock_get_runner

        # Note: We can't assert here that post_run hasn't been called yet because runner instance
        # is only instantiated later inside dispatch method
        runner_container.dispatch(liveaction_db)
        self.assertTrue(global_runner.post_run_called)

        # 2. Verify post_run is also called if _delete_auth_token throws
        runner_container = get_runner_container()
        runner_container._delete_auth_token = mock.Mock(side_effect=ValueError('throw'))
        params = {
            'actionstr': 'bar',
            'mock_status': action_constants.LIVEACTION_STATUS_SUCCEEDED
        }
        liveaction_db = self._get_failingaction_exec_db_model(params)
        liveaction_db = LiveAction.add_or_update(liveaction_db)
        executions.create_execution_object(liveaction_db)

        global_runner = None
        original_get_runner = runner_container._get_runner

        def mock_get_runner(*args, **kwargs):
            global global_runner
            runner = original_get_runner(*args, **kwargs)
            global_runner = runner
            return runner
        runner_container._get_runner = mock_get_runner

        # Note: We can't assert here that post_run hasn't been called yet because runner instance
        # is only instantiated later inside dispatch method
        runner_container.dispatch(liveaction_db)
        self.assertTrue(global_runner.post_run_called)
开发者ID:lyandut,项目名称:st2,代码行数:77,代码来源:test_runner_container.py



注:本文中的st2actions.container.base.get_runner_container函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python service.RunnerContainerService类代码示例发布时间:2022-05-27
下一篇:
Python datasets.Separator类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap