Merge "api 2.64, manilaclient support force extend share"

This commit is contained in:
Zuul 2021-12-03 08:18:59 +00:00 committed by Gerrit Code Review
commit 1bd0613794
5 changed files with 68 additions and 14 deletions

View File

@ -819,6 +819,14 @@ class ResizeShare(command.Command):
default=False,
help=_('Wait for share resize')
)
parser.add_argument(
'--force',
action='store_true',
default=False,
help=_('Only applicable when increasing the size of the '
'shareonly available with microversion '
'2.64 and higher. (admin only)')
)
return parser
def take_action(self, parsed_args):
@ -836,8 +844,18 @@ class ResizeShare(command.Command):
"Share resize failed: %s" % e
))
elif share_size < new_size:
force = False
if parsed_args.force:
if share_client.api_version < api_versions.APIVersion("2.64"):
raise exceptions.CommandError(
'args force is available only for '
'API microversion >= 2.64')
force = True
try:
share_client.shares.extend(share, new_size)
if force:
share_client.shares.extend(share, new_size, force=force)
else:
share_client.shares.extend(share, new_size)
except Exception as e:
raise exceptions.CommandError(_(
"Share resize failed: %s" % e

View File

@ -574,11 +574,12 @@ class SharesTest(utils.TestCase):
self.assertEqual("fake", result)
@ddt.data(
("2.6", "os-extend"),
("2.7", "extend"),
("2.6", "os-extend", False),
("2.7", "extend", False),
("2.64", "extend", True),
)
@ddt.unpack
def test_extend_share(self, microversion, action_name):
def test_extend_share(self, microversion, action_name, force):
size = 123
share = "fake_share"
version = api_versions.APIVersion(microversion)
@ -587,10 +588,15 @@ class SharesTest(utils.TestCase):
with mock.patch.object(manager, "_action",
mock.Mock(return_value="fake")):
result = manager.extend(share, size)
manager._action.assert_called_once_with(
action_name, share, {"new_size": size})
if not force:
result = manager.extend(share, size)
manager._action.assert_called_once_with(
action_name, share, {"new_size": size})
else:
result = manager.extend(share, size, force=force)
manager._action.assert_called_once_with(
action_name, share, {"new_size": size,
"force": "true"})
self.assertEqual("fake", result)
@ddt.data(

View File

@ -96,9 +96,9 @@ class Share(common_base.Resource):
"""Update the share with the provided state."""
self.manager.reset_state(self, state)
def extend(self, new_size):
def extend(self, new_size, force=False):
"""Extend the size of the specified share."""
self.manager.extend(self, new_size)
self.manager.extend(self, new_size, force=force)
def shrink(self, new_size):
"""Shrink the size of the specified share."""
@ -694,22 +694,32 @@ class ShareManager(base.ManagerWithFind):
def reset_state(self, share, state): # noqa
return self._do_reset_state(share, state, "reset_status")
def _do_extend(self, share, new_size, action_name):
def _do_extend(self, share, new_size, action_name, force=False):
"""Extend the size of the specified share.
:param share: either share object or text with its ID.
:param new_size: The desired size to extend share to.
:param force: if set to True, the scheduler's capacity decisions are
not accounted for. Setting this parameter to True does
not mean that the request will always succeed.
"""
return self._action(action_name, share, {"new_size": new_size})
req_body = {"new_size": new_size}
if force:
req_body['force'] = "true"
return self._action(action_name, share, req_body)
@api_versions.wraps("1.0", "2.6")
def extend(self, share, new_size):
return self._do_extend(share, new_size, "os-extend")
@api_versions.wraps("2.7") # noqa
@api_versions.wraps("2.7", "2.63") # noqa
def extend(self, share, new_size): # noqa
return self._do_extend(share, new_size, "extend")
@api_versions.wraps("2.64") # noqa
def extend(self, share, new_size, force=False): # noqa
return self._do_extend(share, new_size, "extend", force=force)
def _do_shrink(self, share, new_size, action_name):
"""Shrink the size of the specified share.

View File

@ -4575,11 +4575,26 @@ def do_pool_list(cs, args):
'--wait',
action='store_true',
help='Wait for share extension')
@cliutils.arg(
'--force',
action='store_true',
help='Force attempt the extension of the share, only available with '
'microversion 2.64 and higher. (admin only)')
@cliutils.service_type('sharev2')
def do_extend(cs, args):
"""Increases the size of an existing share."""
share = _find_share(cs, args.share)
cs.shares.extend(share, args.new_size)
force = False
if args.force:
if cs.api_version < api_versions.APIVersion("2.64"):
raise exceptions.CommandError(
"args 'force' is available only starting with "
"'2.64' API microversion.")
force = True
if force:
cs.shares.extend(share, args.new_size, force=force)
else:
cs.shares.extend(share, args.new_size)
if args.wait:
share = _wait_for_share_status(cs, share)

View File

@ -0,0 +1,5 @@
---
fixes:
- |
`Launchpad bug 1855391 <https://bugs.launchpad.net/python-manilaclient/+bug/1855391>`_
has been fixed by adding a "force" argument to the share extension commands.