From a0f6a2e92096c4242d8737350a0824c7b1106236 Mon Sep 17 00:00:00 2001 From: Kiran Pawar Date: Wed, 8 Feb 2023 19:40:32 +0000 Subject: [PATCH] Add quiesce_wait_time for replica promote Allows to configure optional field 'quiesce_wait_time' in share replica promote for microversion >= 2.75. Closes-bug: #2000171 Change-Id: I9ea0705da97d4343b36db3d8023ca237437768cf Depends-On: Ib02063ee8b82f7374cd89f90e7f24a845c6c7cd7 --- manilaclient/api_versions.py | 2 +- manilaclient/osc/v2/share_replicas.py | 19 ++++++++++++++- .../tests/unit/osc/v2/test_share_replicas.py | 19 +++++++++++++++ manilaclient/tests/unit/v2/fakes.py | 5 ++-- manilaclient/tests/unit/v2/test_shell.py | 11 +++++++++ manilaclient/v2/share_replicas.py | 14 ++++++++++- manilaclient/v2/shell.py | 23 ++++++++++++++++++- ...-for-replica-promote-30d9fa66afc854f2.yaml | 7 ++++++ 8 files changed, 94 insertions(+), 6 deletions(-) create mode 100644 releasenotes/notes/add-quiesce-wait-time-for-replica-promote-30d9fa66afc854f2.yaml diff --git a/manilaclient/api_versions.py b/manilaclient/api_versions.py index 22656d70b..98fbb61ad 100644 --- a/manilaclient/api_versions.py +++ b/manilaclient/api_versions.py @@ -27,7 +27,7 @@ from manilaclient import utils LOG = logging.getLogger(__name__) -MAX_VERSION = '2.73' +MAX_VERSION = '2.75' MIN_VERSION = '2.0' DEPRECATED_VERSION = '1.0' _VERSIONED_METHOD_MAP = {} diff --git a/manilaclient/osc/v2/share_replicas.py b/manilaclient/osc/v2/share_replicas.py index 10ab87145..522501722 100644 --- a/manilaclient/osc/v2/share_replicas.py +++ b/manilaclient/osc/v2/share_replicas.py @@ -349,6 +349,13 @@ class PromoteShareReplica(command.Command): metavar="", help=_("ID of the share replica.") ) + parser.add_argument( + '--quiesce-wait-time', + metavar='', + default=None, + help=_('Quiesce wait time in seconds. Available for ' + 'microversion >= 2.75') + ) return parser def take_action(self, parsed_args): @@ -358,8 +365,18 @@ class PromoteShareReplica(command.Command): share_client.share_replicas, parsed_args.replica) + args = [ + replica, + ] + if parsed_args.quiesce_wait_time: + if share_client.api_version < api_versions.APIVersion("2.75"): + raise exceptions.CommandError( + "'quiesce-wait-time' option is available only starting " + "with '2.75' API microversion.") + args += [parsed_args.quiesce_wait_time] + try: - share_client.share_replicas.promote(replica) + share_client.share_replicas.promote(*args) except Exception as e: raise exceptions.CommandError(_( "Failed to promote replica to 'active': %s" % (e))) diff --git a/manilaclient/tests/unit/osc/v2/test_share_replicas.py b/manilaclient/tests/unit/osc/v2/test_share_replicas.py index e53d9bf24..1b250dc94 100644 --- a/manilaclient/tests/unit/osc/v2/test_share_replicas.py +++ b/manilaclient/tests/unit/osc/v2/test_share_replicas.py @@ -639,6 +639,25 @@ class TestShareReplicaPromote(TestShareReplica): self.share_replica) self.assertIsNone(result) + def test_share_replica_promote_quiesce_wait_time(self): + wait_time = '5' + arglist = [ + self.share_replica.id, + '--quiesce-wait-time', wait_time + ] + verifylist = [ + ('replica', self.share_replica.id), + ('quiesce_wait_time', wait_time) + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + result = self.cmd.take_action(parsed_args) + + self.replicas_mock.promote.assert_called_with( + self.share_replica, + wait_time) + self.assertIsNone(result) + def test_share_replica_promote_exception(self): arglist = [ self.share_replica.id, diff --git a/manilaclient/tests/unit/v2/fakes.py b/manilaclient/tests/unit/v2/fakes.py index dc6221a31..e34866800 100644 --- a/manilaclient/tests/unit/v2/fakes.py +++ b/manilaclient/tests/unit/v2/fakes.py @@ -954,10 +954,11 @@ class FakeHTTPClient(fakes.FakeHTTPClient): if action in ('reset_status', 'reset_replica_state'): attr = action.split('reset_')[1] assert attr in body.get(action) - elif action in ('force_delete', 'resync', 'promote'): + elif action in ('force_delete', 'resync'): assert body[action] is None else: - raise AssertionError("Unexpected share action: %s" % action) + if action not in ('promote'): + raise AssertionError("Unexpected share action: %s" % action) return (resp, {}, _body) # diff --git a/manilaclient/tests/unit/v2/test_shell.py b/manilaclient/tests/unit/v2/test_shell.py index 07dd17993..448425349 100644 --- a/manilaclient/tests/unit/v2/test_shell.py +++ b/manilaclient/tests/unit/v2/test_shell.py @@ -3430,6 +3430,17 @@ class ShellTest(test_utils.TestCase): self.assert_called_anytime('GET', '/share-replicas/5678') + @mock.patch.object(shell_v2, '_find_share_replica', mock.Mock()) + def test_share_replica_promote_quiesce_wait_time(self): + fake_replica = type('FakeShareReplica', (object,), {'id': '1234'}) + shell_v2._find_share_replica.return_value = fake_replica + cmd = ('share-replica-promote ' + fake_replica.id + + ' --quiesce-wait-time 5') + self.run_command(cmd) + self.assert_called( + 'POST', '/share-replicas/1234/action', + body={'promote': {'quiesce_wait_time': '5'}}) + @ddt.data('promote', 'resync') @mock.patch.object(shell_v2, '_find_share_replica', mock.Mock()) def test_share_replica_actions(self, action): diff --git a/manilaclient/v2/share_replicas.py b/manilaclient/v2/share_replicas.py index 0c3b02775..8965e5d93 100644 --- a/manilaclient/v2/share_replicas.py +++ b/manilaclient/v2/share_replicas.py @@ -101,7 +101,7 @@ class ShareReplicaManager(base.ManagerWithFind): """ return self._action('promote', replica) - @api_versions.wraps(constants.REPLICA_GRADUATION_VERSION) # noqa + @api_versions.wraps(constants.REPLICA_GRADUATION_VERSION, '2.74') # noqa def promote(self, replica): # noqa F811 """Promote the provided replica. @@ -109,6 +109,18 @@ class ShareReplicaManager(base.ManagerWithFind): """ return self._action('promote', replica) + @api_versions.wraps('2.75') # noqa + def promote(self, replica, quiesce_wait_time=None): # noqa F811 + """Promote the provided replica. + + :param replica: either replica object or its UUID. + :param body: either replica object or its UUID. + """ + body = None + if quiesce_wait_time: + body = dict(quiesce_wait_time=quiesce_wait_time) + return self._action('promote', replica, body) + @api_versions.wraps("2.11", constants.REPLICA_PRE_GRADUATION_VERSION) @api_versions.experimental_api def create(self, share, availability_zone=None): diff --git a/manilaclient/v2/shell.py b/manilaclient/v2/shell.py index d753fcfc1..a4aea3cd8 100644 --- a/manilaclient/v2/shell.py +++ b/manilaclient/v2/shell.py @@ -6407,13 +6407,34 @@ def do_share_replica_delete(cs, args): 'replica', metavar='', help='ID of the share replica.') -@api_versions.wraps("2.11") +@api_versions.wraps("2.11", "2.74") def do_share_replica_promote(cs, args): """Promote specified replica to 'active' replica_state.""" replica = _find_share_replica(cs, args.replica) cs.share_replicas.promote(replica) +@cliutils.arg( + 'replica', + metavar='', + help='ID of the share replica.') +@cliutils.arg( + '--quiesce-wait-time', + metavar='', + default=None, + help='Quiesce wait time in seconds. Available for ' + 'microversion >= 2.75') +@api_versions.wraps("2.75") # noqa +def do_share_replica_promote(cs, args): # noqa + """Promote specified replica to 'active' replica_state.""" + replica = _find_share_replica(cs, args.replica) + + quiesce_wait_time = None + if args.quiesce_wait_time: + quiesce_wait_time = args.quiesce_wait_time + cs.share_replicas.promote(replica, quiesce_wait_time) + + @api_versions.wraps("2.47") @cliutils.arg( 'replica', diff --git a/releasenotes/notes/add-quiesce-wait-time-for-replica-promote-30d9fa66afc854f2.yaml b/releasenotes/notes/add-quiesce-wait-time-for-replica-promote-30d9fa66afc854f2.yaml new file mode 100644 index 000000000..1fe10b1a7 --- /dev/null +++ b/releasenotes/notes/add-quiesce-wait-time-for-replica-promote-30d9fa66afc854f2.yaml @@ -0,0 +1,7 @@ +--- +features: + - | + Added 'quiesce_wait_time' option to share replica promote API. This will be + used by driver as quiesce wait time for specified replica promote operation + instead of global config value. For more details, refer + `Launchpad bug #2000171 `_