Skip to content

Commit 7e7b3fe

Browse files
Merge pull request #1160 from camporter/improve_hardware_cancel
Improve hardware cancellation to deal with additional cases
2 parents 0c0d364 + 2e738f7 commit 7e7b3fe

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

SoftLayer/managers/hardware.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import socket
1010
import time
1111

12-
1312
import SoftLayer
1413
from SoftLayer.decoration import retry
1514
from SoftLayer.managers import ordering
@@ -86,14 +85,17 @@ def cancel_hardware(self, hardware_id, reason='unneeded', comment='', immediate=
8685
raise SoftLayer.SoftLayerError("Unable to cancel hardware with running transaction")
8786

8887
if 'billingItem' not in hw_billing:
89-
raise SoftLayer.SoftLayerError("Ticket #%s already exists for this server" %
90-
hw_billing['openCancellationTicket']['id'])
88+
if utils.lookup(hw_billing, 'openCancellationTicket', 'id'):
89+
raise SoftLayer.SoftLayerError("Ticket #%s already exists for this server" %
90+
hw_billing['openCancellationTicket']['id'])
91+
raise SoftLayer.SoftLayerError("Cannot locate billing for the server. "
92+
"The server may already be cancelled.")
9193

9294
billing_id = hw_billing['billingItem']['id']
9395

9496
if immediate and not hw_billing['hourlyBillingFlag']:
95-
LOGGER.warning("Immediate cancelation of montly servers is not guaranteed."
96-
"Please check the cancelation ticket for updates.")
97+
LOGGER.warning("Immediate cancellation of monthly servers is not guaranteed."
98+
"Please check the cancellation ticket for updates.")
9799

98100
result = self.client.call('Billing_Item', 'cancelItem',
99101
False, False, cancel_reason, comment, id=billing_id)

tests/managers/hardware_tests.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,15 @@ def test_cancel_hardware_no_billing_item(self):
291291
6327)
292292
self.assertEqual("Ticket #1234 already exists for this server", str(ex))
293293

294+
def test_cancel_hardwareno_billing_item_or_ticket(self):
295+
mock = self.set_mock('SoftLayer_Hardware_Server', 'getObject')
296+
mock.return_value = {'id': 987}
297+
298+
ex = self.assertRaises(SoftLayer.SoftLayerError,
299+
self.hardware.cancel_hardware,
300+
6327)
301+
self.assertEqual("Cannot locate billing for the server. The server may already be cancelled.", str(ex))
302+
294303
def test_cancel_hardware_monthly_now(self):
295304
mock = self.set_mock('SoftLayer_Hardware_Server', 'getObject')
296305
mock.return_value = {'id': 987, 'billingItem': {'id': 1234},

0 commit comments

Comments
 (0)