Skip to content

Commit 8e85dd6

Browse files
author
Lakshmi Kannan
committed
Integration test for results tracker. #1
1 parent 6bfc31a commit 8e85dd6

File tree

8 files changed

+106
-7
lines changed

8 files changed

+106
-7
lines changed

st2actions/st2actions/query/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,5 +115,6 @@ def __init__(self, id, execution_id, query_context):
115115
self.query_context = query_context
116116
self.id = id
117117

118-
def from_model(self, model):
118+
@classmethod
119+
def from_model(cls, model):
119120
return QueryContext(model.id, model.execution_id, model.query_context)

st2actions/st2actions/resultstracker.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ def _bootstrap(self):
105105
continue
106106
query_module_name = state_db.query_module
107107
querier = self.get_querier(query_module_name)
108-
query_contexts_dict[querier].append(context)
108+
if querier is not None:
109+
query_contexts_dict[querier].append(context)
109110

110111
for querier, contexts in six.iteritems(query_contexts_dict):
111112
LOG.info('Found %d pending actions for query module %s', len(contexts), querier)
@@ -120,7 +121,7 @@ def get_querier(self, query_module_name):
120121
except:
121122
LOG.exception('Failed importing query module: %s', query_module_name)
122123
self._failed_imports.add(query_module_name)
123-
continue
124+
self._queriers[query_module_name] = None
124125
else:
125126
self._queriers[query_module_name] = querier.get_instance()
126127

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from st2actions.resultstracker import ResultsTracker
2+
from st2tests.base import (DbTestCase, EventletTestCase)
3+
from st2tests.fixturesloader import FixturesLoader
4+
5+
FIXTURES_PACK = 'generic'
6+
FIXTURES = {'actionstates': ['state1.json', 'state2.json']}
7+
loader = FixturesLoader()
8+
9+
10+
class ResultsTrackerTests(EventletTestCase, DbTestCase):
11+
states = None
12+
models = None
13+
14+
@classmethod
15+
def setUpClass(cls):
16+
super(ResultsTrackerTests, cls).setUpClass()
17+
DbTestCase.setUpClass()
18+
ResultsTrackerTests.models = loader.save_fixtures_to_db(fixtures_pack=FIXTURES_PACK,
19+
fixtures_dict=FIXTURES)
20+
ResultsTrackerTests.states = ResultsTrackerTests.models['actionstates']
21+
22+
def test_bootstrap(self):
23+
tracker = ResultsTracker()
24+
tracker._bootstrap()
25+
26+
@classmethod
27+
def tearDownClass(cls):
28+
loader.delete_models_from_db(ResultsTrackerTests.models)

st2actions/tests/resources/test_querymodule.py

Whitespace-only changes.

st2common/st2common/models/api/action.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from st2common import log as logging
2121
from st2common.models.base import BaseAPI
2222
from st2common.models.db.action import (RunnerTypeDB, ActionDB, ActionExecutionDB)
23+
from st2common.models.db.action import ActionExecutionStateDB
2324
from st2common.constants.action import ACTIONEXEC_STATUSES
2425

2526

@@ -281,3 +282,51 @@ def to_model(cls, execution):
281282
model.callback = getattr(execution, 'callback', dict())
282283
model.result = getattr(execution, 'result', None)
283284
return model
285+
286+
287+
class ActionExecutionStateAPI(BaseAPI):
288+
"""
289+
System entity that represents state of an action in the system.
290+
This is used only in tests for now.
291+
"""
292+
model = ActionExecutionStateDB
293+
schema = {
294+
"title": "ActionExecutionState",
295+
"description": "Execution state of an action.",
296+
"type": "object",
297+
"properties": {
298+
"id": {
299+
"description": "The unique identifier for the action execution state.",
300+
"type": "string"
301+
},
302+
"execution_id": {
303+
"type": "string",
304+
"description": "ID of the action execution.",
305+
"required": True
306+
},
307+
"query_context": {
308+
"type": "object",
309+
"description": "query context to be used by querier.",
310+
"required": True
311+
},
312+
"query_module": {
313+
"type": "string",
314+
"description": "Name of the query module.",
315+
"required": True
316+
}
317+
},
318+
"additionalProperties": False
319+
}
320+
321+
@classmethod
322+
def from_model(cls, model):
323+
doc = super(cls, cls)._from_model(model)
324+
return cls(**doc)
325+
326+
@classmethod
327+
def to_model(cls, state):
328+
model = super(cls, cls).to_model(state)
329+
model.query_module = state.query_module
330+
model.execution_id = state.execution_id
331+
model.query_context = state.query_context
332+
return model
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"execution_id": "549dcfda95e3fc7a9b0912ee",
3+
"query_context": {
4+
"id":"661491fa-3e17-48cf-bc92-05ecc501d700"
5+
},
6+
"query_module": "tests.resources.query_module"
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"execution_id": "549dcfda95e3fc7a9b0912ef",
3+
"query_context": {
4+
"id":"661491fa-3e17-48cf-bc92-05ecc501d701"
5+
},
6+
"query_module": "tests.resources.query_module"
7+
}

st2tests/st2tests/fixturesloader.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,30 @@
2020

2121
from st2common.content.loader import MetaLoader
2222

23-
from st2common.models.api.action import (ActionAPI, ActionExecutionAPI, RunnerTypeAPI)
23+
from st2common.models.api.action import (ActionAPI, ActionExecutionAPI, ActionExecutionStateAPI,
24+
RunnerTypeAPI)
2425
from st2common.models.api.history import (ActionExecutionHistoryAPI)
2526
from st2common.models.api.reactor import (TriggerAPI, TriggerTypeAPI)
2627
from st2common.models.api.rule import (RuleAPI)
2728

28-
from st2common.models.db.action import (ActionDB, ActionExecutionDB, RunnerTypeDB)
29+
from st2common.models.db.action import (ActionDB, ActionExecutionDB, ActionExecutionStateDB,
30+
RunnerTypeDB)
2931
from st2common.models.db.history import (ActionExecutionHistoryDB)
3032
from st2common.models.db.reactor import (RuleDB, TriggerDB, TriggerTypeDB)
3133

32-
from st2common.persistence.action import (Action, ActionExecution, RunnerType)
34+
from st2common.persistence.action import (Action, ActionExecution, ActionExecutionState,
35+
RunnerType)
3336
from st2common.persistence.history import (ActionExecutionHistory)
3437
from st2common.persistence.reactor import (Rule, Trigger, TriggerType)
3538

36-
ALLOWED_DB_FIXTURES = ['actions', 'executions', 'history', 'rules', 'runners',
39+
ALLOWED_DB_FIXTURES = ['actions', 'actionstates', 'executions', 'history', 'rules', 'runners',
3740
'triggertypes', 'triggers']
3841
ALLOWED_FIXTURES = copy.copy(ALLOWED_DB_FIXTURES)
3942
ALLOWED_FIXTURES.extend(['actionchains', 'workflows'])
4043

4144
FIXTURE_DB_MODEL = {
4245
'actions': ActionDB,
46+
'actionstates': ActionExecutionStateDB,
4347
'executions': ActionExecutionDB,
4448
'history': ActionExecutionHistoryDB,
4549
'rules': RuleDB,
@@ -50,6 +54,7 @@
5054

5155
FIXTURE_API_MODEL = {
5256
'actions': ActionAPI,
57+
'actionstates': ActionExecutionStateAPI,
5358
'executions': ActionExecutionAPI,
5459
'history': ActionExecutionHistoryAPI,
5560
'rules': RuleAPI,
@@ -61,6 +66,7 @@
6166

6267
FIXTURE_PERSISTENCE_MODEL = {
6368
'actions': Action,
69+
'actionstates': ActionExecutionState,
6470
'executions': ActionExecution,
6571
'history': ActionExecutionHistory,
6672
'rules': Rule,

0 commit comments

Comments
 (0)