From d92f15a09e59942bb60b7ef3a81c1e21dc16b578 Mon Sep 17 00:00:00 2001 From: Eduardo Santos Date: Fri, 23 Oct 2020 14:17:23 +0000 Subject: [PATCH] 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 --- cinderclient/shell.py | 3 +++ cinderclient/tests/unit/test_shell.py | 12 ++++++++++++ ...867061-fix-py-raw-error-msg-ff3c6da0b01d5d6c.yaml | 7 +++++++ 3 files changed, 22 insertions(+) create mode 100644 releasenotes/notes/bug-1867061-fix-py-raw-error-msg-ff3c6da0b01d5d6c.yaml diff --git a/cinderclient/shell.py b/cinderclient/shell.py index cfd4e82e8..ff8c4c4c8 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 ac7404cbf..c8a6375d8 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 000000000..91d026bf1 --- /dev/null +++ b/releasenotes/notes/bug-1867061-fix-py-raw-error-msg-ff3c6da0b01d5d6c.yaml @@ -0,0 +1,7 @@ +--- +fixes: + - | + `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