Skip to content

Commit 3e0faad

Browse files
author
Fernando Ojeda
committed
Fix hardware detail bandwidth allocation.
1 parent 4c341bf commit 3e0faad

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

SoftLayer/CLI/hardware/detail.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,19 @@ def cli(env, identifier, passwords, price):
9292

9393

9494
def _bw_table(bw_data):
95-
"""Generates a bandwidth useage table"""
95+
"""Generates a bandwidth usage table"""
9696
table = formatting.Table(['Type', 'In GB', 'Out GB', 'Allotment'])
97-
for bw_point in bw_data.get('useage'):
97+
for bw_point in bw_data.get('usage'):
9898
bw_type = 'Private'
9999
allotment = 'N/A'
100100
if bw_point['type']['alias'] == 'PUBLIC_SERVER_BW':
101101
bw_type = 'Public'
102-
allotment = utils.lookup(bw_data, 'allotment', 'amount')
103-
if allotment is None:
102+
if bw_data.get('allotment') is None:
104103
allotment = '-'
104+
else:
105+
allotment = utils.lookup(bw_data, 'allotment', 'amount')
106+
if allotment is None:
107+
allotment = '-'
105108

106109
table.add_row([bw_type, bw_point['amountIn'], bw_point['amountOut'], allotment])
107110
return table

SoftLayer/managers/hardware.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -697,8 +697,11 @@ def get_bandwidth_allocation(self, instance_id):
697697
a_mask = "mask[allocation[amount]]"
698698
allotment = self.client.call('Hardware_Server', 'getBandwidthAllotmentDetail', id=instance_id, mask=a_mask)
699699
u_mask = "mask[amountIn,amountOut,type]"
700-
useage = self.client.call('Hardware_Server', 'getBillingCycleBandwidthUsage', id=instance_id, mask=u_mask)
701-
return {'allotment': allotment.get('allocation'), 'useage': useage}
700+
usage = self.client.call('Hardware_Server', 'getBillingCycleBandwidthUsage', id=instance_id, mask=u_mask)
701+
allotment_bandwidth = None
702+
if allotment is not "":
703+
allotment_bandwidth = allotment.get('allocation')
704+
return {'allotment': allotment_bandwidth, 'usage': usage}
702705

703706

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

tests/managers/hardware_tests.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ def test_get_bandwidth_allocation(self):
446446
self.assert_called_with('SoftLayer_Hardware_Server', 'getBandwidthAllotmentDetail', identifier=1234)
447447
self.assert_called_with('SoftLayer_Hardware_Server', 'getBillingCycleBandwidthUsage', identifier=1234)
448448
self.assertEqual(result['allotment']['amount'], '250')
449-
self.assertEqual(result['useage'][0]['amountIn'], '.448')
449+
self.assertEqual(result['usage'][0]['amountIn'], '.448')
450450

451451
def test_get_bandwidth_allocation_no_allotment(self):
452452
mock = self.set_mock('SoftLayer_Hardware_Server', 'getBandwidthAllotmentDetail')
@@ -456,6 +456,14 @@ def test_get_bandwidth_allocation_no_allotment(self):
456456

457457
self.assertEqual(None, result['allotment'])
458458

459+
def test_get_bandwidth_allocation_empty_allotment(self):
460+
mock = self.set_mock('SoftLayer_Hardware_Server', 'getBandwidthAllotmentDetail')
461+
mock.return_value = ""
462+
463+
result = self.hardware.get_bandwidth_allocation(1234)
464+
465+
self.assertEqual(None, result['allotment'])
466+
459467

460468
class HardwareHelperTests(testing.TestCase):
461469
def test_get_extra_price_id_no_items(self):

0 commit comments

Comments
 (0)