Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
    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.
        with mock.patch(
                "st2actions.container.base.get_runner",
                mock.Mock(return_value=polling_async_runner.get_runner()),
        ):
            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.assertIsNotNone(found[0].query_context)
        self.assertIsNotNone(found[0].query_module)
Exemplo n.º 3
0
    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)
Exemplo n.º 4
0
    def _bootstrap(self):
        all_states = ActionExecutionState.get_all()
        LOG.info('Found %d pending states in db.' % len(all_states))

        query_contexts_dict = defaultdict(list)
        for state_db in all_states:
            try:
                context = QueryContext.from_model(state_db)
            except:
                LOG.exception('Invalid state object: %s', state_db)
                continue
            query_module_name = state_db.query_module
            querier = self.get_querier(query_module_name)

            if querier is not None:
                query_contexts_dict[querier].append(context)

        for querier, contexts in six.iteritems(query_contexts_dict):
            LOG.info('Found %d pending actions for query module %s', len(contexts), querier)
            querier.add_queries(query_contexts=contexts)
Exemplo n.º 5
0
    def test_state_db_not_created_for_async_actions(self):
        runner_container = get_runner_container()

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

        liveaction_db = self._get_liveaction_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 = [
            state for state in states if state.execution_id == liveaction_db.id
        ]

        self.assertTrue(
            len(found) == 0, "There should not be a state db object.")
Exemplo n.º 6
0
    def _bootstrap(self):
        all_states = ActionExecutionState.get_all()
        LOG.info('Found %d pending states in db.' % len(all_states))

        query_contexts_dict = defaultdict(list)
        for state_db in all_states:
            try:
                context = QueryContext.from_model(state_db)
            except:
                LOG.exception('Invalid state object: %s', state_db)
                continue
            query_module_name = state_db.query_module
            querier = self.get_querier(query_module_name)

            if querier is not None:
                query_contexts_dict[querier].append(context)

        for querier, contexts in six.iteritems(query_contexts_dict):
            LOG.info('Found %d pending actions for query module %s',
                     len(contexts), querier)
            querier.add_queries(query_contexts=contexts)