Add --wait flag to the mange share server operation

This patch set adds the --wait flag to the share server
manage operation. This will make the CLI to wait for the
operation to be completed before returning to the prompt.

Updated test_share_server_manage to be test_share_server_
manage_wait and included the waiter flag.

Change-Id: I88a0a9e38b176cb5f241a4ac7997f6af92f9f38b
This commit is contained in:
archanaserver 2021-08-10 10:40:46 +00:00 committed by Victoria Martinez de la Cruz
parent 0f9ba9a7d3
commit 13ec1d3f44
3 changed files with 40 additions and 5 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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.