Skip to content

Commit 11dac93

Browse files
Merge pull request #1161 from camporter/handle_missing_bandwidth_info
Handle missing/empty bandwidth allocation information
2 parents 7e7b3fe + 56474a9 commit 11dac93

File tree

6 files changed

+24
-4
lines changed

6 files changed

+24
-4
lines changed

SoftLayer/CLI/hardware/detail.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ def _bw_table(bw_data):
9999
allotment = 'N/A'
100100
if bw_point['type']['alias'] == 'PUBLIC_SERVER_BW':
101101
bw_type = 'Public'
102-
allotment = bw_data['allotment'].get('amount', '-')
102+
allotment = utils.lookup(bw_data, 'allotment', 'amount')
103+
if allotment is None:
104+
allotment = '-'
103105

104106
table.add_row([bw_type, bw_point['amountIn'], bw_point['amountOut'], allotment])
105107
return table

SoftLayer/CLI/virt/detail.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ def _bw_table(bw_data):
131131
allotment = 'N/A'
132132
if bw_point['type']['alias'] == 'PUBLIC_SERVER_BW':
133133
bw_type = 'Public'
134-
allotment = bw_data['allotment'].get('amount', '-')
134+
allotment = utils.lookup(bw_data, 'allotment', 'amount')
135+
if allotment is None:
136+
allotment = '-'
135137

136138
table.add_row([bw_type, bw_point['amountIn'], bw_point['amountOut'], allotment])
137139
return table

SoftLayer/managers/hardware.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ def get_bandwidth_allocation(self, instance_id):
698698
allotment = self.client.call('Hardware_Server', 'getBandwidthAllotmentDetail', id=instance_id, mask=a_mask)
699699
u_mask = "mask[amountIn,amountOut,type]"
700700
useage = self.client.call('Hardware_Server', 'getBillingCycleBandwidthUsage', id=instance_id, mask=u_mask)
701-
return {'allotment': allotment['allocation'], 'useage': useage}
701+
return {'allotment': allotment.get('allocation'), 'useage': useage}
702702

703703

704704
def _get_extra_price_id(items, key_name, hourly, location):

SoftLayer/managers/vs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1067,7 +1067,7 @@ def get_bandwidth_allocation(self, instance_id):
10671067
allotment = self.client.call('Virtual_Guest', 'getBandwidthAllotmentDetail', id=instance_id, mask=a_mask)
10681068
u_mask = "mask[amountIn,amountOut,type]"
10691069
useage = self.client.call('Virtual_Guest', 'getBillingCycleBandwidthUsage', id=instance_id, mask=u_mask)
1070-
return {'allotment': allotment['allocation'], 'useage': useage}
1070+
return {'allotment': allotment.get('allocation'), 'useage': useage}
10711071

10721072
# pylint: disable=inconsistent-return-statements
10731073
def _get_price_id_for_upgrade(self, package_items, option, value, public=True):

tests/managers/hardware_tests.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,14 @@ def test_get_bandwidth_allocation(self):
448448
self.assertEqual(result['allotment']['amount'], '250')
449449
self.assertEqual(result['useage'][0]['amountIn'], '.448')
450450

451+
def test_get_bandwidth_allocation_no_allotment(self):
452+
mock = self.set_mock('SoftLayer_Hardware_Server', 'getBandwidthAllotmentDetail')
453+
mock.return_value = {}
454+
455+
result = self.hardware.get_bandwidth_allocation(1234)
456+
457+
self.assertEqual(None, result['allotment'])
458+
451459

452460
class HardwareHelperTests(testing.TestCase):
453461
def test_get_extra_price_id_no_items(self):

tests/managers/vs/vs_tests.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,3 +903,11 @@ def test_get_bandwidth_allocation(self):
903903
self.assert_called_with('SoftLayer_Virtual_Guest', 'getBillingCycleBandwidthUsage', identifier=1234)
904904
self.assertEqual(result['allotment']['amount'], '250')
905905
self.assertEqual(result['useage'][0]['amountIn'], '.448')
906+
907+
def test_get_bandwidth_allocation_no_allotment(self):
908+
mock = self.set_mock('SoftLayer_Virtual_Guest', 'getBandwidthAllotmentDetail')
909+
mock.return_value = {}
910+
911+
result = self.vs.get_bandwidth_allocation(1234)
912+
913+
self.assertEqual(None, result['allotment'])

0 commit comments

Comments
 (0)