-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Uniquify requisite_in'd states checks. #68409
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
Open
gpernot-celeste
wants to merge
8
commits into
saltstack:3006.x
Choose a base branch
from
gpernot-celeste:3006.x
base: 3006.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+269
−38
Open
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
fa5de69
Uniquify requisite_in'd states checks.
gpernot-celeste db7d658
fix: remove no-op
gpernot-celeste aa56dc4
clarifications
gpernot-celeste 3ef0957
bug fix and improved tests
gpernot-celeste 57081d2
Merge branch 'salt-fix-requisites-2' into salt-fix-requisites
gpernot-celeste b44d1f6
rename _req_module to _state_args
gpernot-celeste be6dba0
rename _mod_req to state_arg
gpernot-celeste 574e90d
add changelog for #68408
gpernot-celeste File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,222 @@ | ||
| from copy import deepcopy | ||
|
|
||
| import pytest | ||
|
|
||
| import salt.state | ||
| from salt.utils.odict import HashableOrderedDict | ||
|
|
||
| pytestmark = [ | ||
| pytest.mark.core_test, | ||
| ] | ||
|
|
||
|
|
||
| simple_extend_test_cases = [ | ||
| ( | ||
| # Simple addition | ||
| # | ||
| # add_to_extend: | ||
| # foo: | ||
| # file.managed: | ||
| # - required_in: | ||
| # - file: bar | ||
| {}, # extend | ||
| "bar", # id_to_extend | ||
| "file", # state_mod_name | ||
| "require", # req_type | ||
| "foo", # req_id | ||
| "file", # req_state_mod_name | ||
| {"bar": {"file": [{"require": [{"file": "foo"}]}]}}, # expected | ||
| ), | ||
| ( | ||
| # Requisite already exists | ||
| # | ||
| # bar: | ||
| # file.managed: | ||
| # require: | ||
| # - file: foo | ||
| # baz: | ||
| # file.managed: | ||
| # - require: | ||
| # - file: foo | ||
| # | ||
| # add_to_extend: | ||
| # foo: | ||
| # file.managed: | ||
| # - required_in: | ||
| # - file: baz | ||
| { # extend | ||
| "bar": { | ||
| "file": [{"require": [{"file": "foo"}]}], | ||
| }, | ||
| "baz": { | ||
| "file": [{"require": [{"file": "foo"}]}], | ||
| }, | ||
| }, | ||
| "baz", # id_to_extend | ||
| "file", # state_mod_name | ||
| "require", # req_type | ||
| "foo", # req_id | ||
| "file", # req_state_mod_name | ||
| { # expected | ||
| "bar": { | ||
| "file": [{"require": [{"file": "foo"}]}], | ||
| }, | ||
| "baz": { | ||
| "file": [{"require": [{"file": "foo"}]}], | ||
| }, | ||
| }, | ||
| ), | ||
| ( | ||
| # Append requisite | ||
| # | ||
| # bar: | ||
| # file.managed: | ||
| # require: | ||
| # - file: foo | ||
| # baz: | ||
| # file.managed: | ||
| # - require: | ||
| # - file: foo | ||
| # | ||
| # add_to_extend: | ||
| # bar: | ||
| # file.managed: | ||
| # - require_in: | ||
| # - file: baz | ||
| { # extend | ||
| "bar": HashableOrderedDict( | ||
| [ | ||
| ("file", [{"require": [{"file": "foo"}]}]), | ||
| ] | ||
| ), | ||
| "baz": HashableOrderedDict( | ||
| [ | ||
| ("file", [{"require": [{"file": "foo"}]}]), | ||
| ] | ||
| ), | ||
| }, | ||
| "baz", # id_to_extend | ||
| "file", # state_mod_name | ||
| "require", # req_type | ||
| "bar", # req_id | ||
| "file", # req_state_mod_name | ||
| { # expected | ||
| "bar": HashableOrderedDict( | ||
| [ | ||
| ("file", [{"require": [{"file": "foo"}]}]), | ||
| ] | ||
| ), | ||
| "baz": HashableOrderedDict( | ||
| [ | ||
| ("file", [{"require": [{"file": "foo"}, {"file": "bar"}]}]), | ||
| ] | ||
| ), | ||
| }, | ||
| ), | ||
| ( | ||
| # Append with different requisite type | ||
| # | ||
| # bar: | ||
| # file.managed: | ||
| # require: | ||
| # - file: foo | ||
| # baz: | ||
| # file.managed: | ||
| # - require: | ||
| # - file: foo | ||
| # | ||
| # add_to_extend: | ||
| # bar: | ||
| # file.managed: | ||
| # - prereq_in: | ||
| # - file: baz | ||
| { # extend | ||
| "bar": { | ||
| "file": [{"require": [{"file": "foo"}]}], | ||
| }, | ||
| "baz": { | ||
| "file": [{"require": [{"file": "foo"}]}], | ||
| }, | ||
| }, | ||
| "baz", # id_to_extend | ||
| "file", # state_mod_name | ||
| "prereq", # req_type | ||
| "bar", # req_id | ||
| "file", # req_state_mod_name | ||
| { # expected | ||
| "bar": { | ||
| "file": [ | ||
| { | ||
| "require": [ | ||
| {"file": "foo"}, | ||
| ] | ||
| }, | ||
| ], | ||
| }, | ||
| "baz": { | ||
| "file": [ | ||
| { | ||
| "require": [ | ||
| {"file": "foo"}, | ||
| ] | ||
| }, | ||
| { | ||
| "prereq": [ | ||
| {"file": "bar"}, | ||
| ] | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| ), | ||
| ] | ||
|
|
||
|
|
||
| def _flatten_extend(a): | ||
| return { | ||
| (k1, k2, k4, k6, v6) | ||
| for k1, v1 in a.items() | ||
| for k2, v2 in v1.items() | ||
| for v3 in v2 | ||
| for k4, v4 in v3.items() | ||
| for v5 in v4 | ||
| for k6, v6 in v5.items() | ||
| } | ||
|
|
||
|
|
||
| def test_flatten(): | ||
| a = { | ||
| "bar": {"file": [{"require": [{"file": "foo"}]}]}, | ||
| "baz": { | ||
| "file": [ | ||
| {"require": [{"file": "foo"}]}, | ||
| {"prereq": [{"file": "bar"}]}, | ||
| ] | ||
| }, | ||
| } | ||
| b = { | ||
| "baz": { | ||
| "file": [ | ||
| {"prereq": [{"file": "bar"}]}, | ||
| {"require": [{"file": "foo"}]}, | ||
| ] | ||
| }, | ||
| "bar": {"file": [{"require": [{"file": "foo"}]}]}, | ||
| } | ||
| assert _flatten_extend(a) == _flatten_extend(b) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "extend,id_to_extend,state_mod_name,req_type,req_id,req_state_mod_name,expected", | ||
| simple_extend_test_cases, | ||
| ) | ||
| def test_simple_extend( | ||
| extend, id_to_extend, state_mod_name, req_type, req_id, req_state_mod_name, expected | ||
| ): | ||
| # local copy of extend, as it is modified by _add_to_extend | ||
| _extend = deepcopy(extend) | ||
|
|
||
| salt.state.State._add_to_extend( | ||
| _extend, id_to_extend, state_mod_name, req_type, req_id, req_state_mod_name | ||
| ) | ||
| assert _flatten_extend(_extend) == _flatten_extend(expected) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.