diff options
| author | Eduardo Santos <eduardo.experimental@gmail.com> | 2020-10-23 14:17:23 +0000 |
|---|---|---|
| committer | Eduardo Santos <eduardo.experimental@gmail.com> | 2020-10-29 15:09:26 +0000 |
| commit | d92f15a09e59942bb60b7ef3a81c1e21dc16b578 (patch) | |
| tree | c641dfde710cdf18d5137383f18508cb6c55a6d5 | |
| parent | 1e7c24a9c4c8547e4ee3c92f4cb044a4405a5b7c (diff) | |
| download | python-cinderclient-d92f15a09e59942bb60b7ef3a81c1e21dc16b578.tar.gz | |
Fix undesirable raw Python error
Using the cinderclient without a subcommand while
passing an optional argument triggers the raw Python
error `ERROR: 'Namespace' object has no attribute
'func'`. This bug can be reproduced by issuing the
command `cinder --os-volume-api-version 3.40`.
Added a default value to `func` and an empty value to
`command` as placeholders so that a help message is
shown instead of the Python error.
Change-Id: Idb51e8635b97f0da2976f3268d5e19100ec77203
Closes-Bug: #1867061
| -rw-r--r-- | cinderclient/shell.py | 3 | ||||
| -rw-r--r-- | cinderclient/tests/unit/test_shell.py | 12 | ||||
| -rw-r--r-- | releasenotes/notes/bug-1867061-fix-py-raw-error-msg-ff3c6da0b01d5d6c.yaml | 7 |
3 files changed, 22 insertions, 0 deletions
diff --git a/cinderclient/shell.py b/cinderclient/shell.py index cfd4e82..ff8c4c4 100644 --- a/cinderclient/shell.py +++ b/cinderclient/shell.py @@ -225,6 +225,9 @@ class OpenStackCinderShell(object): default=0, help=_('Number of retries.')) + parser.set_defaults(func=self.do_help) + parser.set_defaults(command='') + if osprofiler_profiler: parser.add_argument('--profile', metavar='HMAC_KEY', diff --git a/cinderclient/tests/unit/test_shell.py b/cinderclient/tests/unit/test_shell.py index ac7404c..c8a6375 100644 --- a/cinderclient/tests/unit/test_shell.py +++ b/cinderclient/tests/unit/test_shell.py @@ -148,6 +148,18 @@ class ShellTest(utils.TestCase): self.assertThat(help_text, matchers.MatchesRegex(r, re.DOTALL | re.MULTILINE)) + def test_help_arg_no_subcommand(self): + required = [ + r'.*?^usage: ', + r'.*?(?m)^\s+create\s+Creates a volume.', + r'.*?(?m)^\s+summary\s+Get volumes summary.', + r'.*?(?m)^Run "cinder help SUBCOMMAND" for help on a subcommand.', + ] + help_text = self.shell('--os-volume-api-version 3.40') + for r in required: + self.assertThat(help_text, + matchers.MatchesRegex(r, re.DOTALL | re.MULTILINE)) + @ddt.data('backup-create --help', '--help backup-create') def test_dash_dash_help_on_subcommand(self, cmd): required = ['.*?^Creates a volume backup.'] diff --git a/releasenotes/notes/bug-1867061-fix-py-raw-error-msg-ff3c6da0b01d5d6c.yaml b/releasenotes/notes/bug-1867061-fix-py-raw-error-msg-ff3c6da0b01d5d6c.yaml new file mode 100644 index 0000000..91d026b --- /dev/null +++ b/releasenotes/notes/bug-1867061-fix-py-raw-error-msg-ff3c6da0b01d5d6c.yaml @@ -0,0 +1,7 @@ +--- +fixes: + - | + `Bug #1867061 <https://bugs.launchpad.net/python-cinderclient/+bug/1867061>`_: + Fixed raw Python error message when using ``cinder`` without + a subcommand while passing an optional argument, such as + ``--os-volume-api-version``.
\ No newline at end of file |
