-
-
Notifications
You must be signed in to change notification settings - Fork 774
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
Conversation
Root cause: When a action calls other action which belongs to the different pack, during `render_live_params`, only parent pack configuration is retrieved. Fixes: Passes action reference to `render_live_params`, if action parent pack is different with child action pack, the configuration for child pack is retired and rendered.
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.
If the pack name being passed into the render_live_params is not correct, why not assign the correct pack at https://github.com/StackStorm/st2/blob/master/st2common/st2common/services/workflows.py#L546?
Running task is belong to the |
I am thinking if |
|
What's the expected behavior from our current docs? |
Let me google. If it is not supported, will change code to pass right pack name |
|
#4570 (comment) |
Googed Stackstorm documentation and did not see anywhere mentioned that this is supported. Fix typo for `cancellation`
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.
Also, where are the unit and integration tests?
| 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') |
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.
There's already an action_ref at line 519. They're not the same?
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.
You did not address this yet.
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.
It is not the same. line 519 is get block of action data from action_execution_d_b. This is get action_ref = pack_name:action_name
Not sure about You did not address this yet. means. Changed if else block to one line.
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.
The line numbers may have shifted. But if you go down two line from def request_action_execution(wf_ex_db, task_ex_db, st2_ctx, ac_ex_req, delay=None), there's already an action_ref assigned. Is it different than the action_ref begin assigned in this line.
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.
And if they are not the same, then you just overwrote action_ref that is saved to LiveActionDB below.
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.
Yes, it is different. Changed my variable name.
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.
I just manually tested this and they are the same value. Can you show me an example where they are different.
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.
My bad. I thought it is reading ActionExecution.action. Put log message and tested. Committed change.
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.
Ok. Good you finally see it. I thought maybe I'm not clear enough.
| 'task_name': task_ex_db.task_name, | ||
| 'task_id': task_ex_db.task_id | ||
| } | ||
| }, |
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.
Why do we need a comma here?
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.
Did run nosetests --nocapture st2common/tests/unit/test_param_utils.py and all passed
I assume you are responding to my questions about unit/integration tests. Can you tell me what use case are we fixing here? Where is the unit test and integration test that cover this use case? |
Tested |
|
For the unit test, st2common/tests/unit/services/test_workflow.py looks like a good place to put the test. For the integration test, I am also expecting a new test at https://github.com/StackStorm/st2/blob/master/st2tests/integration/orquesta/test_wiring.py. You will need st2 to be running on your dev system and then run |
|
Also, please remember to add an entry in the CHANGELOG. |
|
For integration test, from st2test framework, it setup Since Two suggestions:
Any suggestions? |
|
I need to see the unit and integration tests in this PR to give you any real feedback. When this PR is merged, circle ci will run |
# Conflicts: # st2common/st2common/services/workflows.py
Added new unit test case for the fix. Modified two dummy packs that unit test can run. Fix code review comments. Updated CHANGELOG.txt
| 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 |
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.
Please stay consistent with imports for this module. Change to from st2common.models.db import pack as pk_db_models and move this line so the import is alphabetical.
| 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') |
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.
You did not address this yet.
| 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 |
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.
Since the pack module is imported above, this import is not required.
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.
Have to have it in order to save it to DB. Later when line 569 param_utils.render_live_params is called, it read config information from DB.
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.
Ok. I see. I misread. You have to change the import here to from st2common.persistence import pack as pk_db_access.
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.
Yes.
|
|
||
| PACK_20 = 'dummy_pack_20' | ||
| PACK_20_PATH = st2tests.fixturesloader.get_fixtures_packs_base_path() + '/' + PACK_20 | ||
|
|
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 we use the pack orquesta_tests as one of the pack here? Also, why dummy_pack_7 and dummy_pack_20? We can't use the other dummy_packs like dummy_pack_1?
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.
Yes, we can move dummy_pack_20 to orquesta_test2.
The reason I used two dummy pack because I was concerning about integration test.
When install dummy_pack_1, there is a error message Failed to register policies: Failed to register policy "/opt/stackstorm/packs/dummy_pack_1/policies/policy_2.yaml" from pack "dummy_pack_1": Referenced policy_type "action.mock_policy_error" doesnt exist
I almost ran all dummy packs and found these two.
| 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) |
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.
Remove the carriage return at the end of the line here.
Remove action and workflow from dummy_pack_20 to orquesta_tests Rename action_ref to spec_action Rename import names for test_workflow.py and reflect changes for dummy_pack_20
In order to run integration test, test used packs has to be installed first. Install `orquesta_tests` and `dummy_pack_7` packs in `` DB Create `virtualenv` for packs Add new testcase in test_wiring.py
From Will find out how file is located at |
| self.assertDictEqual(ex.result, expected_result) | ||
|
|
||
| def test_config_context_renders(self): | ||
| packs = ["orquesta_tests", "dummy_pack_7"] |
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.
These are packs for unit tests. We have separate ones for integration tests. I use the examples pack. But there are other packs that st2 CI uses. Looking at how the st2 environment is setup in CI and reusing existing test packs and installing those test packs on setup is simpler than writing an entire InstallFixturesPacks class here.
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.
These are packs for unit tests. We have separate ones for integration tests. I use the examples pack. But there are other packs that st2 CI uses. Looking at how the st2 environment is setup in CI and reusing existing test packs and installing those test packs on setup is simpler than writing an entire InstallFixturesPacks class here.
Submitted code. Want to make sure I am in the right track. Did look at existing pack to replace dummy_pack_7 and still did not get the right one. I think we should create a new pack in the case integration test like this that needs too packs with complicated setup. Thanks!
st2tests/st2tests/base.py
Outdated
| self._register_pack_configs() | ||
|
|
||
|
|
||
| class InstallFixturesPacks(DbTestCase): |
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.
Please look for a simpler alternative first thru the environment setup in circleci. May be simpler than writing a brand new class to do pack and venv setup here.
| @@ -0,0 +1,12 @@ | |||
| --- | |||
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.
The tests pack I'm asking you to modify is located @ https://github.com/StackStorm/st2tests/tree/master/packs/tests. It is a separate repo. You're adding files in the wrong place.
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.
Sorry about this, did not realize there is a different repo for st2tests. On cicd for integration test, does tests pack installed on the same directory as https://github.com/StackStorm/st2/tree/master/st2tests/tests? Because it needs to be copied to /opt/stackstrom/packs, need to know the source location.
Since i don't understand how https://github.com/StackStorm/st2tests/tree/master/packs/tests is used, for earlier unit test submission, dummy_pack_7 is used for testing, should we change it to the same tests pack?
st2tests/tests/actions/render.py
Outdated
| @@ -0,0 +1,7 @@ | |||
| from st2common.runners.base_action import Action | |||
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.
The tests pack I'm asking you to modify is located @ https://github.com/StackStorm/st2tests/tree/master/packs/tests. It is a separate repo. You're adding files in the wrong place.
st2tests/tests/config.schema.yaml
Outdated
| @@ -0,0 +1,5 @@ | |||
| --- | |||
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.
The tests pack I'm asking you to modify is located @ https://github.com/StackStorm/st2tests/tree/master/packs/tests. It is a separate repo. You're adding files in the wrong place.
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.
Thank you for making progress with this. There're still some more work and things to correct.
|
@jinpingh I just want to let you know that you are doing great here. We are near the finish line for this PR. There are a number of things that is new here (registering pack besides examples pack for integration test) that even if I am the developer working on this, it would involve me doing exploring and trial and error. So I expected back and forth with this PR. The feedbacks on the review has more to do with helping you gain knowledge and get into the habit of writing unit tests and integration tests then anything else. Thank you for your diligence. So take a breather and continue the good work. |
…pack Add new action to `tests` pack for render config context integration test. This is second part of code changes. Please see StackStorm/st2#4570
1. Move tests pack action to https://github.com/StackStorm/st2tests/tree/master/packs/tests Add a default value to config.schema.yaml and renamed action `render` to `render_config_context` Please see StackStorm/st2tests#150 2. Made change in CHANGELOG.rst 3. Rename copy_examples to copy_test_packs in `tools/launchdev.sh` 4. Handle gracefully when authentication is on for setting up virtualenv. 5. Renamed action `render` to `render_config_context` for unit test dummy_pack_7
tools/launchdev.sh
Outdated
| cp -Rp ./contrib/examples $PACKS_BASE_DIR | ||
| cp -Rp ./st2tests/tests $PACKS_BASE_DIR | ||
| cp -p ./st2tests/tests/configs/tests.yaml $CONFIG_BASE_DIR | ||
| cp -Rp ./st2tests/packs/tests $PACKS_BASE_DIR |
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.
Please let me know if this is the right path ./st2tests/packs/tests
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.
The tests pack is in a completely different repo https://github.com/StackStorm/st2tests/. You have to git clone https://github.com/StackStorm/st2tests.git to a temporary location and then copy the directory ./st2tests/packs/tests/ from the temporary location to /opt/stackstorm/packs.
tools/launchdev.sh
Outdated
| break | ||
| fi | ||
| fi | ||
| done < "$ST2_CONF" |
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.
Instead of this while loop, can we just run st2 run packs.setup_virtualenv packs=tests and if it returns ERROR: 401 Client Error: Unauthorized, you echo the warning?
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.
I thought just run st2 run packs.setup_virtualenv packs=tests and if it returns ERROR: 401 Client Error: Unauthorized is easy way but not graceful way.
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.
It's ok with me.
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.
Are you going to change this?
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.
Are you going to change this?
I am not going to change, but if this is too much, i can change it.
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.
Yeah, I prefer simplicity here. If it returns an auth error, then warn users. This is a dev launch script, don't need to go thru the hassle to parse for the auth lines in the config file.
|
Just adding this info here for completeness. It looks like this is related to - #4531. There I fixed the original issue, but I didn't correctly handle child workflow action which this PR fixes 👍 |
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 rename the commit for Clone https://github.com/StackStorm/st2tests.git since tests pack is … to Add step to clone st2tests repo and copy tests pack?
Clone st2tests repo to /tmp directory Copy st2tests/tests pack to /opt/stackstorm/packs Remove /tmp/st2tests directory
|
@jinpingh We are almost done here. So after these minor changes, get everything green before asking for review again. |
f9d2f47 to
c1f0724
Compare
If `st2 run packs.setup_virtualenv packs=tests` returns an error, then warn users
tools/launchdev.sh
Outdated
| if [ "$copy_test_packs" = true ]; then | ||
| st2 run packs.setup_virtualenv packs=tests | ||
| if [ $? != 0 ]; then | ||
| echo "Warning: Please setup virtualenv for pack \"tests\" before run integration test" |
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.
Please change the message to Unable to setup virtualenv for the \"tests\" pack. Please setup virtualenv for the \"tests\" pack before running integration tests.
Change the message to Unable to setup virtualenv for the \"tests\" pack. Please setup virtualenv for the \"tests\" pack before running integration tests.
…m/StackStorm/st2 into issue-4567/config_context_renders
|
Just a heads up - I didn't do extensive end to end testing (e.g. multiple levels of nested workflows and executions), but I tested it with example packs from https://github.com/bigmstone/packConfig and it appears to be working fine. |
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.
@jinpingh Thank you for the hard work. I hope you learned a lot thru this experience.
Thanks for help and valuable inputs. Finally i can close this PR :) ✌
|
Since it got merged in time, I will also cherry pick this changes in a branch for v2.10.4 release 👍 |
Fixes #4567 config_context renders against incorrect pack
Root cause:
When a action calls other action which belongs to the different pack, during
render_live_params, only parent pack configuration is retrieved.Fixes:
Passes action reference to
render_live_params, if action parent pack is different with child action pack, the configuration for child pack is retired and rendered.