Add with_retcode option to ShellCase.run_call(). Also adds a test case for https://github.com/saltstack/salt/issues/6973 - expect a non-zero exit code when running "salt-call --retcode-passthrough state.highstate"

This commit is contained in:
David Anderson 2013-09-13 10:12:11 -06:00
parent 03e1d7f021
commit 1d7309970f
2 changed files with 26 additions and 2 deletions

View file

@ -752,9 +752,9 @@ class ShellCase(AdaptedConfigurationTestCaseMixIn, ShellTestCase):
arg_str = '--config-dir {0} {1}'.format(self.get_config_dir(), arg_str)
return self.run_script('salt-cp', arg_str)
def run_call(self, arg_str):
def run_call(self, arg_str, with_retcode=False):
arg_str = '--config-dir {0} {1}'.format(self.get_config_dir(), arg_str)
return self.run_script('salt-call', arg_str)
return self.run_script('salt-call', arg_str, with_retcode=with_retcode)
class ShellCaseCommonTestsMixIn(CheckShellBinaryNameAndVersionMixIn):

View file

@ -11,6 +11,7 @@
# Import python libs
import os
import sys
import shutil
import yaml
from datetime import datetime
@ -55,6 +56,29 @@ class CallTest(integration.ShellCase, integration.ShellCaseCommonTestsMixIn):
''.join(ret)
)
def test_issue_6973_state_highstate_exit_code(self):
'''
If there is no tops/master_tops or state file matches
for this minion, salt-call should exit non-zero if invoked with
option --retcode-passthrough
'''
src = os.path.join(integration.FILES, 'file/base/top.sls')
dst = os.path.join(integration.FILES, 'file/base/top.sls.bak')
shutil.move(src, dst)
expected_tag = 'no_|-states_|-states_|-None'
expected_comment = 'No Top file or external nodes data matches found'
try:
stdout, retcode = self.run_call(
'-l quiet --retcode-passthrough state.highstate',
with_retcode=True
)
finally:
pass
shutil.move(dst, src)
self.assertIn(expected_tag, ''.join(stdout))
self.assertIn(expected_comment, ''.join(stdout))
self.assertNotEqual(0, retcode)
@skipIf(sys.platform.startswith('win'), 'This test does not apply on Win')
def test_issue_2731_masterless(self):
config_dir = '/tmp/salttest'