Skip to content

Allow minion_id to be specified for certain match functions - #11965

Merged
thatch45 merged 3 commits into
saltstack:developfrom
terminalmage:issue11517
Apr 14, 2014
Merged

thatch45 merged 3 commits into
saltstack:developfrom
terminalmage:issue11517

Conversation

@terminalmage

Copy link
Copy Markdown
Contributor

Rather than use the initial approach for this PR, I've updated it so that it grabs the minion ID from __grains__ rather than expecting it to be overridden. This, in my opinion, is better than expecting users to manually override the minion_id in their Pillar SLS files. It still preserves the added functionality of overriding the minion ID, while operating as one would normally expect it to when not overridden (i.e. using the minion's ID by default, even when used from Pillar SLS files).

More detailed reasoning on this approach below, followed by the original commit msg.

Detailed reasoning for grabbing minion ID from __grains__

The match functions which operate on the minion ID don't use anything from __opts__ other than the minion ID, and they don't call any of the execution functions from __salt__, either. The match types that operate on the minion ID (which were the only ones that I modified in my pull request) just evaluate regexes, globs, etc.

Therefore, instead of passing __opts__ when instantiating the Matcher class instance, instead a bare-bones dictionary containing just the ID is passed (aside from match.compound which also gets the grains). For example:

if minion_id is not None:
    if not isinstance(minion_id, string_types):
        minion_id = str(minion_id)
else:
    minion_id = __grains__['id']
opts['id'] = minion_id
matcher = salt.minion.Matcher(opts, __salt__)

So, the pull request still allows the minion ID to be passed in on the CLI to override the ID against which the match expression is evaluated, but if left out, it uses the value from __grains__['id'].

Original commit message

This commit allows the minion ID to be specified for the functions in
salt/modules/match.py which operate on the minion ID (compound, list,
pcre, glob). Before, they would just use the value of __opts__['id'],
which makes these functions fail to work properly when run from within
Pillar SLS files, due to Pillar evaluation taking place on the master
(and thus __opts__ referring to the master opts instead of the minion
opts).

By adding a minion_id argument to these functions, the ID can be
overridden, and thus be specified using the id grain in Pillar SLS
files.

This commit allows the minion ID to be specified for the functions in
salt/modules/match.py which operate on the minion ID (compound, list,
pcre, glob). Before, they would just use the value of __opts__['id'],
which makes these functions fail to work properly when run from within
Pillar SLS files, due to Pillar evaluation taking place on the master
(and thus __opts__ referring to the master opts instead of the minion
opts).

By adding a minion_id argument to these functions, the ID can be
overridden, and thus be specified using the 'id' grain in Pillar SLS
files.
@terminalmage

Copy link
Copy Markdown
Contributor Author

Refs #11517

@terminalmage

Copy link
Copy Markdown
Contributor Author

Hold off on merging for now, this still needs some discussion.

No need to force the user to submit the ID, just grab it from grains.
Still allows for minion ID to be passed on the CLI.
@terminalmage

Copy link
Copy Markdown
Contributor Author

OK, I've made a change and updated the pull request message above with more information. Should be good to merge, pending review.

@ghost

ghost commented Apr 14, 2014

Copy link
Copy Markdown

Test Failed.

If the failures are unrelated to your code, don't stress, a core developer will know these apart.
In the future, if possible, please branch off a passing commit to avoid false positives.
Refer to this link for build results: http://jenkins.saltstack.com/job/salt-pr-build/3341/

@cachedout

Copy link
Copy Markdown
Contributor

I like this. +1

thatch45 added a commit that referenced this pull request Apr 14, 2014
Allow minion_id to be specified for certain match functions
@thatch45
thatch45 merged commit 72bec3e into saltstack:develop Apr 14, 2014
@steverweber

Copy link
Copy Markdown
Contributor

@cachedout and @terminalmage is this solution using the __grains__['id'] ? because this could be unsafe because the grain ID is not ensured like the opts['id']
https://groups.google.com/forum/#!topic/salt-users/iM2JlMp9Ua0

@basepi

basepi commented Apr 18, 2014

Copy link
Copy Markdown
Contributor

@steverweber #12128 ensures that the grains['id'] matches the id used to auth with the master. So we're good now. Thanks for pointing out that problem.

@terminalmage
terminalmage deleted the issue11517 branch May 22, 2014 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants