From a2b18ef82b397e243bcdf106f61de3a3227a84b4 Mon Sep 17 00:00:00 2001 From: Fernando Ojeda Date: Thu, 6 Sep 2018 12:28:47 -0400 Subject: [PATCH 1/7] fixed vs create flavor test --- SoftLayer/CLI/virt/create.py | 33 ++++-- .../SoftLayer_Product_Package_Preset.py | 84 ++++++++++++++ SoftLayer/fixtures/SoftLayer_Virtual_Guest.py | 108 +++++++++++++++++- SoftLayer/managers/ordering.py | 15 +++ tests/CLI/modules/vs_tests.py | 13 ++- 5 files changed, 241 insertions(+), 12 deletions(-) create mode 100644 SoftLayer/fixtures/SoftLayer_Product_Package_Preset.py diff --git a/SoftLayer/CLI/virt/create.py b/SoftLayer/CLI/virt/create.py index a0997704e..0c8e43275 100644 --- a/SoftLayer/CLI/virt/create.py +++ b/SoftLayer/CLI/virt/create.py @@ -272,26 +272,26 @@ def cli(env, **args): result = vsi.verify_create_instance(**data) total_monthly = 0.0 total_hourly = 0.0 + total_preset_monthly = 0.0 + total_preset_hourly = 0.0 table = formatting.Table(['Item', 'cost']) table.align['Item'] = 'r' table.align['cost'] = 'r' - for price in result['prices']: - total_monthly += float(price.get('recurringFee', 0.0)) - total_hourly += float(price.get('hourlyRecurringFee', 0.0)) - if args.get('billing') == 'hourly': - rate = "%.2f" % float(price['hourlyRecurringFee']) - elif args.get('billing') == 'monthly': - rate = "%.2f" % float(price['recurringFee']) + if str(result['presetId']) is not "": + ordering_mgr = SoftLayer.OrderingManager(env.client) + preset_prices = ordering_mgr.get_preset_prices(result['presetId']) + rate, total_preset_hourly, total_preset_monthly = get_total_recurring_fee(args, preset_prices, table, + total_preset_hourly, total_preset_monthly) - table.add_row([price['item']['description'], rate]) + rate, total_hourly, total_monthly = get_total_recurring_fee(args, result, table, total_hourly, total_monthly) total = 0 if args.get('billing') == 'hourly': - total = total_hourly + total = total_hourly + total_preset_hourly elif args.get('billing') == 'monthly': - total = total_monthly + total = total_monthly + total_preset_monthly billing_rate = 'monthly' if args.get('billing') == 'hourly': @@ -334,6 +334,19 @@ def cli(env, **args): env.fout(output) +def get_total_recurring_fee(args, result, table, total_hourly, total_monthly): + for price in result['prices']: + total_monthly += float(price.get('recurringFee', 0.0)) + total_hourly += float(price.get('hourlyRecurringFee', 0.0)) + if args.get('billing') == 'hourly': + rate = "%.2f" % float(price['hourlyRecurringFee']) + elif args.get('billing') == 'monthly': + rate = "%.2f" % float(price['recurringFee']) + + table.add_row([price['item']['description'], rate]) + return rate, total_hourly, total_monthly + + def _validate_args(env, args): """Raises an ArgumentError if the given arguments are not valid.""" diff --git a/SoftLayer/fixtures/SoftLayer_Product_Package_Preset.py b/SoftLayer/fixtures/SoftLayer_Product_Package_Preset.py new file mode 100644 index 000000000..1fd5f8fd2 --- /dev/null +++ b/SoftLayer/fixtures/SoftLayer_Product_Package_Preset.py @@ -0,0 +1,84 @@ +getObject = { + "description": "AC1.8x60x25\r\n", + "id": 405, + "isActive": "1", + "keyName": "AC1_8X60X25", + "name": "AC1.8x60x25", + "packageId": 835, + "prices": [ + { + "hourlyRecurringFee": "1.425", + "id": 207345, + "oneTimeFee": "0", + "recurringFee": "936.23", + "item": { + "capacity": "1", + "description": "1 x P100 GPU", + "id": 10933, + "keyName": "1_X_P100_GPU", + "itemCategory": { + "categoryCode": "guest_pcie_device0", + "id": 1259, + "name": "PCIe Device - GPU", + } + } + }, + { + "hourlyRecurringFee": "0", + "id": 2202, + "itemId": 1178, + "laborFee": "0", + "recurringFee": "0", + "item": { + "capacity": "25", + "description": "25 GB (SAN)", + "id": 1178, + "keyName": "GUEST_DISK_25_GB_SAN", + "units": "GB", + "itemCategory": { + "categoryCode": "guest_disk0", + "id": 81, + "name": "First Disk", + } + } + }, + { + "hourlyRecurringFee": ".342", + "id": 207361, + "itemId": 10939, + "laborFee": "0", + "recurringFee": "224.69", + "item": { + "capacity": "60", + "description": "60 GB", + "id": 10939, + "keyName": "RAM_0_UNIT_PLACEHOLDER_10", + "itemCategory": { + "categoryCode": "ram", + "id": 3, + "name": "RAM", + } + } + }, + { + "hourlyRecurringFee": ".181", + "id": 209595, + "itemId": 11307, + "laborFee": "0", + "recurringFee": "118.26", + "item": { + "capacity": "8", + "description": "8 x 2.0 GHz or higher Cores", + "id": 11307, + "itemTaxCategoryId": 166, + "keyName": "GUEST_CORE_8", + "itemCategory": { + "categoryCode": "guest_core", + "id": 80, + "name": "Computing Instance", + }, + "totalPhysicalCoreCount": 8 + } + } + ] +} diff --git a/SoftLayer/fixtures/SoftLayer_Virtual_Guest.py b/SoftLayer/fixtures/SoftLayer_Virtual_Guest.py index 776db8778..ed1c2a303 100644 --- a/SoftLayer/fixtures/SoftLayer_Virtual_Guest.py +++ b/SoftLayer/fixtures/SoftLayer_Virtual_Guest.py @@ -419,7 +419,113 @@ setPublicNetworkInterfaceSpeed = True createObject = getObject createObjects = [getObject] -generateOrderTemplate = {} +generateOrderTemplate = { + "imageTemplateId": None, + "location": "1854895", + "packageId": 835, + "presetId": 405, + "prices": [ + { + "hourlyRecurringFee": "0", + "id": 45466, + "recurringFee": "0", + "item": { + "description": "CentOS 7.x - Minimal Install (64 bit)" + } + }, + { + "hourlyRecurringFee": "0", + "id": 2202, + "recurringFee": "0", + "item": { + "description": "25 GB (SAN)" + } + }, + { + "hourlyRecurringFee": "0", + "id": 905, + "recurringFee": "0", + "item": { + "description": "Reboot / Remote Console" + } + }, + { + "hourlyRecurringFee": ".02", + "id": 899, + "recurringFee": "10", + "item": { + "description": "1 Gbps Private Network Uplink" + } + }, + { + "hourlyRecurringFee": "0", + "id": 1800, + "item": { + "description": "0 GB Bandwidth Allotment" + } + }, + { + "hourlyRecurringFee": "0", + "id": 21, + "recurringFee": "0", + "item": { + "description": "1 IP Address" + } + }, + { + "hourlyRecurringFee": "0", + "id": 55, + "recurringFee": "0", + "item": { + "description": "Host Ping" + } + }, + { + "hourlyRecurringFee": "0", + "id": 57, + "recurringFee": "0", + "item": { + "description": "Email and Ticket" + } + }, + { + "hourlyRecurringFee": "0", + "id": 58, + "recurringFee": "0", + "item": { + "description": "Automated Notification" + } + }, + { + "hourlyRecurringFee": "0", + "id": 420, + "recurringFee": "0", + "item": { + "description": "Unlimited SSL VPN Users & 1 PPTP VPN User per account" + } + }, + { + "hourlyRecurringFee": "0", + "id": 418, + "recurringFee": "0", + "item": { + "description": "Nessus Vulnerability Assessment & Reporting" + } + } + ], + "quantity": 1, + "sourceVirtualGuestId": None, + "sshKeys": [], + "useHourlyPricing": True, + "virtualGuests": [ + { + "domain": "test.local", + "hostname": "test" + } + ], + "complexType": "SoftLayer_Container_Product_Order_Virtual_Guest" +} + setUserMetadata = ['meta'] reloadOperatingSystem = 'OK' setTags = True diff --git a/SoftLayer/managers/ordering.py b/SoftLayer/managers/ordering.py index 3677ecedd..1341a7fc2 100644 --- a/SoftLayer/managers/ordering.py +++ b/SoftLayer/managers/ordering.py @@ -34,6 +34,7 @@ def __init__(self, client): self.package_svc = client['Product_Package'] self.order_svc = client['Product_Order'] self.billing_svc = client['Billing_Order'] + self.package_preset = client['Product_Package_Preset'] def get_packages_of_type(self, package_types, mask=None): """Get packages that match a certain type. @@ -369,6 +370,20 @@ def get_price_id_list(self, package_keyname, item_keynames): return prices + def get_preset_prices(self, preset): + """Get preset item prices. + + Retrieve a SoftLayer_Product_Package_Preset record. + + :param int preset: preset identifier. + :returns: A list of price IDs associated with the given preset_id. + + """ + mask = 'mask[prices[item]]' + + prices = self.package_preset.getObject(id=preset, mask=mask) + return prices + def verify_order(self, package_keyname, location, item_keynames, complex_type=None, hourly=True, preset_keyname=None, extras=None, quantity=1): """Verifies an order with the given package and prices. diff --git a/tests/CLI/modules/vs_tests.py b/tests/CLI/modules/vs_tests.py index c976a952e..0b3430e72 100644 --- a/tests/CLI/modules/vs_tests.py +++ b/tests/CLI/modules/vs_tests.py @@ -672,7 +672,18 @@ def test_create_vs_test(self, confirm_mock): '--memory', '2048MB', '--datacenter', 'TEST00', '--os', 'UBUNTU_LATEST']) - self.assertEqual(result.exit_code, -1) + self.assertEqual(result.exit_code, 0) + + @mock.patch('SoftLayer.CLI.formatting.confirm') + def test_create_vs_flavor_test(self, confirm_mock): + confirm_mock.return_value = True + + result = self.run_command(['vs', 'create', '--test', '--hostname', 'TEST', + '--domain', 'TESTING', '--flavor', 'B1_2X8X25', + '--datacenter', 'TEST00', '--os', 'UBUNTU_LATEST']) + + self.assert_no_fail(result) + self.assertEqual(result.exit_code, 0) def test_create_vs_bad_memory(self): result = self.run_command(['vs', 'create', '--hostname', 'TEST', From 28a4e6342447e8aec080206284666879fe4d25e4 Mon Sep 17 00:00:00 2001 From: Fernando Ojeda Date: Fri, 7 Sep 2018 15:43:19 -0400 Subject: [PATCH 2/7] fixed vs create flavor test --- .../SoftLayer_Product_Package_Preset.py | 38 -------------- tests/managers/ordering_tests.py | 51 +++++++++++++++++++ 2 files changed, 51 insertions(+), 38 deletions(-) diff --git a/SoftLayer/fixtures/SoftLayer_Product_Package_Preset.py b/SoftLayer/fixtures/SoftLayer_Product_Package_Preset.py index 1fd5f8fd2..e80fa009d 100644 --- a/SoftLayer/fixtures/SoftLayer_Product_Package_Preset.py +++ b/SoftLayer/fixtures/SoftLayer_Product_Package_Preset.py @@ -1,83 +1,45 @@ getObject = { - "description": "AC1.8x60x25\r\n", "id": 405, - "isActive": "1", "keyName": "AC1_8X60X25", - "name": "AC1.8x60x25", - "packageId": 835, "prices": [ { "hourlyRecurringFee": "1.425", "id": 207345, - "oneTimeFee": "0", "recurringFee": "936.23", "item": { - "capacity": "1", "description": "1 x P100 GPU", "id": 10933, "keyName": "1_X_P100_GPU", - "itemCategory": { - "categoryCode": "guest_pcie_device0", - "id": 1259, - "name": "PCIe Device - GPU", - } } }, { "hourlyRecurringFee": "0", "id": 2202, - "itemId": 1178, - "laborFee": "0", "recurringFee": "0", "item": { - "capacity": "25", "description": "25 GB (SAN)", "id": 1178, "keyName": "GUEST_DISK_25_GB_SAN", - "units": "GB", - "itemCategory": { - "categoryCode": "guest_disk0", - "id": 81, - "name": "First Disk", - } } }, { "hourlyRecurringFee": ".342", "id": 207361, - "itemId": 10939, - "laborFee": "0", "recurringFee": "224.69", "item": { - "capacity": "60", "description": "60 GB", "id": 10939, "keyName": "RAM_0_UNIT_PLACEHOLDER_10", - "itemCategory": { - "categoryCode": "ram", - "id": 3, - "name": "RAM", - } } }, { "hourlyRecurringFee": ".181", "id": 209595, - "itemId": 11307, - "laborFee": "0", "recurringFee": "118.26", "item": { - "capacity": "8", "description": "8 x 2.0 GHz or higher Cores", "id": 11307, - "itemTaxCategoryId": 166, "keyName": "GUEST_CORE_8", - "itemCategory": { - "categoryCode": "guest_core", - "id": 80, - "name": "Computing Instance", - }, - "totalPhysicalCoreCount": 8 } } ] diff --git a/tests/managers/ordering_tests.py b/tests/managers/ordering_tests.py index 5149f6ed8..2ce079a11 100644 --- a/tests/managers/ordering_tests.py +++ b/tests/managers/ordering_tests.py @@ -68,6 +68,57 @@ def test_get_package_id_by_type_returns_valid_id(self): self.assertEqual(46, package_id) + def test_get_preset_prices(self): + preset_id = 405 + preset_prices = self.ordering.get_preset_prices(preset_id) + + self.assertEqual(preset_prices, { + "id": 405, + "keyName": "AC1_8X60X25", + "prices": [ + { + "hourlyRecurringFee": "1.425", + "id": 207345, + "recurringFee": "936.23", + "item": { + "description": "1 x P100 GPU", + "id": 10933, + "keyName": "1_X_P100_GPU", + } + }, + { + "hourlyRecurringFee": "0", + "id": 2202, + "recurringFee": "0", + "item": { + "description": "25 GB (SAN)", + "id": 1178, + "keyName": "GUEST_DISK_25_GB_SAN", + } + }, + { + "hourlyRecurringFee": ".342", + "id": 207361, + "recurringFee": "224.69", + "item": { + "description": "60 GB", + "id": 10939, + "keyName": "RAM_0_UNIT_PLACEHOLDER_10", + } + }, + { + "hourlyRecurringFee": ".181", + "id": 209595, + "recurringFee": "118.26", + "item": { + "description": "8 x 2.0 GHz or higher Cores", + "id": 11307, + "keyName": "GUEST_CORE_8", + } + } + ] + }) + def test_get_package_id_by_type_fails_for_nonexistent_package_type(self): p_mock = self.set_mock('SoftLayer_Product_Package', 'getAllObjects') p_mock.return_value = [] From 7be0cac236dc3ee0758b5eda433d07b73c901a90 Mon Sep 17 00:00:00 2001 From: Fernando Ojeda Date: Fri, 7 Sep 2018 16:11:48 -0400 Subject: [PATCH 3/7] fixed vs create flavor test --- SoftLayer/CLI/virt/create.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/SoftLayer/CLI/virt/create.py b/SoftLayer/CLI/virt/create.py index 0c8e43275..d73caf834 100644 --- a/SoftLayer/CLI/virt/create.py +++ b/SoftLayer/CLI/virt/create.py @@ -283,7 +283,8 @@ def cli(env, **args): ordering_mgr = SoftLayer.OrderingManager(env.client) preset_prices = ordering_mgr.get_preset_prices(result['presetId']) rate, total_preset_hourly, total_preset_monthly = get_total_recurring_fee(args, preset_prices, table, - total_preset_hourly, total_preset_monthly) + total_preset_hourly, + total_preset_monthly) rate, total_hourly, total_monthly = get_total_recurring_fee(args, result, table, total_hourly, total_monthly) From ee58588fa66c2f617356d9220904ff297cde2bd2 Mon Sep 17 00:00:00 2001 From: Fernando Ojeda Date: Fri, 7 Sep 2018 17:59:41 -0400 Subject: [PATCH 4/7] fixed vs create flavor test --- SoftLayer/CLI/virt/create.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/SoftLayer/CLI/virt/create.py b/SoftLayer/CLI/virt/create.py index d73caf834..13ff5c7c8 100644 --- a/SoftLayer/CLI/virt/create.py +++ b/SoftLayer/CLI/virt/create.py @@ -282,11 +282,11 @@ def cli(env, **args): if str(result['presetId']) is not "": ordering_mgr = SoftLayer.OrderingManager(env.client) preset_prices = ordering_mgr.get_preset_prices(result['presetId']) - rate, total_preset_hourly, total_preset_monthly = get_total_recurring_fee(args, preset_prices, table, - total_preset_hourly, - total_preset_monthly) + total_preset_hourly, total_preset_monthly = get_total_recurring_fee(args, preset_prices, table, + total_preset_hourly, + total_preset_monthly) - rate, total_hourly, total_monthly = get_total_recurring_fee(args, result, table, total_hourly, total_monthly) + total_hourly, total_monthly = get_total_recurring_fee(args, result, table, total_hourly, total_monthly) total = 0 if args.get('billing') == 'hourly': @@ -336,6 +336,7 @@ def cli(env, **args): def get_total_recurring_fee(args, result, table, total_hourly, total_monthly): + """Retrieve the total recurring fee of the items prices""" for price in result['prices']: total_monthly += float(price.get('recurringFee', 0.0)) total_hourly += float(price.get('hourlyRecurringFee', 0.0)) @@ -345,7 +346,7 @@ def get_total_recurring_fee(args, result, table, total_hourly, total_monthly): rate = "%.2f" % float(price['recurringFee']) table.add_row([price['item']['description'], rate]) - return rate, total_hourly, total_monthly + return total_hourly, total_monthly def _validate_args(env, args): From 744f8da9a2b6e5130664ddbe89106fade659f161 Mon Sep 17 00:00:00 2001 From: Fernando Ojeda Date: Fri, 7 Sep 2018 19:08:53 -0400 Subject: [PATCH 5/7] fixed vs create flavor test --- SoftLayer/CLI/virt/create.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SoftLayer/CLI/virt/create.py b/SoftLayer/CLI/virt/create.py index 13ff5c7c8..5b5e9cd14 100644 --- a/SoftLayer/CLI/virt/create.py +++ b/SoftLayer/CLI/virt/create.py @@ -279,7 +279,7 @@ def cli(env, **args): table.align['Item'] = 'r' table.align['cost'] = 'r' - if str(result['presetId']) is not "": + if result['presetId']: ordering_mgr = SoftLayer.OrderingManager(env.client) preset_prices = ordering_mgr.get_preset_prices(result['presetId']) total_preset_hourly, total_preset_monthly = get_total_recurring_fee(args, preset_prices, table, From 37ec7ab52df43bad662b79bd4b774b1cc45b79b7 Mon Sep 17 00:00:00 2001 From: Fernando Ojeda Date: Mon, 17 Sep 2018 10:07:13 -0400 Subject: [PATCH 6/7] fixed vs create flavor test --- SoftLayer/CLI/virt/create.py | 58 ++++++++----------- .../SoftLayer_Product_Package_Preset.py | 16 +++++ tests/managers/ordering_tests.py | 53 ++--------------- 3 files changed, 43 insertions(+), 84 deletions(-) diff --git a/SoftLayer/CLI/virt/create.py b/SoftLayer/CLI/virt/create.py index 5b5e9cd14..754c82d6f 100644 --- a/SoftLayer/CLI/virt/create.py +++ b/SoftLayer/CLI/virt/create.py @@ -270,34 +270,17 @@ def cli(env, **args): output = [] if args.get('test'): result = vsi.verify_create_instance(**data) - total_monthly = 0.0 - total_hourly = 0.0 - total_preset_monthly = 0.0 - total_preset_hourly = 0.0 - - table = formatting.Table(['Item', 'cost']) - table.align['Item'] = 'r' - table.align['cost'] = 'r' if result['presetId']: ordering_mgr = SoftLayer.OrderingManager(env.client) preset_prices = ordering_mgr.get_preset_prices(result['presetId']) - total_preset_hourly, total_preset_monthly = get_total_recurring_fee(args, preset_prices, table, - total_preset_hourly, - total_preset_monthly) - - total_hourly, total_monthly = get_total_recurring_fee(args, result, table, total_hourly, total_monthly) - - total = 0 - if args.get('billing') == 'hourly': - total = total_hourly + total_preset_hourly - elif args.get('billing') == 'monthly': - total = total_monthly + total_preset_monthly - - billing_rate = 'monthly' - if args.get('billing') == 'hourly': - billing_rate = 'hourly' - table.add_row(['Total %s cost' % billing_rate, "%.2f" % total]) + search_keys = ["guest_core", "ram"] + for price in preset_prices['prices']: + if price['item']['itemCategory']['categoryCode'] in search_keys: + result['prices'].append(price) + + table = _build_receipt_table(result['prices'], args.get('billing')) + output.append(table) output.append(formatting.FormattedItem( None, @@ -335,18 +318,23 @@ def cli(env, **args): env.fout(output) -def get_total_recurring_fee(args, result, table, total_hourly, total_monthly): +def _build_receipt_table(prices, billing="hourly"): """Retrieve the total recurring fee of the items prices""" - for price in result['prices']: - total_monthly += float(price.get('recurringFee', 0.0)) - total_hourly += float(price.get('hourlyRecurringFee', 0.0)) - if args.get('billing') == 'hourly': - rate = "%.2f" % float(price['hourlyRecurringFee']) - elif args.get('billing') == 'monthly': - rate = "%.2f" % float(price['recurringFee']) - - table.add_row([price['item']['description'], rate]) - return total_hourly, total_monthly + total = 0.000 + table = formatting.Table(['Cost', 'Item']) + table.align['Cost'] = 'r' + table.align['Item'] = 'l' + for price in prices: + rate = 0.000 + if billing == "hourly": + rate += float(price.get('hourlyRecurringFee', 0.000)) + else: + rate += float(price.get('recurringFee', 0.000)) + total += rate + + table.add_row(["%.3f" % rate, price['item']['description']]) + table.add_row(["%.3f" % total, "Total %s cost" % billing]) + return table def _validate_args(env, args): diff --git a/SoftLayer/fixtures/SoftLayer_Product_Package_Preset.py b/SoftLayer/fixtures/SoftLayer_Product_Package_Preset.py index e80fa009d..d111b9595 100644 --- a/SoftLayer/fixtures/SoftLayer_Product_Package_Preset.py +++ b/SoftLayer/fixtures/SoftLayer_Product_Package_Preset.py @@ -10,6 +10,10 @@ "description": "1 x P100 GPU", "id": 10933, "keyName": "1_X_P100_GPU", + "itemCategory": { + "categoryCode": "guest_pcie_device0", + "id": 1259 + } } }, { @@ -20,6 +24,10 @@ "description": "25 GB (SAN)", "id": 1178, "keyName": "GUEST_DISK_25_GB_SAN", + "itemCategory": { + "categoryCode": "guest_disk0", + "id": 81 + } } }, { @@ -30,6 +38,10 @@ "description": "60 GB", "id": 10939, "keyName": "RAM_0_UNIT_PLACEHOLDER_10", + "itemCategory": { + "categoryCode": "ram", + "id": 3 + } } }, { @@ -40,6 +52,10 @@ "description": "8 x 2.0 GHz or higher Cores", "id": 11307, "keyName": "GUEST_CORE_8", + "itemCategory": { + "categoryCode": "guest_core", + "id": 80 + } } } ] diff --git a/tests/managers/ordering_tests.py b/tests/managers/ordering_tests.py index 2ce079a11..f9b662855 100644 --- a/tests/managers/ordering_tests.py +++ b/tests/managers/ordering_tests.py @@ -69,55 +69,10 @@ def test_get_package_id_by_type_returns_valid_id(self): self.assertEqual(46, package_id) def test_get_preset_prices(self): - preset_id = 405 - preset_prices = self.ordering.get_preset_prices(preset_id) - - self.assertEqual(preset_prices, { - "id": 405, - "keyName": "AC1_8X60X25", - "prices": [ - { - "hourlyRecurringFee": "1.425", - "id": 207345, - "recurringFee": "936.23", - "item": { - "description": "1 x P100 GPU", - "id": 10933, - "keyName": "1_X_P100_GPU", - } - }, - { - "hourlyRecurringFee": "0", - "id": 2202, - "recurringFee": "0", - "item": { - "description": "25 GB (SAN)", - "id": 1178, - "keyName": "GUEST_DISK_25_GB_SAN", - } - }, - { - "hourlyRecurringFee": ".342", - "id": 207361, - "recurringFee": "224.69", - "item": { - "description": "60 GB", - "id": 10939, - "keyName": "RAM_0_UNIT_PLACEHOLDER_10", - } - }, - { - "hourlyRecurringFee": ".181", - "id": 209595, - "recurringFee": "118.26", - "item": { - "description": "8 x 2.0 GHz or higher Cores", - "id": 11307, - "keyName": "GUEST_CORE_8", - } - } - ] - }) + result = self.ordering.get_preset_prices(405) + + self.assertEqual(result, fixtures.SoftLayer_Product_Package_Preset.getObject) + self.assert_called_with('SoftLayer_Product_Package_Preset', 'getObject') def test_get_package_id_by_type_fails_for_nonexistent_package_type(self): p_mock = self.set_mock('SoftLayer_Product_Package', 'getAllObjects') From 65af93f95456d1623da78cdeaddd29ca83e1181b Mon Sep 17 00:00:00 2001 From: Fernando Ojeda Date: Mon, 17 Sep 2018 16:23:54 -0400 Subject: [PATCH 7/7] fixed vs create flavor test --- SoftLayer/CLI/virt/create.py | 14 +- .../fixtures/SoftLayer_Product_Package.py | 176 +++++++++++++++++- SoftLayer/managers/ordering.py | 14 ++ tests/managers/ordering_tests.py | 6 + 4 files changed, 208 insertions(+), 2 deletions(-) diff --git a/SoftLayer/CLI/virt/create.py b/SoftLayer/CLI/virt/create.py index 754c82d6f..ee904ba6a 100644 --- a/SoftLayer/CLI/virt/create.py +++ b/SoftLayer/CLI/virt/create.py @@ -273,11 +273,13 @@ def cli(env, **args): if result['presetId']: ordering_mgr = SoftLayer.OrderingManager(env.client) + item_prices = ordering_mgr.get_item_prices(result['packageId']) preset_prices = ordering_mgr.get_preset_prices(result['presetId']) search_keys = ["guest_core", "ram"] for price in preset_prices['prices']: if price['item']['itemCategory']['categoryCode'] in search_keys: - result['prices'].append(price) + item_key_name = price['item']['keyName'] + _add_item_prices(item_key_name, item_prices, result) table = _build_receipt_table(result['prices'], args.get('billing')) @@ -318,6 +320,16 @@ def cli(env, **args): env.fout(output) +def _add_item_prices(item_key_name, item_prices, result): + """Add the flavor item prices to the rest o the items prices""" + for item in item_prices: + if item_key_name == item['item']['keyName']: + if 'pricingLocationGroup' in item: + for location in item['pricingLocationGroup']['locations']: + if result['location'] == str(location['id']): + result['prices'].append(item) + + def _build_receipt_table(prices, billing="hourly"): """Retrieve the total recurring fee of the items prices""" total = 0.000 diff --git a/SoftLayer/fixtures/SoftLayer_Product_Package.py b/SoftLayer/fixtures/SoftLayer_Product_Package.py index 9b5d53741..a6b0251d1 100644 --- a/SoftLayer/fixtures/SoftLayer_Product_Package.py +++ b/SoftLayer/fixtures/SoftLayer_Product_Package.py @@ -916,7 +916,7 @@ 'prices': [{'id': 611}], }] -getItemPrices = [ +getItemPricesISCSI = [ { 'currentPriceFlag': '', 'id': 2152, @@ -1340,3 +1340,177 @@ }] }] }] + +getItemPrices = [ + { + "hourlyRecurringFee": ".093", + "id": 204015, + "recurringFee": "62", + "item": { + "description": "4 x 2.0 GHz or higher Cores", + "id": 859, + "keyName": "GUEST_CORES_4", + }, + "pricingLocationGroup": { + "id": 503, + "locations": [ + { + "id": 449610, + "longName": "Montreal 1", + "name": "mon01", + "statusId": 2 + }, + { + "id": 449618, + "longName": "Montreal 2", + "name": "mon02", + "statusId": 2 + }, + { + "id": 448994, + "longName": "Toronto 1", + "name": "tor01", + "statusId": 2 + }, + { + "id": 350993, + "longName": "Toronto 2", + "name": "tor02", + "statusId": 2 + }, + { + "id": 221894, + "longName": "Amsterdam 2", + "name": "ams02", + "statusId": 2 + }, + { + "id": 265592, + "longName": "Amsterdam 1", + "name": "ams01", + "statusId": 2 + }, + { + "id": 814994, + "longName": "Amsterdam 3", + "name": "ams03", + "statusId": 2 + } + ] + } + }, + { + "hourlyRecurringFee": ".006", + "id": 204663, + "recurringFee": "4.1", + "item": { + "description": "100 GB (LOCAL)", + "id": 3899, + "keyName": "GUEST_DISK_100_GB_LOCAL_3", + }, + "pricingLocationGroup": { + "id": 503, + "locations": [ + { + "id": 449610, + "longName": "Montreal 1", + "name": "mon01", + "statusId": 2 + }, + { + "id": 449618, + "longName": "Montreal 2", + "name": "mon02", + "statusId": 2 + }, + { + "id": 448994, + "longName": "Toronto 1", + "name": "tor01", + "statusId": 2 + }, + { + "id": 350993, + "longName": "Toronto 2", + "name": "tor02", + "statusId": 2 + }, + { + "id": 221894, + "longName": "Amsterdam 2", + "name": "ams02", + "statusId": 2 + }, + { + "id": 265592, + "longName": "Amsterdam 1", + "name": "ams01", + "statusId": 2 + }, + { + "id": 814994, + "longName": "Amsterdam 3", + "name": "ams03", + "statusId": 2 + } + ] + } + }, + { + "hourlyRecurringFee": ".217", + "id": 204255, + "recurringFee": "144", + "item": { + "description": "16 GB ", + "id": 1017, + "keyName": "RAM_16_GB", + }, + "pricingLocationGroup": { + "id": 503, + "locations": [ + { + "id": 449610, + "longName": "Montreal 1", + "name": "mon01", + "statusId": 2 + }, + { + "id": 449618, + "longName": "Montreal 2", + "name": "mon02", + "statusId": 2 + }, + { + "id": 448994, + "longName": "Toronto 1", + "name": "tor01", + "statusId": 2 + }, + { + "id": 350993, + "longName": "Toronto 2", + "name": "tor02", + "statusId": 2 + }, + { + "id": 221894, + "longName": "Amsterdam 2", + "name": "ams02", + "statusId": 2 + }, + { + "id": 265592, + "longName": "Amsterdam 1", + "name": "ams01", + "statusId": 2 + }, + { + "id": 814994, + "longName": "Amsterdam 3", + "name": "ams03", + "statusId": 2 + } + ] + } + } +] diff --git a/SoftLayer/managers/ordering.py b/SoftLayer/managers/ordering.py index 1341a7fc2..01a182ae1 100644 --- a/SoftLayer/managers/ordering.py +++ b/SoftLayer/managers/ordering.py @@ -384,6 +384,20 @@ def get_preset_prices(self, preset): prices = self.package_preset.getObject(id=preset, mask=mask) return prices + def get_item_prices(self, package_id): + """Get item prices. + + Retrieve a SoftLayer_Product_Package item prices record. + + :param int package_id: package identifier. + :returns: A list of price IDs associated with the given package. + + """ + mask = 'mask[pricingLocationGroup[locations]]' + + prices = self.package_svc.getItemPrices(id=package_id, mask=mask) + return prices + def verify_order(self, package_keyname, location, item_keynames, complex_type=None, hourly=True, preset_keyname=None, extras=None, quantity=1): """Verifies an order with the given package and prices. diff --git a/tests/managers/ordering_tests.py b/tests/managers/ordering_tests.py index f9b662855..0ea7c7546 100644 --- a/tests/managers/ordering_tests.py +++ b/tests/managers/ordering_tests.py @@ -74,6 +74,12 @@ def test_get_preset_prices(self): self.assertEqual(result, fixtures.SoftLayer_Product_Package_Preset.getObject) self.assert_called_with('SoftLayer_Product_Package_Preset', 'getObject') + def test_get_item_prices(self): + result = self.ordering.get_item_prices(835) + + self.assertEqual(result, fixtures.SoftLayer_Product_Package.getItemPrices) + self.assert_called_with('SoftLayer_Product_Package', 'getItemPrices') + def test_get_package_id_by_type_fails_for_nonexistent_package_type(self): p_mock = self.set_mock('SoftLayer_Product_Package', 'getAllObjects') p_mock.return_value = []