From 9728e8f24285e4f2b10f77c7326cf9c67252948e Mon Sep 17 00:00:00 2001 From: Christopher Gallo Date: Thu, 20 Feb 2025 13:09:14 -0600 Subject: [PATCH] #2114 fixed an issue when placing an order doesn't find the correct datacenter --- SoftLayer/CLI/order/place.py | 2 +- tests/CLI/modules/order_tests.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/SoftLayer/CLI/order/place.py b/SoftLayer/CLI/order/place.py index 97c41784f..eb6c45e98 100644 --- a/SoftLayer/CLI/order/place.py +++ b/SoftLayer/CLI/order/place.py @@ -65,7 +65,7 @@ def cli(env, package_keyname, location, preset, verify, billing, complex_type, pods = network.get_closed_pods() location_dc = network.get_datacenter_by_keyname(location) for pod in pods: - if location_dc.get('name') in pod.get('name'): + if location_dc and location_dc.get('name') in pod.get('name'): click.secho(f"Warning: Closed soon: {pod.get('name')}", fg='yellow') if extras: diff --git a/tests/CLI/modules/order_tests.py b/tests/CLI/modules/order_tests.py index dc2c892a6..29beca5a7 100644 --- a/tests/CLI/modules/order_tests.py +++ b/tests/CLI/modules/order_tests.py @@ -10,6 +10,7 @@ from unittest import mock as mock from SoftLayer.CLI import exceptions +from SoftLayer.exceptions import SoftLayerError as SoftLayerError from SoftLayer import testing @@ -452,6 +453,15 @@ def test_quote_delete(self): self.assert_no_fail(result) self.assert_called_with('SoftLayer_Billing_Order_Quote', 'deleteQuote', identifier='12345') + def test_empty_get_datacenter(self): + """https://github.com/softlayer/softlayer-python/issues/2114 """ + dc_mock = self.set_mock('SoftLayer_Location', 'getDatacenters') + dc_mock.side_effect = [[], [{'name': 'dal13', 'id': 123}]] + result = self.run_command(['--really', 'order', 'place', 'SOFTWARE_LICENSE_PACKAGE', 'dal13', 'SOMETHING']) + self.assertEqual(result.exit_code, 1) + self.assertIsInstance(result.exception, SoftLayerError) + self.assertEqual(str(result.exception), "A complex type must be specified with the order") + def _get_all_packages(): package_type = {'keyName': 'BARE_METAL_CPU'}