Skip to content

Commit bccbd51

Browse files
committed
Fix max version handling for help output
Commit fefe331 incorrectly set the default API version to the max the client knew about in order to get the full help output, including all microversioned commands. The original intent was to have help print out information for all versions, but still require the user to specify a version if they wanted to use any microversioned version of an API. The code accidentally made it so all commands would request the max version the client knew about. This meant an unspecified request would get the newer functionality rather than the default v3 functionality, and also meant the client could request a microversion higher than what the server knew about, resulting in an unexpected error being returned. To keep the originally intended functionality, but keep all help output, this only uses the max API version for the help command unless the user specifies otherwise. Closes-bug: #1813967 Change-Id: I20f6c5471ffefe5524a4d48c967e2e8db53233f1 Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
1 parent cca0172 commit bccbd51

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

cinderclient/shell.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
from cinderclient import utils
4747

4848

49+
DEFAULT_MAJOR_OS_VOLUME_API_VERSION = "3"
4950
DEFAULT_CINDER_ENDPOINT_TYPE = 'publicURL'
5051
V1_SHELL = 'cinderclient.v1.shell'
5152
V2_SHELL = 'cinderclient.v2.shell'
@@ -527,8 +528,10 @@ def main(self, argv):
527528
'--help' in argv) or ('-h' in argv) or not argv
528529

529530
if not options.os_volume_api_version:
530-
api_version = api_versions.get_api_version(
531-
api_versions.MAX_VERSION)
531+
use_version = DEFAULT_MAJOR_OS_VOLUME_API_VERSION
532+
if do_help:
533+
use_version = api_versions.MAX_VERSION
534+
api_version = api_versions.get_api_version(use_version)
532535
else:
533536
api_version = api_versions.get_api_version(
534537
options.os_volume_api_version)

cinderclient/tests/unit/test_shell.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,11 @@ def test_help_unknown_command(self):
114114
self.assertRaises(exceptions.CommandError, self.shell, 'help foofoo')
115115

116116
def test_help(self):
117+
# Some expected help output, including microversioned commands
117118
required = [
118119
'.*?^usage: ',
119120
'.*?(?m)^\s+create\s+Creates a volume.',
121+
'.*?(?m)^\s+summary\s+Get volumes summary.',
120122
'.*?(?m)^Run "cinder help SUBCOMMAND" for help on a subcommand.',
121123
]
122124
help_text = self.shell('help')
@@ -134,6 +136,16 @@ def test_help_on_subcommand(self):
134136
self.assertThat(help_text,
135137
matchers.MatchesRegex(r, re.DOTALL | re.MULTILINE))
136138

139+
def test_help_on_subcommand_mv(self):
140+
required = [
141+
'.*?^usage: cinder summary',
142+
'.*?(?m)^Get volumes summary.',
143+
]
144+
help_text = self.shell('help summary')
145+
for r in required:
146+
self.assertThat(help_text,
147+
matchers.MatchesRegex(r, re.DOTALL | re.MULTILINE))
148+
137149
@ddt.data('backup-create --help', '--help backup-create')
138150
def test_dash_dash_help_on_subcommand(self, cmd):
139151
required = ['.*?^Creates a volume backup.']

0 commit comments

Comments
 (0)