-
-
Notifications
You must be signed in to change notification settings - Fork 775
config_context renders against incorrect pack #4570
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
e2cca81
a97fd8e
5c64ca0
62a51fb
0e780ad
0c41155
f76e6dd
82ce3c5
c81f042
6f62b3c
eaa3858
c1f0724
82fcc34
3a8598e
c81e6d1
30bd1a0
2cbe564
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -541,9 +541,13 @@ def request_action_execution(wf_ex_db, task_ex_db, st2_ctx, ac_ex_req, delay=Non | |
| # Identify the runner for the action. | ||
| runner_type_db = action_utils.get_runnertype_by_name(action_db.runner_type['name']) | ||
|
|
||
| # Identify action pack name | ||
| action_ref = task_ex_db.task_spec.get('spec').get('action') | ||
|
||
| pack = action_ref.split('.')[0] if action_ref else st2_ctx.get('pack') | ||
|
|
||
| # Set context for the action execution. | ||
| ac_ex_ctx = { | ||
| 'pack': st2_ctx.get('pack'), | ||
| 'pack': pack, | ||
| 'user': st2_ctx.get('user'), | ||
| 'parent': st2_ctx, | ||
| 'orquesta': { | ||
|
|
@@ -1110,4 +1114,4 @@ def update_execution_records(wf_ex_db, conductor, update_lv_ac_on_states=None, | |
| # Invoke post run on the liveaction for the workflow execution. | ||
| if status_changed and wf_lv_ac_db.status in ac_const.LIVEACTION_COMPLETED_STATES: | ||
| LOG.info('[%s] Workflow action execution is completed and invoking post run.', wf_ac_ex_id) | ||
| runners_utils.invoke_post_run(wf_lv_ac_db) | ||
| runners_utils.invoke_post_run(wf_lv_ac_db) | ||
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,8 +32,10 @@ | |
| from st2common.exceptions import action as action_exc | ||
| from st2common.models.db import liveaction as lv_db_models | ||
| from st2common.models.db import execution as ex_db_models | ||
| from st2common.models.db.pack import ConfigDB | ||
|
||
| from st2common.persistence import execution as ex_db_access | ||
| from st2common.persistence import workflow as wf_db_access | ||
| from st2common.persistence.pack import Config | ||
|
||
| from st2common.services import action as action_service | ||
| from st2common.services import workflows as workflow_service | ||
| from st2common.transport import liveaction as lv_ac_xport | ||
|
|
@@ -44,8 +46,16 @@ | |
| TEST_PACK = 'orquesta_tests' | ||
| TEST_PACK_PATH = st2tests.fixturesloader.get_fixtures_packs_base_path() + '/' + TEST_PACK | ||
|
|
||
| PACK_7 = 'dummy_pack_7' | ||
| PACK_7_PATH = st2tests.fixturesloader.get_fixtures_packs_base_path() + '/' + PACK_7 | ||
|
|
||
| PACK_20 = 'dummy_pack_20' | ||
| PACK_20_PATH = st2tests.fixturesloader.get_fixtures_packs_base_path() + '/' + PACK_20 | ||
|
|
||
|
||
| PACKS = [ | ||
| TEST_PACK_PATH, | ||
| PACK_7_PATH, | ||
| PACK_20_PATH, | ||
| st2tests.fixturesloader.get_fixtures_packs_base_path() + '/core' | ||
| ] | ||
|
|
||
|
|
@@ -363,3 +373,67 @@ def test_evaluate_action_execution_delay(self): | |
| ac_ex_req = {'action': 'core.noop', 'input': None, 'item_id': 1} | ||
| actual_delay = workflow_service.eval_action_execution_delay(task_ex_req, ac_ex_req, True) | ||
| self.assertIsNone(actual_delay) | ||
|
|
||
| def test_request_action_execution_render(self): | ||
| # Manually create ConfigDB | ||
| output = 'Testing' | ||
| value = { | ||
| "config_item_one": output | ||
| } | ||
| config_db = ConfigDB(pack=PACK_7, values=value) | ||
| config = Config.add_or_update(config_db) | ||
| self.assertEqual(len(config), 3) | ||
|
|
||
| wf_meta = self.get_wf_fixture_meta_data(PACK_20_PATH, 'render_config_context.yaml') | ||
|
|
||
| # Manually create the liveaction and action execution objects without publishing. | ||
| lv_ac_db = lv_db_models.LiveActionDB(action=wf_meta['name']) | ||
| lv_ac_db, ac_ex_db = action_service.create_request(lv_ac_db) | ||
|
|
||
| # Request the workflow execution. | ||
| wf_def = self.get_wf_def(PACK_20_PATH, wf_meta) | ||
| st2_ctx = self.mock_st2_context(ac_ex_db) | ||
| wf_ex_db = workflow_service.request(wf_def, ac_ex_db, st2_ctx) | ||
| spec_module = specs_loader.get_spec_module(wf_ex_db.spec['catalog']) | ||
| wf_spec = spec_module.WorkflowSpec.deserialize(wf_ex_db.spec) | ||
|
|
||
| # Pass down appropriate st2 context to the task and action execution(s). | ||
| root_st2_ctx = wf_ex_db.context.get('st2', {}) | ||
| st2_ctx = { | ||
| 'execution_id': wf_ex_db.action_execution, | ||
| 'user': root_st2_ctx.get('user'), | ||
| 'pack': root_st2_ctx.get('pack') | ||
| } | ||
|
|
||
| # Manually request task execution. | ||
| task_route = 0 | ||
| task_id = 'task1' | ||
| task_spec = wf_spec.tasks.get_task(task_id) | ||
| task_ctx = {'foo': 'bar'} | ||
|
|
||
| task_ex_req = { | ||
| 'id': task_id, | ||
| 'route': task_route, | ||
| 'spec': task_spec, | ||
| 'ctx': task_ctx, | ||
| 'actions': [ | ||
| {'action': 'dummy_pack_7.render', 'input': None} | ||
| ] | ||
| } | ||
| workflow_service.request_task_execution(wf_ex_db, st2_ctx, task_ex_req) | ||
|
|
||
| # Check task execution is saved to the database. | ||
| task_ex_dbs = wf_db_access.TaskExecution.query(workflow_execution=str(wf_ex_db.id)) | ||
| self.assertEqual(len(task_ex_dbs), 1) | ||
| workflow_service.request_task_execution(wf_ex_db, st2_ctx, task_ex_req) | ||
|
|
||
| # Manually request action execution | ||
| task_ex_db = task_ex_dbs[0] | ||
| action_ex_db = workflow_service.request_action_execution(wf_ex_db, task_ex_db, st2_ctx, | ||
| task_ex_req['actions'][0]) | ||
|
|
||
| # Check required attributes. | ||
| self.assertIsNotNone(str(action_ex_db.id)) | ||
| self.assertEqual(task_ex_db.workflow_execution, str(wf_ex_db.id)) | ||
| expected_parameters = {'value1': output} | ||
| self.assertEqual(expected_parameters, action_ex_db.parameters) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| --- | ||
| config_item_one: "testing" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| --- | ||
| name: render_config_context | ||
| pack: dummy_pack_20 | ||
| description: Run render config context workflow | ||
| runner_type: orquesta | ||
| entry_point: workflows/render_config_context.yaml | ||
| enabled: true | ||
| parameters: {} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| version: 1.0 | ||
| description: Testing config context render". | ||
| tasks: | ||
| task1: | ||
| action: dummy_pack_7.render | ||
| output: | ||
| - context_value: <% task(task1).result.result.context_value %> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| from st2common.runners.base_action import Action | ||
|
|
||
|
|
||
| class PrintPythonVersionAction(Action): | ||
|
|
||
| def run(self, value1): | ||
| return {"context_value": value1} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| --- | ||
| name: render | ||
| runner_type: python-script | ||
| description: Action that uses config context | ||
| enabled: true | ||
| entry_point: render.py | ||
| parameters: | ||
| value1: | ||
| description: Input for action1. Defaults to config_context value. | ||
| required: false | ||
| type: "string" | ||
| default: "{{ config_context.config_item_one }}" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| config_item_one: | ||
| description: "Item use to test config context." | ||
| type: "string" | ||
| required: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you change this to "Fix rendering of
config_contextin orquesta task that references action in different pack (bug fix) #4570"?