def test_exit_status_unknown_argument(self): ''' Ensure correct exit status when an unknown argument is passed to salt-minion. ''' minion = testprogram.TestDaemonSaltMinion( name='unknown_argument', parent_dir=self._test_dir, ) # Call setup here to ensure config and script exist minion.setup() stdout, stderr, status = minion.run( args=['-d', '--unknown-argument'], catch_stderr=True, with_retcode=True, ) self.assert_exit_status( status, 'EX_USAGE', message='unknown argument', stdout=stdout, stderr=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 minion.shutdown()
def test_exit_status_unknown_user(self): ''' Ensure correct exit status when the minion is configured to run as an unknown user. ''' minion = testprogram.TestDaemonSaltMinion( name='unknown_user', configs={'minion': { 'map': { 'user': '******' } }}, parent_dir=self._test_dir, ) # Call setup here to ensure config and script exist minion.setup() stdout, stderr, status = minion.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=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 minion.shutdown()
def test_exit_status_unknown_user(self): ''' Ensure correct exit status when the minion is configured to run as an unknown user. ''' minion = testprogram.TestDaemonSaltMinion( name='unknown_user', configs={'minion': { 'map': { 'user': '******' } }}, parent_dir=self._test_dir, ) # Call setup here to ensure config and script exist minion.setup() stdout, stderr, status = minion.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=integration.utils.decode_byte_list(stderr))
def _initscript_setup(self, minions): '''Re-usable setup for running salt-minion tests''' user = getpass.getuser() _minions = [] for mname in minions: minion = testprogram.TestDaemonSaltMinion( name=mname, config={'user': user}, parent_dir=self._test_dir, ) # Call setup here to ensure config and script exist minion.setup() _minions.append(minion) # Need salt-call, salt-minion for wrapper script salt_call = testprogram.TestProgramSaltCall(parent_dir=self._test_dir) # Ensure that run-time files are generated salt_call.setup() sysconf_dir = os.path.dirname(_minions[0].config_dir) cmd_env = { 'PATH': ':'.join([salt_call.script_dir, os.getenv('PATH')]), 'PYTHONPATH': ':'.join(sys.path), 'SALTMINION_DEBUG': '1' if DEBUG else '', 'SALTMINION_PYTHON': sys.executable, 'SALTMINION_SYSCONFDIR': sysconf_dir, 'SALTMINION_BINDIR': _minions[0].script_dir, 'SALTMINION_CONFIGS': '\n'.join([ '{0} {1}'.format(user, minion.config_dir) for minion in _minions ]), } default_dir = os.path.join(sysconf_dir, 'default') if not os.path.exists(default_dir): os.makedirs(default_dir) with open(os.path.join(default_dir, 'salt'), 'w') as defaults: # Test suites is quite slow - extend the timeout defaults.write('TIMEOUT=60\n' 'TICK=1\n') init_script = testprogram.TestProgram( name='init:salt-minion', program=os.path.join(integration.CODE_DIR, 'pkg', 'rpm', 'salt-minion'), env=cmd_env, ) return _minions, salt_call, init_script
def _initscript_setup(self, minions): '''Re-usable setup for running salt-minion tests''' _minions = [] for mname in minions: pid_file = 'salt-{0}.pid'.format(mname) minion = testprogram.TestDaemonSaltMinion( name=mname, root_dir='init_script', config_dir=os.path.join('etc', mname), parent_dir=self._test_dir, pid_file=pid_file, configs={ 'minion': { 'map': { 'pidfile': os.path.join('var', 'run', pid_file), 'sock_dir': os.path.join('var', 'run', 'salt', mname), 'log_file': os.path.join('var', 'log', 'salt', mname), }, }, }, ) # Call setup here to ensure config and script exist minion.setup() _minions.append(minion) # Need salt-call, salt-minion for wrapper script salt_call = testprogram.TestProgramSaltCall(root_dir='init_script', parent_dir=self._test_dir) # Ensure that run-time files are generated salt_call.setup() sysconf_dir = os.path.dirname(_minions[0].abs_path(_minions[0].config_dir)) cmd_env = { 'PATH': ':'.join([salt_call.abs_path(salt_call.script_dir), os.getenv('PATH')]), 'SALTMINION_DEBUG': '1' if DEBUG else '', 'SALTMINION_PYTHON': sys.executable, 'SALTMINION_SYSCONFDIR': sysconf_dir, 'SALTMINION_BINDIR': _minions[0].abs_path(_minions[0].script_dir), } default_dir = os.path.join(sysconf_dir, 'default') if not os.path.exists(default_dir): os.makedirs(default_dir) with open(os.path.join(default_dir, 'salt'), 'w') as defaults: # Test suites is quite slow - extend the timeout defaults.write( 'TIMEOUT=60\n' 'TICK=1\n' ) init_script = testprogram.TestProgram( name='init:salt-minion', program=os.path.join(integration.CODE_DIR, 'pkg', 'rpm', 'salt-minion'), env=cmd_env, ) return _minions, salt_call, init_script
def test_exit_status_unknown_argument(self): ''' Ensure correct exit status when an unknown argument is passed to salt-minion. ''' minion = testprogram.TestDaemonSaltMinion( name='unknown_argument', parent_dir=self._test_dir, ) # Call setup here to ensure config and script exist minion.setup() stdout, stderr, status = minion.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 )
def test_exit_status_correct_usage(self): ''' Ensure correct exit status when salt-minion starts correctly. ''' minion = testprogram.TestDaemonSaltMinion( name='correct_usage', parent_dir=self._test_dir, ) # Call setup here to ensure config and script exist minion.setup() stdout, stderr, status = minion.run( args=['-d'], catch_stderr=True, with_retcode=True, ) self.assert_exit_status( status, 'EX_OK', message='correct usage', stdout=stdout, stderr=stderr ) minion.shutdown()