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
This commit is contained in:
yara 2021-01-13 04:29:27 +00:00 committed by paulali
parent bf3e7cb716
commit 153aa61146
3 changed files with 71 additions and 8 deletions

View File

@ -1467,20 +1467,54 @@ class ShellTest(test_utils.TestCase):
args = Arguments(metadata=input[0]) args = Arguments(metadata=input[0])
self.assertEqual(shell_v2._extract_metadata(args), input[1]) self.assertEqual(shell_v2._extract_metadata(args), input[1])
def test_extend(self): @ddt.data('--wait', '')
self.run_command('extend 1234 77') def test_extend_with_wait_option(self, wait_option):
expected = {'extend': {'new_size': 77}} share_to_extend = shares.Share('fake', {'id': '1234',
self.assert_called('POST', '/shares/1234/action', body=expected) '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): def test_reset_state(self):
self.run_command('reset-state 1234') self.run_command('reset-state 1234')
expected = {'reset_status': {'status': 'available'}} expected = {'reset_status': {'status': 'available'}}
self.assert_called('POST', '/shares/1234/action', body=expected) self.assert_called('POST', '/shares/1234/action', body=expected)
def test_shrink(self): @ddt.data('--wait', '')
self.run_command('shrink 1234 77') def test_shrink_with_wait_option(self, wait_option):
expected = {'shrink': {'new_size': 77}} share_to_shrink = shares.Share('fake', {'id': '1234',
self.assert_called('POST', '/shares/1234/action', body=expected) '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): def test_reset_state_with_flag(self):
self.run_command('reset-state --state error 1234') self.run_command('reset-state --state error 1234')

View File

@ -4268,11 +4268,21 @@ def do_pool_list(cs, args):
metavar='<new_size>', metavar='<new_size>',
type=int, type=int,
help='New size of share, in GiBs.') 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): def do_extend(cs, args):
"""Increases the size of an existing share.""" """Increases the size of an existing share."""
share = _find_share(cs, args.share) share = _find_share(cs, args.share)
cs.shares.extend(share, args.new_size) 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='<share>', @cliutils.arg('share', metavar='<share>',
help='Name or ID of share to shrink.') help='Name or ID of share to shrink.')
@ -4280,11 +4290,21 @@ def do_extend(cs, args):
metavar='<new_size>', metavar='<new_size>',
type=int, type=int,
help='New size of share, in GiBs.') 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): def do_shrink(cs, args):
"""Decreases the size of an existing share.""" """Decreases the size of an existing share."""
share = _find_share(cs, args.share) share = _find_share(cs, args.share)
cs.shares.shrink(share, args.new_size) 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)
############################################################################## ##############################################################################
# #

View File

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