Browse Source

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
changes/37/770537/7
yara 1 month ago
committed by paulali
parent
commit
153aa61146
3 changed files with 71 additions and 8 deletions
  1. +42
    -8
      manilaclient/tests/unit/v2/test_shell.py
  2. +20
    -0
      manilaclient/v2/shell.py
  3. +9
    -0
      releasenotes/notes/bug-1898308-add-wait-to-share-extend-shrink-c9cc413c50d9832a.yaml

+ 42
- 8
manilaclient/tests/unit/v2/test_shell.py View File

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


+ 20
- 0
manilaclient/v2/shell.py View File

@ -4268,11 +4268,21 @@ def do_pool_list(cs, args):
metavar='<new_size>',
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='<share>',
help='Name or ID of share to shrink.')
@ -4280,11 +4290,21 @@ def do_extend(cs, args):
metavar='<new_size>',
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)
##############################################################################
#


+ 9
- 0
releasenotes/notes/bug-1898308-add-wait-to-share-extend-shrink-c9cc413c50d9832a.yaml 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.

Loading…
Cancel
Save