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
This commit is contained in:
		| @@ -225,6 +225,9 @@ class OpenStackCinderShell(object): | |||||||
|                             default=0, |                             default=0, | ||||||
|                             help=_('Number of retries.')) |                             help=_('Number of retries.')) | ||||||
|  |  | ||||||
|  |         parser.set_defaults(func=self.do_help) | ||||||
|  |         parser.set_defaults(command='') | ||||||
|  |  | ||||||
|         if osprofiler_profiler: |         if osprofiler_profiler: | ||||||
|             parser.add_argument('--profile', |             parser.add_argument('--profile', | ||||||
|                                 metavar='HMAC_KEY', |                                 metavar='HMAC_KEY', | ||||||
|   | |||||||
| @@ -148,6 +148,18 @@ class ShellTest(utils.TestCase): | |||||||
|             self.assertThat(help_text, |             self.assertThat(help_text, | ||||||
|                             matchers.MatchesRegex(r, re.DOTALL | re.MULTILINE)) |                             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') |     @ddt.data('backup-create --help', '--help backup-create') | ||||||
|     def test_dash_dash_help_on_subcommand(self, cmd): |     def test_dash_dash_help_on_subcommand(self, cmd): | ||||||
|         required = ['.*?^Creates a volume backup.'] |         required = ['.*?^Creates a volume backup.'] | ||||||
|   | |||||||
| @@ -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``. | ||||||
		Reference in New Issue
	
	Block a user
	 Eduardo Santos
					Eduardo Santos