Skip to content

Commit fd58dfa

Browse files
author
Nathan Beittenmiller
committed
Updating cancel_hardware() so it can cancel BMC as well. This makes the "sl server cancel" command work for all types of bare metal servers.
1 parent 8349f8e commit fd58dfa

3 files changed

Lines changed: 25 additions & 0 deletions

File tree

SoftLayer/managers/hardware.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ def cancel_hardware(self, hardware_id, reason='unneeded', comment=''):
3434
cancellation.
3535
"""
3636

37+
# Check to see if this is actually a pre-configured server (BMC). They
38+
# require a different cancellation call.
39+
server = self.get_hardware(hardware_id,
40+
mask='id,bareMetalInstanceFlag')
41+
42+
if server.get('bareMetalInstanceFlag'):
43+
return self.cancel_metal(hardware_id)
44+
3745
reasons = self.get_cancellation_reasons()
3846
cancel_reason = reasons['unneeded']
3947

SoftLayer/tests/fixtures/Hardware_Server.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
'primaryIpAddress': '172.16.1.100',
77
'hostname': 'hardware-test1',
88
'domain': 'test.sftlyr.ws',
9+
'bareMetalInstanceFlag': True,
910
'fullyQualifiedDomainName': 'hardware-test1.test.sftlyr.ws',
1011
'processorPhysicalCoreAmount': 2,
1112
'memoryCapacity': 2,

SoftLayer/tests/managers/hardware_tests.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,10 @@ def test_cancel_metal_on_anniversary(self):
237237

238238
def test_cancel_hardware_without_reason(self):
239239
hw_id = 987
240+
self.client['Hardware_Server'].getObject.return_value = {
241+
'id': hw_id,
242+
'bareMetalInstanceFlag': False,
243+
}
240244
result = self.hardware.cancel_hardware(hw_id)
241245

242246
reasons = self.hardware.get_cancellation_reasons()
@@ -247,6 +251,10 @@ def test_cancel_hardware_without_reason(self):
247251

248252
def test_cancel_hardware_with_reason_and_comment(self):
249253
hw_id = 987
254+
self.client['Hardware_Server'].getObject.return_value = {
255+
'id': hw_id,
256+
'bareMetalInstanceFlag': False,
257+
}
250258
reason = 'sales'
251259
comment = 'Test Comment'
252260

@@ -258,6 +266,14 @@ def test_cancel_hardware_with_reason_and_comment(self):
258266
f.assert_called_once_with(hw_id, reasons[reason], comment, True,
259267
'HARDWARE')
260268

269+
def test_cancel_hardware_on_bmc(self):
270+
hw_id = 6327
271+
272+
result = self.hardware.cancel_hardware(hw_id)
273+
f = self.client['Billing_Item'].cancelServiceOnAnniversaryDate
274+
f.assert_called_once_with(id=hw_id)
275+
self.assertEqual(result, Billing_Item.cancelServiceOnAnniversaryDate)
276+
261277
def test_change_port_speed_public(self):
262278
hw_id = 1
263279
speed = 100

0 commit comments

Comments
 (0)