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 #1982428 Change-Id: Iee32d0041a03fcb1ce426eb10cbc3067caf14533
This commit is contained in:
parent
3103b8c56a
commit
7c17a407ab
|
@ -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,18 @@ 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)
|
||||
if info.get('export_locations'):
|
||||
info['export_locations'] = (
|
||||
cliutils.convert_dict_list_to_string(
|
||||
info['export_locations'],
|
||||
ignored_keys=['replica_state', 'availability_zone',
|
||||
'share_replica_id']))
|
||||
cliutils.print_dict(info)
|
||||
|
||||
|
||||
def _find_message(cs, message):
|
||||
"""Get a message by ID."""
|
||||
return apiclient_utils.find_resource(cs.messages, message)
|
||||
|
@ -1764,12 +1777,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),
|
||||
|
|
|
@ -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