Skip to content

Commit 9c958e1

Browse files
author
Nathan Beittenmiller
committed
Making cancel_hardware() work with BMC. This makes the "sl server cancel" command work for all bare metal server types. Also fixed some unit tests I broke.
1 parent 731114f commit 9c958e1

5 files changed

Lines changed: 51 additions & 12 deletions

File tree

SoftLayer/managers/hardware.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ def cancel_hardware(self, hardware_id, reason='unneeded', comment=''):
3333
:param string comment: An optional comment to include with the
3434
cancellation.
3535
"""
36+
# Check to see if this is actually a pre-configured server (BMC). They
37+
# require a different cancellation call.
38+
server = self.get_hardware(hardware_id,
39+
mask='id,bareMetalInstanceFlag')
40+
41+
if server.get('bareMetalInstanceFlag'):
42+
return self.cancel_metal(hardware_id)
3643

3744
reasons = self.get_cancellation_reasons()
3845
cancel_reason = reasons['unneeded']

SoftLayer/tests/CLI/modules/server_tests.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ def test_ServerCreateOptions(self):
7171

7272
expected = {
7373
'cpu': [
74-
{'description': 'Dual Quad Core Pancake 200 - 1.60GHz',
75-
'id': 723},
76-
{'description': 'Dual Quad Core Pancake 200 - 1.80GHz',
77-
'id': 724}],
74+
{'Description': 'Dual Quad Core Pancake 200 - 1.60GHz',
75+
'ID': 723},
76+
{'Description': 'Dual Quad Core Pancake 200 - 1.80GHz',
77+
'ID': 724}],
7878
'datacenter': ['RANDOM_LOCATION'],
7979
'disk': ['250_SATA_II', '500_SATA_II'],
8080
'disk_controllers': ['None', 'RAID0'],
@@ -112,10 +112,10 @@ def test_ServerCreateOptions_with_cpu_only(self):
112112

113113
expected = {
114114
'cpu': [
115-
{'description': 'Dual Quad Core Pancake 200 - 1.60GHz',
116-
'id': 723},
117-
{'description': 'Dual Quad Core Pancake 200 - 1.80GHz',
118-
'id': 724}
115+
{'Description': 'Dual Quad Core Pancake 200 - 1.60GHz',
116+
'ID': 723},
117+
{'Description': 'Dual Quad Core Pancake 200 - 1.80GHz',
118+
'ID': 724}
119119
],
120120
}
121121

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/fixtures/Product_Package.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
getAllObjects = [
22
{'id': 13, 'name': 'Mock Testing Package', 'description': 'a thing'},
3-
{'id': 27, 'name': 'An additional testing category'},
4-
{'id': 50, 'name': 'Bare Metal Instance'},
3+
{'id': 27, 'name': 'An additional testing category',
4+
'description': 'Another thing - OUTLET'},
5+
{'id': 50, 'name': 'Bare Metal Instance',
6+
'description': 'Bare Metal Instance'},
57
]
68
getObject = getAllObjects[0]
79

SoftLayer/tests/managers/hardware_tests.py

Lines changed: 31 additions & 2 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()
@@ -250,6 +254,11 @@ def test_cancel_hardware_with_reason_and_comment(self):
250254
reason = 'sales'
251255
comment = 'Test Comment'
252256

257+
self.client['Hardware_Server'].getObject.return_value = {
258+
'id': hw_id,
259+
'bareMetalInstanceFlag': False,
260+
}
261+
253262
self.hardware.cancel_hardware(hw_id, reason, comment)
254263

255264
reasons = self.hardware.get_cancellation_reasons()
@@ -258,6 +267,14 @@ def test_cancel_hardware_with_reason_and_comment(self):
258267
f.assert_called_once_with(hw_id, reasons[reason], comment, True,
259268
'HARDWARE')
260269

270+
def test_cancel_hardware_on_bmc(self):
271+
hw_id = 6327
272+
273+
result = self.hardware.cancel_hardware(hw_id)
274+
f = self.client['Billing_Item'].cancelServiceOnAnniversaryDate
275+
f.assert_called_once_with(id=hw_id)
276+
self.assertEqual(result, Billing_Item.cancelServiceOnAnniversaryDate)
277+
261278
def test_change_port_speed_public(self):
262279
hw_id = 1
263280
speed = 100
@@ -277,8 +294,20 @@ def test_change_port_speed_private(self):
277294
def test_get_available_dedicated_server_packages(self):
278295
self.hardware.get_available_dedicated_server_packages()
279296

280-
f = self.client['Product_Package'].getObject
281-
f.assert_has_calls([call(id=13, mask='mask[id, name, description]')])
297+
filter_mock = {
298+
'type': {
299+
'keyName': {
300+
'operation': 'in',
301+
'options': [{
302+
'name': 'data',
303+
'value': ['BARE_METAL_CPU']
304+
}]
305+
}
306+
}
307+
}
308+
f = self.client['Product_Package'].getAllObjects
309+
f.assert_has_calls([call(mask='id,name,description,type',
310+
filter=filter_mock)])
282311

283312
def test_get_dedicated_server_options(self):
284313
package_id = 13

0 commit comments

Comments
 (0)