From 376429ec1d848dcb1e49c63370ab07be89dec2b4 Mon Sep 17 00:00:00 2001 From: archanaserver Date: Thu, 8 Jul 2021 09:06:27 +0000 Subject: [PATCH] Add --wait flag to the create share group operation This patch set adds the --wait flag to the share group operation. This will make the CLI to wait for the operation to be completed before returning to the prompt. Updated test_share_group_create to be test_share_group_create_wait and included the waiter flag Partial-Bug: #1898318 Change-Id: Id3e163de48bdd918ae55438d812187ba4d5461c9 --- manilaclient/tests/unit/v2/test_shell.py | 60 ++++++++++++++----- manilaclient/v2/shell.py | 15 ++++- ...aree-group-operation-cd8310b241d377b0.yaml | 6 ++ 3 files changed, 65 insertions(+), 16 deletions(-) create mode 100644 releasenotes/notes/bug-1898318-add-wait-flag-to-create-sharee-group-operation-cd8310b241d377b0.yaml diff --git a/manilaclient/tests/unit/v2/test_shell.py b/manilaclient/tests/unit/v2/test_shell.py index 583e9b5d5..811a75373 100644 --- a/manilaclient/tests/unit/v2/test_shell.py +++ b/manilaclient/tests/unit/v2/test_shell.py @@ -34,6 +34,7 @@ from manilaclient.tests.unit.v2 import fakes from manilaclient import utils from manilaclient.v2 import messages from manilaclient.v2 import security_services +from manilaclient.v2 import share_group_types from manilaclient.v2 import share_groups from manilaclient.v2 import share_instances from manilaclient.v2 import share_network_subnets @@ -2663,29 +2664,52 @@ class ShellTest(test_utils.TestCase): shell_v2._find_share_group.assert_has_calls( [mock.call(self.shell.cs, "1234")]) - def test_share_group_create(self): - fake_share_type_1 = type('FakeShareType1', (object,), {'id': '1234'}) - fake_share_type_2 = type('FakeShareType2', (object,), {'id': '5678'}) + def test_share_group_create_wait(self): + fake_manager = mock.Mock() + fake_share_type1 = share_types.ShareType( + fake_manager, {'name': '1234', 'uuid': '1234'}) + fake_share_type2 = share_types.ShareType( + fake_manager, {'name': '5678', 'uuid': '5678'}) + fake_share_group_type = share_group_types.ShareGroupType( + fake_manager, {'name': 'fake_sg', 'uuid': '2345'}) + fake_share_network = share_networks.ShareNetwork( + fake_manager, {'id': '3456', 'uuid': '3456'}) + fake_share_group = share_groups.ShareGroup( + fake_manager, {'id': 'fake-sg-id', 'name': 'fake_sg'}) + self.mock_object( shell_v2, '_find_share_type', - mock.Mock(side_effect=[fake_share_type_1, fake_share_type_2])) - fake_share_group_type = type( - 'FakeShareGroupType', (object,), {'id': '2345'}) + mock.Mock(side_effect=[fake_share_type1, fake_share_type2])) self.mock_object( shell_v2, '_find_share_group_type', - mock.Mock(return_value=fake_share_group_type)) - fake_share_network = type( - 'FakeShareNetwork', (object,), {'id': '3456'}) + mock.Mock(side_effect=[fake_share_group_type])) self.mock_object( shell_v2, '_find_share_network', - mock.Mock(return_value=fake_share_network)) + mock.Mock(side_effect=[fake_share_network])) + self.mock_object( + shell_v2, '_wait_for_resource_status', + mock.Mock(side_effect=[fake_share_group]) + ) self.run_command( - 'share-group-create --name fake_sg ' - '--description my_group --share-types 1234,5678 ' - '--share-group-type fake_sg_type ' - '--share-network fake_share_network ' - '--availability-zone fake_az') + 'share-group-create --name fake_sg --description my_group ' + '--share-types 1234,5678 ' + '--share-group-type fake_sg ' + '--share-network 3456 ' + '--availability-zone fake_az --wait') + + shell_v2._find_share_type.assert_has_calls([ + mock.call(self.shell.cs, '1234'), + mock.call(self.shell.cs, '5678') + ]) + + shell_v2._find_share_group_type.assert_has_calls([ + mock.call(self.shell.cs, 'fake_sg') + ]) + + shell_v2._find_share_network.assert_has_calls([ + mock.call(self.shell.cs, '3456') + ]) expected = { 'share_group': { @@ -2699,6 +2723,12 @@ class ShellTest(test_utils.TestCase): } self.assert_called('POST', '/share-groups', body=expected) + shell_v2._wait_for_resource_status.assert_has_calls([ + mock.call(self.shell.cs, fake_share_group, + resource_type='share_group', + expected_status='available') + ]) + @ddt.data( '--name fake_name --availability-zone fake_az', '--description my_fake_description --name fake_name', diff --git a/manilaclient/v2/shell.py b/manilaclient/v2/shell.py index f0b62dd71..2ad2db9b4 100644 --- a/manilaclient/v2/shell.py +++ b/manilaclient/v2/shell.py @@ -5286,10 +5286,14 @@ def do_share_group_type_access_remove(cs, args): metavar='', help='Optional availability zone in which group should be created. ' '(Default=None)') +@cliutils.arg( + '--wait', + action='store_true', + default=False, + help='Wait for share group to create') @cliutils.service_type('sharev2') def do_share_group_create(cs, args): """Creates a new share group.""" - share_types = [] if args.share_types: s_types = args.share_types.split(',') @@ -5321,6 +5325,15 @@ def do_share_group_create(cs, args): } share_group = cs.share_groups.create(**kwargs) + + if args.wait: + try: + share_group = _wait_for_resource_status( + cs, share_group, resource_type='share_group', + expected_status='available') + except exceptions.CommandError as e: + print(e, file=sys.stderr) + _print_share_group(cs, share_group) diff --git a/releasenotes/notes/bug-1898318-add-wait-flag-to-create-sharee-group-operation-cd8310b241d377b0.yaml b/releasenotes/notes/bug-1898318-add-wait-flag-to-create-sharee-group-operation-cd8310b241d377b0.yaml new file mode 100644 index 000000000..b6dfa2527 --- /dev/null +++ b/releasenotes/notes/bug-1898318-add-wait-flag-to-create-sharee-group-operation-cd8310b241d377b0.yaml @@ -0,0 +1,6 @@ +--- +features: + - | + The command "manila share-group-create" now accepts an optional + "--wait" that allows users to let the client poll for the + completion of the operation.