Skip to content

Commit ad4186c

Browse files
#1575 unit tests for bandwidth pooling code
1 parent 2e7ac4a commit ad4186c

File tree

6 files changed

+86
-191
lines changed

6 files changed

+86
-191
lines changed

SoftLayer/fixtures/SoftLayer_Account.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,3 +1207,21 @@
12071207
"version": 4
12081208
}
12091209
}]
1210+
1211+
getBandwidthAllotments = [{
1212+
'billingCyclePublicBandwidthUsage': {
1213+
'amountIn': '6.94517',
1214+
'amountOut': '6.8859'
1215+
},
1216+
'id': 309961,
1217+
'locationGroup': {
1218+
'description': 'All Datacenters in Mexico',
1219+
'id': 262,
1220+
'locationGroupTypeId': 1,
1221+
'name': 'MEX',
1222+
'securityLevelId': None
1223+
},
1224+
'name': 'MexRegion',
1225+
'projectedPublicBandwidthUsage': 9.88,
1226+
'totalBandwidthAllocated': 3361
1227+
}]
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
getObject = {
2+
'id': 309961,
3+
'bareMetalInstanceCount': 0,
4+
'hardwareCount': 2,
5+
'virtualGuestCount': 0
6+
}

docs/cli/account.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,7 @@ Account Commands
4343
.. click:: SoftLayer.CLI.account.licenses:cli
4444
:prog: account licenses
4545
:show-nested:
46+
47+
.. click:: SoftLayer.CLI.account.bandwidth_pools:cli
48+
:prog: account bandwidth-pools
49+
:show-nested:

tests/CLI/modules/account_tests.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,9 @@ def test_acccount_licenses(self):
136136
self.assert_no_fail(result)
137137
self.assert_called_with('SoftLayer_Account', 'getActiveVirtualLicenses')
138138
self.assert_called_with('SoftLayer_Account', 'getActiveAccountLicenses')
139+
140+
def test_bandwidth_pools(self):
141+
result = self.run_command(['account', 'bandwidth-pools'])
142+
self.assert_no_fail(result)
143+
self.assert_called_with('SoftLayer_Account', 'getBandwidthAllotments')
144+
self.assert_called_with('SoftLayer_Network_Bandwidth_Version1_Allotment', 'getObject')

tests/CLI/modules/report_tests.py

Lines changed: 42 additions & 191 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import json
1010

11+
from pprint import pprint as pp
1112

1213
class ReportTests(testing.TestCase):
1314

@@ -76,8 +77,7 @@ def test_bandwidth_report(self):
7677
'hostname': 'host3',
7778
'virtualRack': {'id': 2, 'bandwidthAllotmentTypeId': 2},
7879
}]
79-
summary_data = self.set_mock('SoftLayer_Metric_Tracking_Object',
80-
'getSummaryData')
80+
summary_data = self.set_mock('SoftLayer_Metric_Tracking_Object', 'getSummaryData')
8181
summary_data.return_value = [
8282
{'type': 'publicIn_net_octet', 'counter': 10},
8383
{'type': 'publicOut_net_octet', 'counter': 20},
@@ -93,86 +93,23 @@ def test_bandwidth_report(self):
9393
])
9494

9595
self.assert_no_fail(result)
96+
9697
stripped_output = '[' + result.output.split('[', 1)[1]
97-
self.assertEqual([
98-
{
99-
'hostname': 'pool1',
100-
'pool': None,
101-
'private_in': 30,
102-
'private_out': 40,
103-
'public_in': 10,
104-
'public_out': 20,
105-
'type': 'pool'
106-
}, {
107-
'hostname': 'pool3',
108-
'pool': None,
109-
'private_in': 30,
110-
'private_out': 40,
111-
'public_in': 10,
112-
'public_out': 20,
113-
'type': 'pool'
114-
}, {
115-
'hostname': 'host1',
116-
'pool': None,
117-
'private_in': 30,
118-
'private_out': 40,
119-
'public_in': 10,
120-
'public_out': 20,
121-
'type': 'hardware'
122-
}, {
123-
'hostname': 'host3',
124-
'pool': None,
125-
'private_in': 30,
126-
'private_out': 40,
127-
'public_in': 10,
128-
'public_out': 20,
129-
'type': 'hardware'
130-
}, {
131-
'hostname': 'host1',
132-
'pool': None,
133-
'private_in': 30,
134-
'private_out': 40,
135-
'public_in': 10,
136-
'public_out': 20,
137-
'type': 'virtual'
138-
}, {
139-
'hostname': 'host3',
140-
'pool': 2,
141-
'private_in': 30,
142-
'private_out': 40,
143-
'public_in': 10,
144-
'public_out': 20,
145-
'type': 'virtual'}],
146-
json.loads(stripped_output),
147-
)
148-
self.assertEqual(
149-
6,
150-
len(self.calls('SoftLayer_Metric_Tracking_Object',
151-
'getSummaryData')),
152-
)
153-
self.assert_called_with('SoftLayer_Metric_Tracking_Object',
154-
'getSummaryData',
155-
identifier=1)
156-
self.assert_called_with('SoftLayer_Metric_Tracking_Object',
157-
'getSummaryData',
158-
identifier=3)
159-
self.assert_called_with('SoftLayer_Metric_Tracking_Object',
160-
'getSummaryData',
161-
identifier=101)
162-
self.assert_called_with('SoftLayer_Metric_Tracking_Object',
163-
'getSummaryData',
164-
identifier=103)
165-
self.assert_called_with('SoftLayer_Metric_Tracking_Object',
166-
'getSummaryData',
167-
identifier=201)
168-
self.assert_called_with('SoftLayer_Metric_Tracking_Object',
169-
'getSummaryData',
170-
identifier=203)
171-
call = self.calls('SoftLayer_Metric_Tracking_Object', 'getSummaryData',
172-
identifier=1)[0]
173-
expected_args = (
174-
'2016-02-04 00:00:00 ',
175-
'2016-03-04 12:34:56 ',
98+
json_output = json.loads(stripped_output)
99+
pp(json.loads(stripped_output))
100+
print("======= ^^^^^^^^^ ==============")
101+
self.assertEqual(json_output[0]['hostname'], 'pool1')
102+
self.assertEqual(json_output[0]['private_in'], 30)
103+
104+
self.assertEqual(6, len(self.calls('SoftLayer_Metric_Tracking_Object', 'getSummaryData')))
105+
self.assert_called_with('SoftLayer_Metric_Tracking_Object', 'getSummaryData', identifier=1)
106+
self.assert_called_with('SoftLayer_Metric_Tracking_Object', 'getSummaryData', identifier=3)
107+
self.assert_called_with('SoftLayer_Metric_Tracking_Object', 'getSummaryData', identifier=101)
108+
self.assert_called_with('SoftLayer_Metric_Tracking_Object', 'getSummaryData', identifier=103)
109+
self.assert_called_with('SoftLayer_Metric_Tracking_Object', 'getSummaryData', identifier=201)
110+
self.assert_called_with('SoftLayer_Metric_Tracking_Object', 'getSummaryData', identifier=203)
111+
call = self.calls('SoftLayer_Metric_Tracking_Object', 'getSummaryData', identifier=1)[0]
112+
expected_args = ('2016-02-04 00:00:00 ', '2016-03-04 12:34:56 ',
176113
[{
177114
'keyName': 'PUBLICIN',
178115
'name': 'publicIn',
@@ -242,64 +179,19 @@ def test_virtual_bandwidth_report(self):
242179

243180
self.assert_no_fail(result)
244181
stripped_output = '[' + result.output.split('[', 1)[1]
245-
self.assertEqual([
246-
{
247-
'hostname': 'pool1',
248-
'pool': None,
249-
'private_in': 30,
250-
'private_out': 40,
251-
'public_in': 10,
252-
'public_out': 20,
253-
'type': 'pool',
254-
}, {
255-
'hostname': 'pool3',
256-
'pool': None,
257-
'private_in': 30,
258-
'private_out': 40,
259-
'public_in': 10,
260-
'public_out': 20,
261-
'type': 'pool',
262-
}, {
263-
'hostname': 'host1',
264-
'pool': None,
265-
'private_in': 30,
266-
'private_out': 40,
267-
'public_in': 10,
268-
'public_out': 20,
269-
'type': 'virtual',
270-
}, {
271-
'hostname': 'host3',
272-
'pool': 2,
273-
'private_in': 30,
274-
'private_out': 40,
275-
'public_in': 10,
276-
'public_out': 20,
277-
'type': 'virtual',
278-
}],
279-
json.loads(stripped_output),
280-
)
281-
self.assertEqual(
282-
4,
283-
len(self.calls('SoftLayer_Metric_Tracking_Object',
284-
'getSummaryData')),
285-
)
286-
self.assert_called_with('SoftLayer_Metric_Tracking_Object',
287-
'getSummaryData',
288-
identifier=1)
289-
self.assert_called_with('SoftLayer_Metric_Tracking_Object',
290-
'getSummaryData',
291-
identifier=3)
292-
self.assert_called_with('SoftLayer_Metric_Tracking_Object',
293-
'getSummaryData',
294-
identifier=201)
295-
self.assert_called_with('SoftLayer_Metric_Tracking_Object',
296-
'getSummaryData',
297-
identifier=203)
298-
call = self.calls('SoftLayer_Metric_Tracking_Object', 'getSummaryData',
299-
identifier=1)[0]
300-
expected_args = (
301-
'2016-02-04 00:00:00 ',
302-
'2016-03-04 12:34:56 ',
182+
json_output = json.loads(stripped_output)
183+
self.assertEqual(json_output[0]['hostname'], 'pool1')
184+
self.assertEqual(json_output[1]['private_in'], 0)
185+
self.assertEqual(json_output[2]['private_in'], 30)
186+
self.assertEqual(json_output[3]['type'], 'virtual')
187+
188+
self.assertEqual(4, len(self.calls('SoftLayer_Metric_Tracking_Object', 'getSummaryData')))
189+
self.assert_called_with('SoftLayer_Metric_Tracking_Object', 'getSummaryData', identifier=1)
190+
self.assert_called_with('SoftLayer_Metric_Tracking_Object', 'getSummaryData', identifier=3)
191+
self.assert_called_with('SoftLayer_Metric_Tracking_Object', 'getSummaryData', identifier=201)
192+
self.assert_called_with('SoftLayer_Metric_Tracking_Object', 'getSummaryData', identifier=203)
193+
call = self.calls('SoftLayer_Metric_Tracking_Object', 'getSummaryData', identifier=1)[0]
194+
expected_args = ('2016-02-04 00:00:00 ', '2016-03-04 12:34:56 ',
303195
[{
304196
'keyName': 'PUBLICIN',
305197
'name': 'publicIn',
@@ -370,59 +262,18 @@ def test_server_bandwidth_report(self):
370262

371263
self.assert_no_fail(result)
372264
stripped_output = '[' + result.output.split('[', 1)[1]
373-
self.assertEqual([
374-
{
375-
'hostname': 'pool1',
376-
'pool': None,
377-
'private_in': 30,
378-
'private_out': 40,
379-
'public_in': 10,
380-
'public_out': 20,
381-
'type': 'pool',
382-
}, {
383-
'hostname': 'pool3',
384-
'pool': None,
385-
'private_in': 30,
386-
'private_out': 40,
387-
'public_in': 10,
388-
'public_out': 20,
389-
'type': 'pool',
390-
}, {
391-
'hostname': 'host1',
392-
'pool': None,
393-
'private_in': 30,
394-
'private_out': 40,
395-
'public_in': 10,
396-
'public_out': 20,
397-
'type': 'hardware',
398-
}, {
399-
'hostname': 'host3',
400-
'pool': None,
401-
'private_in': 30,
402-
'private_out': 40,
403-
'public_in': 10,
404-
'public_out': 20,
405-
'type': 'hardware',
406-
}, ],
407-
json.loads(stripped_output),
408-
)
409-
self.assertEqual(
410-
4,
411-
len(self.calls('SoftLayer_Metric_Tracking_Object',
412-
'getSummaryData')),
413-
)
414-
self.assert_called_with('SoftLayer_Metric_Tracking_Object',
415-
'getSummaryData',
416-
identifier=101)
417-
self.assert_called_with('SoftLayer_Metric_Tracking_Object',
418-
'getSummaryData',
419-
identifier=103)
265+
json_output = json.loads(stripped_output)
266+
self.assertEqual(json_output[0]['hostname'], 'pool1')
267+
self.assertEqual(json_output[1]['private_in'], 0)
268+
self.assertEqual(json_output[2]['private_in'], 30)
269+
self.assertEqual(json_output[3]['type'], 'hardware')
270+
271+
self.assertEqual(4, len(self.calls('SoftLayer_Metric_Tracking_Object', 'getSummaryData')))
272+
self.assert_called_with('SoftLayer_Metric_Tracking_Object', 'getSummaryData', identifier=101)
273+
self.assert_called_with('SoftLayer_Metric_Tracking_Object', 'getSummaryData', identifier=103)
420274

421-
call = self.calls('SoftLayer_Metric_Tracking_Object', 'getSummaryData',
422-
identifier=1)[0]
423-
expected_args = (
424-
'2016-02-04 00:00:00 ',
425-
'2016-03-04 12:34:56 ',
275+
call = self.calls('SoftLayer_Metric_Tracking_Object', 'getSummaryData', identifier=1)[0]
276+
expected_args = ('2016-02-04 00:00:00 ', '2016-03-04 12:34:56 ',
426277
[{
427278
'keyName': 'PUBLICIN',
428279
'name': 'publicIn',

tests/managers/account_tests.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
44
55
"""
6+
from unittest import mock as mock
67

78
from SoftLayer.managers.account import AccountManager as AccountManager
89
from SoftLayer import SoftLayerAPIError
@@ -166,3 +167,12 @@ def test_get_routers_with_datacenter(self):
166167
self.manager.get_routers(location='dal13')
167168
object_filter = {'routers': {'topLevelLocation': {'name': {'operation': 'dal13'}}}}
168169
self.assert_called_with("SoftLayer_Account", "getRouters", filter=object_filter)
170+
171+
def test_get_bandwidth_pools(self):
172+
self.manager.get_bandwidth_pools()
173+
self.assert_called_with('SoftLayer_Account', 'getBandwidthAllotments', mask=mock.ANY)
174+
175+
def test_get_bandwidth_pool_counts(self):
176+
total = self.manager.get_bandwidth_pool_counts(1234)
177+
self.assert_called_with('SoftLayer_Network_Bandwidth_Version1_Allotment', 'getObject', identifier=1234)
178+
self.assertEqual(total, 2)

0 commit comments

Comments
 (0)