mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Test exit status of salt-syndic
This commit is contained in:
parent
8a5f1aa1cf
commit
5a8c2fcd2c
2 changed files with 96 additions and 5 deletions
|
@ -13,6 +13,7 @@ import os
|
|||
import yaml
|
||||
import signal
|
||||
import shutil
|
||||
import logging
|
||||
|
||||
# Import Salt Testing libs
|
||||
from salttesting.helpers import ensure_in_syspath
|
||||
|
@ -20,10 +21,17 @@ ensure_in_syspath('../../')
|
|||
|
||||
# Import salt libs
|
||||
import integration
|
||||
from integration.utils import testprogram
|
||||
import salt.utils
|
||||
|
||||
|
||||
class SyndicTest(integration.ShellCase, integration.ShellCaseCommonTestsMixIn):
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class SyndicTest(integration.ShellCase, testprogram.TestProgramCase, integration.ShellCaseCommonTestsMixIn):
|
||||
'''
|
||||
Test the salt-syndic command
|
||||
'''
|
||||
|
||||
_call_binary_ = 'salt-syndic'
|
||||
|
||||
|
@ -79,7 +87,77 @@ class SyndicTest(integration.ShellCase, integration.ShellCaseCommonTestsMixIn):
|
|||
if os.path.isdir(config_dir):
|
||||
shutil.rmtree(config_dir)
|
||||
|
||||
def test_exit_status_unknown_user(self):
|
||||
'''
|
||||
Ensure correct exit status when the syndic is configured to run as an unknown user.
|
||||
'''
|
||||
|
||||
syndic = testprogram.TestDaemonSaltSyndic(
|
||||
name='unknown_user',
|
||||
config_base={'user': 'unknown'},
|
||||
parent_dir=self._test_dir,
|
||||
)
|
||||
# Call setup here to ensure config and script exist
|
||||
syndic.setup()
|
||||
stdout, stderr, status = syndic.run(
|
||||
args=['-d'],
|
||||
catch_stderr=True,
|
||||
with_retcode=True,
|
||||
)
|
||||
self.assert_exit_status(
|
||||
status, 'EX_NOUSER',
|
||||
message='unknown user not on system',
|
||||
stdout=stdout, stderr=stderr
|
||||
)
|
||||
# syndic.shutdown() should be unnecessary since the start-up should fail
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
def test_exit_status_unknown_argument(self):
|
||||
'''
|
||||
Ensure correct exit status when an unknown argument is passed to salt-syndic.
|
||||
'''
|
||||
|
||||
syndic = testprogram.TestDaemonSaltSyndic(
|
||||
name='unknown_argument',
|
||||
parent_dir=self._test_dir,
|
||||
)
|
||||
# Syndic setup here to ensure config and script exist
|
||||
syndic.setup()
|
||||
stdout, stderr, status = syndic.run(
|
||||
args=['-d', '--unknown-argument'],
|
||||
catch_stderr=True,
|
||||
with_retcode=True,
|
||||
)
|
||||
self.assert_exit_status(
|
||||
status, 'EX_USAGE',
|
||||
message='unknown argument',
|
||||
stdout=stdout, stderr=stderr
|
||||
)
|
||||
# syndic.shutdown() should be unnecessary since the start-up should fail
|
||||
|
||||
def test_exit_status_correct_usage(self):
|
||||
'''
|
||||
Ensure correct exit status when salt-syndic starts correctly.
|
||||
'''
|
||||
|
||||
syndic = testprogram.TestDaemonSaltSyndic(
|
||||
name='correct_usage',
|
||||
parent_dir=self._test_dir,
|
||||
)
|
||||
# Syndic setup here to ensure config and script exist
|
||||
syndic.setup()
|
||||
stdout, stderr, status = syndic.run(
|
||||
args=['-d', '-l', 'debug'],
|
||||
catch_stderr=True,
|
||||
with_retcode=True,
|
||||
)
|
||||
self.assert_exit_status(
|
||||
status, 'EX_OK',
|
||||
message='correct usage',
|
||||
stdout=stdout, stderr=stderr
|
||||
)
|
||||
syndic.shutdown()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from integration import run_tests
|
||||
run_tests(SyndicTest)
|
||||
integration.run_tests(SyndicTest)
|
||||
|
|
|
@ -756,6 +756,7 @@ class TestDaemon(TestProgram):
|
|||
if not self._shutdown and self.process and self.process.returncode == exitcodes.EX_OK:
|
||||
future = datetime.now() + timedelta(seconds=timeout)
|
||||
pid = self.wait_for_daemon_pid(timeout)
|
||||
LOG.info('Attempting to shutdown "{0}" pid {1} with {2}'.format(self.name, pid, signum))
|
||||
while True:
|
||||
try:
|
||||
os.kill(pid, signum)
|
||||
|
@ -764,7 +765,19 @@ class TestDaemon(TestProgram):
|
|||
break
|
||||
raise
|
||||
if datetime.now() > future:
|
||||
raise TimeoutError('Timeout waiting for "{0}" pid'.format(pid))
|
||||
# One last attempt with a big hammer
|
||||
try:
|
||||
pgid = os.getpgid(pid)
|
||||
os.killpg(pgid, signum)
|
||||
time.sleep(0.1)
|
||||
LOG.warn('Sending SIGKILL to "{0}" pid {1}'.format(self.name, pid))
|
||||
os.killpg(pgid, signal.SIGKILL)
|
||||
time.sleep(0.1)
|
||||
os.killpg(pgid, signal.SIGKILL)
|
||||
except OSError as err:
|
||||
if errno.ESRCH == err.errno:
|
||||
break
|
||||
raise TimeoutError('Timeout waiting for "{0}" pid {1} to shutdown'.format(self.name, pid))
|
||||
time.sleep(0.1)
|
||||
self._shutdown = True
|
||||
|
||||
|
@ -820,7 +833,7 @@ class TestDaemonSaltSyndic(TestSaltDaemon):
|
|||
'''
|
||||
|
||||
configs = {
|
||||
'master':{},
|
||||
'master':{'map':{'syndic_master':'localhost',},},
|
||||
'minion':{'map':{'id':'{name}',},},
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue