Skip to content
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

Matcher in loader, take 4 #48809

Merged
merged 44 commits into from Sep 26, 2018
Merged

Matcher in loader, take 4 #48809

merged 44 commits into from Sep 26, 2018

Conversation

cro
Copy link
Contributor

@cro cro commented Jul 27, 2018

What does this PR do?

Creates a new directory salt/matchers and migrates the matcher functions into separate .py files in this directory. These functions are loaded at minion startup, but can be reloaded with the new saltutil.refresh_matchers function.

Tests written?

Matcher tests apply here.

Commits signed with GPG?

Yes

@cro cro requested a review from a team as a code owner July 27, 2018 22:07
@ghost ghost self-requested a review July 27, 2018 22:07
@cro
Copy link
Contributor Author

cro commented Jul 27, 2018

Previous incarnations:

#48624
#48784
#48785

@@ -203,8 +203,8 @@ def test_multi_local_async_post(self):
self.assertEqual(len(ret), 2)
self.assertIn('jid', ret[0])
self.assertIn('jid', ret[1])
self.assertEqual(ret[0]['minions'], sorted(['minion', 'sub_minion', 'localhost']))
self.assertEqual(ret[1]['minions'], sorted(['minion', 'sub_minion', 'localhost']))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these getting removed?

This was added for testing the enable_ssh_minions feature added in 2018.3.

It does need the ssh daemon started in runtests.py with python -m tests.runtests --ssh, but those minions should still be returning from the tornado tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, this is what I needed to know, thanks.

Copy link
Contributor

@gtmanfred gtmanfred left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After talking to Nicole, those tests are not the flaky ones that she marked in 2017.7, so they should still be passing.

These should be returning localhost, because it should be matching the minions for the enable_ssh_minions targeting. in salt.utils.minions

https://github.com/saltstack/salt/blob/develop/salt/utils/minions.py#L715

Copy link
Contributor

@isbm isbm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cro 💥 very cool! 💥

@gtmanfred
Copy link
Contributor

@rallytime looks like these tests are failing on the head of develop too? can you confirm?

@cro revert the test changes, and I will fix them in a different PR, and approve this one.

@gtmanfred
Copy link
Contributor

Trying the tests inside of test-kitchen to see if I can verify them in our test setup.

@gtmanfred
Copy link
Contributor

The tests look better, and do not appear to be failing on the tornado tests anymore, rerunning the tests that did not post unittest results.

Copy link
Contributor

@cachedout cachedout left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My big concern here is that these functions all take self and then get converted on-the-fly to class-based methods from the context of the minion.

I presume that this was to avoid changing the interface to the Matchers from the minion's perspective but I'm not sure this is the right decision. IMHO, we should modify the minion-side logic so that it just calls functions. This is the pattern in every other pluggable system in Salt and I am very hesitant about diverging from that.


Matchers are modules that provide Salt's targeting abilities. As of the
Flourine release, matchers can be dynamically loaded. Currently new matchers
cannot be created, but existing matchers may have their functionality altered or
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this just because the CLI would need to be modified as well? I feel like this needs more explanation.

@rallytime rallytime changed the base branch from develop to fluorine August 6, 2018 20:28
@rallytime
Copy link
Contributor

@cro I have changed the base branch of this PR from develop to fluorine for inclusion in the Fluorine feature release.

Also, if you could make the changes requested above ASAP, that would be great so we can get this merged in. Thanks!

@cachedout
Copy link
Contributor

Bump @cro

@cro
Copy link
Contributor Author

cro commented Aug 14, 2018

So if I understand correctly @cachedout, you would like to see this behave more like executors, which are loaded specifically with a call to salt.loader.executors(), and then referenced with the standard LazyLoader pattern, e.g.

matchers = salt.loader.matchers(opts)
matchers['list_match.match'](...)

@cro cro force-pushed the matcher_in_loader2 branch 2 times, most recently from 6561a34 to d62b87d Compare August 14, 2018 22:33
@cro
Copy link
Contributor Author

cro commented Aug 14, 2018

K, d62b87d there removes the Matcher class and goes instead with the bare loader.

@cro
Copy link
Contributor Author

cro commented Aug 14, 2018

Tests may not pass fully yet, I have a mock or two I have to figure out what to do with.

@cachedout
Copy link
Contributor

@cro Correct. I know that's a bit of a pain but the consistency will be a win in the long run. Thanks for doing this!

@cachedout
Copy link
Contributor

try:
return matcher.pcre_match(tgt)
return matcher['pcre_match.match'](tgt)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be plural, I think.

@cachedout
Copy link
Contributor

@rallytime
Copy link
Contributor

@cro Any update here? We need these tests fixed before we can get this in.

cro and others added 8 commits September 21, 2018 09:36
This is faster than splitting into a list and then iterating over it.
By using a generator comprehension, we avoid pre-allocating an entire
list of objects.
This reverses the order in which matches are attempted so that we start
with more deeply-nested matches first. The rationale for this is that it
is much more likely that when one uses `foo:bar:baz:hello:world`, they
are looking for a deeply-nested dictionary containing a key `hello`
which maps to `world`, than a key named `foo` matching the string
`bar:baz:hello:world`. The one case in which this change would be less
performant would be in the case where the value being checked is a
UNIX-style PATH (which uses colons as separators).
*Just* in case something else that invokes this starts using tuples at
some point, it'll save us a traceback.
@rallytime
Copy link
Contributor

@cro Getting closer, but there are still some tests that need to be fixed here:

https://jenkinsci.saltstack.com/job/pr-kitchen-centos7-py3/job/PR-48809/24/

All of those test failures are related to the changes in this PR.

or tgt.startswith(__opts__['id'] + ',') \
or tgt.endswith(',' + __opts__['id'])
if isinstance(tgt, collections.Sequence) and not isinstance(tgt, six.string_types):
result = bool(__opts__['id'] in tgt)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__opts__['id'] in tgt already returns a bool, so wrapping it in bool() is redundant.

Also, we can skip the type checking altogether by just relying on exception handling to narrow down what type the target is. I've opened cro#16 with one possible way we could do this.

@terminalmage
Copy link
Contributor

AWS is having some issues, but tests did pass on the one platform where they finished without SSH connection issues. This should be good to merge once we can get the test suite to run to completion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants