Added "--wait" option for creating/deleting a share group snapshot
1) Creating a share group snapshot $ manila share-group-snapshot-create --name share-group-snap-1 --wait <CLI waits on the share group snapshot to become available before providing group snapshot details> 2) Deleting a share group $ manila share-group-snapshot-delete share-group-snap-1 --wait <CLI waits on the share group snapshot to be deleted before returning to the prompt> Closes-Bug: #1898319 Change-Id: Id8e4a7c4808152a41b35ec2e6c09f1d439cf14e2
This commit is contained in:
parent
3103b8c56a
commit
9a29099b31
@ -3066,6 +3066,7 @@ class ShellTest(test_utils.TestCase):
|
|||||||
'--description my_fake_description --name fake_name fake-sg-id',
|
'--description my_fake_description --name fake_name fake-sg-id',
|
||||||
)
|
)
|
||||||
@mock.patch.object(shell_v2, '_find_share_group', mock.Mock())
|
@mock.patch.object(shell_v2, '_find_share_group', mock.Mock())
|
||||||
|
@mock.patch.object(shell_v2, '_wait_for_resource_status', mock.Mock())
|
||||||
def test_share_group_snapshot_create(self, data):
|
def test_share_group_snapshot_create(self, data):
|
||||||
fake_sg = type('FakeShareGroup', (object,), {'id': '1234'})
|
fake_sg = type('FakeShareGroup', (object,), {'id': '1234'})
|
||||||
shell_v2._find_share_group.return_value = fake_sg
|
shell_v2._find_share_group.return_value = fake_sg
|
||||||
@ -3074,6 +3075,21 @@ class ShellTest(test_utils.TestCase):
|
|||||||
|
|
||||||
shell_v2._find_share_group.assert_called_with(mock.ANY, 'fake-sg-id')
|
shell_v2._find_share_group.assert_called_with(mock.ANY, 'fake-sg-id')
|
||||||
self.assert_called('POST', '/share-group-snapshots')
|
self.assert_called('POST', '/share-group-snapshots')
|
||||||
|
self.assertEqual(0, shell_v2._wait_for_resource_status.call_count)
|
||||||
|
|
||||||
|
@mock.patch.object(shell_v2, '_find_share_group', mock.Mock())
|
||||||
|
@mock.patch.object(shell_v2, '_wait_for_resource_status', mock.Mock())
|
||||||
|
def test_share_group_snapshot_create_with_wait(self):
|
||||||
|
fake_sg = type('FakeShareGroup', (object,), {'id': '1234'})
|
||||||
|
shell_v2._find_share_group.return_value = fake_sg
|
||||||
|
self.run_command('share-group-snapshot-create fake-sg-id --wait')
|
||||||
|
|
||||||
|
shell_v2._find_share_group.assert_called_with(mock.ANY, 'fake-sg-id')
|
||||||
|
self.assert_called('POST', '/share-group-snapshots')
|
||||||
|
# _wait_for_resource_status should be triggered once
|
||||||
|
shell_v2._wait_for_resource_status.assert_called_once_with(
|
||||||
|
self.shell.cs, mock.ANY, resource_type='share_group_snapshot',
|
||||||
|
expected_status='available')
|
||||||
|
|
||||||
@mock.patch.object(cliutils, 'print_list', mock.Mock())
|
@mock.patch.object(cliutils, 'print_list', mock.Mock())
|
||||||
def test_share_group_snapshot_list(self):
|
def test_share_group_snapshot_list(self):
|
||||||
@ -3175,6 +3191,7 @@ class ShellTest(test_utils.TestCase):
|
|||||||
self.run_command, 'share-group-snapshot-update 1234')
|
self.run_command, 'share-group-snapshot-update 1234')
|
||||||
|
|
||||||
@mock.patch.object(shell_v2, '_find_share_group_snapshot', mock.Mock())
|
@mock.patch.object(shell_v2, '_find_share_group_snapshot', mock.Mock())
|
||||||
|
@mock.patch.object(shell_v2, '_wait_for_resource_status', mock.Mock())
|
||||||
def test_share_group_snapshot_delete(self):
|
def test_share_group_snapshot_delete(self):
|
||||||
fake_sg_snapshot = type('FakeSGSnapshot', (object,), {'id': '1234'})
|
fake_sg_snapshot = type('FakeSGSnapshot', (object,), {'id': '1234'})
|
||||||
shell_v2._find_share_group_snapshot.return_value = fake_sg_snapshot
|
shell_v2._find_share_group_snapshot.return_value = fake_sg_snapshot
|
||||||
@ -3182,6 +3199,22 @@ class ShellTest(test_utils.TestCase):
|
|||||||
self.run_command('share-group-snapshot-delete fake-group-snapshot')
|
self.run_command('share-group-snapshot-delete fake-group-snapshot')
|
||||||
|
|
||||||
self.assert_called('DELETE', '/share-group-snapshots/1234')
|
self.assert_called('DELETE', '/share-group-snapshots/1234')
|
||||||
|
self.assertEqual(0, shell_v2._wait_for_resource_status.call_count)
|
||||||
|
|
||||||
|
@mock.patch.object(shell_v2, '_find_share_group_snapshot', mock.Mock())
|
||||||
|
@mock.patch.object(shell_v2, '_wait_for_resource_status', mock.Mock())
|
||||||
|
def test_share_group_snapshot_delete_with_wait(self):
|
||||||
|
fake_sg_snapshot = type('FakeSGSnapshot', (object,), {'id': '1234'})
|
||||||
|
shell_v2._find_share_group_snapshot.return_value = fake_sg_snapshot
|
||||||
|
|
||||||
|
self.run_command('share-group-snapshot-delete fake-group-snapshot'
|
||||||
|
' --wait')
|
||||||
|
|
||||||
|
self.assert_called('DELETE', '/share-group-snapshots/1234')
|
||||||
|
# _wait_for_resource_status should be triggered once
|
||||||
|
shell_v2._wait_for_resource_status.assert_called_once_with(
|
||||||
|
self.shell.cs, mock.ANY, resource_type='share_group_snapshot',
|
||||||
|
expected_status='deleted')
|
||||||
|
|
||||||
@mock.patch.object(shell_v2, '_find_share_group_snapshot', mock.Mock())
|
@mock.patch.object(shell_v2, '_find_share_group_snapshot', mock.Mock())
|
||||||
def test_share_group_snapshot_delete_force(self):
|
def test_share_group_snapshot_delete_force(self):
|
||||||
|
@ -6039,12 +6039,21 @@ def do_share_group_reset_state(cs, args):
|
|||||||
metavar='<description>',
|
metavar='<description>',
|
||||||
help='Optional share group snapshot description. (Default=None)',
|
help='Optional share group snapshot description. (Default=None)',
|
||||||
default=None)
|
default=None)
|
||||||
|
@cliutils.arg(
|
||||||
|
'--wait',
|
||||||
|
action='store_true',
|
||||||
|
default=False,
|
||||||
|
help='Wait for share group snapshot to be created')
|
||||||
@cliutils.service_type('sharev2')
|
@cliutils.service_type('sharev2')
|
||||||
def do_share_group_snapshot_create(cs, args):
|
def do_share_group_snapshot_create(cs, args):
|
||||||
"""Creates a new share group snapshot."""
|
"""Creates a new share group snapshot."""
|
||||||
kwargs = {'name': args.name, 'description': args.description}
|
kwargs = {'name': args.name, 'description': args.description}
|
||||||
share_group = _find_share_group(cs, args.share_group)
|
share_group = _find_share_group(cs, args.share_group)
|
||||||
sg_snapshot = cs.share_group_snapshots.create(share_group.id, **kwargs)
|
sg_snapshot = cs.share_group_snapshots.create(share_group.id, **kwargs)
|
||||||
|
if args.wait:
|
||||||
|
_wait_for_resource_status(
|
||||||
|
cs, sg_snapshot, resource_type='share_group_snapshot',
|
||||||
|
expected_status='available')
|
||||||
_print_share_group_snapshot(cs, sg_snapshot)
|
_print_share_group_snapshot(cs, sg_snapshot)
|
||||||
|
|
||||||
|
|
||||||
@ -6245,6 +6254,11 @@ def do_share_group_snapshot_update(cs, args):
|
|||||||
default=False,
|
default=False,
|
||||||
help='Attempt to force delete the share group snapshot(s) (Default=False)'
|
help='Attempt to force delete the share group snapshot(s) (Default=False)'
|
||||||
' (Admin only).')
|
' (Admin only).')
|
||||||
|
@cliutils.arg(
|
||||||
|
'--wait',
|
||||||
|
action='store_true',
|
||||||
|
default=False,
|
||||||
|
help='Wait for share group snapshot to be deleted')
|
||||||
@cliutils.service_type('sharev2')
|
@cliutils.service_type('sharev2')
|
||||||
def do_share_group_snapshot_delete(cs, args):
|
def do_share_group_snapshot_delete(cs, args):
|
||||||
"""Remove one or more share group snapshots."""
|
"""Remove one or more share group snapshots."""
|
||||||
@ -6257,6 +6271,10 @@ def do_share_group_snapshot_delete(cs, args):
|
|||||||
try:
|
try:
|
||||||
sg_snapshot_ref = _find_share_group_snapshot(cs, sg_snapshot)
|
sg_snapshot_ref = _find_share_group_snapshot(cs, sg_snapshot)
|
||||||
cs.share_group_snapshots.delete(sg_snapshot_ref, **kwargs)
|
cs.share_group_snapshots.delete(sg_snapshot_ref, **kwargs)
|
||||||
|
if args.wait:
|
||||||
|
_wait_for_resource_status(
|
||||||
|
cs, sg_snapshot, resource_type='share_group_snapshot',
|
||||||
|
expected_status='deleted')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
failure_count += 1
|
failure_count += 1
|
||||||
print("Delete for share group snapshot %s failed: %s" % (
|
print("Delete for share group snapshot %s failed: %s" % (
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
features:
|
||||||
|
- |
|
||||||
|
The commands "share-group-snapshot-create" and
|
||||||
|
"share-group-snapshot-delete" now accept an optional "--wait"
|
||||||
|
option that allows users to let the client poll for the completion
|
||||||
|
of the operation.
|
Loading…
Reference in New Issue
Block a user