mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 09:23:56 +00:00
Merge pull request #41666 from rallytime/merge-develop
[develop] Merge forward from nitrogen to develop
This commit is contained in:
commit
9cf9cde6da
@ -418,7 +418,7 @@ def _memdata(osdata):
|
||||
mem = __salt__['cmd.run']('{0} -n hw.physmem'.format(sysctl))
|
||||
if osdata['kernel'] == 'NetBSD' and mem.startswith('-'):
|
||||
mem = __salt__['cmd.run']('{0} -n hw.physmem64'.format(sysctl))
|
||||
grains['mem_total'] = int(mem) / 1024 / 1024
|
||||
grains['mem_total'] = int(mem) // 1024 // 1024
|
||||
elif osdata['kernel'] == 'SunOS':
|
||||
prtconf = '/usr/sbin/prtconf 2>/dev/null'
|
||||
for line in __salt__['cmd.run'](prtconf, python_shell=True).splitlines():
|
||||
|
@ -696,6 +696,7 @@ def grains(opts, force_refresh=False, proxy=None):
|
||||
# one parameter. Then the grains can have access to the
|
||||
# proxymodule for retrieving information from the connected
|
||||
# device.
|
||||
log.trace('Loading {0} grain'.format(key))
|
||||
if funcs[key].__code__.co_argcount == 1:
|
||||
ret = funcs[key](proxy)
|
||||
else:
|
||||
@ -1157,9 +1158,10 @@ class LazyLoader(salt.utils.lazy.LazyDict):
|
||||
# The files are added in order of priority, so order *must* be retained.
|
||||
self.file_mapping = salt.utils.odict.OrderedDict()
|
||||
|
||||
for mod_dir in sorted(self.module_dirs):
|
||||
for mod_dir in self.module_dirs:
|
||||
files = []
|
||||
try:
|
||||
# Make sure we have a sorted listdir in order to have expectable override results
|
||||
files = sorted(os.listdir(mod_dir))
|
||||
except OSError:
|
||||
continue # Next mod_dir
|
||||
|
@ -35,21 +35,6 @@ def __virtual__():
|
||||
return __virtualname__
|
||||
|
||||
|
||||
def _check_systemd_salt_config():
|
||||
conf = '/etc/sysctl.d/99-salt.conf'
|
||||
if not os.path.exists(conf):
|
||||
sysctl_dir = os.path.split(conf)[0]
|
||||
if not os.path.exists(sysctl_dir):
|
||||
os.makedirs(sysctl_dir)
|
||||
try:
|
||||
with salt.utils.fopen(conf, 'w'):
|
||||
pass
|
||||
except (IOError, OSError):
|
||||
msg = 'Could not create file: {0}'
|
||||
raise CommandExecutionError(msg.format(conf))
|
||||
return conf
|
||||
|
||||
|
||||
def default_config():
|
||||
'''
|
||||
Linux hosts using systemd 207 or later ignore ``/etc/sysctl.conf`` and only
|
||||
@ -65,7 +50,7 @@ def default_config():
|
||||
'''
|
||||
if salt.utils.systemd.booted(__context__) \
|
||||
and salt.utils.systemd.version(__context__) >= 207:
|
||||
return _check_systemd_salt_config()
|
||||
return '/etc/sysctl.d/99-salt.conf'
|
||||
return '/etc/sysctl.conf'
|
||||
|
||||
|
||||
@ -180,6 +165,9 @@ def persist(name, value, config=None):
|
||||
edited = False
|
||||
# If the sysctl.conf is not present, add it
|
||||
if not os.path.isfile(config):
|
||||
sysctl_dir = os.path.dirname(config)
|
||||
if not os.path.exists(sysctl_dir):
|
||||
os.makedirs(sysctl_dir)
|
||||
try:
|
||||
with salt.utils.fopen(config, 'w+') as _fh:
|
||||
_fh.write('#\n# Kernel sysctl configuration\n#\n')
|
||||
|
@ -335,6 +335,7 @@ def mod_run_check(cmd_kwargs, onlyif, unless, creates):
|
||||
# to quote problems
|
||||
cmd_kwargs = copy.deepcopy(cmd_kwargs)
|
||||
cmd_kwargs['use_vt'] = False
|
||||
cmd_kwargs['bg'] = False
|
||||
|
||||
if onlyif is not None:
|
||||
if isinstance(onlyif, string_types):
|
||||
|
@ -32,6 +32,8 @@ class LoaderGrainsTest(ModuleCase):
|
||||
# self.opts['grains'] = grains(self.opts)
|
||||
|
||||
def test_grains_overwrite(self):
|
||||
# Force a grains sync
|
||||
self.run_function('saltutil.sync_grains')
|
||||
# To avoid a race condition on Windows, we need to make sure the
|
||||
# `test_custom_grain2.py` file is present in the _grains directory
|
||||
# before trying to get the grains. This test may execute before the
|
||||
|
@ -95,15 +95,17 @@ class MasterTest(ShellCase, testprogram.TestProgramCase, ShellCaseCommonTestsMix
|
||||
catch_stderr=True,
|
||||
with_retcode=True,
|
||||
)
|
||||
try:
|
||||
self.assert_exit_status(
|
||||
status, 'EX_NOUSER',
|
||||
message='unknown user not on system',
|
||||
stdout=stdout,
|
||||
stderr=tests.integration.utils.decode_byte_list(stderr)
|
||||
)
|
||||
# Although the start-up should fail, call shutdown() to set the internal
|
||||
# _shutdown flag and avoid the registered atexit calls to cause timeout
|
||||
# exeptions and respective traceback
|
||||
finally:
|
||||
# Although the start-up should fail, call shutdown() to set the
|
||||
# internal _shutdown flag and avoid the registered atexit calls to
|
||||
# cause timeout exeptions and respective traceback
|
||||
master.shutdown()
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
@ -123,15 +125,17 @@ class MasterTest(ShellCase, testprogram.TestProgramCase, ShellCaseCommonTestsMix
|
||||
catch_stderr=True,
|
||||
with_retcode=True,
|
||||
)
|
||||
try:
|
||||
self.assert_exit_status(
|
||||
status, 'EX_USAGE',
|
||||
message='unknown argument',
|
||||
stdout=stdout,
|
||||
stderr=tests.integration.utils.decode_byte_list(stderr)
|
||||
)
|
||||
# Although the start-up should fail, call shutdown() to set the internal
|
||||
# _shutdown flag and avoid the registered atexit calls to cause timeout
|
||||
# exeptions and respective traceback
|
||||
finally:
|
||||
# Although the start-up should fail, call shutdown() to set the
|
||||
# internal _shutdown flag and avoid the registered atexit calls to
|
||||
# cause timeout exeptions and respective traceback
|
||||
master.shutdown()
|
||||
|
||||
def test_exit_status_correct_usage(self):
|
||||
@ -150,23 +154,28 @@ class MasterTest(ShellCase, testprogram.TestProgramCase, ShellCaseCommonTestsMix
|
||||
catch_stderr=True,
|
||||
with_retcode=True,
|
||||
)
|
||||
try:
|
||||
self.assert_exit_status(
|
||||
status, 'EX_OK',
|
||||
message='correct usage',
|
||||
stdout=stdout,
|
||||
stderr=tests.integration.utils.decode_byte_list(stderr)
|
||||
)
|
||||
master.shutdown()
|
||||
finally:
|
||||
master.shutdown(wait_for_orphans=3)
|
||||
|
||||
# Do the test again to check does master shut down correctly
|
||||
stdout, stderr, status = master.run(
|
||||
args=['-d'],
|
||||
catch_stderr=True,
|
||||
with_retcode=True,
|
||||
)
|
||||
try:
|
||||
self.assert_exit_status(
|
||||
status, 'EX_OK',
|
||||
message='correct usage',
|
||||
stdout=stdout,
|
||||
stderr=tests.integration.utils.decode_byte_list(stderr)
|
||||
)
|
||||
master.shutdown()
|
||||
finally:
|
||||
master.shutdown(wait_for_orphans=3)
|
||||
|
@ -292,15 +292,17 @@ class MinionTest(ShellCase, testprogram.TestProgramCase, ShellCaseCommonTestsMix
|
||||
catch_stderr=True,
|
||||
with_retcode=True,
|
||||
)
|
||||
try:
|
||||
self.assert_exit_status(
|
||||
status, 'EX_NOUSER',
|
||||
message='unknown user not on system',
|
||||
stdout=stdout,
|
||||
stderr=tests.integration.utils.decode_byte_list(stderr)
|
||||
)
|
||||
# Although the start-up should fail, call shutdown() to set the internal
|
||||
# _shutdown flag and avoid the registered atexit calls to cause timeout
|
||||
# exeptions and respective traceback
|
||||
finally:
|
||||
# Although the start-up should fail, call shutdown() to set the
|
||||
# internal _shutdown flag and avoid the registered atexit calls to
|
||||
# cause timeout exeptions and respective traceback
|
||||
minion.shutdown()
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
@ -320,15 +322,17 @@ class MinionTest(ShellCase, testprogram.TestProgramCase, ShellCaseCommonTestsMix
|
||||
catch_stderr=True,
|
||||
with_retcode=True,
|
||||
)
|
||||
try:
|
||||
self.assert_exit_status(
|
||||
status, 'EX_USAGE',
|
||||
message='unknown argument',
|
||||
stdout=stdout,
|
||||
stderr=tests.integration.utils.decode_byte_list(stderr)
|
||||
)
|
||||
# Although the start-up should fail, call shutdown() to set the internal
|
||||
# _shutdown flag and avoid the registered atexit calls to cause timeout
|
||||
# exeptions and respective traceback
|
||||
finally:
|
||||
# Although the start-up should fail, call shutdown() to set the
|
||||
# internal _shutdown flag and avoid the registered atexit calls to
|
||||
# cause timeout exeptions and respective traceback
|
||||
minion.shutdown()
|
||||
|
||||
def test_exit_status_correct_usage(self):
|
||||
@ -352,4 +356,4 @@ class MinionTest(ShellCase, testprogram.TestProgramCase, ShellCaseCommonTestsMix
|
||||
message='correct usage',
|
||||
stdout=stdout, stderr=stderr
|
||||
)
|
||||
minion.shutdown()
|
||||
minion.shutdown(wait_for_orphans=3)
|
||||
|
@ -45,13 +45,18 @@ class ProxyTest(testprogram.TestProgramCase):
|
||||
# without daemonizing - protect that with a timeout.
|
||||
timeout=60,
|
||||
)
|
||||
try:
|
||||
self.assert_exit_status(
|
||||
status, 'EX_USAGE',
|
||||
message='no --proxyid specified',
|
||||
stdout=stdout,
|
||||
stderr=tests.integration.utils.decode_byte_list(stderr)
|
||||
)
|
||||
# proxy.shutdown() should be unnecessary since the start-up should fail
|
||||
finally:
|
||||
# Although the start-up should fail, call shutdown() to set the
|
||||
# internal _shutdown flag and avoid the registered atexit calls to
|
||||
# cause timeout exeptions and respective traceback
|
||||
proxy.shutdown()
|
||||
|
||||
def test_exit_status_unknown_user(self):
|
||||
'''
|
||||
@ -70,13 +75,18 @@ class ProxyTest(testprogram.TestProgramCase):
|
||||
catch_stderr=True,
|
||||
with_retcode=True,
|
||||
)
|
||||
try:
|
||||
self.assert_exit_status(
|
||||
status, 'EX_NOUSER',
|
||||
message='unknown user not on system',
|
||||
stdout=stdout,
|
||||
stderr=tests.integration.utils.decode_byte_list(stderr)
|
||||
)
|
||||
# proxy.shutdown() should be unnecessary since the start-up should fail
|
||||
finally:
|
||||
# Although the start-up should fail, call shutdown() to set the
|
||||
# internal _shutdown flag and avoid the registered atexit calls to
|
||||
# cause timeout exeptions and respective traceback
|
||||
proxy.shutdown()
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
def test_exit_status_unknown_argument(self):
|
||||
@ -95,12 +105,17 @@ class ProxyTest(testprogram.TestProgramCase):
|
||||
catch_stderr=True,
|
||||
with_retcode=True,
|
||||
)
|
||||
try:
|
||||
self.assert_exit_status(
|
||||
status, 'EX_USAGE',
|
||||
message='unknown argument',
|
||||
stdout=stdout, stderr=stderr
|
||||
)
|
||||
# proxy.shutdown() should be unnecessary since the start-up should fail
|
||||
finally:
|
||||
# Although the start-up should fail, call shutdown() to set the
|
||||
# internal _shutdown flag and avoid the registered atexit calls to
|
||||
# cause timeout exeptions and respective traceback
|
||||
proxy.shutdown()
|
||||
|
||||
def test_exit_status_correct_usage(self):
|
||||
'''
|
||||
@ -118,10 +133,12 @@ class ProxyTest(testprogram.TestProgramCase):
|
||||
catch_stderr=True,
|
||||
with_retcode=True,
|
||||
)
|
||||
try:
|
||||
self.assert_exit_status(
|
||||
status, 'EX_OK',
|
||||
message='correct usage',
|
||||
stdout=stdout,
|
||||
stderr=tests.integration.utils.decode_byte_list(stderr)
|
||||
)
|
||||
proxy.shutdown()
|
||||
finally:
|
||||
proxy.shutdown(wait_for_orphans=3)
|
||||
|
@ -102,14 +102,16 @@ class SyndicTest(ShellCase, testprogram.TestProgramCase, ShellCaseCommonTestsMix
|
||||
catch_stderr=True,
|
||||
with_retcode=True,
|
||||
)
|
||||
try:
|
||||
self.assert_exit_status(
|
||||
status, 'EX_NOUSER',
|
||||
message='unknown user not on system',
|
||||
stdout=stdout, stderr=stderr
|
||||
)
|
||||
# Although the start-up should fail, call shutdown() to set the internal
|
||||
# _shutdown flag and avoid the registered atexit calls to cause timeout
|
||||
# exeptions and respective traceback
|
||||
finally:
|
||||
# Although the start-up should fail, call shutdown() to set the
|
||||
# internal _shutdown flag and avoid the registered atexit calls to
|
||||
# cause timeout exeptions and respective traceback
|
||||
syndic.shutdown()
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
@ -129,14 +131,16 @@ class SyndicTest(ShellCase, testprogram.TestProgramCase, ShellCaseCommonTestsMix
|
||||
catch_stderr=True,
|
||||
with_retcode=True,
|
||||
)
|
||||
try:
|
||||
self.assert_exit_status(
|
||||
status, 'EX_USAGE',
|
||||
message='unknown argument',
|
||||
stdout=stdout, stderr=stderr
|
||||
)
|
||||
# Although the start-up should fail, call shutdown() to set the internal
|
||||
# _shutdown flag and avoid the registered atexit calls to cause timeout
|
||||
# exeptions and respective traceback
|
||||
finally:
|
||||
# Although the start-up should fail, call shutdown() to set the
|
||||
# internal _shutdown flag and avoid the registered atexit calls to
|
||||
# cause timeout exeptions and respective traceback
|
||||
syndic.shutdown()
|
||||
|
||||
def test_exit_status_correct_usage(self):
|
||||
@ -155,9 +159,11 @@ class SyndicTest(ShellCase, testprogram.TestProgramCase, ShellCaseCommonTestsMix
|
||||
catch_stderr=True,
|
||||
with_retcode=True,
|
||||
)
|
||||
try:
|
||||
self.assert_exit_status(
|
||||
status, 'EX_OK',
|
||||
message='correct usage',
|
||||
stdout=stdout, stderr=stderr
|
||||
)
|
||||
syndic.shutdown()
|
||||
finally:
|
||||
syndic.shutdown(wait_for_orphans=3)
|
||||
|
@ -29,7 +29,7 @@ import salt.ext.six as six
|
||||
|
||||
from tests.support.unit import TestCase
|
||||
from tests.support.paths import CODE_DIR
|
||||
from tests.support.processes import terminate_process
|
||||
from tests.support.processes import terminate_process, terminate_process_list
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@ -416,10 +416,10 @@ class TestProgram(six.with_metaclass(TestProgramMeta, object)):
|
||||
elif sys.platform.lower().startswith('win') and timeout is not None:
|
||||
raise RuntimeError('Timeout is not supported under windows')
|
||||
|
||||
argv = [self.program]
|
||||
argv.extend(args)
|
||||
log.debug('TestProgram.run: {0} Environment {1}'.format(argv, env_delta))
|
||||
process = subprocess.Popen(argv, **popen_kwargs)
|
||||
self.argv = [self.program]
|
||||
self.argv.extend(args)
|
||||
log.debug('TestProgram.run: %s Environment %s', self.argv, env_delta)
|
||||
process = subprocess.Popen(self.argv, **popen_kwargs)
|
||||
self.process = process
|
||||
|
||||
if timeout is not None:
|
||||
@ -766,7 +766,12 @@ class TestDaemon(TestProgram):
|
||||
pass
|
||||
return ret
|
||||
|
||||
def shutdown(self, signum=signal.SIGTERM, timeout=10):
|
||||
def find_orphans(self, cmdline):
|
||||
'''Find orphaned processes matching the specified cmdline'''
|
||||
return [x for x in psutils.process_iter()
|
||||
if x.ppid() == 1 and x.cmdline()[-len(cmdline):] == cmdline]
|
||||
|
||||
def shutdown(self, signum=signal.SIGTERM, timeout=10, wait_for_orphans=0):
|
||||
'''Shutdown a running daemon'''
|
||||
if not self._shutdown:
|
||||
try:
|
||||
@ -777,6 +782,24 @@ class TestDaemon(TestProgram):
|
||||
if self.process:
|
||||
terminate_process(pid=self.process.pid, kill_children=True)
|
||||
self.process.wait()
|
||||
if wait_for_orphans:
|
||||
# NOTE: The process for finding orphans is greedy, it just
|
||||
# looks for processes with the same cmdline which are owned by
|
||||
# PID 1.
|
||||
orphans = self.find_orphans(self.argv)
|
||||
last = time.time()
|
||||
while True:
|
||||
if orphans:
|
||||
log.debug(
|
||||
'Terminating orphaned child processes: %s',
|
||||
orphans
|
||||
)
|
||||
terminate_process_list(orphans)
|
||||
last = time.time()
|
||||
if (time.time() - last) >= wait_for_orphans:
|
||||
break
|
||||
time.sleep(0.25)
|
||||
orphans = self.find_orphans(self.argv)
|
||||
self.process = None
|
||||
self._shutdown = True
|
||||
|
||||
|
@ -16,7 +16,7 @@ import logging
|
||||
|
||||
# Import pytest-salt libs
|
||||
from pytestsalt.utils import SaltRunEventListener as PytestSaltRunEventListener
|
||||
from pytestsalt.utils import collect_child_processes, terminate_process # pylint: disable=unused-import
|
||||
from pytestsalt.utils import collect_child_processes, terminate_process, terminate_process_list # pylint: disable=unused-import
|
||||
from pytestsalt.fixtures.daemons import Salt as PytestSalt
|
||||
from pytestsalt.fixtures.daemons import SaltKey as PytestSaltKey
|
||||
from pytestsalt.fixtures.daemons import SaltRun as PytestSaltRun
|
||||
|
Loading…
Reference in New Issue
Block a user