From 153aa61146abcce593ddd82231de6ce2ec88f211 Mon Sep 17 00:00:00 2001 From: yara Date: Wed, 13 Jan 2021 04:29:27 +0000 Subject: [PATCH] Add a waiter to share extend/shrink This option enables "extend" and "shrink" commands to wait until the action has completed. Change-Id: I41fc08f29149cf12abbf7ca75fd30f897061bd05 Partially-implements: bp add-wait-to-async-commands Closes-Bug: #1898308 --- manilaclient/tests/unit/v2/test_shell.py | 50 ++++++++++++++++--- manilaclient/v2/shell.py | 20 ++++++++ ...-share-extend-shrink-c9cc413c50d9832a.yaml | 9 ++++ 3 files changed, 71 insertions(+), 8 deletions(-) create mode 100644 releasenotes/notes/bug-1898308-add-wait-to-share-extend-shrink-c9cc413c50d9832a.yaml diff --git a/manilaclient/tests/unit/v2/test_shell.py b/manilaclient/tests/unit/v2/test_shell.py index 7e60dfa3f..018ce0540 100644 --- a/manilaclient/tests/unit/v2/test_shell.py +++ b/manilaclient/tests/unit/v2/test_shell.py @@ -1467,20 +1467,54 @@ class ShellTest(test_utils.TestCase): args = Arguments(metadata=input[0]) self.assertEqual(shell_v2._extract_metadata(args), input[1]) - def test_extend(self): - self.run_command('extend 1234 77') - expected = {'extend': {'new_size': 77}} - self.assert_called('POST', '/shares/1234/action', body=expected) + @ddt.data('--wait', '') + def test_extend_with_wait_option(self, wait_option): + share_to_extend = shares.Share('fake', {'id': '1234', + 'status': 'extending'}) + already_extended_share = shares.Share('fake', {'id': '1234', + 'status': 'available'}) + fake_shares = [share_to_extend] * 3 + fake_shares.append(already_extended_share) + self.mock_object(shell_v2, '_find_share', + mock.Mock(side_effect=fake_shares)) + expected_extend_body = {'extend': {'new_size': 77}} + self.run_command('extend 1234 77 %s' % wait_option) + self.assert_called_anytime('POST', '/shares/1234/action', + body=expected_extend_body, + clear_callstack=False) + if wait_option: + shell_v2._find_share.assert_has_calls( + [mock.call(self.shell.cs, '1234')] * 4) + else: + shell_v2._find_share.assert_called_with( + self.shell.cs, '1234') def test_reset_state(self): self.run_command('reset-state 1234') expected = {'reset_status': {'status': 'available'}} self.assert_called('POST', '/shares/1234/action', body=expected) - def test_shrink(self): - self.run_command('shrink 1234 77') - expected = {'shrink': {'new_size': 77}} - self.assert_called('POST', '/shares/1234/action', body=expected) + @ddt.data('--wait', '') + def test_shrink_with_wait_option(self, wait_option): + share_to_shrink = shares.Share('fake', {'id': '1234', + 'status': 'shrinking'}) + already_shrank_share = shares.Share('fake', {'id': '1234', + 'status': 'available'}) + fake_shares = [share_to_shrink] * 3 + fake_shares.append(already_shrank_share) + self.mock_object(shell_v2, '_find_share', + mock.Mock(side_effect=fake_shares)) + expected_shrink_body = {'shrink': {'new_size': 77}} + self.run_command('shrink 1234 77 %s' % wait_option) + self.assert_called_anytime('POST', '/shares/1234/action', + body=expected_shrink_body, + clear_callstack=False) + if wait_option: + shell_v2._find_share.assert_has_calls( + [mock.call(self.shell.cs, '1234')] * 4) + else: + shell_v2._find_share.assert_called_with( + self.shell.cs, '1234') def test_reset_state_with_flag(self): self.run_command('reset-state --state error 1234') diff --git a/manilaclient/v2/shell.py b/manilaclient/v2/shell.py index 3b778fa1c..6de83bd1d 100644 --- a/manilaclient/v2/shell.py +++ b/manilaclient/v2/shell.py @@ -4268,11 +4268,21 @@ def do_pool_list(cs, args): metavar='', type=int, help='New size of share, in GiBs.') +@cliutils.arg( + '--wait', + action='store_true', + help='Wait for share extension') +@cliutils.service_type('sharev2') def do_extend(cs, args): """Increases the size of an existing share.""" share = _find_share(cs, args.share) cs.shares.extend(share, args.new_size) + if args.wait: + share = _wait_for_share_status(cs, share) + else: + share = _find_share(cs, args.share) + _print_share(cs, share) @cliutils.arg('share', metavar='', help='Name or ID of share to shrink.') @@ -4280,11 +4290,21 @@ def do_extend(cs, args): metavar='', type=int, help='New size of share, in GiBs.') +@cliutils.arg( + '--wait', + action='store_true', + help='Wait for share shrinkage') +@cliutils.service_type('sharev2') def do_shrink(cs, args): """Decreases the size of an existing share.""" share = _find_share(cs, args.share) cs.shares.shrink(share, args.new_size) + if args.wait: + share = _wait_for_share_status(cs, share) + else: + share = _find_share(cs, args.share) + _print_share(cs, share) ############################################################################## # diff --git a/releasenotes/notes/bug-1898308-add-wait-to-share-extend-shrink-c9cc413c50d9832a.yaml b/releasenotes/notes/bug-1898308-add-wait-to-share-extend-shrink-c9cc413c50d9832a.yaml new file mode 100644 index 000000000..cceeaa6ae --- /dev/null +++ b/releasenotes/notes/bug-1898308-add-wait-to-share-extend-shrink-c9cc413c50d9832a.yaml @@ -0,0 +1,9 @@ +--- +features: + - | + The commands "manila extend" and "manila shrink" now + accept an optional "--wait" option that allows users + to let the client poll for the completion of the + operation. + +