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

performance improvement: stop iterating runner dunder #53553

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .testing.pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,10 @@ additional-builtins=__opts__,
__serializers__,
__reg__,
__executors__,
__events__
__events__,
__jid__,
__user__,
__tag__


# List of strings which can identify a callback function by name. A callback
Expand Down
21 changes: 4 additions & 17 deletions salt/client/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import traceback
import collections
import os
import copy as pycopy

# Import Salt libs
import salt.exceptions
Expand Down Expand Up @@ -333,22 +332,10 @@ def low(self, fun, low, print_event=True, full_return=False):
}

try:
self_functions = pycopy.copy(self.functions)
salt.utils.lazy.verify_fun(self_functions, fun)

# Inject some useful globals to *all* the function's global
# namespace only once per module-- not per func
completed_funcs = []

for mod_name in six.iterkeys(self_functions):
if '.' not in mod_name:
continue
mod, _ = mod_name.split('.', 1)
if mod in completed_funcs:
continue
completed_funcs.append(mod)
for global_key, value in six.iteritems(func_globals):
self.functions[mod_name].__globals__[global_key] = value
salt.utils.lazy.verify_fun(self.functions, fun)

# Inject some useful globals to *all* the function's globals
self.functions.inject_globals.update(func_globals)

# There are some discrepancies of what a "low" structure is in the
# publisher world it is a dict including stuff such as jid, fun,
Expand Down
31 changes: 31 additions & 0 deletions tests/integration/client/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

# Import Salt libs
import salt.runner
import salt.utils.jid


class RunnerModuleTest(TestCase, AdaptedConfigurationTestCaseMixin):
Expand All @@ -25,6 +26,16 @@ def setUp(self):
'''
self.runner = salt.runner.RunnerClient(self.get_config('client_config'))

low = {'client': 'runner', 'fun': 'saltutil.sync_all'}
low.update(self.eauth_creds)
self.runner.cmd_sync(low)

def teardown(self):
'''
Configure an eauth user to test with
'''
del self.runner

def test_eauth(self):
'''
Test executing master_call with lowdata
Expand Down Expand Up @@ -144,3 +155,23 @@ def test_invalid_kwargs_are_ignored(self):

ret = self.runner.cmd_sync(low)
self.assertEqual(ret[0], 'foo')

def test_globals_are_set_as_expected(self):
low = {
'client': 'runner',
'fun': 'testrunner.return_globals',
}
low.update(self.eauth_creds)
ret = self.runner.cmd_sync(low)

for key in ['__jid__', '__user__', '__tag__', '__jid_event__']:
self.assertIn(key, ret)

def test_runner_calling_runner_works(self):
low = {
'client': 'runner',
'fun': 'testrunner.call_other_runner',
}
low.update(self.eauth_creds)
ret = self.runner.cmd_sync(low)
self.assertTrue(salt.utils.jid.is_jid(ret), msg='got __jid__ from nested runner call')
10 changes: 10 additions & 0 deletions tests/integration/files/file/base/_runners/testrunner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
# see tests/integration/client/test_runner.py


def call_other_runner():
return __salt__['testrunner2.other_runner']()


def return_globals():
return list(globals().keys())
6 changes: 6 additions & 0 deletions tests/integration/files/file/base/_runners/testrunner2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
# see tests/integration/client/test_runner.py


def other_runner():
return __jid__