Add capability to specify state args as a dict#68368
Add capability to specify state args as a dict#68368bdrx312 wants to merge 5 commits intosaltstack:masterfrom
Conversation
b2a27d9 to
a8b7362
Compare
Alright I'll look at updating docs when I get some time. |
lkubb
left a comment
There was a problem hiding this comment.
Thanks for creating this! Just some minor comments.
@twangboy Alright I made a first pass at updating the documentation. |
|
Build html is failing with the following: DetailsIt appears it doesn't like my doc links What is the correct way to link these documents? |
@twangboy I updated the docs. Can you look over them and provide any feed back? I also have this question: #68368 (comment) |
|
What I meant by "add some docs" was to give some overall guidance on the different options for formatting the state, not going in to each state and changing the docs. |
I did update to give the different options https://github.com/saltstack/salt/pull/68368/files#diff-a0d563ea5979d3e412a93128f06d255fd9175f5ad9df06d193d6bcee9088af07R172-R201 I did not notice that page you linked; I will update that too. I also updated the examples because I think we want examples to show the recommended/ideal way to implement something. I find tools more difficult to use and frustrating when the tools improve over time and have better ways to configure and implement things but don't update the examples to use the newer methods. As a unrelated side note but related to documentation, I started trying to on-board some team members so we can try to use salt and they found that user guide you linked, started at the beginning, and clicked through next on each page. When they got to the fourth page (State system behind the scenes https://docs.saltproject.io/salt/user-guide/en/latest/topics/state-system.html) they got a little overwhelmed by the information on that page and also didn't understand why they were already reading about what seemed like low level or implementation details. I think it would be good if that State system behind the scenes came much later in the user guide once the basics were covered. |
|
@twangboy Alright I submitted a pull request for the user guide repo saltstack/salt-user-guide#8. |
Also add some more type hints and change some format calls to f strings. Fix state retry tests with invalid assumptions of duration and comment.
|
one major problem with this change. since you changed all the tests you no longer are testing backwards comparability. which was my MAJOR problem with this change to begin with. This change cannot and should not go through without VERY comprehensive tests that test the old style. This change without those tests could break every single install out there. |
|
Thanks for catching and fixing an issue with my wrapper module and sorry for introducing it!
I don't think that's correct – I could only spot a single existing test ( Edit: I still have to investigate the underlying issue, but this PR exhibiting a TypeError for the faulty format (which wasn't there before) could be a breaking change nonetheless. |
I think that was the first place when I testing where I made a syntax change in a test to see if it was working correctly. That test change can be reverted if desired.
We can make the code just emit a warning log message and then continue by ignoring the invalid values instead of raising the exception which seems to be the existing behavior. Continuing when invalid values (syntax error) are specified does not seem like a great idea though since the user/developer was probably trying to specify some argument that will not be getting applied and will possibly configure their system incorrectly. |
|
I would say revert the test and add a new to so that both scenarios are tested. |
There are other tests now in tests/pytests/functional/modules/state/test_state.py that are testing the new syntax. I don't think that one specifically needs to test both. |
then revert the test. don't remove a test that was working fine for the old format. edit: sorry looks like it already was reverted. |
You are correct. I saw that single change and saw RED. and just assumed they had gone through and changed everything. my anger had made me make a mistake. personally I am not a fan of this change. I hate this format with a passion. I will say one test i would like to see. is a single test that takes all three possible formats and checks the lowstate output comes out the same. should all come back as
and agreed on the TypeError. if it causes a TypeError here. it is possible that it could break something more that isn't being tested. fundamentally a format change should make no behavior changes. |
| A standard way to extend is via the extend declaration. The extend | ||
| declaration is a top level declaration like ``include`` that allows | ||
| overriding or augmenting state declarations from other SLS files. | ||
| Use ``extend`` to override arguments, append requisites, | ||
| or otherwise modify an existing ID without editing the original SLS. | ||
|
|
||
| Overview | ||
| -------- | ||
|
|
||
| - ``extend`` is a top-level mapping at the same syntactic level as ``include`` or a top-level ID. | ||
| - The SLS module that defines the target ID must be included so the ID exists before the | ||
| extend merge is applied. | ||
| - Requisite lists (for example ``watch`` and ``require``) are appended; most other keys | ||
| are replaced by the extend entry. | ||
| - Only one top-level ``extend`` mapping may appear in a single SLS file; later mappings | ||
| will overwrite earlier ones. | ||
|
|
||
| Example | ||
| ------- | ||
|
|
||
| The following shows the original SLS entries (the files being extended) and an extending SLS | ||
| that includes them and declares a single ``extend`` block. | ||
|
|
||
| Original: ``salt://http/init.sls`` | ||
|
|
||
| .. code-block:: yaml | ||
|
|
||
| apache: | ||
| pkg.installed: [] | ||
| file: | ||
| - name: /etc/httpd/conf/httpd.conf | ||
| - source: salt://http/httpd.conf | ||
| service.running: | ||
| - name: httpd | ||
| - watch: | ||
| - file: apache | ||
|
|
||
| Original: ``salt://ssh/init.sls`` | ||
|
|
||
| .. code-block:: yaml | ||
|
|
||
| ssh-server: | ||
| pkg.installed: [] | ||
| service.running: | ||
| - name: sshd | ||
|
|
||
| Extending SLS: ``salt://profile/webserver_extend.sls`` |
There was a problem hiding this comment.
why is this document change that has nothing to do with the format change included? this should be a separate PR
| Behavior for this example | ||
| ------------------------- | ||
|
|
||
| - The ``apache:file`` mapping in the extending SLS overrides with the | ||
| ``name`` and ``source`` values from the original ``file`` mapping | ||
| in ``http/init.sls`` with the values supplied under ``extend``. | ||
| - The ``ssh-server:service:watch`` list is appended with ``file: /etc/ssh/banner``; any | ||
| existing watch entries declared in ``ssh/init.sls`` are preserved. | ||
| - The banner resource is declared locally (``/etc/ssh/banner``) so the appended watch has | ||
| a concrete state to observe; if the resource were absent from the compiled data the | ||
| relationship would be invalid. | ||
|
|
||
| Minimal patterns | ||
| ---------------- | ||
|
|
||
| Replace a mapping (overwrite): | ||
|
|
||
| .. code-block:: yaml | ||
|
|
||
| extend: | ||
| apache: | ||
| file: | ||
| - name: /etc/httpd/conf/httpd.conf | ||
| - source: salt://http/httpd2.conf | ||
|
|
||
| Append to a requisite list (merge): | ||
|
|
||
| .. code-block:: yaml | ||
|
|
||
| extend: | ||
| ssh-server: | ||
| service: | ||
| - watch: | ||
| - file: /etc/ssh/banner |
There was a problem hiding this comment.
same as above. these document changes are not a part of the format change.
bdrx312
left a comment
There was a problem hiding this comment.
I will say one test i would like to see. is a single test that takes all three possible formats and checks the lowstate output comes out the same.
Good idea. Added
|
got some pre-commit failures |
…tation to use new dict arguments format in examples Revert change to an existing test back to using the old arguments format Relax raising exception on invalid argument type in the state arguments to instead just log a warning and ignore the item
Also add some more type hints and change some format calls to f strings. Fix state retry tests with invalid assumptions of duration and comment.
What does this PR do?
Adds the ability to specify arguments to a state as a dictionary instead of having to specify a list of individual key: value pairs
What issues does this PR fix or reference?
Fixes #68367
Previous Behavior
Could only specify arguments to a state like this
New Behavior
Can specify arguments to a state like this
Merge requirements satisfied?
[NOTICE] Bug fixes or features added to Salt require tests.
Commits signed with GPG?
No