diff --git a/SoftLayer/CLI/hardware/detail.py b/SoftLayer/CLI/hardware/detail.py index e254ad33e..3a55f1b6d 100644 --- a/SoftLayer/CLI/hardware/detail.py +++ b/SoftLayer/CLI/hardware/detail.py @@ -99,7 +99,9 @@ def _bw_table(bw_data): allotment = 'N/A' if bw_point['type']['alias'] == 'PUBLIC_SERVER_BW': bw_type = 'Public' - allotment = bw_data['allotment'].get('amount', '-') + allotment = utils.lookup(bw_data, 'allotment', 'amount') + if allotment is None: + allotment = '-' table.add_row([bw_type, bw_point['amountIn'], bw_point['amountOut'], allotment]) return table diff --git a/SoftLayer/CLI/virt/detail.py b/SoftLayer/CLI/virt/detail.py index 53ae7e04d..bf93a8342 100644 --- a/SoftLayer/CLI/virt/detail.py +++ b/SoftLayer/CLI/virt/detail.py @@ -131,7 +131,9 @@ def _bw_table(bw_data): allotment = 'N/A' if bw_point['type']['alias'] == 'PUBLIC_SERVER_BW': bw_type = 'Public' - allotment = bw_data['allotment'].get('amount', '-') + allotment = utils.lookup(bw_data, 'allotment', 'amount') + if allotment is None: + allotment = '-' table.add_row([bw_type, bw_point['amountIn'], bw_point['amountOut'], allotment]) return table diff --git a/SoftLayer/managers/hardware.py b/SoftLayer/managers/hardware.py index f5b01646b..fb85c3282 100644 --- a/SoftLayer/managers/hardware.py +++ b/SoftLayer/managers/hardware.py @@ -698,7 +698,7 @@ def get_bandwidth_allocation(self, instance_id): allotment = self.client.call('Hardware_Server', 'getBandwidthAllotmentDetail', id=instance_id, mask=a_mask) u_mask = "mask[amountIn,amountOut,type]" useage = self.client.call('Hardware_Server', 'getBillingCycleBandwidthUsage', id=instance_id, mask=u_mask) - return {'allotment': allotment['allocation'], 'useage': useage} + return {'allotment': allotment.get('allocation'), 'useage': useage} def _get_extra_price_id(items, key_name, hourly, location): diff --git a/SoftLayer/managers/vs.py b/SoftLayer/managers/vs.py index 85bbdf9d9..de845096b 100644 --- a/SoftLayer/managers/vs.py +++ b/SoftLayer/managers/vs.py @@ -1067,7 +1067,7 @@ def get_bandwidth_allocation(self, instance_id): allotment = self.client.call('Virtual_Guest', 'getBandwidthAllotmentDetail', id=instance_id, mask=a_mask) u_mask = "mask[amountIn,amountOut,type]" useage = self.client.call('Virtual_Guest', 'getBillingCycleBandwidthUsage', id=instance_id, mask=u_mask) - return {'allotment': allotment['allocation'], 'useage': useage} + return {'allotment': allotment.get('allocation'), 'useage': useage} # pylint: disable=inconsistent-return-statements def _get_price_id_for_upgrade(self, package_items, option, value, public=True): diff --git a/tests/managers/hardware_tests.py b/tests/managers/hardware_tests.py index 120f60601..7cff11303 100644 --- a/tests/managers/hardware_tests.py +++ b/tests/managers/hardware_tests.py @@ -448,6 +448,14 @@ def test_get_bandwidth_allocation(self): self.assertEqual(result['allotment']['amount'], '250') self.assertEqual(result['useage'][0]['amountIn'], '.448') + def test_get_bandwidth_allocation_no_allotment(self): + mock = self.set_mock('SoftLayer_Hardware_Server', 'getBandwidthAllotmentDetail') + mock.return_value = {} + + result = self.hardware.get_bandwidth_allocation(1234) + + self.assertEqual(None, result['allotment']) + class HardwareHelperTests(testing.TestCase): def test_get_extra_price_id_no_items(self): diff --git a/tests/managers/vs/vs_tests.py b/tests/managers/vs/vs_tests.py index 2816f8b06..14d41966c 100644 --- a/tests/managers/vs/vs_tests.py +++ b/tests/managers/vs/vs_tests.py @@ -903,3 +903,11 @@ def test_get_bandwidth_allocation(self): self.assert_called_with('SoftLayer_Virtual_Guest', 'getBillingCycleBandwidthUsage', identifier=1234) self.assertEqual(result['allotment']['amount'], '250') self.assertEqual(result['useage'][0]['amountIn'], '.448') + + def test_get_bandwidth_allocation_no_allotment(self): + mock = self.set_mock('SoftLayer_Virtual_Guest', 'getBandwidthAllotmentDetail') + mock.return_value = {} + + result = self.vs.get_bandwidth_allocation(1234) + + self.assertEqual(None, result['allotment'])