Skip to content

Commit 47d14d0

Browse files
caberoscaberos
authored andcommitted
fix team code review comments
1 parent b97540b commit 47d14d0

File tree

5 files changed

+39
-34
lines changed

5 files changed

+39
-34
lines changed

SoftLayer/CLI/vlan/cancel.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from SoftLayer.CLI import environment
88
from SoftLayer.CLI import exceptions
99
from SoftLayer.CLI import formatting
10-
from SoftLayer.managers.billing import BillingManager
1110

1211

1312
@click.command()
@@ -17,14 +16,20 @@ def cli(env, identifier):
1716
"""Cancel network vlan."""
1817

1918
mgr = SoftLayer.NetworkManager(env.client)
20-
billing = BillingManager(env.client)
19+
2120
if not (env.skip_confirmations or formatting.no_going_back(identifier)):
2221
raise exceptions.CLIAbort('Aborted')
2322

23+
reasons = mgr.get_cancel_failure_reasons(identifier)
24+
if len(reasons) > 0:
25+
raise exceptions.CLIAbort(reasons)
2426
item = mgr.get_vlan(identifier).get('billingItem')
2527
if item:
26-
billing.cancel_item(item.get('id'), 'cancel by cli command')
27-
env.fout('Cancel Successfully')
28+
mgr.cancel_item(item.get('id'),
29+
True,
30+
'Cancel by cli command',
31+
'Cancel by cli command')
2832
else:
29-
res = mgr.get_cancel_failure_reasons(identifier)
30-
raise exceptions.ArgumentError(res)
33+
raise exceptions.CLIAbort(
34+
"VLAN is an automatically assigned and free of charge VLAN,"
35+
" it will automatically be removed from your account when it is empty")

SoftLayer/fixtures/SoftLayer_Network_Vlan.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,8 @@
2121
getList = [getObject]
2222

2323
cancel = True
24+
25+
getCancelFailureReasons = [
26+
"1 bare metal server(s) still on the VLAN ",
27+
"1 virtual guest(s) still on the VLAN "
28+
]

SoftLayer/managers/billing.py

Lines changed: 0 additions & 27 deletions
This file was deleted.

SoftLayer/managers/network.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,8 +755,22 @@ def set_subnet_ipddress_note(self, identifier, note):
755755
return result
756756

757757
def get_cancel_failure_reasons(self, identifier):
758-
"""get the reasons by cannot cancel the VLAN
758+
"""get the reasons why we cannot cancel the VLAN.
759759
760760
:param integer identifier: the instance ID
761761
"""
762762
return self.vlan.getCancelFailureReasons(id=identifier)
763+
764+
def cancel_item(self, identifier, cancel_immediately,
765+
reason_cancel, customer_note):
766+
"""Cancel a billing item immediately, deleting all its data.
767+
768+
:param integer identifier: the instance ID to cancel
769+
:param string reason_cancel: reason cancel
770+
"""
771+
return self.client.call('SoftLayer_Billing_Item', 'cancelItem',
772+
True,
773+
cancel_immediately,
774+
reason_cancel,
775+
customer_note,
776+
id=identifier)

tests/CLI/modules/vlan_tests.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,17 @@ def test_vlan_list(self):
103103
@mock.patch('SoftLayer.CLI.formatting.no_going_back')
104104
def test_vlan_cancel(self, confirm_mock):
105105
confirm_mock.return_value = True
106+
mock = self.set_mock('SoftLayer_Network_Vlan', 'getCancelFailureReasons')
107+
mock.return_value = []
106108
result = self.run_command(['vlan', 'cancel', '1234'])
107109
self.assert_no_fail(result)
108110

111+
@mock.patch('SoftLayer.CLI.formatting.no_going_back')
112+
def test_vlan_cancel_error(self, confirm_mock):
113+
confirm_mock.return_value = True
114+
result = self.run_command(['vlan', 'cancel', '1234'])
115+
self.assertTrue(result.exit_code, 2)
116+
109117
@mock.patch('SoftLayer.CLI.formatting.no_going_back')
110118
def test_vlan_cancel_fail(self, confirm_mock):
111119
confirm_mock.return_value = False

0 commit comments

Comments
 (0)