From 81f9fc3125922a7308fb9deaace7601d2e6edb8a Mon Sep 17 00:00:00 2001 From: haixin <653186640@qq.com> Date: Sat, 9 Oct 2021 16:01:15 +0800 Subject: [PATCH] api 2.64, manilaclient support force extend share Partial-bug: #1855391 Change-Id: Ife4f42a77217a2c9d2553159126caa72da70fd83 --- manilaclient/osc/v2/share.py | 20 ++++++++++++++++++- manilaclient/tests/unit/v2/test_shares.py | 20 ++++++++++++------- manilaclient/v2/shares.py | 20 ++++++++++++++----- manilaclient/v2/shell.py | 17 +++++++++++++++- ...t-force-extend-share-6b5ebcfe1de0ca7b.yaml | 5 +++++ 5 files changed, 68 insertions(+), 14 deletions(-) create mode 100644 releasenotes/notes/bug-1855391-support-force-extend-share-6b5ebcfe1de0ca7b.yaml diff --git a/manilaclient/osc/v2/share.py b/manilaclient/osc/v2/share.py index 04d54a545..d8d4b95ec 100644 --- a/manilaclient/osc/v2/share.py +++ b/manilaclient/osc/v2/share.py @@ -797,6 +797,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 ' + 'share,only available with microversion ' + '2.64 and higher. (admin only)') + ) return parser def take_action(self, parsed_args): @@ -814,8 +822,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 diff --git a/manilaclient/tests/unit/v2/test_shares.py b/manilaclient/tests/unit/v2/test_shares.py index c18fc7a0e..0b9598ca2 100644 --- a/manilaclient/tests/unit/v2/test_shares.py +++ b/manilaclient/tests/unit/v2/test_shares.py @@ -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( diff --git a/manilaclient/v2/shares.py b/manilaclient/v2/shares.py index 2b1f052ba..3c36e062f 100644 --- a/manilaclient/v2/shares.py +++ b/manilaclient/v2/shares.py @@ -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. diff --git a/manilaclient/v2/shell.py b/manilaclient/v2/shell.py index db3922719..5a4b58ab9 100644 --- a/manilaclient/v2/shell.py +++ b/manilaclient/v2/shell.py @@ -4562,11 +4562,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) diff --git a/releasenotes/notes/bug-1855391-support-force-extend-share-6b5ebcfe1de0ca7b.yaml b/releasenotes/notes/bug-1855391-support-force-extend-share-6b5ebcfe1de0ca7b.yaml new file mode 100644 index 000000000..2c7d88846 --- /dev/null +++ b/releasenotes/notes/bug-1855391-support-force-extend-share-6b5ebcfe1de0ca7b.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + `Launchpad bug 1855391 `_ + has been fixed by adding a "force" argument to the share extension commands.