Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions SoftLayer/CLI/subnet/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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'
Expand Down
4 changes: 0 additions & 4 deletions SoftLayer/managers/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}],
Expand Down
56 changes: 56 additions & 0 deletions tests/CLI/modules/subnet_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])

Expand Down Expand Up @@ -39,3 +44,54 @@ 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': 'Total monthly cost', 'cost': '0.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', '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)

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')
3 changes: 0 additions & 3 deletions tests/managers/network_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down