Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions SoftLayer/managers/hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import socket
import time


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

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

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

if immediate and not hw_billing['hourlyBillingFlag']:
LOGGER.warning("Immediate cancelation of montly servers is not guaranteed."
"Please check the cancelation ticket for updates.")
LOGGER.warning("Immediate cancellation of monthly servers is not guaranteed."
"Please check the cancellation ticket for updates.")

result = self.client.call('Billing_Item', 'cancelItem',
False, False, cancel_reason, comment, id=billing_id)
Expand Down
9 changes: 9 additions & 0 deletions tests/managers/hardware_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,15 @@ def test_cancel_hardware_no_billing_item(self):
6327)
self.assertEqual("Ticket #1234 already exists for this server", str(ex))

def test_cancel_hardwareno_billing_item_or_ticket(self):
mock = self.set_mock('SoftLayer_Hardware_Server', 'getObject')
mock.return_value = {'id': 987}

ex = self.assertRaises(SoftLayer.SoftLayerError,
self.hardware.cancel_hardware,
6327)
self.assertEqual("Cannot locate billing for the server. The server may already be cancelled.", str(ex))

def test_cancel_hardware_monthly_now(self):
mock = self.set_mock('SoftLayer_Hardware_Server', 'getObject')
mock.return_value = {'id': 987, 'billingItem': {'id': 1234},
Expand Down