Merge branch '2019.2.1' into tcp_leak

This commit is contained in:
Daniel Wozniak 2019-06-23 16:12:14 -07:00 committed by GitHub
commit 7eb5d41f37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 75 additions and 19 deletions

View File

@ -434,3 +434,14 @@ class Beacon(object):
Reset the beacons to defaults
'''
self.opts['beacons'] = {}
comment = 'Beacon Reset'
complete = True
# Fire the complete event back along with updated list of beacons
evt = salt.utils.event.get_event('minion', opts=self.opts)
evt.fire_event({'complete': complete, 'comment': comment,
'beacons': self.opts['beacons']},
tag='/salt/minion/minion_beacon_reset_complete')
return True

View File

@ -389,7 +389,7 @@ def _file_lists(load, form):
rel_dest = _translate_sep(
os.path.relpath(
os.path.realpath(os.path.normpath(joined)),
fs_root
os.path.realpath(fs_root)
)
)
log.trace(

View File

@ -1706,7 +1706,7 @@ class LazyLoader(salt.utils.lazy.LazyDict):
# enforce depends
try:
Depends.enforce_dependencies(self._dict, self.tag)
Depends.enforce_dependencies(self._dict, self.tag, name)
except RuntimeError as exc:
log.info(
'Depends.enforce_dependencies() failed for the following '

View File

@ -614,7 +614,7 @@ def reset(**kwargs):
ret = {'comment': [],
'result': True}
if 'test' in kwargs and kwargs['test']:
if kwargs.get('test'):
ret['comment'] = 'Beacons would be reset.'
else:
try:
@ -629,7 +629,7 @@ def reset(**kwargs):
ret['comment'] = 'Beacon configuration reset.'
else:
ret['result'] = False
ret['comment'] = event_ret['comment']
ret['comment'] = 'Something went wrong.'
return ret
except KeyError:
# Effectively a no-op, since we can't really return without an event system

View File

@ -55,11 +55,16 @@ def install(app_id, enable=True):
salt '*' assistive.install com.smileonmymac.textexpander
'''
ge_el_capitan = True if _LooseVersion(__grains__['osrelease']) >= salt.utils.stringutils.to_str('10.11') else False
ge_mojave = True if _LooseVersion(__grains__['osrelease']) >= salt.utils.stringutils.to_str('10.14') else False
client_type = _client_type(app_id)
enable_str = '1' if enable else '0'
cmd = 'sqlite3 "/Library/Application Support/com.apple.TCC/TCC.db" ' \
'"INSERT or REPLACE INTO access VALUES(\'kTCCServiceAccessibility\',\'{0}\',{1},{2},1,NULL{3})"'.\
format(app_id, client_type, enable_str, ',NULL' if ge_el_capitan else '')
'"INSERT or REPLACE INTO access VALUES(\'kTCCServiceAccessibility\',\'{0}\',{1},{2},1,NULL{3}{4})"'.\
format(app_id,
client_type,
enable_str,
',NULL' if ge_el_capitan else '',
",NULL,NULL,NULL,NULL,''" if ge_mojave else '')
call = __salt__['cmd.run_all'](
cmd,

View File

@ -132,7 +132,7 @@ class Depends(object):
return retcode
@classmethod
def enforce_dependencies(cls, functions, kind):
def enforce_dependencies(cls, functions, kind, tgt_mod):
'''
This is a class global method to enforce the dependencies that you
currently know about.
@ -141,6 +141,8 @@ class Depends(object):
'''
for dependency, dependent_dict in six.iteritems(cls.dependency_dict[kind]):
for (mod_name, func_name), (frame, params) in six.iteritems(dependent_dict):
if mod_name != tgt_mod:
continue
if 'retcode' in params or 'nonzero_retcode' in params:
try:
retcode = cls.run_command(dependency, mod_name, func_name)

View File

@ -5,6 +5,7 @@ Jinja loading utils to enable a more powerful backend for jinja templates
# Import python libs
from __future__ import absolute_import, unicode_literals
import atexit
import collections
import logging
import os.path
@ -54,8 +55,18 @@ class SaltCacheLoader(BaseLoader):
Templates are cached like regular salt states
and only loaded once per loader instance.
'''
_cached_client = None
@classmethod
def shutdown(cls):
if cls._cached_client is None:
return
cls._cached_client.destroy()
cls._cached_client = None
def __init__(self, opts, saltenv='base', encoding='utf-8',
pillar_rend=False):
pillar_rend=False, _file_client=None):
self.opts = opts
self.saltenv = saltenv
self.encoding = encoding
@ -69,7 +80,7 @@ class SaltCacheLoader(BaseLoader):
self.searchpath = [os.path.join(opts['cachedir'], 'files', saltenv)]
log.debug('Jinja search path: %s', self.searchpath)
self.cached = []
self._file_client = None
self._file_client = _file_client
# Instantiate the fileclient
self.file_client()
@ -77,9 +88,14 @@ class SaltCacheLoader(BaseLoader):
'''
Return a file client. Instantiates on first call.
'''
if not self._file_client:
self._file_client = salt.fileclient.get_file_client(
self.opts, self.pillar_rend)
# If there was no file_client passed to the class, create a cache_client
# and use that. This avoids opening a new file_client every time this
# class is instantiated
if self._file_client is None:
if not SaltCacheLoader._cached_client:
SaltCacheLoader._cached_client = salt.fileclient.get_file_client(
self.opts, self.pillar_rend)
self._file_client = SaltCacheLoader._cached_client
return self._file_client
def cache_file(self, template):
@ -171,6 +187,9 @@ class SaltCacheLoader(BaseLoader):
raise TemplateNotFound(template)
atexit.register(SaltCacheLoader.shutdown)
class PrintableDict(OrderedDict):
'''
Ensures that dict str() and repr() are YAML friendly.

View File

@ -286,6 +286,7 @@ class CPModuleTest(ModuleCase):
self.assertNotIn('bacon', data)
@skipIf(not SSL3_SUPPORT, 'Requires python with SSL3 support')
@skipIf(salt.utils.platform.is_darwin() and six.PY2, 'This test hangs on OS X on Py2')
@with_tempfile()
def test_get_url_https(self, tgt):
'''
@ -305,6 +306,7 @@ class CPModuleTest(ModuleCase):
self.assertNotIn('AYBABTU', data)
@skipIf(not SSL3_SUPPORT, 'Requires python with SSL3 support')
@skipIf(salt.utils.platform.is_darwin() and six.PY2, 'This test hangs on OS X on Py2')
def test_get_url_https_dest_empty(self):
'''
cp.get_url with https:// source given and destination omitted.
@ -322,6 +324,7 @@ class CPModuleTest(ModuleCase):
self.assertNotIn('AYBABTU', data)
@skipIf(not SSL3_SUPPORT, 'Requires python with SSL3 support')
@skipIf(salt.utils.platform.is_darwin() and six.PY2, 'This test hangs on OS X on Py2')
def test_get_url_https_no_dest(self):
'''
cp.get_url with https:// source given and destination set as None
@ -397,6 +400,7 @@ class CPModuleTest(ModuleCase):
self.assertEqual(ret, False)
@skipIf(not SSL3_SUPPORT, 'Requires python with SSL3 support')
@skipIf(salt.utils.platform.is_darwin() and six.PY2, 'This test hangs on OS X on Py2')
def test_get_file_str_https(self):
'''
cp.get_file_str with https:// source given

View File

@ -1864,6 +1864,7 @@ class StateModuleTest(ModuleCase, SaltReturnAssertsMixin):
pass
@skipIf(sys.platform.startswith('win'), 'Skipped until parallel states can be fixed on Windows')
@skipIf(salt.utils.platform.is_darwin() and six.PY2, 'This test hangs on OS X on Py2')
def test_parallel_state_with_long_tag(self):
'''
This tests the case where the state being executed has a long ID dec or

View File

@ -74,6 +74,9 @@ else:
FILEPILLARDEF = '/tmp/filepillar-defaultvalue'
FILEPILLARGIT = '/tmp/filepillar-bar'
TEST_SYSTEM_USER = 'test_system_user'
TEST_SYSTEM_GROUP = 'test_system_group'
def _test_managed_file_mode_keep_helper(testcase, local=False):
'''
@ -2300,6 +2303,7 @@ class FileTest(ModuleCase, SaltReturnAssertsMixin):
self.assertEqual([salt.utils.stringutils.to_str(line) for line in expected], contents)
@with_tempdir()
@skipIf(salt.utils.platform.is_darwin() and six.PY2, 'This test hangs on OS X on Py2')
def test_issue_11003_immutable_lazy_proxy_sum(self, base_dir):
# causes the Import-Module ServerManager error on Windows
template_path = os.path.join(TMP_STATE_TREE, 'issue-11003.sls')
@ -2343,7 +2347,7 @@ class FileTest(ModuleCase, SaltReturnAssertsMixin):
with salt.utils.files.fopen(template_path, 'w') as fp_:
fp_.write(os.linesep.join(sls_template).format(testcase_filedest))
ret = self.run_function('state.sls', mods='issue-11003')
ret = self.run_function('state.sls', mods='issue-11003', timeout=600)
for name, step in six.iteritems(ret):
self.assertSaltTrueReturn({name: step})
with salt.utils.files.fopen(testcase_filedest) as fp_:
@ -2476,7 +2480,7 @@ class FileTest(ModuleCase, SaltReturnAssertsMixin):
@skip_if_not_root
@skipIf(not HAS_PWD, "pwd not available. Skipping test")
@skipIf(not HAS_GRP, "grp not available. Skipping test")
@with_system_user_and_group('user12209', 'group12209',
@with_system_user_and_group(TEST_SYSTEM_USER, TEST_SYSTEM_GROUP,
on_existing='delete', delete=True)
@with_tempdir()
def test_issue_12209_follow_symlinks(self, tempdir, user, group):
@ -2512,7 +2516,7 @@ class FileTest(ModuleCase, SaltReturnAssertsMixin):
@skip_if_not_root
@skipIf(not HAS_PWD, "pwd not available. Skipping test")
@skipIf(not HAS_GRP, "grp not available. Skipping test")
@with_system_user_and_group('user12209', 'group12209',
@with_system_user_and_group(TEST_SYSTEM_USER, TEST_SYSTEM_GROUP,
on_existing='delete', delete=True)
@with_tempdir()
def test_issue_12209_no_follow_symlinks(self, tempdir, user, group):
@ -2637,7 +2641,7 @@ class FileTest(ModuleCase, SaltReturnAssertsMixin):
@skip_if_not_root
@skipIf(not HAS_PWD, "pwd not available. Skipping test")
@skipIf(not HAS_GRP, "grp not available. Skipping test")
@with_system_user_and_group('test_setuid_user', 'test_setuid_group',
@with_system_user_and_group(TEST_SYSTEM_USER, TEST_SYSTEM_GROUP,
on_existing='delete', delete=True)
def test_owner_after_setuid(self, user, group):
@ -2694,7 +2698,7 @@ class FileTest(ModuleCase, SaltReturnAssertsMixin):
@skip_if_not_root
@skipIf(not HAS_PWD, "pwd not available. Skipping test")
@skipIf(not HAS_GRP, "grp not available. Skipping test")
@with_system_user_and_group('user12209', 'group12209',
@with_system_user_and_group(TEST_SYSTEM_USER, TEST_SYSTEM_GROUP,
on_existing='delete', delete=True)
@with_tempdir()
def test_issue_48336_file_managed_mode_setuid(self, tempdir, user, group):

View File

@ -497,6 +497,7 @@ class PipStateTest(ModuleCase, SaltReturnAssertsMixin):
if os.path.isfile(requirements_file):
os.unlink(requirements_file)
@skipIf(salt.utils.platform.is_darwin() and six.PY2, 'This test hangs on OS X on Py2')
def test_22359_pip_installed_unless_does_not_trigger_warnings(self):
# This test case should be moved to a format_call unit test specific to
# the state internal keywords
@ -509,12 +510,12 @@ class PipStateTest(ModuleCase, SaltReturnAssertsMixin):
)
)
false_cmd = '/bin/false'
false_cmd = salt.utils.path.which('false')
if salt.utils.platform.is_windows():
false_cmd = 'exit 1 >nul'
try:
ret = self.run_state(
'pip.installed', name='pep8', bin_env=venv_dir, unless=false_cmd
'pip.installed', name='pep8', bin_env=venv_dir, unless=false_cmd, timeout=600
)
self.assertSaltTrueReturn(ret)
self.assertNotIn('warnings', next(six.itervalues(ret)))

View File

@ -9,6 +9,13 @@ from __future__ import absolute_import, unicode_literals, print_function
# Import Salt Testing libs
from tests.support.case import ModuleCase
from tests.support.helpers import flaky
from tests.support.unit import skipIf
# Import Salt libs
import salt.utils.platform
# Import 3rd-party libs
from salt.ext import six
class TestJinjaRenderer(ModuleCase):
@ -24,6 +31,7 @@ class TestJinjaRenderer(ModuleCase):
self.assertTrue(state_ret['result'])
@flaky
@skipIf(salt.utils.platform.is_darwin() and six.PY2, 'This test hangs on OS X on Py2')
def test_salt_contains_function(self):
'''
Test if we are able to check if a function exists inside the "salt"

View File

@ -495,6 +495,7 @@ class SSHThinTestCase(TestCase):
@patch('salt.utils.thin.zipfile', MagicMock())
@patch('salt.utils.thin.os.getcwd', MagicMock())
@patch('salt.utils.thin.os.chdir', MagicMock())
@patch('salt.utils.thin.os.close', MagicMock())
@patch('salt.utils.thin.tempfile.mkdtemp', MagicMock())
@patch('salt.utils.thin.tempfile.mkstemp', MagicMock(return_value=(3, ".temporary")))
@patch('salt.utils.thin.shutil', MagicMock())