diff --git a/manilaclient/tests/unit/v2/test_shell.py b/manilaclient/tests/unit/v2/test_shell.py index e6af7b50a..b082cf35b 100644 --- a/manilaclient/tests/unit/v2/test_shell.py +++ b/manilaclient/tests/unit/v2/test_shell.py @@ -838,19 +838,30 @@ class ShellTest(test_utils.TestCase): }, ) @ddt.unpack - def test_share_server_manage(self, driver_args, valid_params, - version=None, network_id=None, - subnet_id=None): + def test_share_server_manage_wait(self, driver_args, valid_params, + version=None, network_id=None, + subnet_id=None): + fake_manager = mock.Mock() subnet_support = (version is None or api_versions.APIVersion(version) >= api_versions.APIVersion('2.51')) network_id = '3456' if network_id is None else network_id - fake_share_network = type( - 'FakeShareNetwork', (object,), {'id': network_id}) + fake_share_network = share_networks.ShareNetwork( + fake_manager, {'id': network_id, 'uuid': network_id}) self.mock_object( shell_v2, '_find_share_network', mock.Mock(return_value=fake_share_network)) + fake_share_server = share_servers.ShareServer( + fake_manager, {'id': 'fake'}) + self.mock_object( + shell_v2, '_find_share_server', + mock.Mock(return_value=fake_share_server)) + + self.mock_object( + shell_v2, '_wait_for_resource_status', + mock.Mock() + ) command = ('share-server-manage ' '%(host)s ' '%(share_network_id)s ' @@ -879,6 +890,11 @@ class ShellTest(test_utils.TestCase): self.assert_called('POST', '/share-servers/manage', body=expected) + shell_v2._wait_for_resource_status.assert_has_calls([ + mock.call(self.shell.cs, fake_share_server, + resource_type='share_server', expected_status='active') + ]) + @ddt.data(constants.STATUS_ERROR, constants.STATUS_ACTIVE, constants.STATUS_MANAGE_ERROR, constants.STATUS_UNMANAGE_ERROR, constants.STATUS_DELETING, constants.STATUS_CREATING) diff --git a/manilaclient/v2/shell.py b/manilaclient/v2/shell.py index db3922719..330cbe8b0 100644 --- a/manilaclient/v2/shell.py +++ b/manilaclient/v2/shell.py @@ -1581,6 +1581,11 @@ def do_manage(cs, args): "The default subnet will be used if it's not specified. Available " "for microversion >= 2.51 (Optional, Default=None).", default=None) +@cliutils.arg( + '--wait', + action='store_true', + default='False', + help='Wait for share server to manage') def do_share_server_manage(cs, args): """Manage share server not handled by Manila (Admin only).""" driver_options = _extract_key_value_options(args, 'driver_options') @@ -1600,6 +1605,14 @@ def do_share_server_manage(cs, args): args.host, args.share_network, args.identifier, **manage_kwargs) + if args.wait: + try: + _wait_for_resource_status( + cs, share_server, resource_type='share_server', + expected_status='active') + except exceptions.CommandError as e: + print(e, file=sys.stderr) + cliutils.print_dict(share_server._info) diff --git a/releasenotes/notes/bug-1898315-add-wait-flag-to-manage-share-server-operation-be6488c2a57536e1.yaml b/releasenotes/notes/bug-1898315-add-wait-flag-to-manage-share-server-operation-be6488c2a57536e1.yaml new file mode 100644 index 000000000..017de1960 --- /dev/null +++ b/releasenotes/notes/bug-1898315-add-wait-flag-to-manage-share-server-operation-be6488c2a57536e1.yaml @@ -0,0 +1,6 @@ +--- +features: + - | + The command "manila share-server-manage" now accepts an optional + "--wait" that allows users to let the client poll for the + completion of the operation.