From ed34956613807cf67d0bc9e84f1658ae537e49a4 Mon Sep 17 00:00:00 2001 From: Goutham Pacha Ravi Date: Tue, 8 Aug 2023 16:16:01 -0700 Subject: [PATCH] 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) --- manilaclient/osc/v2/share.py | 4 ++-- manilaclient/tests/unit/osc/v2/test_share.py | 2 ++ manilaclient/v2/share_types.py | 6 +++--- ...2030686-fix-default-share-lookup-cc7e592a0dc855e1.yaml | 8 ++++++++ 4 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 releasenotes/notes/bug-2030686-fix-default-share-lookup-cc7e592a0dc855e1.yaml diff --git a/manilaclient/osc/v2/share.py b/manilaclient/osc/v2/share.py index 16de74b6d..1dcc42035 100644 --- a/manilaclient/osc/v2/share.py +++ b/manilaclient/osc/v2/share.py @@ -205,8 +205,8 @@ class CreateShare(command.ShowOne): parsed_args.share_type).id elif not parsed_args.snapshot_id: try: - share_type = apiutils.find_resource( - share_client.share_types, 'default').id + share_type = share_client.share_types.get( + share_type='default').id except apiclient_exceptions.CommandError: msg = ("There is no default share type available. You must " "pick a valid share type to create a share.") diff --git a/manilaclient/tests/unit/osc/v2/test_share.py b/manilaclient/tests/unit/osc/v2/test_share.py index 344579df7..443e78f65 100644 --- a/manilaclient/tests/unit/osc/v2/test_share.py +++ b/manilaclient/tests/unit/osc/v2/test_share.py @@ -372,6 +372,8 @@ class TestShareCreate(TestShare): osc_exceptions.CommandError, self.cmd.take_action, parsed_args) + self.share_types_mock.get.assert_called_once_with( + share_type='default') @ddt.data('None', 'NONE', 'none') def test_create_share_with_the_name_none(self, name): diff --git a/manilaclient/v2/share_types.py b/manilaclient/v2/share_types.py index ec401f076..e2383e769 100644 --- a/manilaclient/v2/share_types.py +++ b/manilaclient/v2/share_types.py @@ -122,10 +122,10 @@ class ShareTypeManager(base.ManagerWithFind): return self._list("/types%s" % query_string, "share_types") def show(self, share_type): - """Get a share. + """Get a share type. - :param share: either share object or text with its ID. - :rtype: :class:`Share` + :param share type: either share type object or text with its ID. + :rtype: :class:`ShareType` """ type_id = base.getid(share_type) return self._get("/types/%s" % type_id, "share_type") diff --git a/releasenotes/notes/bug-2030686-fix-default-share-lookup-cc7e592a0dc855e1.yaml b/releasenotes/notes/bug-2030686-fix-default-share-lookup-cc7e592a0dc855e1.yaml new file mode 100644 index 000000000..790fec16f --- /dev/null +++ b/releasenotes/notes/bug-2030686-fix-default-share-lookup-cc7e592a0dc855e1.yaml @@ -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 `_ for more + details.