mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Update tests which used string kwargs
This commit is contained in:
parent
36c928c53e
commit
9f6d08d606
6 changed files with 47 additions and 53 deletions
|
@ -1741,6 +1741,10 @@ class ModuleCase(TestCase, SaltClientTestCaseMixIn):
|
|||
know_to_return_none = (
|
||||
'file.chown', 'file.chgrp', 'ssh.recv_known_host'
|
||||
)
|
||||
if 'f_arg' in kwargs:
|
||||
kwargs['arg'] = kwargs.pop('f_arg')
|
||||
if 'f_timeout' in kwargs:
|
||||
kwargs['timeout'] = kwargs.pop('f_timeout')
|
||||
orig = self.client.cmd(
|
||||
minion_tgt, function, arg, timeout=timeout, kwarg=kwargs
|
||||
)
|
||||
|
|
|
@ -21,18 +21,14 @@ class StdTest(integration.ModuleCase):
|
|||
'''
|
||||
cmd_iter = self.client.cmd_cli(
|
||||
'minion',
|
||||
'test.kwarg',
|
||||
['foo=bar', 'baz=quo'],
|
||||
'test.arg',
|
||||
['foo', 'bar', 'baz'],
|
||||
kwarg={'qux': 'quux'}
|
||||
)
|
||||
for ret in cmd_iter:
|
||||
data = ret['minion']['ret']
|
||||
self.assertIn('foo', data)
|
||||
self.assertIn('baz', data)
|
||||
self.assertIn('qux', data)
|
||||
self.assertEqual(data['foo'], 'bar')
|
||||
self.assertEqual(data['baz'], 'quo')
|
||||
self.assertEqual(data['qux'], 'quux')
|
||||
self.assertEqual(data['args'], ['foo', 'bar', 'baz'])
|
||||
self.assertEqual(data['kwargs']['qux'], 'quux')
|
||||
|
||||
def test_iter(self):
|
||||
'''
|
||||
|
@ -40,18 +36,14 @@ class StdTest(integration.ModuleCase):
|
|||
'''
|
||||
cmd_iter = self.client.cmd_iter(
|
||||
'minion',
|
||||
'test.kwarg',
|
||||
['foo=bar', 'baz=quo'],
|
||||
'test.arg',
|
||||
['foo', 'bar', 'baz'],
|
||||
kwarg={'qux': 'quux'}
|
||||
)
|
||||
for ret in cmd_iter:
|
||||
data = ret['minion']['ret']
|
||||
self.assertIn('foo', data)
|
||||
self.assertIn('baz', data)
|
||||
self.assertIn('qux', data)
|
||||
self.assertEqual(data['foo'], 'bar')
|
||||
self.assertEqual(data['baz'], 'quo')
|
||||
self.assertEqual(data['qux'], 'quux')
|
||||
self.assertEqual(data['args'], ['foo', 'bar', 'baz'])
|
||||
self.assertEqual(data['kwargs']['qux'], 'quux')
|
||||
|
||||
def test_iter_no_block(self):
|
||||
'''
|
||||
|
@ -59,20 +51,16 @@ class StdTest(integration.ModuleCase):
|
|||
'''
|
||||
cmd_iter = self.client.cmd_iter_no_block(
|
||||
'minion',
|
||||
'test.kwarg',
|
||||
['foo=bar', 'baz=quo'],
|
||||
'test.arg',
|
||||
['foo', 'bar', 'baz'],
|
||||
kwarg={'qux': 'quux'}
|
||||
)
|
||||
for ret in cmd_iter:
|
||||
if ret is None:
|
||||
continue
|
||||
data = ret['minion']['ret']
|
||||
self.assertIn('foo', data)
|
||||
self.assertIn('baz', data)
|
||||
self.assertIn('qux', data)
|
||||
self.assertEqual(data['foo'], 'bar')
|
||||
self.assertEqual(data['baz'], 'quo')
|
||||
self.assertEqual(data['qux'], 'quux')
|
||||
self.assertEqual(data['args'], ['foo', 'bar', 'baz'])
|
||||
self.assertEqual(data['kwargs']['qux'], 'quux')
|
||||
|
||||
def test_full_returns(self):
|
||||
'''
|
||||
|
@ -80,17 +68,13 @@ class StdTest(integration.ModuleCase):
|
|||
'''
|
||||
ret = self.client.cmd_full_return(
|
||||
'minion',
|
||||
'test.kwarg',
|
||||
['foo=bar', 'baz=quo'],
|
||||
'test.arg',
|
||||
['foo', 'bar', 'baz'],
|
||||
kwarg={'qux': 'quux'}
|
||||
)
|
||||
data = ret['minion']
|
||||
self.assertIn('foo', data['ret'])
|
||||
self.assertIn('baz', data['ret'])
|
||||
self.assertIn('qux', data['ret'])
|
||||
self.assertEqual(data['ret']['foo'], 'bar')
|
||||
self.assertEqual(data['ret']['baz'], 'quo')
|
||||
self.assertEqual(data['ret']['qux'], 'quux')
|
||||
data = ret['minion']['ret']
|
||||
self.assertEqual(data['args'], ['foo', 'bar', 'baz'])
|
||||
self.assertEqual(data['kwargs']['qux'], 'quux')
|
||||
|
||||
def test_kwarg_type(self):
|
||||
'''
|
||||
|
|
|
@ -262,19 +262,21 @@ class CMDModuleTest(integration.ModuleCase):
|
|||
'''
|
||||
cmd.run trigger timeout
|
||||
'''
|
||||
out = self.run_function('cmd.run', ['sleep 2 && echo hello', 'timeout=1'])
|
||||
|
||||
self.assertTrue(
|
||||
'Timed out' in self.run_function(
|
||||
'cmd.run', ['sleep 2 && echo hello', 'timeout=1'], python_shell=True))
|
||||
out = self.run_function('cmd.run',
|
||||
['sleep 2 && echo hello'],
|
||||
f_timeout=1,
|
||||
python_shell=True)
|
||||
self.assertTrue('Timed out' in out)
|
||||
|
||||
def test_timeout_success(self):
|
||||
'''
|
||||
cmd.run sufficient timeout to succeed
|
||||
'''
|
||||
self.assertTrue(
|
||||
'hello' == self.run_function(
|
||||
'cmd.run', ['sleep 1 && echo hello', 'timeout=2'], python_shell=True))
|
||||
out = self.run_function('cmd.run',
|
||||
['sleep 1 && echo hello'],
|
||||
f_timeout=2,
|
||||
python_shell=True)
|
||||
self.assertEqual(out, 'hello')
|
||||
|
||||
def test_run_cwd_doesnt_exist_issue_7154(self):
|
||||
'''
|
||||
|
|
|
@ -106,11 +106,8 @@ class CPModuleTest(integration.ModuleCase):
|
|||
tgt = os.path.join(integration.TMP, 'scene33')
|
||||
self.run_function(
|
||||
'cp.get_template',
|
||||
[
|
||||
'salt://grail/scene33',
|
||||
tgt,
|
||||
'spam=bacon',
|
||||
])
|
||||
['salt://grail/scene33', tgt],
|
||||
spam='bacon')
|
||||
with salt.utils.fopen(tgt, 'r') as scene:
|
||||
data = scene.read()
|
||||
self.assertIn('bacon', data)
|
||||
|
|
|
@ -25,7 +25,8 @@ class PublishModuleTest(integration.ModuleCase,
|
|||
|
||||
ret = self.run_function(
|
||||
'publish.publish',
|
||||
['minion', 'test.kwarg', 'arg="cheese=spam"']
|
||||
['minion', 'test.kwarg'],
|
||||
f_arg='cheese=spam'
|
||||
)
|
||||
ret = ret['minion']
|
||||
|
||||
|
@ -45,7 +46,7 @@ class PublishModuleTest(integration.ModuleCase,
|
|||
self.assertTrue(name in ret)
|
||||
|
||||
self.assertEqual(ret['cheese'], 'spam')
|
||||
self.assertEqual(ret['__pub_arg'], ['cheese=spam'])
|
||||
self.assertEqual(ret['__pub_arg'], [{'cheese': 'spam'}])
|
||||
self.assertEqual(ret['__pub_id'], 'minion')
|
||||
self.assertEqual(ret['__pub_fun'], 'test.kwarg')
|
||||
|
||||
|
@ -99,7 +100,8 @@ class PublishModuleTest(integration.ModuleCase,
|
|||
'''
|
||||
ret = self.run_function(
|
||||
'publish.full_data',
|
||||
['minion', 'test.kwarg', 'arg="cheese=spam"']
|
||||
['minion', 'test.kwarg'],
|
||||
f_arg='cheese=spam'
|
||||
)
|
||||
ret = ret['minion']['ret']
|
||||
|
||||
|
@ -119,13 +121,14 @@ class PublishModuleTest(integration.ModuleCase,
|
|||
self.assertTrue(name in ret)
|
||||
|
||||
self.assertEqual(ret['cheese'], 'spam')
|
||||
self.assertEqual(ret['__pub_arg'], ['cheese=spam'])
|
||||
self.assertEqual(ret['__pub_arg'], [{'cheese': 'spam'}])
|
||||
self.assertEqual(ret['__pub_id'], 'minion')
|
||||
self.assertEqual(ret['__pub_fun'], 'test.kwarg')
|
||||
|
||||
ret = self.run_function(
|
||||
'publish.full_data',
|
||||
['minion', 'test.kwarg', 'cheese=spam']
|
||||
['minion', 'test.kwarg'],
|
||||
cheese='spam'
|
||||
)
|
||||
self.assertIn(
|
||||
'The following keyword arguments are not valid', ret
|
||||
|
|
|
@ -13,6 +13,7 @@ ensure_in_syspath('../../')
|
|||
|
||||
# Import Salt libs
|
||||
import integration
|
||||
import salt.utils.args
|
||||
|
||||
|
||||
@requires_salt_modules('test.ping', 'test.arg')
|
||||
|
@ -25,7 +26,7 @@ class ArgumentTestCase(integration.ModuleCase):
|
|||
'''
|
||||
self.assertIn(
|
||||
("ERROR executing 'test.ping': The following keyword arguments"),
|
||||
self.run_function('test.ping', ['foo=bar'])
|
||||
self.run_function('test.ping', foo='bar')
|
||||
)
|
||||
|
||||
def test_kwarg_name_containing_dashes(self):
|
||||
|
@ -34,9 +35,12 @@ class ArgumentTestCase(integration.ModuleCase):
|
|||
are properly identified as kwargs. If this fails, then the KWARG_REGEX
|
||||
variable in salt/utils/__init__.py needs to be fixed.
|
||||
'''
|
||||
# We need to use parse_input here because run_function now requires
|
||||
# kwargs to be passed in as *actual* kwargs, and dashes are not valid
|
||||
# characters in Python kwargs.
|
||||
self.assertEqual(
|
||||
self.run_function(
|
||||
'test.arg', ['foo-bar=baz']
|
||||
'test.arg', salt.utils.args.parse_input(['foo-bar=baz'])
|
||||
).get('kwargs', {}).get('foo-bar'),
|
||||
'baz'
|
||||
)
|
||||
|
|
Loading…
Add table
Reference in a new issue