Merge pull request #44491 from Ch3LL/ssh_raw

Add salt-ssh raw integration tests
This commit is contained in:
Nicole Thomas 2017-11-13 10:47:11 -05:00 committed by GitHub
commit 18624d6798
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 6 deletions

View file

@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# Import Python libs
from __future__ import absolute_import
# Import Salt Testing Libs
from tests.support.case import SSHCase
from tests.support.unit import skipIf
# Import Salt Libs
import salt.utils
@skipIf(salt.utils.is_windows(), 'salt-ssh not available on Windows')
class SSHRawTest(SSHCase):
'''
testing salt-ssh with raw calls
'''
def test_ssh_raw(self):
'''
test salt-ssh with -r argument
'''
msg = 'running raw msg'
ret = self.run_function('echo {0}'.format(msg), raw=True)
self.assertEqual(ret['stdout'], msg + '\n')

View file

@ -125,12 +125,13 @@ class ShellTestCase(TestCase, AdaptedConfigurationTestCaseMixin):
return self.run_script('salt', arg_str, with_retcode=with_retcode, catch_stderr=catch_stderr)
def run_ssh(self, arg_str, with_retcode=False, timeout=25,
catch_stderr=False, wipe=False):
catch_stderr=False, wipe=False, raw=False):
'''
Execute salt-ssh
'''
arg_str = '{0} -c {1} -i --priv {2} --roster-file {3} localhost {4} --out=json'.format(
arg_str = '{0} {1} -c {2} -i --priv {3} --roster-file {4} localhost {5} --out=json'.format(
' -W' if wipe else '',
' -r' if raw else '',
self.get_config_dir(),
os.path.join(RUNTIME_VARS.TMP_CONF_DIR, 'key_test'),
os.path.join(RUNTIME_VARS.TMP_CONF_DIR, 'roster'),
@ -456,12 +457,13 @@ class ShellCase(ShellTestCase, AdaptedConfigurationTestCaseMixin, ScriptPathMixi
timeout=timeout)
def run_ssh(self, arg_str, with_retcode=False, catch_stderr=False,
timeout=60, wipe=True): # pylint: disable=W0221
timeout=60, wipe=True, raw=False): # pylint: disable=W0221
'''
Execute salt-ssh
'''
arg_str = '-ldebug{0} -c {1} -i --priv {2} --roster-file {3} --out=json localhost {4}'.format(
arg_str = '{0} -ldebug{1} -c {2} -i --priv {3} --roster-file {4} --out=json localhost {5}'.format(
' -W' if wipe else '',
' -r' if raw else '',
self.get_config_dir(),
os.path.join(RUNTIME_VARS.TMP_CONF_DIR, 'key_test'),
os.path.join(RUNTIME_VARS.TMP_CONF_DIR, 'roster'),
@ -801,12 +803,12 @@ class SSHCase(ShellCase):
def _arg_str(self, function, arg):
return '{0} {1}'.format(function, ' '.join(arg))
def run_function(self, function, arg=(), timeout=90, wipe=True, **kwargs):
def run_function(self, function, arg=(), timeout=90, wipe=True, raw=False, **kwargs):
'''
We use a 90s timeout here, which some slower systems do end up needing
'''
ret = self.run_ssh(self._arg_str(function, arg), timeout=timeout,
wipe=wipe)
wipe=wipe, raw=raw)
try:
return json.loads(ret)['localhost']
except Exception: