Skip to content

Commit 47c019a

Browse files
fixed verifyOrder SoftLayerAPIError(SoftLayer_Exception_Public): Reserved Capacity #0 not found
1 parent b73a46b commit 47c019a

File tree

3 files changed

+34
-16
lines changed

3 files changed

+34
-16
lines changed

SoftLayer/fixtures/SoftLayer_Billing_Order_Quote.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
'quantity': 1,
4040
'packageId': 50,
4141
'useHourlyPricing': '',
42+
'reservedCapacityId': '',
4243

4344
}
4445

SoftLayer/managers/ordering.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,16 @@ def verify_quote(self, quote_id, extra):
198198
:param int quantity: Quantity to override default
199199
"""
200200
container = self.generate_order_template(quote_id, extra)
201+
clean_container = {}
201202

202-
return self.client.call('SoftLayer_Billing_Order_Quote', 'verifyOrder', container, id=quote_id)
203+
# There are a few fields that wil cause exceptions in the XML endpoing if you send in ''
204+
# reservedCapacityId and hostId specifically. But we clean all just to be safe.
205+
# This for some reason is only a problem on verify_quote.
206+
for key in container.keys():
207+
if container.get(key) != '':
208+
clean_container[key] = container[key]
209+
210+
return self.client.call('SoftLayer_Billing_Order_Quote', 'verifyOrder', clean_container, id=quote_id)
203211

204212
def order_quote(self, quote_id, extra):
205213
"""Places an order using a quote

tests/managers/ordering_tests.py

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,8 @@ def test_generate_order_template(self):
145145
extras = {'hardware': [{'hostname': 'test1', 'domain': 'example.com'}]}
146146

147147
result = self.ordering.generate_order_template(1234, extras, quantity=1)
148-
self.assertEqual(result, {'presetId': '',
149-
'hardware': [{'domain': 'example.com',
150-
'hostname': 'test1'}],
151-
'useHourlyPricing': '',
152-
'packageId': 50,
153-
'prices': [{'id': 1921}],
154-
'quantity': 1})
148+
self.assert_called_with('SoftLayer_Billing_Order_Quote', 'getRecalculatedOrderContainer')
149+
self.assertEqual(result['hardware'][0]['domain'], 'example.com')
155150

156151
def test_generate_order_template_virtual(self):
157152
extras = {
@@ -162,14 +157,8 @@ def test_generate_order_template_virtual(self):
162157
'testProperty': 100
163158
}
164159
result = self.ordering.generate_order_template(1234, extras, quantity=1)
165-
self.assertEqual(result, {'presetId': '',
166-
'hardware': [{'domain': 'example.com',
167-
'hostname': 'test1'}],
168-
'useHourlyPricing': '',
169-
'packageId': 50,
170-
'prices': [{'id': 1921}],
171-
'quantity': 1,
172-
'testProperty': 100})
160+
self.assert_called_with('SoftLayer_Billing_Order_Quote', 'getRecalculatedOrderContainer')
161+
self.assertEqual(result['testProperty'], 100)
173162

174163
def test_generate_order_template_extra_quantity(self):
175164
self.assertRaises(ValueError,
@@ -666,3 +655,23 @@ def test_issues1067(self):
666655
package = 'DUAL_INTEL_XEON_PROCESSOR_SCALABLE_FAMILY_4_DRIVES'
667656
result = self.ordering.get_price_id_list(package, item_keynames, None)
668657
self.assertIn(201161, result)
658+
659+
660+
def test_clean_quote_verify(self):
661+
from pprint import pprint as pp
662+
extras = {
663+
'hardware': [{
664+
'hostname': 'test1',
665+
'domain': 'example.com'
666+
}],
667+
'testProperty': ''
668+
}
669+
result = self.ordering.verify_quote(1234, extras)
670+
671+
self.assertEqual(result, fixtures.SoftLayer_Billing_Order_Quote.verifyOrder)
672+
self.assert_called_with('SoftLayer_Billing_Order_Quote', 'verifyOrder')
673+
call = self.calls('SoftLayer_Billing_Order_Quote', 'verifyOrder')[0]
674+
order_container = call.args[0]
675+
self.assertNotIn('testProperty', order_container)
676+
self.assertNotIn('reservedCapacityId', order_container)
677+

0 commit comments

Comments
 (0)