From 5b790dbb7980cc1440cd8aeb59883853d387aacf Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Thu, 24 Apr 2014 15:42:17 +0100 Subject: [PATCH 1/5] Allow getting `stderr` from the commands. --- tests/integration/__init__.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/integration/__init__.py b/tests/integration/__init__.py index 5e283e57d8..f28f6ea20d 100644 --- a/tests/integration/__init__.py +++ b/tests/integration/__init__.py @@ -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): ''' From 762d0b1e248da29f67b97832c818a5a89ad7190e Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Thu, 24 Apr 2014 15:42:47 +0100 Subject: [PATCH 2/5] Check for extra arguments to '--doc' and fail. Fixes #12261. --- salt/utils/parsers.py | 3 ++- tests/integration/shell/matcher.py | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/salt/utils/parsers.py b/salt/utils/parsers.py index c3e82c30af..e6109585f6 100644 --- a/salt/utils/parsers.py +++ b/salt/utils/parsers.py @@ -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: diff --git a/tests/integration/shell/matcher.py b/tests/integration/shell/matcher.py index 27d8cb4e09..0bb7696f4d 100644 --- a/tests/integration/shell/matcher.py +++ b/tests/integration/shell/matcher.py @@ -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') From f3fa2aef74d67c0c7ed442e0d4fb4b1f62a46617 Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Thu, 24 Apr 2014 15:56:58 +0100 Subject: [PATCH 3/5] Handle too many arguments for docs in salt-call. Refs #12261. --- salt/utils/parsers.py | 6 ++++-- tests/integration/shell/call.py | 7 +++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/salt/utils/parsers.py b/salt/utils/parsers.py index e6109585f6..f30f673673 100644 --- a/salt/utils/parsers.py +++ b/salt/utils/parsers.py @@ -2044,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) @@ -2053,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:] diff --git a/tests/integration/shell/call.py b/tests/integration/shell/call.py index 65dc54d76b..36ef03c3e3 100644 --- a/tests/integration/shell/call.py +++ b/tests/integration/shell/call.py @@ -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 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_6973_state_highstate_exit_code(self): ''' If there is no tops/master_tops or state file matches From b969cd15f7649d209449ba16b58c1d79391e9e38 Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Thu, 24 Apr 2014 16:01:25 +0100 Subject: [PATCH 4/5] Handle too many arguments for docs in salt-run. Refs #12261. --- salt/utils/parsers.py | 3 +++ tests/integration/shell/runner.py | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/salt/utils/parsers.py b/salt/utils/parsers.py index f30f673673..5992b90bec 100644 --- a/salt/utils/parsers.py +++ b/salt/utils/parsers.py @@ -2119,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: diff --git a/tests/integration/shell/runner.py b/tests/integration/shell/runner.py index 30346460d3..5ed2dff63b 100644 --- a/tests/integration/shell/runner.py +++ b/tests/integration/shell/runner.py @@ -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 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') From 13106807b1f7963891d503ebd83d53af56482398 Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Thu, 24 Apr 2014 16:04:51 +0100 Subject: [PATCH 5/5] Better examples on tests --- tests/integration/shell/call.py | 2 +- tests/integration/shell/runner.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration/shell/call.py b/tests/integration/shell/call.py index 36ef03c3e3..7775aad673 100644 --- a/tests/integration/shell/call.py +++ b/tests/integration/shell/call.py @@ -62,7 +62,7 @@ class CallTest(integration.ShellCase, integration.ShellCaseCommonTestsMixIn): ''' Test to see if passing additional arguments shows an error ''' - data = self.run_call('-d salt ldap.search "filter=ou=People"', catch_stderr=True) + 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): diff --git a/tests/integration/shell/runner.py b/tests/integration/shell/runner.py index 5ed2dff63b..56df29d86a 100644 --- a/tests/integration/shell/runner.py +++ b/tests/integration/shell/runner.py @@ -50,7 +50,7 @@ class RunTest(integration.ShellCase, integration.ShellCaseCommonTestsMixIn): ''' Test to see if passing additional arguments shows an error ''' - data = self.run_run('-d salt ldap.search "filter=ou=People"', catch_stderr=True) + 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):