Merge "Added "--wait" option for creating/deleting a share group snapshot"
This commit is contained in:
commit
e58355919c
@ -3143,6 +3143,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
|
||||||
@ -3151,6 +3152,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):
|
||||||
@ -3252,6 +3268,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
|
||||||
@ -3259,6 +3276,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):
|
||||||
|
@ -6042,12 +6042,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)
|
||||||
|
|
||||||
|
|
||||||
@ -6248,6 +6257,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."""
|
||||||
@ -6260,6 +6274,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