Skip to content

Commit 8d589ae

Browse files
Merge pull request #2214 from softlayer/issues2114
fixed an issue when placing an order doesn't find the correct datacenter
2 parents 8b34597 + 9728e8f commit 8d589ae

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

SoftLayer/CLI/order/place.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def cli(env, package_keyname, location, preset, verify, billing, complex_type,
6565
pods = network.get_closed_pods()
6666
location_dc = network.get_datacenter_by_keyname(location)
6767
for pod in pods:
68-
if location_dc.get('name') in pod.get('name'):
68+
if location_dc and location_dc.get('name') in pod.get('name'):
6969
click.secho(f"Warning: Closed soon: {pod.get('name')}", fg='yellow')
7070

7171
if extras:

tests/CLI/modules/order_tests.py

+10
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from unittest import mock as mock
1111

1212
from SoftLayer.CLI import exceptions
13+
from SoftLayer.exceptions import SoftLayerError as SoftLayerError
1314
from SoftLayer import testing
1415

1516

@@ -452,6 +453,15 @@ def test_quote_delete(self):
452453
self.assert_no_fail(result)
453454
self.assert_called_with('SoftLayer_Billing_Order_Quote', 'deleteQuote', identifier='12345')
454455

456+
def test_empty_get_datacenter(self):
457+
"""https://github.com/softlayer/softlayer-python/issues/2114 """
458+
dc_mock = self.set_mock('SoftLayer_Location', 'getDatacenters')
459+
dc_mock.side_effect = [[], [{'name': 'dal13', 'id': 123}]]
460+
result = self.run_command(['--really', 'order', 'place', 'SOFTWARE_LICENSE_PACKAGE', 'dal13', 'SOMETHING'])
461+
self.assertEqual(result.exit_code, 1)
462+
self.assertIsInstance(result.exception, SoftLayerError)
463+
self.assertEqual(str(result.exception), "A complex type must be specified with the order")
464+
455465

456466
def _get_all_packages():
457467
package_type = {'keyName': 'BARE_METAL_CPU'}

0 commit comments

Comments
 (0)