Merge pull request #46248 from garethgreenaway/45325_display_usage_for_runners

[develop] display usage for runners when missing arguments
This commit is contained in:
Nicole Thomas 2018-03-01 14:44:18 -05:00 committed by GitHub
commit 4df31ac297
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 1 deletions

View File

@ -384,7 +384,11 @@ class SyncClientMixin(object):
# Initialize a context for executing the method.
with tornado.stack_context.StackContext(self.functions.context_dict.clone):
data['return'] = self.functions[fun](*args, **kwargs)
func = self.functions[fun]
try:
data['return'] = func(*args, **kwargs)
except TypeError as exc:
data['return'] = '\nPassed invalid arguments: {0}\n\nUsage:\n{1}'.format(exc, func.__doc__)
try:
data['success'] = self.context.get('retcode', 0) == 0
except AttributeError:

View File

@ -34,3 +34,15 @@ class ManageTest(ShellCase):
ret = self.run_run_plus('cache.flush', bank='cachetest/runner', key='test_cache')
ret = self.run_run_plus('cache.list', bank='cachetest/runner')
self.assertNotIn('test_cache', ret['return'])
def test_cache_invalid(self):
'''
Store, list, fetch, then flush data
'''
# Store the data
ret = self.run_run_plus(
'cache.store',
)
# Make sure we can see the new key
expected = 'Passed invalid arguments:'
self.assertIn(expected, ret['return'])

View File

@ -30,6 +30,14 @@ class ManageTest(ShellCase):
self.assertEqual(ret['return'], {})
self.assertEqual(ret['out'], [])
def test_lookup_jid_invalid(self):
'''
jobs.lookup_jid
'''
ret = self.run_run_plus('jobs.lookup_jid')
expected = 'Passed invalid arguments:'
self.assertIn(expected, ret['return'])
@skipIf(True, 'to be re-enabled when #23623 is merged')
def test_list_jobs(self):
'''

View File

@ -25,3 +25,11 @@ class SaltRunnerTest(ShellCase):
self.assertEqual(out_ret, 'True')
self.assertTrue(return_ret)
def test_salt_cmd_invalid(self):
'''
test return values of salt.cmd invalid parameters
'''
ret = self.run_run_plus('salt.cmd')
expected = 'Passed invalid arguments:'
self.assertIn(expected, ret['return'])