Skip to content

Commit 37ec7ab

Browse files
author
Fernando Ojeda
committed
fixed vs create flavor test
1 parent 744f8da commit 37ec7ab

File tree

3 files changed

+43
-84
lines changed

3 files changed

+43
-84
lines changed

SoftLayer/CLI/virt/create.py

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -270,34 +270,17 @@ def cli(env, **args):
270270
output = []
271271
if args.get('test'):
272272
result = vsi.verify_create_instance(**data)
273-
total_monthly = 0.0
274-
total_hourly = 0.0
275-
total_preset_monthly = 0.0
276-
total_preset_hourly = 0.0
277-
278-
table = formatting.Table(['Item', 'cost'])
279-
table.align['Item'] = 'r'
280-
table.align['cost'] = 'r'
281273

282274
if result['presetId']:
283275
ordering_mgr = SoftLayer.OrderingManager(env.client)
284276
preset_prices = ordering_mgr.get_preset_prices(result['presetId'])
285-
total_preset_hourly, total_preset_monthly = get_total_recurring_fee(args, preset_prices, table,
286-
total_preset_hourly,
287-
total_preset_monthly)
288-
289-
total_hourly, total_monthly = get_total_recurring_fee(args, result, table, total_hourly, total_monthly)
290-
291-
total = 0
292-
if args.get('billing') == 'hourly':
293-
total = total_hourly + total_preset_hourly
294-
elif args.get('billing') == 'monthly':
295-
total = total_monthly + total_preset_monthly
296-
297-
billing_rate = 'monthly'
298-
if args.get('billing') == 'hourly':
299-
billing_rate = 'hourly'
300-
table.add_row(['Total %s cost' % billing_rate, "%.2f" % total])
277+
search_keys = ["guest_core", "ram"]
278+
for price in preset_prices['prices']:
279+
if price['item']['itemCategory']['categoryCode'] in search_keys:
280+
result['prices'].append(price)
281+
282+
table = _build_receipt_table(result['prices'], args.get('billing'))
283+
301284
output.append(table)
302285
output.append(formatting.FormattedItem(
303286
None,
@@ -335,18 +318,23 @@ def cli(env, **args):
335318
env.fout(output)
336319

337320

338-
def get_total_recurring_fee(args, result, table, total_hourly, total_monthly):
321+
def _build_receipt_table(prices, billing="hourly"):
339322
"""Retrieve the total recurring fee of the items prices"""
340-
for price in result['prices']:
341-
total_monthly += float(price.get('recurringFee', 0.0))
342-
total_hourly += float(price.get('hourlyRecurringFee', 0.0))
343-
if args.get('billing') == 'hourly':
344-
rate = "%.2f" % float(price['hourlyRecurringFee'])
345-
elif args.get('billing') == 'monthly':
346-
rate = "%.2f" % float(price['recurringFee'])
347-
348-
table.add_row([price['item']['description'], rate])
349-
return total_hourly, total_monthly
323+
total = 0.000
324+
table = formatting.Table(['Cost', 'Item'])
325+
table.align['Cost'] = 'r'
326+
table.align['Item'] = 'l'
327+
for price in prices:
328+
rate = 0.000
329+
if billing == "hourly":
330+
rate += float(price.get('hourlyRecurringFee', 0.000))
331+
else:
332+
rate += float(price.get('recurringFee', 0.000))
333+
total += rate
334+
335+
table.add_row(["%.3f" % rate, price['item']['description']])
336+
table.add_row(["%.3f" % total, "Total %s cost" % billing])
337+
return table
350338

351339

352340
def _validate_args(env, args):

SoftLayer/fixtures/SoftLayer_Product_Package_Preset.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
"description": "1 x P100 GPU",
1111
"id": 10933,
1212
"keyName": "1_X_P100_GPU",
13+
"itemCategory": {
14+
"categoryCode": "guest_pcie_device0",
15+
"id": 1259
16+
}
1317
}
1418
},
1519
{
@@ -20,6 +24,10 @@
2024
"description": "25 GB (SAN)",
2125
"id": 1178,
2226
"keyName": "GUEST_DISK_25_GB_SAN",
27+
"itemCategory": {
28+
"categoryCode": "guest_disk0",
29+
"id": 81
30+
}
2331
}
2432
},
2533
{
@@ -30,6 +38,10 @@
3038
"description": "60 GB",
3139
"id": 10939,
3240
"keyName": "RAM_0_UNIT_PLACEHOLDER_10",
41+
"itemCategory": {
42+
"categoryCode": "ram",
43+
"id": 3
44+
}
3345
}
3446
},
3547
{
@@ -40,6 +52,10 @@
4052
"description": "8 x 2.0 GHz or higher Cores",
4153
"id": 11307,
4254
"keyName": "GUEST_CORE_8",
55+
"itemCategory": {
56+
"categoryCode": "guest_core",
57+
"id": 80
58+
}
4359
}
4460
}
4561
]

tests/managers/ordering_tests.py

Lines changed: 4 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -69,55 +69,10 @@ def test_get_package_id_by_type_returns_valid_id(self):
6969
self.assertEqual(46, package_id)
7070

7171
def test_get_preset_prices(self):
72-
preset_id = 405
73-
preset_prices = self.ordering.get_preset_prices(preset_id)
74-
75-
self.assertEqual(preset_prices, {
76-
"id": 405,
77-
"keyName": "AC1_8X60X25",
78-
"prices": [
79-
{
80-
"hourlyRecurringFee": "1.425",
81-
"id": 207345,
82-
"recurringFee": "936.23",
83-
"item": {
84-
"description": "1 x P100 GPU",
85-
"id": 10933,
86-
"keyName": "1_X_P100_GPU",
87-
}
88-
},
89-
{
90-
"hourlyRecurringFee": "0",
91-
"id": 2202,
92-
"recurringFee": "0",
93-
"item": {
94-
"description": "25 GB (SAN)",
95-
"id": 1178,
96-
"keyName": "GUEST_DISK_25_GB_SAN",
97-
}
98-
},
99-
{
100-
"hourlyRecurringFee": ".342",
101-
"id": 207361,
102-
"recurringFee": "224.69",
103-
"item": {
104-
"description": "60 GB",
105-
"id": 10939,
106-
"keyName": "RAM_0_UNIT_PLACEHOLDER_10",
107-
}
108-
},
109-
{
110-
"hourlyRecurringFee": ".181",
111-
"id": 209595,
112-
"recurringFee": "118.26",
113-
"item": {
114-
"description": "8 x 2.0 GHz or higher Cores",
115-
"id": 11307,
116-
"keyName": "GUEST_CORE_8",
117-
}
118-
}
119-
]
120-
})
72+
result = self.ordering.get_preset_prices(405)
73+
74+
self.assertEqual(result, fixtures.SoftLayer_Product_Package_Preset.getObject)
75+
self.assert_called_with('SoftLayer_Product_Package_Preset', 'getObject')
12176

12277
def test_get_package_id_by_type_fails_for_nonexistent_package_type(self):
12378
p_mock = self.set_mock('SoftLayer_Product_Package', 'getAllObjects')

0 commit comments

Comments
 (0)