Skip to content

Commit 259e264

Browse files
Merge pull request #2077 from ramkishor-ch/issue_2035
Added force flag and unit test cases in slcli hardware cancel, slcli hardware create
2 parents f982312 + 6df4ccb commit 259e264

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

SoftLayer/CLI/hardware/cancel.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
help="An optional comment to add to the cancellation ticket")
2121
@click.option('--reason',
2222
help="An optional cancellation reason. See cancel-reasons for a list of available options")
23+
@click.option('--force', default=False, is_flag=True, help="Force modify")
2324
@environment.pass_env
24-
def cli(env, identifier, immediate, comment, reason):
25+
def cli(env, identifier, immediate, comment, reason, force):
2526
"""Cancel a dedicated server."""
2627

2728
mgr = SoftLayer.HardwareManager(env.client)
@@ -30,4 +31,9 @@ def cli(env, identifier, immediate, comment, reason):
3031
if not (env.skip_confirmations or formatting.no_going_back(hw_id)):
3132
raise exceptions.CLIAbort('Aborted')
3233

34+
if not force:
35+
if not (env.skip_confirmations or
36+
formatting.confirm("This action will incur charges on your account. Continue?")):
37+
raise exceptions.CLIAbort('Aborted')
38+
3339
mgr.cancel_hardware(hw_id, reason, comment, immediate)

SoftLayer/CLI/hardware/create.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@
3737
help="The ID of the private ROUTER on which you want the virtual server placed")
3838
@helpers.multi_option('--key', '-k', help="SSH keys to add to the root user")
3939
@helpers.multi_option('--extra', '-e', help="Extra option Key Names")
40+
@click.option('--force', default=False, is_flag=True, help="Force modify")
4041
@environment.pass_env
41-
def cli(env, **args):
42+
def cli(env, force, **args):
4243
"""Order/create a dedicated server."""
4344
mgr = SoftLayer.HardwareManager(env.client)
4445
network = SoftLayer.NetworkManager(env.client)
@@ -105,9 +106,10 @@ def cli(env, **args):
105106
for pod in pods:
106107
if args.get('datacenter') in pod['name']:
107108
click.secho(f"Warning: Closed soon: {pod['name']}", fg='yellow')
108-
if not (env.skip_confirmations or formatting.confirm(
109-
"This action will incur charges on your account. Continue?")):
110-
raise exceptions.CLIAbort('Aborting dedicated server order.')
109+
if not force:
110+
if not (env.skip_confirmations or formatting.confirm(
111+
"This action will incur charges on your account. Continue?")):
112+
raise exceptions.CLIAbort('Aborting dedicated server order.')
111113

112114
result = mgr.place_order(**order)
113115

tests/CLI/modules/server_tests.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,7 @@ def test_create_hw_no_confirm(self, confirm_mock):
922922
'--network=TEST_NETWORK', '--os=UBUNTU_12_64'])
923923

924924
self.assertEqual(result.exit_code, 2)
925+
self.assertEqual('Aborting dedicated server order.', result.exception.message)
925926

926927
@mock.patch('SoftLayer.CLI.formatting.confirm')
927928
def test_authorize_hw_no_confirm(self, confirm_mock):

tests/managers/hardware_tests.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,3 +1052,11 @@ def test_is_private(self):
10521052
item_public = {'attributes': [{'attributeTypeKeyName': 'NOT_PRIVATE_NETWORK_ONLY'}]}
10531053
self.assertTrue(managers.hardware._is_private_port_speed_item(item_private))
10541054
self.assertFalse(managers.hardware._is_private_port_speed_item(item_public))
1055+
1056+
@mock.patch('SoftLayer.CLI.formatting.confirm')
1057+
def test_hardware_cancel_no_force(self, confirm_mock):
1058+
confirm_mock.return_value = False
1059+
result = self.run_command(['hardware', 'cancel', '102'])
1060+
1061+
self.assertEqual(2, result.exit_code)
1062+
self.assertEqual('Aborted', result.exception.message)

0 commit comments

Comments
 (0)