Add --wait flag to share-server-unmanage
This change adds the --wait flag to the share-server-unmanage command, allowing users to wait for the asynchronous operation to complete before returning to the command prompt. When --wait is specified, share-server-unmanage waits until the server is removed. Closes-Bug: #1898315 Change-Id: I90f9c7048a1d5cc21064c4b1d000732dc5fd50d6 Signed-off-by: Premlata <premlata84277@gmail.com>
This commit is contained in:
@@ -1027,6 +1027,30 @@ class ShellTest(test_utils.TestCase):
|
||||
self.assert_called('POST', '/share-servers/1234/action',
|
||||
body={'unmanage': {'force': True}})
|
||||
|
||||
@mock.patch.object(shell_v2, '_wait_for_resource_status', mock.Mock())
|
||||
def test_share_server_unmanage_wait(self):
|
||||
self.run_command('share-server-unmanage 1234 --wait')
|
||||
|
||||
self.assert_called('POST', '/share-servers/1234/action',
|
||||
body={'unmanage': {'force': False}}, pos=-2)
|
||||
expected_share_server = shell_v2._find_share_server(
|
||||
self.shell.cs, '1234')
|
||||
shell_v2._wait_for_resource_status.assert_called_once_with(
|
||||
self.shell.cs, expected_share_server,
|
||||
resource_type='share_server', expected_status='unmanaged')
|
||||
|
||||
@mock.patch.object(shell_v2, '_wait_for_resource_status', mock.Mock())
|
||||
def test_share_server_unmanage_wait_with_force(self):
|
||||
self.run_command('share-server-unmanage 1234 --force --wait')
|
||||
|
||||
self.assert_called('POST', '/share-servers/1234/action',
|
||||
body={'unmanage': {'force': True}}, pos=-2)
|
||||
expected_share_server = shell_v2._find_share_server(
|
||||
self.shell.cs, '1234')
|
||||
shell_v2._wait_for_resource_status.assert_called_once_with(
|
||||
self.shell.cs, expected_share_server,
|
||||
resource_type='share_server', expected_status='unmanaged')
|
||||
|
||||
@ddt.data({'cmd_args': '--driver_options opt1=opt1 opt2=opt2',
|
||||
'valid_params': {
|
||||
'driver_options': {'opt1': 'opt1', 'opt2': 'opt2'},
|
||||
|
||||
@@ -1766,12 +1766,22 @@ 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(s) to be unmanaged')
|
||||
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:
|
||||
share_server_ref = _find_share_server(cs, server)
|
||||
_wait_for_resource_status(
|
||||
cs, share_server_ref, resource_type='share_server',
|
||||
expected_status='unmanaged')
|
||||
except Exception as e:
|
||||
failure_count += 1
|
||||
print("Unmanage for share server %s failed: %s" % (server, e),
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
The command "manila share-server-unmanage" now accepts an optional
|
||||
"--wait" flag that allows users to let the client poll for the
|
||||
completion of the operation.
|
||||
Reference in New Issue
Block a user