diff --git a/manilaclient/tests/unit/v2/test_shell.py b/manilaclient/tests/unit/v2/test_shell.py index 58e1dc65d..41343d9be 100644 --- a/manilaclient/tests/unit/v2/test_shell.py +++ b/manilaclient/tests/unit/v2/test_shell.py @@ -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'}, diff --git a/manilaclient/v2/shell.py b/manilaclient/v2/shell.py index b83884c16..999552c98 100644 --- a/manilaclient/v2/shell.py +++ b/manilaclient/v2/shell.py @@ -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), diff --git a/releasenotes/notes/add-wait-flag-share-server-unmanage-819dd42abc2a4d2b.yaml b/releasenotes/notes/add-wait-flag-share-server-unmanage-819dd42abc2a4d2b.yaml new file mode 100644 index 000000000..8d5543bca --- /dev/null +++ b/releasenotes/notes/add-wait-flag-share-server-unmanage-819dd42abc2a4d2b.yaml @@ -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.