Add "--wait" option for deleting a share server

This RFE adds a "--wait" flag to share server
delete, to make the CLI wait on the share server
to be deleted before returning to the prompt.

Closes-Bug: #1898316
Change-Id: I98feeebf1c20d30f42e57b937655537ac206bc25
This commit is contained in:
kafilat-adeleke 2021-03-30 08:07:05 +01:00 committed by Kafilat Adeleke
parent 47d0002d5c
commit 2a1fb2bf8d
3 changed files with 60 additions and 13 deletions

View File

@ -3467,25 +3467,47 @@ class ShellTest(test_utils.TestCase):
'DELETE', '/types/%s' % fake_share_type.id,
clear_callstack=False)
@ddt.data(('1234', ), ('1234', '5678'))
def test_share_server_delete(self, server_ids):
@ddt.data(('share_server_xyz', ), ('share_server_abc', 'share_server_xyz'))
def test_share_server_delete_wait(self, share_servers_to_delete):
fake_manager = mock.Mock()
fake_share_servers = [
share_servers.ShareServer('fake', {'id': server_id}, True)
for server_id in server_ids
share_servers.ShareServer(fake_manager, {'id': '1234'})
for share_server in share_servers_to_delete
]
share_server_not_found_error = ("Delete for share server %s "
"failed: No server with a "
"name or ID of '%s' exists.")
share_servers_are_not_found_errors = [
exceptions.CommandError(share_server_not_found_error
% (share_server, share_server))
for share_server in share_servers_to_delete
]
self.mock_object(
shell_v2, '_find_share_server',
mock.Mock(side_effect=fake_share_servers))
shell_v2, '_find_share_server', mock.Mock(
side_effect=(fake_share_servers +
share_servers_are_not_found_errors)))
self.run_command('share-server-delete %s' % ' '.join(server_ids))
self.mock_object(
shell_v2, '_wait_for_resource_status',
mock.Mock()
)
self.run_command('share-server-delete %s --wait' % ' '
.join(share_servers_to_delete))
shell_v2._find_share_server.assert_has_calls([
mock.call(self.shell.cs, s_id) for s_id in server_ids
mock.call(self.shell.cs, share_server)
for share_server in share_servers_to_delete
])
for server in fake_share_servers:
self.assert_called_anytime(
'DELETE', '/share-servers/%s' % server.id,
clear_callstack=False)
fake_manager.delete.assert_has_calls([
mock.call(share_server) for share_server in fake_share_servers])
shell_v2._wait_for_resource_status.assert_has_calls([
mock.call(self.shell.cs, share_server,
resource_type='share_server', expected_status='deleted')
for share_server in fake_share_servers
])
self.assertEqual(len(share_servers_to_delete),
fake_manager.delete.call_count)
@mock.patch.object(cliutils, 'print_list', mock.Mock())
def test_message_list(self):

View File

@ -56,6 +56,7 @@ def _wait_for_resource_status(cs,
'share_group': _find_share_group,
'share_group_snapshot': _find_share_group_snapshot,
'share_instance': _find_share_instance,
'share_server': _find_share_server,
}
print_resource = {
@ -4223,15 +4224,22 @@ def do_share_server_details(cs, args):
nargs='+',
type=str,
help='ID of the share server(s) to delete.')
@cliutils.arg(
'--wait',
action='store_true',
help='Wait for share server to delete')
@cliutils.service_type('sharev2')
def do_share_server_delete(cs, args):
"""Delete one or more share servers (Admin only)."""
failure_count = 0
share_servers_to_delete = []
for server_id in args.id:
try:
id_ref = _find_share_server(cs, server_id)
cs.share_servers.delete(id_ref)
share_servers_to_delete.append(id_ref)
id_ref.delete()
except Exception as e:
failure_count += 1
print("Delete for share server %s failed: %s" % (
@ -4241,6 +4249,15 @@ def do_share_server_delete(cs, args):
raise exceptions.CommandError("Unable to delete any of the specified "
"share servers.")
if args.wait:
for share_server in share_servers_to_delete:
try:
_wait_for_resource_status(
cs, share_server, resource_type='share_server',
expected_status='deleted')
except exceptions.CommandError as e:
print(e, file=sys.stderr)
@cliutils.arg(
'--columns',

View File

@ -0,0 +1,8 @@
---
features:
- |
The command "manila share-server-delete" now accepts an optional
"--wait" that allows users to let the client poll for the
completion of the operation.