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
This commit is contained in:
parent
8399923d50
commit
a0f6a2e920
|
@ -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 = {}
|
||||
|
|
|
@ -349,6 +349,13 @@ class PromoteShareReplica(command.Command):
|
|||
metavar="<replica>",
|
||||
help=_("ID of the share replica.")
|
||||
)
|
||||
parser.add_argument(
|
||||
'--quiesce-wait-time',
|
||||
metavar='<quiesce-wait-time>',
|
||||
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)))
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
|
||||
#
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -6407,13 +6407,34 @@ def do_share_replica_delete(cs, args):
|
|||
'replica',
|
||||
metavar='<replica>',
|
||||
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='<replica>',
|
||||
help='ID of the share replica.')
|
||||
@cliutils.arg(
|
||||
'--quiesce-wait-time',
|
||||
metavar='<quiesce-wait-time>',
|
||||
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',
|
||||
|
|
|
@ -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 <https://bugs.launchpad.net/manila/+bug/2000171>`_
|
Loading…
Reference in New Issue