Skip to content

Commit a2b18ef

Browse files
author
Fernando Ojeda
committed
fixed vs create flavor test
1 parent 1d65b44 commit a2b18ef

File tree

5 files changed

+241
-12
lines changed

5 files changed

+241
-12
lines changed

SoftLayer/CLI/virt/create.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -272,26 +272,26 @@ def cli(env, **args):
272272
result = vsi.verify_create_instance(**data)
273273
total_monthly = 0.0
274274
total_hourly = 0.0
275+
total_preset_monthly = 0.0
276+
total_preset_hourly = 0.0
275277

276278
table = formatting.Table(['Item', 'cost'])
277279
table.align['Item'] = 'r'
278280
table.align['cost'] = 'r'
279281

280-
for price in result['prices']:
281-
total_monthly += float(price.get('recurringFee', 0.0))
282-
total_hourly += float(price.get('hourlyRecurringFee', 0.0))
283-
if args.get('billing') == 'hourly':
284-
rate = "%.2f" % float(price['hourlyRecurringFee'])
285-
elif args.get('billing') == 'monthly':
286-
rate = "%.2f" % float(price['recurringFee'])
282+
if str(result['presetId']) is not "":
283+
ordering_mgr = SoftLayer.OrderingManager(env.client)
284+
preset_prices = ordering_mgr.get_preset_prices(result['presetId'])
285+
rate, total_preset_hourly, total_preset_monthly = get_total_recurring_fee(args, preset_prices, table,
286+
total_preset_hourly, total_preset_monthly)
287287

288-
table.add_row([price['item']['description'], rate])
288+
rate, total_hourly, total_monthly = get_total_recurring_fee(args, result, table, total_hourly, total_monthly)
289289

290290
total = 0
291291
if args.get('billing') == 'hourly':
292-
total = total_hourly
292+
total = total_hourly + total_preset_hourly
293293
elif args.get('billing') == 'monthly':
294-
total = total_monthly
294+
total = total_monthly + total_preset_monthly
295295

296296
billing_rate = 'monthly'
297297
if args.get('billing') == 'hourly':
@@ -334,6 +334,19 @@ def cli(env, **args):
334334
env.fout(output)
335335

336336

337+
def get_total_recurring_fee(args, result, table, total_hourly, total_monthly):
338+
for price in result['prices']:
339+
total_monthly += float(price.get('recurringFee', 0.0))
340+
total_hourly += float(price.get('hourlyRecurringFee', 0.0))
341+
if args.get('billing') == 'hourly':
342+
rate = "%.2f" % float(price['hourlyRecurringFee'])
343+
elif args.get('billing') == 'monthly':
344+
rate = "%.2f" % float(price['recurringFee'])
345+
346+
table.add_row([price['item']['description'], rate])
347+
return rate, total_hourly, total_monthly
348+
349+
337350
def _validate_args(env, args):
338351
"""Raises an ArgumentError if the given arguments are not valid."""
339352

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
getObject = {
2+
"description": "AC1.8x60x25\r\n",
3+
"id": 405,
4+
"isActive": "1",
5+
"keyName": "AC1_8X60X25",
6+
"name": "AC1.8x60x25",
7+
"packageId": 835,
8+
"prices": [
9+
{
10+
"hourlyRecurringFee": "1.425",
11+
"id": 207345,
12+
"oneTimeFee": "0",
13+
"recurringFee": "936.23",
14+
"item": {
15+
"capacity": "1",
16+
"description": "1 x P100 GPU",
17+
"id": 10933,
18+
"keyName": "1_X_P100_GPU",
19+
"itemCategory": {
20+
"categoryCode": "guest_pcie_device0",
21+
"id": 1259,
22+
"name": "PCIe Device - GPU",
23+
}
24+
}
25+
},
26+
{
27+
"hourlyRecurringFee": "0",
28+
"id": 2202,
29+
"itemId": 1178,
30+
"laborFee": "0",
31+
"recurringFee": "0",
32+
"item": {
33+
"capacity": "25",
34+
"description": "25 GB (SAN)",
35+
"id": 1178,
36+
"keyName": "GUEST_DISK_25_GB_SAN",
37+
"units": "GB",
38+
"itemCategory": {
39+
"categoryCode": "guest_disk0",
40+
"id": 81,
41+
"name": "First Disk",
42+
}
43+
}
44+
},
45+
{
46+
"hourlyRecurringFee": ".342",
47+
"id": 207361,
48+
"itemId": 10939,
49+
"laborFee": "0",
50+
"recurringFee": "224.69",
51+
"item": {
52+
"capacity": "60",
53+
"description": "60 GB",
54+
"id": 10939,
55+
"keyName": "RAM_0_UNIT_PLACEHOLDER_10",
56+
"itemCategory": {
57+
"categoryCode": "ram",
58+
"id": 3,
59+
"name": "RAM",
60+
}
61+
}
62+
},
63+
{
64+
"hourlyRecurringFee": ".181",
65+
"id": 209595,
66+
"itemId": 11307,
67+
"laborFee": "0",
68+
"recurringFee": "118.26",
69+
"item": {
70+
"capacity": "8",
71+
"description": "8 x 2.0 GHz or higher Cores",
72+
"id": 11307,
73+
"itemTaxCategoryId": 166,
74+
"keyName": "GUEST_CORE_8",
75+
"itemCategory": {
76+
"categoryCode": "guest_core",
77+
"id": 80,
78+
"name": "Computing Instance",
79+
},
80+
"totalPhysicalCoreCount": 8
81+
}
82+
}
83+
]
84+
}

SoftLayer/fixtures/SoftLayer_Virtual_Guest.py

Lines changed: 107 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,113 @@
419419
setPublicNetworkInterfaceSpeed = True
420420
createObject = getObject
421421
createObjects = [getObject]
422-
generateOrderTemplate = {}
422+
generateOrderTemplate = {
423+
"imageTemplateId": None,
424+
"location": "1854895",
425+
"packageId": 835,
426+
"presetId": 405,
427+
"prices": [
428+
{
429+
"hourlyRecurringFee": "0",
430+
"id": 45466,
431+
"recurringFee": "0",
432+
"item": {
433+
"description": "CentOS 7.x - Minimal Install (64 bit)"
434+
}
435+
},
436+
{
437+
"hourlyRecurringFee": "0",
438+
"id": 2202,
439+
"recurringFee": "0",
440+
"item": {
441+
"description": "25 GB (SAN)"
442+
}
443+
},
444+
{
445+
"hourlyRecurringFee": "0",
446+
"id": 905,
447+
"recurringFee": "0",
448+
"item": {
449+
"description": "Reboot / Remote Console"
450+
}
451+
},
452+
{
453+
"hourlyRecurringFee": ".02",
454+
"id": 899,
455+
"recurringFee": "10",
456+
"item": {
457+
"description": "1 Gbps Private Network Uplink"
458+
}
459+
},
460+
{
461+
"hourlyRecurringFee": "0",
462+
"id": 1800,
463+
"item": {
464+
"description": "0 GB Bandwidth Allotment"
465+
}
466+
},
467+
{
468+
"hourlyRecurringFee": "0",
469+
"id": 21,
470+
"recurringFee": "0",
471+
"item": {
472+
"description": "1 IP Address"
473+
}
474+
},
475+
{
476+
"hourlyRecurringFee": "0",
477+
"id": 55,
478+
"recurringFee": "0",
479+
"item": {
480+
"description": "Host Ping"
481+
}
482+
},
483+
{
484+
"hourlyRecurringFee": "0",
485+
"id": 57,
486+
"recurringFee": "0",
487+
"item": {
488+
"description": "Email and Ticket"
489+
}
490+
},
491+
{
492+
"hourlyRecurringFee": "0",
493+
"id": 58,
494+
"recurringFee": "0",
495+
"item": {
496+
"description": "Automated Notification"
497+
}
498+
},
499+
{
500+
"hourlyRecurringFee": "0",
501+
"id": 420,
502+
"recurringFee": "0",
503+
"item": {
504+
"description": "Unlimited SSL VPN Users & 1 PPTP VPN User per account"
505+
}
506+
},
507+
{
508+
"hourlyRecurringFee": "0",
509+
"id": 418,
510+
"recurringFee": "0",
511+
"item": {
512+
"description": "Nessus Vulnerability Assessment & Reporting"
513+
}
514+
}
515+
],
516+
"quantity": 1,
517+
"sourceVirtualGuestId": None,
518+
"sshKeys": [],
519+
"useHourlyPricing": True,
520+
"virtualGuests": [
521+
{
522+
"domain": "test.local",
523+
"hostname": "test"
524+
}
525+
],
526+
"complexType": "SoftLayer_Container_Product_Order_Virtual_Guest"
527+
}
528+
423529
setUserMetadata = ['meta']
424530
reloadOperatingSystem = 'OK'
425531
setTags = True

SoftLayer/managers/ordering.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def __init__(self, client):
3434
self.package_svc = client['Product_Package']
3535
self.order_svc = client['Product_Order']
3636
self.billing_svc = client['Billing_Order']
37+
self.package_preset = client['Product_Package_Preset']
3738

3839
def get_packages_of_type(self, package_types, mask=None):
3940
"""Get packages that match a certain type.
@@ -369,6 +370,20 @@ def get_price_id_list(self, package_keyname, item_keynames):
369370

370371
return prices
371372

373+
def get_preset_prices(self, preset):
374+
"""Get preset item prices.
375+
376+
Retrieve a SoftLayer_Product_Package_Preset record.
377+
378+
:param int preset: preset identifier.
379+
:returns: A list of price IDs associated with the given preset_id.
380+
381+
"""
382+
mask = 'mask[prices[item]]'
383+
384+
prices = self.package_preset.getObject(id=preset, mask=mask)
385+
return prices
386+
372387
def verify_order(self, package_keyname, location, item_keynames, complex_type=None,
373388
hourly=True, preset_keyname=None, extras=None, quantity=1):
374389
"""Verifies an order with the given package and prices.

tests/CLI/modules/vs_tests.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,18 @@ def test_create_vs_test(self, confirm_mock):
672672
'--memory', '2048MB', '--datacenter',
673673
'TEST00', '--os', 'UBUNTU_LATEST'])
674674

675-
self.assertEqual(result.exit_code, -1)
675+
self.assertEqual(result.exit_code, 0)
676+
677+
@mock.patch('SoftLayer.CLI.formatting.confirm')
678+
def test_create_vs_flavor_test(self, confirm_mock):
679+
confirm_mock.return_value = True
680+
681+
result = self.run_command(['vs', 'create', '--test', '--hostname', 'TEST',
682+
'--domain', 'TESTING', '--flavor', 'B1_2X8X25',
683+
'--datacenter', 'TEST00', '--os', 'UBUNTU_LATEST'])
684+
685+
self.assert_no_fail(result)
686+
self.assertEqual(result.exit_code, 0)
676687

677688
def test_create_vs_bad_memory(self):
678689
result = self.run_command(['vs', 'create', '--hostname', 'TEST',

0 commit comments

Comments
 (0)