Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example text and some features for slcli block volume-cancel, slcli block volume-duplicate command #2015 #2061

Merged
merged 1 commit into from Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 12 additions & 4 deletions SoftLayer/CLI/block/cancel.py
Expand Up @@ -16,14 +16,22 @@
is_flag=True,
help="Cancels the block storage volume immediately instead "
"of on the billing anniversary")
@click.option('--force', default=False, is_flag=True, help="Force cancel block volume without confirmation")
@environment.pass_env
def cli(env, volume_id, reason, immediate):
"""Cancel an existing block storage volume."""
def cli(env, volume_id, reason, immediate, force):
"""Cancel an existing block storage volume.

Example::
slcli block volume-cancel 12345678 --immediate -f
This command cancels volume with ID 12345678 immediately and without asking for confirmation.
"""

block_storage_manager = SoftLayer.BlockStorageManager(env.client)

if not (env.skip_confirmations or formatting.no_going_back(volume_id)):
raise exceptions.CLIAbort('Aborted')
if not force:
if not (env.skip_confirmations or
formatting.confirm(f"This will cancel the block volume: {volume_id} and cannot be undone. Continue?")):
raise exceptions.CLIAbort('Aborted')

cancelled = block_storage_manager.cancel_block_volume(volume_id,
reason, immediate)
Expand Down
8 changes: 7 additions & 1 deletion SoftLayer/CLI/block/duplicate.py
Expand Up @@ -64,7 +64,13 @@
def cli(env, origin_volume_id, origin_snapshot_id, duplicate_size,
duplicate_iops, duplicate_tier, duplicate_snapshot_size, billing,
dependent_duplicate):
"""Order a duplicate block storage volume."""
"""Order a duplicate block storage volume.

Example::
slcli block volume-duplicate 12345678
This command shows order a new volume by duplicating the volume with ID 12345678.
"""

block_manager = SoftLayer.BlockStorageManager(env.client)

hourly_billing_flag = False
Expand Down
15 changes: 15 additions & 0 deletions tests/CLI/modules/block_tests.py
Expand Up @@ -978,3 +978,18 @@ def test_block_duplicate_covert_status(self):

self.assert_no_fail(result)
self.assert_called_with('SoftLayer_Network_Storage', 'getDuplicateConversionStatus')

@mock.patch('SoftLayer.CLI.formatting.confirm')
def test_cancel_block_volume_force(self, confirm_mock):
confirm_mock.return_value = False
result = self.run_command(['block', 'volume-cancel', '12345678', '--immediate', '--force'])
self.assert_no_fail(result)
self.assertEqual('Block volume with id 12345678 has been marked'
' for immediate cancellation\n', result.output)

@mock.patch('SoftLayer.CLI.formatting.confirm')
def test_cancel_block_volume_no_force(self, confirm_mock):
confirm_mock.return_value = False
result = self.run_command(['block', 'volume-cancel', '12345678'])
self.assertEqual(2, result.exit_code)
self.assertEqual('Aborted', result.exception.message)