From 23406bbf32e657e95144bf1759ac8d6bb3ded6f6 Mon Sep 17 00:00:00 2001 From: Albert Camacho Date: Mon, 8 Apr 2019 18:30:20 -0400 Subject: [PATCH 1/4] #1129 fixed issue in slcli subnet create --- SoftLayer/CLI/subnet/create.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SoftLayer/CLI/subnet/create.py b/SoftLayer/CLI/subnet/create.py index 0f81c574b..45c3f4619 100644 --- a/SoftLayer/CLI/subnet/create.py +++ b/SoftLayer/CLI/subnet/create.py @@ -13,7 +13,7 @@ @click.argument('network', type=click.Choice(['public', 'private'])) @click.argument('quantity', type=click.INT) @click.argument('vlan-id') -@click.option('--v6', '--ipv6', is_flag=True, help="Order IPv6 Addresses") +@click.option('--ipv6', '--v6', is_flag=True, help="Order IPv6 Addresses") @click.option('--test', is_flag=True, help="Do not order the subnet; just get a quote") From 2758e336183f06daa0e6f841fdd25f9bc4a6fea4 Mon Sep 17 00:00:00 2001 From: Albert Camacho Date: Tue, 9 Apr 2019 17:35:53 -0400 Subject: [PATCH 2/4] exception when there is no prices was refactored --- SoftLayer/CLI/subnet/create.py | 12 ++++-------- SoftLayer/managers/network.py | 4 ---- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/SoftLayer/CLI/subnet/create.py b/SoftLayer/CLI/subnet/create.py index 45c3f4619..1844cf627 100644 --- a/SoftLayer/CLI/subnet/create.py +++ b/SoftLayer/CLI/subnet/create.py @@ -42,14 +42,10 @@ def cli(env, network, quantity, vlan_id, ipv6, test): if ipv6: version = 6 - result = mgr.add_subnet(network, - quantity=quantity, - vlan_id=vlan_id, - version=version, - test_order=test) - if not result: - raise exceptions.CLIAbort( - 'Unable to place order: No valid price IDs found.') + try: + result = mgr.add_subnet(network, quantity=quantity, vlan_id=vlan_id, version=version, test_order=test) + except SoftLayer.SoftLayerAPIError: + raise exceptions.CLIAbort('There is no price id for {} {} ipv{}'.format(quantity, network, version)) table = formatting.Table(['Item', 'cost']) table.align['Item'] = 'r' diff --git a/SoftLayer/managers/network.py b/SoftLayer/managers/network.py index 4223143ae..4ecd76d3f 100644 --- a/SoftLayer/managers/network.py +++ b/SoftLayer/managers/network.py @@ -150,10 +150,6 @@ def add_subnet(self, subnet_type, quantity=None, vlan_id=None, version=4, price_id = item['prices'][0]['id'] break - if not price_id: - raise TypeError('Invalid combination specified for ordering a' - ' subnet.') - order = { 'packageId': 0, 'prices': [{'id': price_id}], From fe3c15ec846c91013648b95c72f6b2503f8b7607 Mon Sep 17 00:00:00 2001 From: "Albert J. Camacho" Date: Wed, 10 Apr 2019 11:55:20 -0400 Subject: [PATCH 3/4] #1129 unit tests --- tests/CLI/modules/subnet_tests.py | 57 +++++++++++++++++++++++++++++++ tests/managers/network_tests.py | 3 -- 2 files changed, 57 insertions(+), 3 deletions(-) diff --git a/tests/CLI/modules/subnet_tests.py b/tests/CLI/modules/subnet_tests.py index 72825e0f9..9fa7d3925 100644 --- a/tests/CLI/modules/subnet_tests.py +++ b/tests/CLI/modules/subnet_tests.py @@ -4,12 +4,17 @@ :license: MIT, see LICENSE for more details. """ +from SoftLayer.fixtures import SoftLayer_Product_Order +from SoftLayer.fixtures import SoftLayer_Product_Package from SoftLayer import testing import json +import mock +import SoftLayer class SubnetTests(testing.TestCase): + def test_detail(self): result = self.run_command(['subnet', 'detail', '1234']) @@ -39,3 +44,55 @@ def test_detail(self): def test_list(self): result = self.run_command(['subnet', 'list']) self.assert_no_fail(result) + + @mock.patch('SoftLayer.CLI.formatting.confirm') + def test_create_subnet_ipv4(self, confirm_mock): + confirm_mock.return_value = True + + item_mock = self.set_mock('SoftLayer_Product_Package', 'getItems') + item_mock.return_value = SoftLayer_Product_Package.getItems + + place_mock = self.set_mock('SoftLayer_Product_Order', 'placeOrder') + place_mock.return_value = SoftLayer_Product_Order.placeOrder + + result = self.run_command(['subnet', 'create', 'private', '8', '12346']) + self.assert_no_fail(result) + + output = [ + {'Item': 'this is a thing', 'cost': '2.00'}, + {'Item': 'Total monthly cost', 'cost': '2.00'} + ] + + self.assertEqual(output, json.loads(result.output)) + + @mock.patch('SoftLayer.CLI.formatting.confirm') + def test_create_subnet_ipv6(self, confirm_mock): + confirm_mock.return_value = True + + item_mock = self.set_mock('SoftLayer_Product_Package', 'getItems') + item_mock.return_value = SoftLayer_Product_Package.getItems + + place_mock = self.set_mock('SoftLayer_Product_Order', 'placeOrder') + place_mock.return_value = SoftLayer_Product_Order.placeOrder + + result = self.run_command(['subnet', 'create', '--v6', 'public', '64', '12346', '--test']) + self.assert_no_fail(result) + + output = [ + {'Item': 'this is a thing', 'cost': '2.00'}, + {'Item': 'Total monthly cost', 'cost': '2.00'} + ] + + self.assertEqual(output, json.loads(result.output)) + + def test_create_subnet_no_prices_found(self): + item_mock = self.set_mock('SoftLayer_Product_Package', 'getItems') + item_mock.return_value = SoftLayer_Product_Package.getItems + + verify_mock = self.set_mock('SoftLayer_Product_Order', 'verifyOrder') + verify_mock.side_effect = SoftLayer.SoftLayerAPIError('SoftLayer_Exception', 'Price not found') + + result = self.run_command(['subnet', 'create', '--v6', 'public', '32', '12346', '--test']) + + self.assertRaises(SoftLayer.SoftLayerAPIError, verify_mock) + self.assertEqual(result.exception.message, 'There is no price id for 32 public ipv6') diff --git a/tests/managers/network_tests.py b/tests/managers/network_tests.py index 7a84bebae..223b7a3b5 100644 --- a/tests/managers/network_tests.py +++ b/tests/managers/network_tests.py @@ -24,9 +24,6 @@ def test_ip_lookup(self): 'getByIpAddress', args=('10.0.1.37',)) - def test_add_subnet_raises_exception_on_failure(self): - self.assertRaises(TypeError, self.network.add_subnet, ('bad')) - def test_add_global_ip(self): # Test a global IPv4 order result = self.network.add_global_ip(test_order=True) From 6d5b3f41d84194a6e8a06ea0333a9cd099beb9c4 Mon Sep 17 00:00:00 2001 From: "Albert J. Camacho" Date: Wed, 10 Apr 2019 12:22:40 -0400 Subject: [PATCH 4/4] #1129 fix unit tests --- tests/CLI/modules/subnet_tests.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/CLI/modules/subnet_tests.py b/tests/CLI/modules/subnet_tests.py index 9fa7d3925..47cb7e473 100644 --- a/tests/CLI/modules/subnet_tests.py +++ b/tests/CLI/modules/subnet_tests.py @@ -59,8 +59,7 @@ def test_create_subnet_ipv4(self, confirm_mock): self.assert_no_fail(result) output = [ - {'Item': 'this is a thing', 'cost': '2.00'}, - {'Item': 'Total monthly cost', 'cost': '2.00'} + {'Item': 'Total monthly cost', 'cost': '0.00'} ] self.assertEqual(output, json.loads(result.output)) @@ -72,8 +71,8 @@ def test_create_subnet_ipv6(self, confirm_mock): item_mock = self.set_mock('SoftLayer_Product_Package', 'getItems') item_mock.return_value = SoftLayer_Product_Package.getItems - place_mock = self.set_mock('SoftLayer_Product_Order', 'placeOrder') - place_mock.return_value = SoftLayer_Product_Order.placeOrder + place_mock = self.set_mock('SoftLayer_Product_Order', 'verifyOrder') + place_mock.return_value = SoftLayer_Product_Order.verifyOrder result = self.run_command(['subnet', 'create', '--v6', 'public', '64', '12346', '--test']) self.assert_no_fail(result)