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

Python executions.create_execution_object函数代码示例

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

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



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

示例1: 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


示例2: test_execution_creation_action_triggered_by_rule

 def test_execution_creation_action_triggered_by_rule(self):
     # Wait for the action execution to complete and then confirm outcome.
     trigger_type = self.MODELS['triggertypes']['triggertype2.yaml']
     trigger = self.MODELS['triggers']['trigger2.yaml']
     trigger_instance = self.MODELS['triggerinstances']['trigger_instance_1.yaml']
     test_liveaction = self.FIXTURES['liveactions']['liveaction3.yaml']
     rule = self.MODELS['rules']['rule3.yaml']
     # Setup LiveAction to point to right rule and trigger_instance.
     # XXX: We need support for dynamic fixtures.
     test_liveaction['context']['rule']['id'] = str(rule.id)
     test_liveaction['context']['trigger_instance']['id'] = str(trigger_instance.id)
     test_liveaction_api = LiveActionAPI(**test_liveaction)
     test_liveaction = LiveAction.add_or_update(LiveActionAPI.to_model(test_liveaction_api))
     liveaction = LiveAction.get(context__trigger_instance__id=str(trigger_instance.id))
     self.assertIsNotNone(liveaction)
     self.assertEqual(liveaction.status, action_constants.LIVEACTION_STATUS_REQUESTED)
     executions_util.create_execution_object(liveaction)
     execution = self._get_action_execution(liveaction__id=str(liveaction.id),
                                            raise_exception=True)
     self.assertDictEqual(execution.trigger, vars(TriggerAPI.from_model(trigger)))
     self.assertDictEqual(execution.trigger_type, vars(TriggerTypeAPI.from_model(trigger_type)))
     self.assertDictEqual(execution.trigger_instance,
                          vars(TriggerInstanceAPI.from_model(trigger_instance)))
     self.assertDictEqual(execution.rule, vars(RuleAPI.from_model(rule)))
     action = action_utils.get_action_by_ref(liveaction.action)
     self.assertDictEqual(execution.action, vars(ActionAPI.from_model(action)))
     runner = RunnerType.get_by_name(action.runner_type['name'])
     self.assertDictEqual(execution.runner, vars(RunnerTypeAPI.from_model(runner)))
     liveaction = LiveAction.get_by_id(str(liveaction.id))
     self.assertEquals(execution.liveaction['id'], str(liveaction.id))
开发者ID:ruslantum,项目名称:st2,代码行数:30,代码来源:test_executions_util.py


示例3: test_execution_creation_with_web_url

 def test_execution_creation_with_web_url(self):
     liveaction = self.MODELS['liveactions']['liveaction1.yaml']
     executions_util.create_execution_object(liveaction)
     execution = self._get_action_execution(liveaction__id=str(liveaction.id),
                                            raise_exception=True)
     self.assertTrue(execution.web_url is not None)
     execution_id = str(execution.id)
     self.assertTrue(('history/%s/general' % execution_id) in execution.web_url)
开发者ID:nzlosh,项目名称:st2,代码行数:8,代码来源:test_executions_util.py


示例4: test_abandon_executions_on_complete

 def test_abandon_executions_on_complete(self):
     liveaction_db = self.MODELS['liveactions']['successful_liveaction.yaml']
     executions_util.create_execution_object(liveaction_db)
     expected_msg = 'LiveAction %s already in a completed state %s\.' % \
                    (str(liveaction_db.id), liveaction_db.status)
     self.assertRaisesRegexp(ValueError, expected_msg,
                             executions_util.abandon_execution_if_incomplete,
                             liveaction_id=str(liveaction_db.id))
开发者ID:AlexeyDeyneko,项目名称:st2,代码行数:8,代码来源:test_executions_util.py


示例5: test_abandon_executions

    def test_abandon_executions(self):
        liveaction_db = self.MODELS['liveactions']['liveaction1.yaml']
        executions_util.create_execution_object(liveaction_db)
        execution_db = executions_util.abandon_execution_if_incomplete(
            liveaction_id=str(liveaction_db.id))

        self.assertEquals(execution_db.status, 'abandoned')

        runners_utils.invoke_post_run.assert_called_once()
开发者ID:nzlosh,项目名称:st2,代码行数:9,代码来源:test_executions_util.py


示例6: _create_liveaction_db

    def _create_liveaction_db(self, status=action_constants.LIVEACTION_STATUS_REQUESTED):
        action_ref = 'wolfpack.action-1'
        parameters = {'actionstr': 'fu'}
        liveaction_db = LiveActionDB(action=action_ref, parameters=parameters, status=status)

        liveaction_db = LiveAction.add_or_update(liveaction_db)
        execution_service.create_execution_object(liveaction_db, publish=False)

        return liveaction_db
开发者ID:StackStorm,项目名称:st2,代码行数:9,代码来源:test_scheduler.py


示例7: _create_inquiry

 def _create_inquiry(self, ttl, timestamp):
     action_db = self.models['actions']['ask.yaml']
     liveaction_db = LiveActionDB()
     liveaction_db.status = action_constants.LIVEACTION_STATUS_PENDING
     liveaction_db.start_timestamp = timestamp
     liveaction_db.action = ResourceReference(name=action_db.name, pack=action_db.pack).ref
     liveaction_db.result = {'ttl': ttl}
     liveaction_db = LiveAction.add_or_update(liveaction_db)
     executions.create_execution_object(liveaction_db)
开发者ID:nzlosh,项目名称:st2,代码行数:9,代码来源:test_garbage_collector.py


示例8: 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


示例9: 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


示例10: 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


示例11: setUp

    def setUp(self):
        super(RunnersUtilityTests, self).setUp()

        loader = fixturesloader.FixturesLoader()

        self.models = loader.save_fixtures_to_db(
            fixtures_pack=FIXTURES_PACK,
            fixtures_dict=TEST_FIXTURES
        )

        self.liveaction_db = self.models['liveactions']['liveaction1.yaml']
        exe_svc.create_execution_object(self.liveaction_db)
        self.action_db = action_db_utils.get_action_by_ref(self.liveaction_db.action)
开发者ID:lyandut,项目名称:st2,代码行数:13,代码来源:test_runners_utils.py


示例12: test_execution_update

 def test_execution_update(self):
     liveaction = self.MODELS['liveactions']['liveaction1.yaml']
     executions_util.create_execution_object(liveaction)
     liveaction.status = 'running'
     pre_update_timestamp = date_utils.get_datetime_utc_now()
     executions_util.update_execution(liveaction)
     post_update_timestamp = date_utils.get_datetime_utc_now()
     execution = self._get_action_execution(liveaction__id=str(liveaction.id),
                                            raise_exception=True)
     self.assertEquals(len(execution.log), 2)
     self.assertEquals(execution.log[1]['status'], liveaction.status)
     self.assertGreater(execution.log[1]['timestamp'], pre_update_timestamp)
     self.assertLess(execution.log[1]['timestamp'], post_update_timestamp)
开发者ID:nzlosh,项目名称:st2,代码行数:13,代码来源:test_executions_util.py


示例13: 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


示例14: test_execution_creation_manual_action_run

 def test_execution_creation_manual_action_run(self):
     liveaction = self.MODELS['liveactions']['liveaction1.yaml']
     executions_util.create_execution_object(liveaction)
     execution = self._get_action_execution(liveaction__id=str(liveaction.id),
                                            raise_exception=True)
     self.assertDictEqual(execution.trigger, {})
     self.assertDictEqual(execution.trigger_type, {})
     self.assertDictEqual(execution.trigger_instance, {})
     self.assertDictEqual(execution.rule, {})
     action = action_utils.get_action_by_ref('core.local')
     self.assertDictEqual(execution.action, vars(ActionAPI.from_model(action)))
     runner = RunnerType.get_by_name(action.runner_type['name'])
     self.assertDictEqual(execution.runner, vars(RunnerTypeAPI.from_model(runner)))
     liveaction = LiveAction.get_by_id(str(liveaction.id))
     self.assertEquals(execution.liveaction['id'], str(liveaction.id))
开发者ID:ruslantum,项目名称:st2,代码行数:15,代码来源:test_executions_util.py


示例15: test_execution_creation_chains

 def test_execution_creation_chains(self):
     childliveaction = self.MODELS['liveactions']['childliveaction.yaml']
     child_exec = executions_util.create_execution_object(childliveaction)
     parent_execution_id = childliveaction.context['parent']['execution_id']
     parent_execution = ActionExecution.get_by_id(parent_execution_id)
     child_execs = parent_execution.children
     self.assertTrue(str(child_exec.id) in child_execs)
开发者ID:AlexeyDeyneko,项目名称:st2,代码行数:7,代码来源:test_executions_util.py


示例16: test_delayed_executions_recovery_before_timeout

    def test_delayed_executions_recovery_before_timeout(self):
        # Create a live action that's delayed but has not passed the timeout.
        liveaction = LiveActionDB(action='wolfpack.action-1',
                                  parameters={'actionstr': 'foo'},
                                  start_timestamp=date_utils.get_datetime_utc_now(),
                                  status=action_constants.LIVEACTION_STATUS_DELAYED)

        liveaction = LiveAction.add_or_update(liveaction, publish=False)
        executions.create_execution_object(liveaction, publish=False)

        # Run the rescheduling routine.
        scheduler.recover_delayed_executions()

        # The live action is expected to stay "delayed".
        liveaction = LiveAction.get_by_id(str(liveaction.id))
        self.assertEqual(liveaction.status, action_constants.LIVEACTION_STATUS_DELAYED)
开发者ID:meirwah,项目名称:st2,代码行数:16,代码来源:test_scheduler.py


示例17: 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


示例18: 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


示例19: 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


示例20: test_worker_shutdown

    def test_worker_shutdown(self):
        action_worker = actions_worker.get_worker()
        temp_file = None

        # Create a temporary file that is deleted when the file is closed and then set up an
        # action to wait for this file to be deleted. This allows this test to run the action
        # over a separate thread, run the shutdown sequence on the main thread, and then let
        # the local runner to exit gracefully and allow _run_action to finish execution.
        with tempfile.NamedTemporaryFile() as fp:
            temp_file = fp.name
            self.assertIsNotNone(temp_file)
            self.assertTrue(os.path.isfile(temp_file))

            # Launch the action execution in a separate thread.
            params = {'cmd': 'while [ -e \'%s\' ]; do sleep 0.1; done' % temp_file}
            liveaction_db = self._get_liveaction_model(WorkerTestCase.local_action_db, params)
            liveaction_db = LiveAction.add_or_update(liveaction_db)
            executions.create_execution_object(liveaction_db)
            runner_thread = eventlet.spawn(action_worker._run_action, liveaction_db)

            # Wait for the worker up to 10s to add the liveaction to _running_liveactions.
            for i in range(0, int(10 / 0.1)):
                eventlet.sleep(0.1)
                if len(action_worker._running_liveactions) > 0:
                    break

            self.assertEqual(len(action_worker._running_liveactions), 1)

            # Shutdown the worker to trigger the abandon process.
            action_worker.shutdown()
            liveaction_db = LiveAction.get_by_id(liveaction_db.id)

            # Verify that _running_liveactions is empty and the liveaction is abandoned.
            self.assertEqual(len(action_worker._running_liveactions), 0)
            self.assertEqual(liveaction_db.status, action_constants.LIVEACTION_STATUS_ABANDONED,
                             str(liveaction_db))

        # Make sure the temporary file has been deleted.
        self.assertFalse(os.path.isfile(temp_file))

        # Wait for the local runner to complete. This will activate the finally block in
        # _run_action but will not result in KeyError because the discard method is used to
        # to remove the liveaction from _running_liveactions.
        runner_thread.wait()
开发者ID:nzlosh,项目名称:st2,代码行数:44,代码来源:test_worker.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python executions.get_descendants函数代码示例发布时间:2022-05-27
下一篇:
Python action.update_status函数代码示例发布时间: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