Add "--wait" option for unmanaging a share server
Unmanaging a share server: $ manila share-server-unmanage 441d806f-f0e0-4c90-b7e2-a553c6aa76b2 --wait <CLI waits for share server to be removed before returning to the prompt> Closes-Bug: #1898315 Closes-Bug: #1982428 Change-Id: Iee32d0041a03fcb1ce426eb10cbc3067caf14533
This commit is contained in:
parent
3103b8c56a
commit
c2a9b04dc8
|
@ -960,10 +960,22 @@ class ShellTest(test_utils.TestCase):
|
|||
uri = '/shares/%s/action' % fake_share.id
|
||||
api.client.post.assert_called_once_with(uri, body={'unmanage': None})
|
||||
|
||||
@mock.patch.object(shell_v2, '_wait_for_resource_status', mock.Mock())
|
||||
def test_share_server_unmanage(self):
|
||||
self.run_command('share-server-unmanage 1234')
|
||||
self.assert_called('POST', '/share-servers/1234/action',
|
||||
body={'unmanage': {'force': False}})
|
||||
self.assertEqual(0, shell_v2._wait_for_resource_status.call_count)
|
||||
|
||||
@mock.patch.object(shell_v2, '_wait_for_resource_status', mock.Mock())
|
||||
def test_share_server_unmanage_with_wait(self):
|
||||
self.run_command('share-server-unmanage 1234 --wait')
|
||||
self.assert_called('POST', '/share-servers/1234/action',
|
||||
body={'unmanage': {'force': False}})
|
||||
# _wait_for_resource_status should be triggered once
|
||||
shell_v2._wait_for_resource_status.assert_called_once_with(
|
||||
self.shell.cs, '1234', resource_type='share_server',
|
||||
expected_status='deleted')
|
||||
|
||||
def test_share_server_unmanage_force(self):
|
||||
self.run_command('share-server-unmanage 1234 --force')
|
||||
|
|
|
@ -67,6 +67,7 @@ def _wait_for_resource_status(cs,
|
|||
'share_group': _print_share_group,
|
||||
'share_group_snapshot': _print_share_group_snapshot,
|
||||
'share_instance': _print_share_instance,
|
||||
'share_server': _print_share_server,
|
||||
'share_access_rule': _print_share_access_rule,
|
||||
}
|
||||
|
||||
|
@ -383,6 +384,15 @@ def _find_share_server(cs, share_server):
|
|||
return apiclient_utils.find_resource(cs.share_servers, share_server)
|
||||
|
||||
|
||||
def _print_share_server(cs, share_server):
|
||||
info = share_server._info.copy()
|
||||
info.pop('links', None)
|
||||
# All 'backend_details' data already present as separated strings,
|
||||
# so remove big dict from view.
|
||||
info.pop('backend_details', None)
|
||||
cliutils.print_dict(info)
|
||||
|
||||
|
||||
def _find_message(cs, message):
|
||||
"""Get a message by ID."""
|
||||
return apiclient_utils.find_resource(cs.messages, message)
|
||||
|
@ -1659,7 +1669,7 @@ def do_share_server_manage(cs, args):
|
|||
except exceptions.CommandError as e:
|
||||
print(e, file=sys.stderr)
|
||||
|
||||
cliutils.print_dict(share_server._info)
|
||||
_print_share_server(cs, share_server)
|
||||
|
||||
|
||||
@cliutils.arg(
|
||||
|
@ -1764,12 +1774,21 @@ def do_unmanage(cs, args):
|
|||
default=False,
|
||||
help="Enforces the unmanage share server operation, even if the back-end "
|
||||
"driver does not support it.")
|
||||
@cliutils.arg(
|
||||
'--wait',
|
||||
action='store_true',
|
||||
default=False,
|
||||
help='Wait for share server to unmanage')
|
||||
def do_share_server_unmanage(cs, args):
|
||||
"""Unmanage share server (Admin only)."""
|
||||
failure_count = 0
|
||||
for server in args.share_server:
|
||||
try:
|
||||
cs.share_servers.unmanage(server, args.force)
|
||||
if args.wait:
|
||||
_wait_for_resource_status(
|
||||
cs, server, resource_type='share_server',
|
||||
expected_status='deleted')
|
||||
except Exception as e:
|
||||
failure_count += 1
|
||||
print("Unmanage for share server %s failed: %s" % (server, e),
|
||||
|
@ -4631,11 +4650,7 @@ def do_share_server_list(cs, args):
|
|||
def do_share_server_show(cs, args):
|
||||
"""Show share server info (Admin only)."""
|
||||
share_server = cs.share_servers.get(args.id)
|
||||
# All 'backend_details' data already present as separated strings,
|
||||
# so remove big dict from view.
|
||||
if "backend_details" in share_server._info:
|
||||
del share_server._info["backend_details"]
|
||||
cliutils.print_dict(share_server._info)
|
||||
_print_share_server(cs, share_server)
|
||||
|
||||
|
||||
@cliutils.arg(
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
features:
|
||||
- |
|
||||
The commands "share-server-unmanage" now accepts an optional
|
||||
"--wait" option that allows users to let the client poll for
|
||||
the completion of the operation.
|
Loading…
Reference in New Issue