Skip to content

Commit 867a04b

Browse files
Merge pull request #1213 from FernandoOjeda/fo_vs_detail
Fix vs detail.
2 parents 01f580f + b8da338 commit 867a04b

File tree

4 files changed

+35
-7
lines changed

4 files changed

+35
-7
lines changed

SoftLayer/CLI/virt/detail.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,15 @@ def cli(env, identifier, passwords=False, price=False):
126126
def _bw_table(bw_data):
127127
"""Generates a bandwidth useage table"""
128128
table = formatting.Table(['Type', 'In GB', 'Out GB', 'Allotment'])
129-
for bw_point in bw_data.get('useage'):
129+
for bw_point in bw_data.get('usage'):
130130
bw_type = 'Private'
131131
allotment = 'N/A'
132132
if bw_point['type']['alias'] == 'PUBLIC_SERVER_BW':
133133
bw_type = 'Public'
134-
allotment = utils.lookup(bw_data, 'allotment', 'amount')
135-
if allotment is None:
134+
if not bw_data.get('allotment'):
136135
allotment = '-'
136+
else:
137+
allotment = utils.lookup(bw_data, 'allotment', 'amount')
137138

138139
table.add_row([bw_type, bw_point['amountIn'], bw_point['amountOut'], allotment])
139140
return table

SoftLayer/managers/vs.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,8 +1074,10 @@ def get_bandwidth_allocation(self, instance_id):
10741074
a_mask = "mask[allocation[amount]]"
10751075
allotment = self.client.call('Virtual_Guest', 'getBandwidthAllotmentDetail', id=instance_id, mask=a_mask)
10761076
u_mask = "mask[amountIn,amountOut,type]"
1077-
useage = self.client.call('Virtual_Guest', 'getBillingCycleBandwidthUsage', id=instance_id, mask=u_mask)
1078-
return {'allotment': allotment.get('allocation'), 'useage': useage}
1077+
usage = self.client.call('Virtual_Guest', 'getBillingCycleBandwidthUsage', id=instance_id, mask=u_mask)
1078+
if allotment:
1079+
return {'allotment': allotment.get('allocation'), 'usage': usage}
1080+
return {'allotment': allotment, 'usage': usage}
10791081

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

tests/CLI/modules/vs/vs_tests.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,17 @@ def test_detail_vs_empty_tag(self):
205205
['example-tag'],
206206
)
207207

208+
def test_detail_vs_empty_allotment(self):
209+
mock = self.set_mock('SoftLayer_Virtual_Guest', 'getBandwidthAllotmentDetail')
210+
mock.return_value = None
211+
result = self.run_command(['vs', 'detail', '100'])
212+
213+
self.assert_no_fail(result)
214+
self.assertEqual(
215+
json.loads(result.output)['Bandwidth'][0]['Allotment'],
216+
'-',
217+
)
218+
208219
def test_detail_vs_dedicated_host_not_found(self):
209220
ex = SoftLayerAPIError('SoftLayer_Exception', 'Not found')
210221
mock = self.set_mock('SoftLayer_Virtual_DedicatedHost', 'getObject')

tests/managers/vs/vs_tests.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -902,12 +902,26 @@ def test_get_bandwidth_allocation(self):
902902
self.assert_called_with('SoftLayer_Virtual_Guest', 'getBandwidthAllotmentDetail', identifier=1234)
903903
self.assert_called_with('SoftLayer_Virtual_Guest', 'getBillingCycleBandwidthUsage', identifier=1234)
904904
self.assertEqual(result['allotment']['amount'], '250')
905-
self.assertEqual(result['useage'][0]['amountIn'], '.448')
905+
self.assertEqual(result['usage'][0]['amountIn'], '.448')
906906

907907
def test_get_bandwidth_allocation_no_allotment(self):
908908
mock = self.set_mock('SoftLayer_Virtual_Guest', 'getBandwidthAllotmentDetail')
909-
mock.return_value = {}
909+
mock.return_value = None
910910

911911
result = self.vs.get_bandwidth_allocation(1234)
912912

913913
self.assertEqual(None, result['allotment'])
914+
915+
def test_get_bandwidth_allocation_with_allotment(self):
916+
mock = self.set_mock('SoftLayer_Virtual_Guest', 'getBandwidthAllotmentDetail')
917+
mock.return_value = {
918+
"allocationId": 11111,
919+
"id": 22222,
920+
"allocation": {
921+
"amount": "2000"
922+
}
923+
}
924+
925+
result = self.vs.get_bandwidth_allocation(1234)
926+
927+
self.assertEqual(2000, int(result['allotment']['amount']))

0 commit comments

Comments
 (0)