Merge pull request #12263 from s0undt3ch/issues/12261-too-many-args-to-docs

Fail soon on too many args to docs
This commit is contained in:
Joseph Hall 2014-04-25 07:03:39 -06:00
commit f971ec3af3
5 changed files with 40 additions and 13 deletions

View File

@ -1626,7 +1626,8 @@ class SaltCMDOptionParser(OptionParser, ConfigDirMixIn, MergeConfigMixIn,
self.args.insert(1, 'sys.doc')
if self.args[1] != 'sys.doc':
self.args.insert(1, 'sys.doc')
self.args[2] = self.args[2]
if len(self.args) > 3:
self.error('You can only get documentation for one method at one time.')
if self.options.list:
try:
@ -2043,8 +2044,7 @@ class SaltCallOptionParser(OptionParser, ConfigDirMixIn, MergeConfigMixIn,
)
def _mixin_after_parsed(self):
if not self.args and not self.options.grains_run \
and not self.options.doc:
if not self.args and not self.options.grains_run and not self.options.doc:
self.print_help()
self.exit(1)
@ -2052,6 +2052,9 @@ class SaltCallOptionParser(OptionParser, ConfigDirMixIn, MergeConfigMixIn,
if self.options.grains_run:
self.error('-g/--grains does not accept any arguments')
if self.options.doc and len(self.args) > 1:
self.error('You can only get documentation for one method at one time')
self.config['fun'] = self.args[0]
self.config['arg'] = self.args[1:]
@ -2116,6 +2119,9 @@ class SaltRunOptionParser(OptionParser, ConfigDirMixIn, MergeConfigMixIn,
)
def _mixin_after_parsed(self):
if self.options.doc and len(self.args) > 1:
self.error('You can only get documentation for one method at one time')
if len(self.args) > 0:
self.config['fun'] = self.args[0]
else:

View File

@ -878,28 +878,28 @@ class ShellCase(AdaptedConfigurationTestCaseMixIn, ShellTestCase):
_script_dir_ = SCRIPT_DIR
_python_executable_ = PYEXEC
def run_salt(self, arg_str, with_retcode=False):
def run_salt(self, arg_str, with_retcode=False, catch_stderr=False):
'''
Execute salt
'''
arg_str = '-c {0} {1}'.format(self.get_config_dir(), arg_str)
return self.run_script('salt', arg_str, with_retcode=with_retcode)
return self.run_script('salt', arg_str, with_retcode=with_retcode, catch_stderr=catch_stderr)
def run_run(self, arg_str, with_retcode=False):
def run_run(self, arg_str, with_retcode=False, catch_stderr=False):
'''
Execute salt-run
'''
arg_str = '-c {0} {1}'.format(self.get_config_dir(), arg_str)
return self.run_script('salt-run', arg_str, with_retcode=with_retcode)
return self.run_script('salt-run', arg_str, with_retcode=with_retcode, catch_stderr=catch_stderr)
def run_run_plus(self, fun, options='', *arg):
def run_run_plus(self, fun, options='', catch_stderr=False, *arg):
'''
Execute Salt run and the salt run function and return the data from
each in a dict
'''
ret = {}
ret['out'] = self.run_run(
'{0} {1} {2}'.format(options, fun, ' '.join(arg))
'{0} {1} {2}'.format(options, fun, ' '.join(arg)), catch_stderr=catch_stderr
)
opts = salt.config.master_config(
self.get_config_file_path('master')
@ -922,16 +922,16 @@ class ShellCase(AdaptedConfigurationTestCaseMixIn, ShellTestCase):
with_retcode=with_retcode
)
def run_cp(self, arg_str, with_retcode=False):
def run_cp(self, arg_str, with_retcode=False, catch_stderr=False):
'''
Execute salt-cp
'''
arg_str = '--config-dir {0} {1}'.format(self.get_config_dir(), arg_str)
return self.run_script('salt-cp', arg_str, with_retcode=with_retcode)
return self.run_script('salt-cp', arg_str, with_retcode=with_retcode, catch_stderr=catch_stderr)
def run_call(self, arg_str, with_retcode=False):
def run_call(self, arg_str, with_retcode=False, catch_stderr=False):
arg_str = '--config-dir {0} {1}'.format(self.get_config_dir(), arg_str)
return self.run_script('salt-call', arg_str, with_retcode=with_retcode)
return self.run_script('salt-call', arg_str, with_retcode=with_retcode, catch_stderr=catch_stderr)
def run_cloud(self, arg_str, catch_stderr=False, timeout=None):
'''

View File

@ -58,6 +58,13 @@ class CallTest(integration.ShellCase, integration.ShellCaseCommonTestsMixIn):
''.join(ret)
)
def test_salt_documentation_too_many_arguments(self):
'''
Test to see if passing additional arguments shows an error
'''
data = self.run_call('-d virtualenv.create /tmp/ve', catch_stderr=True)
self.assertIn('You can only get documentation for one method at one time', '\n'.join(data[1]))
def test_issue_6973_state_highstate_exit_code(self):
'''
If there is no tops/master_tops or state file matches

View File

@ -219,6 +219,13 @@ class MatchTest(integration.ShellCase, integration.ShellCaseCommonTestsMixIn):
data = self.run_salt('\'*\' sys.doc user')
self.assertIn('user.add:', data)
def test_salt_documentation_too_many_arguments(self):
'''
Test to see if passing additional arguments shows an error
'''
data = self.run_salt('-d minion salt ldap.search "filter=ou=People"', catch_stderr=True)
self.assertIn('You can only get documentation for one method at one time', '\n'.join(data[1]))
def test_issue_7754(self):
old_cwd = os.getcwd()
config_dir = os.path.join(integration.TMP, 'issue-7754')

View File

@ -46,6 +46,13 @@ class RunTest(integration.ShellCase, integration.ShellCaseCommonTestsMixIn):
data = '\n'.join(data)
self.assertNotIn('jobs.SaltException:', data)
def test_salt_documentation_too_many_arguments(self):
'''
Test to see if passing additional arguments shows an error
'''
data = self.run_run('-d virt.list foo', catch_stderr=True)
self.assertIn('You can only get documentation for one method at one time', '\n'.join(data[1]))
def test_issue_7754(self):
old_cwd = os.getcwd()
config_dir = os.path.join(integration.TMP, 'issue-7754')