Fix default share type resolution in OSC

This patch also fixes an incorrect docstring
in the share types SDK method.

Closes-Bug: #2030686
Change-Id: Iaea9746e6f4e133574f5504d906a49cc80fa4243
(cherry picked from commit a870c13cf1bdba15c30f0935ac2f5c637e6e8fee)
This commit is contained in:
Goutham Pacha Ravi 2023-08-08 16:16:01 -07:00
parent 4080d49426
commit ed34956613
4 changed files with 15 additions and 5 deletions

@ -205,8 +205,8 @@ class CreateShare(command.ShowOne):
parsed_args.share_type).id parsed_args.share_type).id
elif not parsed_args.snapshot_id: elif not parsed_args.snapshot_id:
try: try:
share_type = apiutils.find_resource( share_type = share_client.share_types.get(
share_client.share_types, 'default').id share_type='default').id
except apiclient_exceptions.CommandError: except apiclient_exceptions.CommandError:
msg = ("There is no default share type available. You must " msg = ("There is no default share type available. You must "
"pick a valid share type to create a share.") "pick a valid share type to create a share.")

@ -372,6 +372,8 @@ class TestShareCreate(TestShare):
osc_exceptions.CommandError, osc_exceptions.CommandError,
self.cmd.take_action, self.cmd.take_action,
parsed_args) parsed_args)
self.share_types_mock.get.assert_called_once_with(
share_type='default')
@ddt.data('None', 'NONE', 'none') @ddt.data('None', 'NONE', 'none')
def test_create_share_with_the_name_none(self, name): def test_create_share_with_the_name_none(self, name):

@ -122,10 +122,10 @@ class ShareTypeManager(base.ManagerWithFind):
return self._list("/types%s" % query_string, "share_types") return self._list("/types%s" % query_string, "share_types")
def show(self, share_type): def show(self, share_type):
"""Get a share. """Get a share type.
:param share: either share object or text with its ID. :param share type: either share type object or text with its ID.
:rtype: :class:`Share` :rtype: :class:`ShareType`
""" """
type_id = base.getid(share_type) type_id = base.getid(share_type)
return self._get("/types/%s" % type_id, "share_type") return self._get("/types/%s" % type_id, "share_type")

@ -0,0 +1,8 @@
---
fixes:
- |
Fixed default share type lookup associated with the "openstack share
create" command. The lookup now resolves default share types correctly
even on environments where the default type isn't named "default". See
`launchpad bug #2030686 <https://launchpad.net/bugs/2030686>`_ for more
details.