Repository navigation
Conversation
|
I do not know the implications of this change, but there are some lint issues you'll need to fix first. Then I'll have someone else on the core team review this. |
|
Thanks @xeacott ! I fixed the lint and build errors. Looking forward to feedback. |
|
Before we can get this merged, you'll need to change the target branch and add a test. This means re-basing and targeting |
|
This should go into 2019.2.1. |
cmcmarrow
left a comment
There was a problem hiding this comment.
Thanks for the code, but salt now want tests with every code change now.
There was a problem hiding this comment.
for key in sorted(funcs.keys()): sorted_keys is never used again. Also it does not change the readability of the code.
There was a problem hiding this comment.
Absolutely, was planning to do this. Less lines is better 🐍
|
Rebased on master. Will add test asap |
Codecov Report
@@ Coverage Diff @@
## master #54853 +/- ##
==========================================
- Coverage 11.67% 10.64% -1.03%
==========================================
Files 1520 1519 -1
Lines 253244 252797 -447
Branches 54003 53891 -112
==========================================
- Hits 29561 26908 -2653
- Misses 221590 224212 +2622
+ Partials 2093 1677 -416
Continue to review full report at Codecov.
|
|
May I propose that this commit doesn't, in fact, need a test? The commit simply sorts the keys to execute grains modules in alphabetical order. What type of test is warranted here? |
|
@jtraub91 you kind of stated it yourself:
I would assert that there should be tests written to ensure that grains are evaluated in the correct order. TBH it's really weird that there aren't (apparently) any tests covering this situation. But if there's a faulty behavior, we shouldn't add code to salt that fixes the faulty behavior unless we can write a test that fail when the faulty behavior exists. Otherwise someone may come in and change the code later, re-introducing this error. |
|
@waynew understood. I added better testing for this situation. The real issue is that there are 'core' grains that aren't in the 'core' grains module. If you look at loader.py core grains will always run first however 'non-core' grains that are included in the repo can only be overwritten with an alphabetically-superseding module name (with this change). Perhaps the better way to handle this is to change all the non-core grains included in the repo (e.g. napalm, zfs, etc.) to have __virtualname__ = 'core'. Then they would always get run first no matter custom module name. <- that sounds like a good way to go now that I say it, although there may be other complications introduced. I'm going to take a break for today, but interested to hear your thought if any, as I mull this over and test it soon. |
|
Another issue with grains precedence, /etc/salt/minion grains take precedence over custom _grains We will want to either make a change to the code, or the docs (https://docs.saltstack.com/en/latest/topics/grains/#precedence). This probably belongs in a separate issue / PR. |
|
I'll bring this up with the core team - it seems like we will probably want to take a step back and figure out a long-term strategy for these. |
|
I've spoke with some of my colleagues and the path forward that makes most sense to us, is the following: Since there are grains included in this repo which aren't under the modules scope 'core.' (e.g. napalm, zfs, etc) and changing these to be
|
|
I'm willing to investigate further and make this change (and add a test), but have been unsuccessful so far. The logic to execute the modules within |
|
@jtraub91 Sorry for the delay - we finally had a chance to discuss things, and from what I can tell what you're heading after seems like the right direction. I'd say it's "sort of" a breaking change - those grains are salt core grains even though they don't live in the We'd love to see a solid set of unit tests that verify that grains are evaluated in the order the documentation says they are. If you're not able to, that's understandable. But it would be awesome and appreciated! If not, at least some minimal test to verify that your code does what it says it will will be 👍 . |
|
But if those grains are 'core' grains then there should be no worries aliasing them under the Accidental reliance aside, from what you are saying, it sounds like, to me, all 'core' grains that aren't namespaced under 'core' should be. After all that is the criteria that |
That's the way I understand it, yes! |
|
@jtraub91 Would you mind also resolving the merge conflict? |
|
Closing this due to inactivity. Anyone should feel free to re-open it if they want to see it through to the end in one release cycle. |
What does this PR do?
Fixes problem due to grains module evaluation. Specifically for proxyenabled grains modules, the salt-core included non-core grains were being evaluated after custom grains. So for example, the grains included in grains/napalm.py were being evaluated after my custom grains included in /srv/salt/_grains. This was a problem since I wished to overwrite grains according to the precedence define in the docs and it was not behaving the way it should.
The way I solved this (while not perfect) was to sort the non-core (not core.xxx) grains so that if you wish to overwrite a non-core salt-core included grain's key, simply use a __virtualname__ that has a later key alphabetically. E.g. my custom grain module 'napalm_mod' will overwrite similar keys in 'napalm' grains module
What issues does this PR fix or reference?
#54694
Previous Behavior
Non-core salt-core include grains module would be evaluated last, thus taking precedence over custom grains
New Behavior
Custom grain will take precedence if virtualname has a later key alphabetically
Tests written?
No
Commits signed with GPG?
No