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:

committed by
Kafilat Adeleke

parent
47d0002d5c
commit
2a1fb2bf8d
@@ -3467,25 +3467,47 @@ class ShellTest(test_utils.TestCase):
|
|||||||
'DELETE', '/types/%s' % fake_share_type.id,
|
'DELETE', '/types/%s' % fake_share_type.id,
|
||||||
clear_callstack=False)
|
clear_callstack=False)
|
||||||
|
|
||||||
@ddt.data(('1234', ), ('1234', '5678'))
|
@ddt.data(('share_server_xyz', ), ('share_server_abc', 'share_server_xyz'))
|
||||||
def test_share_server_delete(self, server_ids):
|
def test_share_server_delete_wait(self, share_servers_to_delete):
|
||||||
|
fake_manager = mock.Mock()
|
||||||
fake_share_servers = [
|
fake_share_servers = [
|
||||||
share_servers.ShareServer('fake', {'id': server_id}, True)
|
share_servers.ShareServer(fake_manager, {'id': '1234'})
|
||||||
for server_id in server_ids
|
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(
|
self.mock_object(
|
||||||
shell_v2, '_find_share_server',
|
shell_v2, '_find_share_server', mock.Mock(
|
||||||
mock.Mock(side_effect=fake_share_servers))
|
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([
|
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:
|
fake_manager.delete.assert_has_calls([
|
||||||
self.assert_called_anytime(
|
mock.call(share_server) for share_server in fake_share_servers])
|
||||||
'DELETE', '/share-servers/%s' % server.id,
|
shell_v2._wait_for_resource_status.assert_has_calls([
|
||||||
clear_callstack=False)
|
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())
|
@mock.patch.object(cliutils, 'print_list', mock.Mock())
|
||||||
def test_message_list(self):
|
def test_message_list(self):
|
||||||
|
@@ -56,6 +56,7 @@ def _wait_for_resource_status(cs,
|
|||||||
'share_group': _find_share_group,
|
'share_group': _find_share_group,
|
||||||
'share_group_snapshot': _find_share_group_snapshot,
|
'share_group_snapshot': _find_share_group_snapshot,
|
||||||
'share_instance': _find_share_instance,
|
'share_instance': _find_share_instance,
|
||||||
|
'share_server': _find_share_server,
|
||||||
}
|
}
|
||||||
|
|
||||||
print_resource = {
|
print_resource = {
|
||||||
@@ -4223,15 +4224,22 @@ def do_share_server_details(cs, args):
|
|||||||
nargs='+',
|
nargs='+',
|
||||||
type=str,
|
type=str,
|
||||||
help='ID of the share server(s) to delete.')
|
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):
|
def do_share_server_delete(cs, args):
|
||||||
"""Delete one or more share servers (Admin only)."""
|
"""Delete one or more share servers (Admin only)."""
|
||||||
|
|
||||||
failure_count = 0
|
failure_count = 0
|
||||||
|
share_servers_to_delete = []
|
||||||
|
|
||||||
for server_id in args.id:
|
for server_id in args.id:
|
||||||
try:
|
try:
|
||||||
id_ref = _find_share_server(cs, server_id)
|
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:
|
except Exception as e:
|
||||||
failure_count += 1
|
failure_count += 1
|
||||||
print("Delete for share server %s failed: %s" % (
|
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 "
|
raise exceptions.CommandError("Unable to delete any of the specified "
|
||||||
"share servers.")
|
"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(
|
@cliutils.arg(
|
||||||
'--columns',
|
'--columns',
|
||||||
|
@@ -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.
|
||||||
|
|
Reference in New Issue
Block a user