mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 08:58:59 +00:00
Add cmd module integration tests for windows and fix space in path issue
This commit is contained in:
parent
05f2d65de3
commit
9312a993a5
@ -2127,7 +2127,10 @@ def script(source,
|
||||
os.chmod(path, 320)
|
||||
os.chown(path, __salt__['file.user_to_uid'](runas), -1)
|
||||
|
||||
path = _cmd_quote(path)
|
||||
if salt.utils.is_windows() and shell != 'powershell':
|
||||
path = _cmd_quote(path, escape=False)
|
||||
else:
|
||||
path = _cmd_quote(path)
|
||||
|
||||
ret = _run(path + ' ' + str(args) if args else path,
|
||||
cwd=cwd,
|
||||
|
@ -166,7 +166,7 @@ def get_sam_name(username):
|
||||
return '\\'.join([domain, username])
|
||||
|
||||
|
||||
def escape_argument(arg):
|
||||
def escape_argument(arg, escape=True):
|
||||
'''
|
||||
Escape the argument for the cmd.exe shell.
|
||||
See http://blogs.msdn.com/b/twistylittlepassagesallalike/archive/2011/04/23/everyone-quotes-arguments-the-wrong-way.aspx
|
||||
@ -183,6 +183,8 @@ def escape_argument(arg):
|
||||
if not arg or re.search(r'(["\s])', arg):
|
||||
arg = '"' + arg.replace('"', r'\"') + '"'
|
||||
|
||||
if not escape:
|
||||
return arg
|
||||
return escape_for_cmd_exe(arg)
|
||||
|
||||
|
||||
|
@ -9,6 +9,7 @@ import textwrap
|
||||
|
||||
# Import Salt Testing libs
|
||||
from tests.support.case import ModuleCase
|
||||
from tests.support.unit import skipIf
|
||||
from tests.support.helpers import (
|
||||
destructiveTest,
|
||||
skip_if_binaries_missing,
|
||||
@ -71,7 +72,7 @@ class CMDModuleTest(ModuleCase):
|
||||
'''
|
||||
self.assertEqual(self.run_function('cmd.run_stdout',
|
||||
['echo "cheese"']).rstrip(),
|
||||
'cheese')
|
||||
'cheese' if not salt.utils.is_windows() else '"cheese"')
|
||||
|
||||
def test_stderr(self):
|
||||
'''
|
||||
@ -86,7 +87,7 @@ class CMDModuleTest(ModuleCase):
|
||||
['echo "cheese" 1>&2',
|
||||
'shell={0}'.format(shell)], python_shell=True
|
||||
).rstrip(),
|
||||
'cheese')
|
||||
'cheese' if not salt.utils.is_windows() else '"cheese"')
|
||||
|
||||
def test_run_all(self):
|
||||
'''
|
||||
@ -107,7 +108,7 @@ class CMDModuleTest(ModuleCase):
|
||||
self.assertTrue(isinstance(ret.get('retcode'), int))
|
||||
self.assertTrue(isinstance(ret.get('stdout'), six.string_types))
|
||||
self.assertTrue(isinstance(ret.get('stderr'), six.string_types))
|
||||
self.assertEqual(ret.get('stderr').rstrip(), 'cheese')
|
||||
self.assertEqual(ret.get('stderr').rstrip(), 'cheese' if not salt.utils.is_windows() else '"cheese"')
|
||||
|
||||
def test_retcode(self):
|
||||
'''
|
||||
@ -217,10 +218,13 @@ class CMDModuleTest(ModuleCase):
|
||||
'''
|
||||
cmd = '''echo 'SELECT * FROM foo WHERE bar="baz"' '''
|
||||
expected_result = 'SELECT * FROM foo WHERE bar="baz"'
|
||||
if salt.utils.is_windows():
|
||||
expected_result = '\'SELECT * FROM foo WHERE bar="baz"\''
|
||||
result = self.run_function('cmd.run_stdout', [cmd]).strip()
|
||||
self.assertEqual(result, expected_result)
|
||||
|
||||
@skip_if_not_root
|
||||
@skipIf(salt.utils.is_windows, 'skip windows, requires password')
|
||||
def test_quotes_runas(self):
|
||||
'''
|
||||
cmd.run with quoted command
|
||||
@ -234,6 +238,7 @@ class CMDModuleTest(ModuleCase):
|
||||
runas=runas).strip()
|
||||
self.assertEqual(result, expected_result)
|
||||
|
||||
@skipIf(not salt.utils.which_bin('sleep'), 'sleep cmd not installed')
|
||||
def test_timeout(self):
|
||||
'''
|
||||
cmd.run trigger timeout
|
||||
@ -244,6 +249,7 @@ class CMDModuleTest(ModuleCase):
|
||||
python_shell=True)
|
||||
self.assertTrue('Timed out' in out)
|
||||
|
||||
@skipIf(not salt.utils.which_bin('sleep'), 'sleep cmd not installed')
|
||||
def test_timeout_success(self):
|
||||
'''
|
||||
cmd.run sufficient timeout to succeed
|
||||
|
@ -8,6 +8,7 @@ integration.modules.test_autoruns
|
||||
integration.modules.test_beacons
|
||||
integration.modules.test_config
|
||||
integration.modules.test_cp
|
||||
integration.modules.test_cmdmod
|
||||
integration.modules.test_data
|
||||
integration.modules.test_disk
|
||||
integration.modules.test_firewall
|
||||
|
Loading…
Reference in New Issue
Block a user