Skip to content

Commit 8dfee70

Browse files
Merge pull request #1165 from FernandoOjeda/fo_loadbal_unit_test
Unit test for loadbal order, ns-list, ns-detail.
2 parents 61f16b7 + 745ec85 commit 8dfee70

File tree

6 files changed

+284
-3
lines changed

6 files changed

+284
-3
lines changed

SoftLayer/fixtures/SoftLayer_Account.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,32 @@
323323
'subnetType': 'PRIMARY',
324324
'ipAddressCount': 10,
325325
'virtualGuests': [],
326-
'hardware': []
327-
}]
326+
'hardware': [],
327+
"podName": "dal05.pod04",
328+
"networkVlan": {
329+
"accountId": 123,
330+
"id": 2581232,
331+
"modifyDate": "2019-07-17T01:09:51+08:00",
332+
"vlanNumber": 795
333+
}
334+
},
335+
{
336+
"gateway": "5.111.11.111",
337+
"id": '111',
338+
"modifyDate": "2018-07-24T17:14:57+08:00",
339+
'networkIdentifier': '10.0.0.1',
340+
'ipAddressCount': 10,
341+
'cidr': '/24',
342+
'virtualGuests': [],
343+
'hardware': [],
344+
"networkVlanId": 22222,
345+
"sortOrder": "2",
346+
"subnetType": "SECONDARY_ON_VLAN",
347+
"totalIpAddresses": "8",
348+
"usableIpAddressCount": "5",
349+
"version": 4
350+
}
351+
]
328352

329353
getSshKeys = [{'id': '100', 'label': 'Test 1'},
330354
{'id': '101', 'label': 'Test 2',

SoftLayer/fixtures/SoftLayer_Network_Application_Delivery_Controller.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,45 @@
1313
'longName': 'Dallas 9',
1414
'name': 'dal09',
1515
},
16+
"networkVlans": [
17+
{
18+
"accountId": 11111,
19+
"id": 33333,
20+
"modifyDate": "2019-07-17T01:09:38+08:00",
21+
"name": "FirewallTesting",
22+
"primarySubnetId": 91111,
23+
"vlanNumber": 1711
24+
},
25+
{
26+
"accountId": 11111,
27+
"id": 862222,
28+
"modifyDate": "2019-07-17T01:09:42+08:00",
29+
"primarySubnetId": 502211,
30+
"vlanNumber": 722
31+
}
32+
],
1633
'password': {
1734
'password': 'aaaaa',
1835
'username': 'root'
1936
},
37+
"subnets": [
38+
{
39+
"broadcastAddress": "",
40+
"cidr": 32,
41+
"gateway": "",
42+
"id": 74222,
43+
"modifyDate": "2016-10-26T23:39:12+08:00",
44+
"netmask": "255.255.255.255",
45+
"networkIdentifier": "159.253.111.111",
46+
"networkVlanId": 3611111,
47+
"sortOrder": "4",
48+
"subnetType": "STATIC_IP_ROUTED",
49+
"totalIpAddresses": "2",
50+
"usableIpAddressCount": "2",
51+
"version": 4,
52+
"addressSpace": "PUBLIC"
53+
}
54+
],
2055
'type': {
2156
'keyName': 'NETSCALER_VPX',
2257
'name': 'NetScaler VPX'

SoftLayer/fixtures/SoftLayer_Network_LBaaS_LoadBalancer.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,26 @@
116116
],
117117
}
118118
getAllObjects = [getObject]
119+
120+
getLoadBalancer = {
121+
"accountId": 3071234,
122+
"createDate": "2019-08-12T21:49:43+08:00",
123+
"id": 81234,
124+
"isPublic": 0,
125+
"locationId": 265592,
126+
"modifyDate": "2019-08-14T06:26:06+08:00",
127+
"name": "dcabero-01",
128+
"uuid": "0a2da082-4474-4e16-9f02-4de11111",
129+
"datacenter": {
130+
"id": 265592,
131+
"longName": "Amsterdam 1",
132+
"name": "ams01",
133+
"statusId": 2
134+
}
135+
}
136+
137+
cancelLoadBalancer = True
138+
119139
getLoadBalancerMemberHealth = [
120140
{
121141
'poolUuid': '1c5f3ba6-ec7d-4cf8-8815-9bb174224a76',

SoftLayer/fixtures/SoftLayer_Product_Package.py

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,44 @@
784784
'sortOrder': 10}],
785785
'subDescription': 'Bare Metal Server',
786786
'unitSize': 1,
787+
"itemPrices": [
788+
{
789+
"hourlyRecurringFee": ".027",
790+
"id": 205911,
791+
"laborFee": "0",
792+
"locationGroupId": 505,
793+
"item": {
794+
"capacity": "0",
795+
"description": "Load Balancer Uptime",
796+
"id": 10785,
797+
"keyName": "LOAD_BALANCER_UPTIME",
798+
}
799+
},
800+
{
801+
"hourlyRecurringFee": "0",
802+
"id": 199467,
803+
"laborFee": "0",
804+
"locationGroupId": '',
805+
"recurringFee": "0",
806+
"item": {
807+
"capacity": "0",
808+
"description": "Load Balancer Bandwidth",
809+
"id": 10051,
810+
"keyName": "LOAD_BALANCER_BANDWIDTH",
811+
}
812+
},
813+
{
814+
"hourlyRecurringFee": ".028",
815+
"id": 205913,
816+
"laborFee": "0",
817+
"locationGroupId": 507,
818+
"item": {
819+
"capacity": "0",
820+
"description": "Load Balancer Uptime",
821+
"id": 10785,
822+
"keyName": "LOAD_BALANCER_UPTIME",
823+
}
824+
}]
787825
}]
788826

789827
getItems = [
@@ -1144,6 +1182,91 @@
11441182
'quantity': 1
11451183
}
11461184

1185+
itemsLoadbal = [
1186+
{
1187+
"capacity": "0",
1188+
"description": "Load Balancer as a Service",
1189+
"id": 10043,
1190+
"keyName": "LOAD_BALANCER_AS_A_SERVICE",
1191+
"itemCategory": {
1192+
"categoryCode": "load_balancer_as_a_service",
1193+
"id": 1116,
1194+
"name": "Load Balancer As A Service",
1195+
},
1196+
"prices": [
1197+
{
1198+
"hourlyRecurringFee": "0",
1199+
"id": 199447,
1200+
"locationGroupId": '',
1201+
"recurringFee": "0",
1202+
}
1203+
]
1204+
},
1205+
{
1206+
"capacity": "0",
1207+
"description": "Load Balancer Uptime",
1208+
"id": 10785,
1209+
"keyName": "LOAD_BALANCER_UPTIME",
1210+
"itemCategory": {
1211+
"categoryCode": "load_balancer_uptime",
1212+
"id": 1119,
1213+
"name": "Load Balancer Uptime",
1214+
},
1215+
"prices": [
1216+
{
1217+
"hourlyRecurringFee": ".028",
1218+
"id": 205913,
1219+
"locationGroupId": 507,
1220+
}]}
1221+
]
1222+
1223+
regionsLoadbal = [{'description': 'WDC01 - Washington, DC - East Coast U.S.',
1224+
'keyname': 'WASHINGTON_DC',
1225+
'location': {'location': {'id': 37473,
1226+
'longName': 'Washington 1',
1227+
'name': 'wdc01',
1228+
"groups": [
1229+
{
1230+
"description": "Location Group 4",
1231+
"id": 507,
1232+
"locationGroupTypeId": 82,
1233+
"name": "Location Group 4",
1234+
"locationGroupType": {
1235+
"name": "PRICING"
1236+
}
1237+
},
1238+
{
1239+
"description": "COS Cross Region - EU",
1240+
"id": 1303,
1241+
"locationGroupTypeId": 82,
1242+
"name": "eu",
1243+
"locationGroupType": {
1244+
"name": "PRICING"
1245+
}
1246+
},
1247+
{
1248+
"description": "COS Regional Frankfurt",
1249+
"id": 1783,
1250+
"locationGroupTypeId": 82,
1251+
"name": "eu-de",
1252+
"locationGroupType": {
1253+
"name": "PRICING"
1254+
}
1255+
}
1256+
]
1257+
}},
1258+
'sortOrder': 10}]
1259+
1260+
getAllObjectsLoadbal = [
1261+
{
1262+
"id": 805,
1263+
"keyName": "LBAAS",
1264+
"name": "Load Balancer As A Service (LBaaS)",
1265+
"items": itemsLoadbal,
1266+
"regions": regionsLoadbal
1267+
}
1268+
]
1269+
11471270
getAllObjectsDH = [{
11481271
"subDescription": "Dedicated Host",
11491272
"name": "Dedicated Host",

tests/CLI/modules/loadbal_tests.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from SoftLayer.CLI.exceptions import ArgumentError
1010
from SoftLayer import exceptions
1111
from SoftLayer.fixtures import SoftLayer_Network_LBaaS_LoadBalancer
12+
from SoftLayer.fixtures import SoftLayer_Product_Package
1213
from SoftLayer import testing
1314

1415

@@ -214,3 +215,81 @@ def test_lb_health_update_fails(self, update_lb_health_monitors):
214215
def test_lb_detail(self):
215216
result = self.run_command(['lb', 'detail', '1111111'])
216217
self.assert_no_fail(result)
218+
219+
def test_order(self):
220+
result = self.run_command(['loadbal', 'order', '--name', 'test', '--datacenter', 'par01', '--label',
221+
'labeltest', '--subnet', '759282'])
222+
223+
self.assert_no_fail(result)
224+
225+
def test_order_with_frontend(self):
226+
result = self.run_command(['loadbal', 'order', '--name', 'test', '--datacenter', 'par01', '--label',
227+
'labeltest', '--frontend', 'TCP:80', '--backend', 'TCP:80', '--subnet', '759282'])
228+
229+
self.assert_no_fail(result)
230+
231+
def test_order_with_backend(self):
232+
result = self.run_command(['loadbal', 'order', '--name', 'test', '--datacenter', 'par01', '--label',
233+
'labeltest', '--backend', 'HTTP:80', '--subnet', '759282'])
234+
235+
self.assert_no_fail(result)
236+
237+
def test_order_backend_fail(self):
238+
result = self.run_command(['loadbal', 'order', '--name', 'test', '--datacenter', 'par01', '--label',
239+
'labeltest', '--backend', 'HTTP', '--subnet', '759282'])
240+
241+
self.assertEqual(result.exit_code, 2)
242+
self.assertIsInstance(result.exception, ArgumentError)
243+
244+
def test_verify_order(self):
245+
result = self.run_command(['loadbal', 'order', '--verify', '--name', 'test', '--datacenter', 'par01', '--label',
246+
'labeltest', '--subnet', '759282'])
247+
248+
self.assert_no_fail(result)
249+
250+
def test_order_options(self):
251+
mock = self.set_mock('SoftLayer_Product_Package', 'getAllObjects')
252+
mock.return_value = SoftLayer_Product_Package.getAllObjectsLoadbal
253+
result = self.run_command(['loadbal', 'order-options'])
254+
255+
self.assert_no_fail(result)
256+
257+
def test_order_options_with_datacenter(self):
258+
mock = self.set_mock('SoftLayer_Product_Package', 'getAllObjects')
259+
mock.return_value = SoftLayer_Product_Package.getAllObjectsLoadbal
260+
result = self.run_command(['loadbal', 'order-options', '--datacenter', 'ams03'])
261+
262+
self.assert_no_fail(result)
263+
264+
def test_cancel(self):
265+
result = self.run_command(['loadbal', 'cancel', '11111'])
266+
267+
self.assert_no_fail(result)
268+
self.assert_called_with('SoftLayer_Network_LBaaS_LoadBalancer', 'cancelLoadBalancer')
269+
270+
@mock.patch('SoftLayer.LoadBalancerManager.cancel_lbaas')
271+
def test_cancel_fail(self, cancel_lbaas):
272+
fault_string = 'Id must be string'
273+
cancel_lbaas.side_effect = exceptions.SoftLayerAPIError(mock.ANY, fault_string)
274+
result = self.run_command(['loadbal', 'cancel', '11111'])
275+
276+
self.assertIn("ERROR: {}".format(fault_string),
277+
result.output)
278+
279+
def test_ns_list(self):
280+
result = self.run_command(['loadbal', 'ns-list'])
281+
282+
self.assert_no_fail(result)
283+
284+
def test_ns_list_empty(self):
285+
mock = self.set_mock('SoftLayer_Account', 'getApplicationDeliveryControllers')
286+
mock.return_value = []
287+
288+
result = self.run_command(['loadbal', 'ns-list'])
289+
290+
self.assert_no_fail(result)
291+
292+
def test_ns_detail(self):
293+
result = self.run_command(['loadbal', 'ns-detail', '11111'])
294+
295+
self.assert_no_fail(result)

tests/managers/network_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ def test_resolve_global_ip_ids_no_results(self):
435435

436436
def test_resolve_subnet_ids(self):
437437
_id = self.network.resolve_subnet_ids('10.0.0.1/29')
438-
self.assertEqual(_id, ['100'])
438+
self.assertEqual(_id, ['100', '111'])
439439

440440
def test_resolve_subnet_ids_no_results(self):
441441
mock = self.set_mock('SoftLayer_Account', 'getSubnets')

0 commit comments

Comments
 (0)