當前位置: 首頁>>代碼示例>>Python>>正文


Python ActionExecutionState.get_by_id方法代碼示例

本文整理匯總了Python中st2common.persistence.executionstate.ActionExecutionState.get_by_id方法的典型用法代碼示例。如果您正苦於以下問題:Python ActionExecutionState.get_by_id方法的具體用法?Python ActionExecutionState.get_by_id怎麽用?Python ActionExecutionState.get_by_id使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在st2common.persistence.executionstate.ActionExecutionState的用法示例。


在下文中一共展示了ActionExecutionState.get_by_id方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_execution_cancellation

# 需要導入模塊: from st2common.persistence.executionstate import ActionExecutionState [as 別名]
# 或者: from st2common.persistence.executionstate.ActionExecutionState import get_by_id [as 別名]
    def test_execution_cancellation(self):
        tracker = self._get_tracker()
        querier = tracker.get_querier('test_querymodule')
        querier._delete_state_object = mock.Mock(return_value=None)
        runners_utils.invoke_post_run = mock.Mock(return_value=None)

        # Ensure state objects are present.
        state1 = ActionExecutionState.get_by_id(ResultsTrackerTests.states['state1.yaml'].id)
        state2 = ActionExecutionState.get_by_id(ResultsTrackerTests.states['state2.yaml'].id)
        self.assertIsNotNone(state1)
        self.assertIsNotNone(state2)

        with mock.patch.object(
                querier.__class__, 'query',
                mock.MagicMock(return_value=(action_constants.LIVEACTION_STATUS_CANCELED, {}))):
            tracker._bootstrap()
            eventlet.sleep(2)

            exec_id = str(ResultsTrackerTests.states['state1.yaml'].execution_id)
            exec_db = LiveAction.get_by_id(exec_id)
            self.assertDictEqual(exec_db.result, {})

            exec_id = str(ResultsTrackerTests.states['state2.yaml'].execution_id)
            exec_db = LiveAction.get_by_id(exec_id)
            self.assertDictEqual(exec_db.result, {})

            tracker.shutdown()

        # Ensure deletes are called.
        self.assertEqual(2, querier._delete_state_object.call_count)

        # Ensure invoke_post_run is called.
        self.assertEqual(2, runners_utils.invoke_post_run.call_count)
開發者ID:nzlosh,項目名稱:st2,代碼行數:35,代碼來源:test_resultstracker.py

示例2: test_keep_state_object_on_error_at_update_result

# 需要導入模塊: from st2common.persistence.executionstate import ActionExecutionState [as 別名]
# 或者: from st2common.persistence.executionstate.ActionExecutionState import get_by_id [as 別名]
    def test_keep_state_object_on_error_at_update_result(self):
        tracker = self._get_tracker()
        querier = tracker.get_querier('test_querymodule')
        querier._delete_state_object = mock.Mock(return_value=None)
        querier.delete_state_object_on_error = False

        # Ensure state objects are present.
        state1 = ActionExecutionState.get_by_id(ResultsTrackerTests.states['state1.yaml'].id)
        state2 = ActionExecutionState.get_by_id(ResultsTrackerTests.states['state2.yaml'].id)
        self.assertIsNotNone(state1)
        self.assertIsNotNone(state2)

        with mock.patch.object(
                querier.__class__, '_update_action_results',
                mock.MagicMock(side_effect=Exception('Mock update exception.'))):
            tracker._bootstrap()
            eventlet.sleep(1)

            exec_id = str(ResultsTrackerTests.states['state1.yaml'].execution_id)
            exec_db = LiveAction.get_by_id(exec_id)
            self.assertDictEqual(exec_db.result, {})

            exec_id = str(ResultsTrackerTests.states['state2.yaml'].execution_id)
            exec_db = LiveAction.get_by_id(exec_id)
            self.assertDictEqual(exec_db.result, {})

            tracker.shutdown()

        # Ensure deletes are not called.
        querier._delete_state_object.assert_not_called()
開發者ID:nzlosh,項目名稱:st2,代碼行數:32,代碼來源:test_resultstracker.py

示例3: _update_state_models

# 需要導入模塊: from st2common.persistence.executionstate import ActionExecutionState [as 別名]
# 或者: from st2common.persistence.executionstate.ActionExecutionState import get_by_id [as 別名]
 def _update_state_models(cls):
     states = ResultsTrackerTests.states
     state1 = ActionExecutionState.get_by_id(states['state1.yaml'].id)
     state1.execution_id = ResultsTrackerTests.liveactions['liveaction1.yaml'].id
     state2 = ActionExecutionState.get_by_id(states['state2.yaml'].id)
     state2.execution_id = ResultsTrackerTests.liveactions['liveaction2.yaml'].id
     ResultsTrackerTests.states['state1.yaml'] = ActionExecutionState.add_or_update(state1)
     ResultsTrackerTests.states['state2.yaml'] = ActionExecutionState.add_or_update(state2)
開發者ID:nzlosh,項目名稱:st2,代碼行數:10,代碼來源:test_resultstracker.py

示例4: test_state_crud

# 需要導入模塊: from st2common.persistence.executionstate import ActionExecutionState [as 別名]
# 或者: from st2common.persistence.executionstate.ActionExecutionState import get_by_id [as 別名]
 def test_state_crud(self):
     saved = ActionExecutionStateTests._create_save_actionstate()
     retrieved = ActionExecutionState.get_by_id(saved.id)
     self.assertDictEqual(saved.query_context, retrieved.query_context)
     self.assertEqual(saved.query_module, retrieved.query_module)
     ActionExecutionStateTests._delete(model_objects=[retrieved])
     try:
         retrieved = ActionExecutionState.get_by_id(saved.id)
     except StackStormDBObjectNotFoundError:
         retrieved = None
     self.assertIsNone(retrieved, 'managed to retrieve after failure.')
開發者ID:StackStorm,項目名稱:st2,代碼行數:13,代碼來源:test_db_action_state.py

示例5: _delete_state_object

# 需要導入模塊: from st2common.persistence.executionstate import ActionExecutionState [as 別名]
# 或者: from st2common.persistence.executionstate.ActionExecutionState import get_by_id [as 別名]
 def _delete_state_object(self, query_context):
     state_db = ActionExecutionState.get_by_id(query_context.id)
     if state_db is not None:
         try:
             ActionExecutionState.delete(state_db)
         except:
             LOG.exception('Failed clearing state object: %s', state_db)
開發者ID:ruslantum,項目名稱:st2,代碼行數:9,代碼來源:base.py

示例6: test_action_deleted

# 需要導入模塊: from st2common.persistence.executionstate import ActionExecutionState [as 別名]
# 或者: from st2common.persistence.executionstate.ActionExecutionState import get_by_id [as 別名]
    def test_action_deleted(self):
        tracker = self._get_tracker()
        action_db_utils.get_runnertype_by_name = mock.Mock(return_value=None)

        # Ensure state objects are present.
        state1 = ActionExecutionState.get_by_id(ResultsTrackerTests.states['state1.yaml'].id)
        state2 = ActionExecutionState.get_by_id(ResultsTrackerTests.states['state2.yaml'].id)
        self.assertIsNotNone(state1)
        self.assertIsNotNone(state2)

        # Process the state objects.
        tracker._bootstrap()
        eventlet.sleep(1)

        exec_id = str(ResultsTrackerTests.states['state1.yaml'].execution_id)
        exec_db = LiveAction.get_by_id(exec_id)
        self.assertTrue(exec_db.result['called_with'][exec_id] is not None,
                        exec_db.result)

        exec_id = str(ResultsTrackerTests.states['state2.yaml'].execution_id)
        exec_db = LiveAction.get_by_id(exec_id)
        self.assertTrue(exec_db.result['called_with'][exec_id] is not None,
                        exec_db.result)

        tracker.shutdown()

        # Ensure state objects are deleted.
        self.assertRaises(
            StackStormDBObjectNotFoundError,
            ActionExecutionState.get_by_id,
            ResultsTrackerTests.states['state1.yaml'].id
        )

        self.assertRaises(
            StackStormDBObjectNotFoundError,
            ActionExecutionState.get_by_id,
            ResultsTrackerTests.states['state2.yaml'].id
        )

        # Ensure get_runnertype_by_name in invoke_post_run is not called.
        action_db_utils.get_runnertype_by_name.assert_not_called()
開發者ID:nzlosh,項目名稱:st2,代碼行數:43,代碼來源:test_resultstracker.py

示例7: test_query_process

# 需要導入模塊: from st2common.persistence.executionstate import ActionExecutionState [as 別名]
# 或者: from st2common.persistence.executionstate.ActionExecutionState import get_by_id [as 別名]
    def test_query_process(self):
        tracker = results_tracker.get_tracker()
        runners_utils.invoke_post_run = mock.Mock(return_value=None)

        # Ensure state objects are present.
        state1 = ActionExecutionState.get_by_id(ResultsTrackerTests.states['state1.yaml'].id)
        state2 = ActionExecutionState.get_by_id(ResultsTrackerTests.states['state2.yaml'].id)
        self.assertIsNotNone(state1)
        self.assertIsNotNone(state2)

        # Process the state objects.
        tracker._bootstrap()
        eventlet.sleep(1)

        exec_id = str(ResultsTrackerTests.states['state1.yaml'].execution_id)
        exec_db = LiveAction.get_by_id(exec_id)
        self.assertTrue(exec_db.result['called_with'][exec_id] is not None,
                        exec_db.result)

        exec_id = str(ResultsTrackerTests.states['state2.yaml'].execution_id)
        exec_db = LiveAction.get_by_id(exec_id)
        self.assertTrue(exec_db.result['called_with'][exec_id] is not None,
                        exec_db.result)

        tracker.shutdown()

        # Ensure state objects are deleted.
        self.assertRaises(
            StackStormDBObjectNotFoundError,
            ActionExecutionState.get_by_id,
            ResultsTrackerTests.states['state1.yaml'].id
        )

        self.assertRaises(
            StackStormDBObjectNotFoundError,
            ActionExecutionState.get_by_id,
            ResultsTrackerTests.states['state2.yaml'].id
        )

        # Ensure invoke_post_run is called.
        self.assertEqual(2, runners_utils.invoke_post_run.call_count)
開發者ID:lyandut,項目名稱:st2,代碼行數:43,代碼來源:test_resultstracker.py


注:本文中的st2common.persistence.executionstate.ActionExecutionState.get_by_id方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。