Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Example text and some features for slcli block volume-cancel, slcli block volume-duplicate command
  • Loading branch information
J Jayasilan authored and J Jayasilan committed Aug 4, 2023
1 parent e5b143f commit ca37722
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
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)

0 comments on commit ca37722

Please sign in to comment.