[OSC] Don't use default type with snapshot clones

When creating a share with OSC, the client looks up the
default share type when one is unspecified. However, one
doesn't need to specify a share type when creating a share
from a snapshot.

Change-Id: I39984c2b953b16d2cdbc92ecaf5f3b701a33b283
Closes-Bug: #1980985
Signed-off-by: Goutham Pacha Ravi <gouthampravi@gmail.com>
This commit is contained in:
Goutham Pacha Ravi 2022-07-08 00:59:24 +05:30
parent 992a94247a
commit 06f7ea6255
3 changed files with 19 additions and 9 deletions

View File

@ -156,8 +156,9 @@ class CreateShare(command.ShowOne):
'--share-type',
metavar='<share-type>',
default=None,
help=_('Optional share type. Use of optional shares type '
'is deprecated. (Default=Default)')
help=_('The share type to create the share with. If not '
'specified, unless creating from a snapshot, the default '
'share type will be used.')
)
parser.add_argument(
'--availability-zone',
@ -191,7 +192,6 @@ class CreateShare(command.ShowOne):
return parser
def take_action(self, parsed_args):
# TODO(s0ru): the table shows 'Field', 'Value'
share_client = self.app.client_manager.share
if parsed_args.name:
@ -199,10 +199,11 @@ class CreateShare(command.ShowOne):
raise apiclient_exceptions.CommandError(
"Share name cannot be with the value 'None'")
share_type = None
if parsed_args.share_type:
share_type = apiutils.find_resource(share_client.share_types,
parsed_args.share_type).id
else:
elif not parsed_args.snapshot_id:
try:
share_type = apiutils.find_resource(
share_client.share_types, 'default').id

View File

@ -230,20 +230,24 @@ class TestShareCreate(TestShare):
arglist = [
self.new_share.share_proto,
str(self.new_share.size),
'--share-type', self.share_type.id,
'--snapshot-id', self.share_snapshot.id
]
verifylist = [
('share_proto', self.new_share.share_proto),
('size', self.new_share.size),
('share_type', self.share_type.id),
('snapshot_id', self.share_snapshot.id)
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
with mock.patch(
'manilaclient.common.apiclient.utils.find_resource',
mock.Mock(return_value=self.share_snapshot)):
columns, data = self.cmd.take_action(parsed_args)
osc_shares.apiutils.find_resource.assert_called_once_with(
mock.ANY, self.share_snapshot.id)
self.shares_mock.create.assert_called_with(
availability_zone=None,
@ -254,12 +258,11 @@ class TestShareCreate(TestShare):
share_group_id=None,
share_network=None,
share_proto=self.new_share.share_proto,
share_type=self.share_type.id,
share_type=None,
size=self.new_share.size,
snapshot_id=self.share_snapshot.id,
scheduler_hints={}
)
self.assertCountEqual(self.columns, columns)
self.assertCountEqual(self.datalist, data)

View File

@ -0,0 +1,6 @@
---
fixes:
- |
When creating a share from snapshot with 'openstack share create', the
client no longer forces the use of a share type. See `bug #1980985
<https://launchpad.net/bugs/1980985>`_ for more information.