Skip to content

Commit c78e79c

Browse files
J JayasilanJ Jayasilan
authored andcommitted
Vlan unit test
1 parent 17aa0d2 commit c78e79c

File tree

1 file changed

+176
-6
lines changed

1 file changed

+176
-6
lines changed

tests/CLI/modules/vlan_tests.py

Lines changed: 176 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import json
88
from unittest import mock as mock
99

10+
from SoftLayer.CLI import exceptions
11+
from SoftLayer import exceptions as ex
1012
from SoftLayer.fixtures import SoftLayer_Product_Order
1113
from SoftLayer.fixtures import SoftLayer_Product_Package
1214
from SoftLayer import testing
@@ -93,6 +95,163 @@ def test_vlan_edit(self, click):
9395
self.assert_no_fail(result)
9496
self.assert_called_with('SoftLayer_Network_Vlan', 'editObject', identifier=100)
9597

98+
@mock.patch('SoftLayer.CLI.vlan.edit.click')
99+
def test_vlan_edit_not_any(self, click):
100+
result = self.run_command(['vlan', 'edit', '100'])
101+
self.assertTrue(result.exit_code, 2)
102+
self.assertEqual("At least one option is required", result.exception.message)
103+
104+
def test_vlan_create_not_data_pod(self):
105+
_mock = self.set_mock('SoftLayer_Product_Package', 'getItems')
106+
_mock.return_value = SoftLayer_Product_Package.getItemsVLAN
107+
order_mock = self.set_mock('SoftLayer_Product_Order', 'placeOrder')
108+
order_mock.return_value = SoftLayer_Product_Order.vlan_placeOrder
109+
110+
result = self.run_command(['vlan', 'create', '--name', 'my_vlan', '--datacenter', '', '--pod', ''])
111+
self.assertIsInstance(result.exception, exceptions.CLIAbort)
112+
self.assertIn("--datacenter or --pod is required to", result.exception.message)
113+
114+
def test_vlan_create_network_extra_route_exception(self):
115+
_mock = self.set_mock('SoftLayer_Product_Package', 'getItems')
116+
_mock.return_value = SoftLayer_Product_Package.getItemsVLAN
117+
order_mock = self.set_mock('SoftLayer_Product_Order', 'placeOrder')
118+
order_mock.return_value = SoftLayer_Product_Order.vlan_placeOrder
119+
result = self.run_command(['vlan', 'create',
120+
'--name', 'TEST001',
121+
'--datacenter', 'dal09',
122+
'--network', 'private',
123+
'--pod', 'dal09.pod01'
124+
])
125+
self.assertIsInstance(result.exception, exceptions.CLIAbort)
126+
self.assertIn("Unable to find pod name", result.exception.message)
127+
128+
@mock.patch('SoftLayer.CLI.formatting.confirm')
129+
def test_vlan_create_network_priv(self, confirm_mock):
130+
confirm_mock.return_value = True
131+
get_pods_mock = self.set_mock('SoftLayer_Network_Pod', 'getAllObjects')
132+
get_pods_mock.return_value = [{
133+
'name': 'ams03.pod01',
134+
'frontendRouterId': 468136,
135+
'backendRouterId': 468132}]
136+
result = self.run_command(['vlan', 'create',
137+
'--name', 'TEST001',
138+
'--datacenter', 'ams03',
139+
'--network', 'private',
140+
'--pod', 'ams03.pod01'
141+
])
142+
143+
self.assert_called_with('SoftLayer_Network_Pod', 'getAllObjects')
144+
self.assertIsInstance(result.exception, ex.SoftLayerError)
145+
146+
@mock.patch('SoftLayer.CLI.formatting.no_going_back')
147+
def test_vlan_create_option(self, confirm_mock):
148+
confirm_mock.return_value = True
149+
datacenter_mock = self.set_mock('SoftLayer_Location_Datacenter', 'getDatacenters')
150+
datacenter_mock.return_value = [{'id': 814994,
151+
'name': 'ams03'
152+
}]
153+
router_mock = self.set_mock('SoftLayer_Location_Datacenter', 'getHardwareRouters')
154+
router_mock.return_value = [{'hostname': 'bcr01a.ams03'}]
155+
result = self.run_command(['vlan', 'create-options'])
156+
print(result.output)
157+
self.assert_no_fail(result)
158+
159+
@mock.patch('SoftLayer.CLI.formatting.no_going_back')
160+
def test_vlan_list_get_pod_with_closed_announcement(self, ngb_mock):
161+
ngb_mock.return_value = True
162+
vlan_mock = self.set_mock('SoftLayer_Account', 'getNetworkVlans')
163+
gpods_mock = self.set_mock('SoftLayer_Network_Pod', 'getAllObjects')
164+
vlan_mock.return_value = {'primaryRouter': {
165+
'fullyQualifiedDomainName': 'bcr01a.fra02.softlayer.com',
166+
'id': 462912},
167+
'tagReferences': ''}
168+
gpods_mock.return_value = [{'backendRouterId': 462912,
169+
'backendRouterName': 'bcr01a.fra02',
170+
'datacenterId': 449506,
171+
'datacenterLongName': 'Frankfurt 2',
172+
'frontendRouterId': 335916,
173+
'frontendRouterName': 'fcr01a.fra02',
174+
'name': 'fra02.pod01',
175+
'capabilities': ['SUPPORTS_SECURITY_GROUP', 'CLOSURE_ANNOUNCED']}]
176+
result = self.run_command(['vlan', 'list'])
177+
self.assert_no_fail(result)
178+
179+
@mock.patch('SoftLayer.CLI.formatting.no_going_back')
180+
def test_vlan_list_get_pod_with_closed_announcement_no_closure(self, ngb_mock):
181+
ngb_mock.return_value = True
182+
vlan_mock = self.set_mock('SoftLayer_Account', 'getNetworkVlans')
183+
gpods_mock = self.set_mock('SoftLayer_Network_Pod', 'getAllObjects')
184+
vlan_mock.return_value = {
185+
'primaryRouter': {'fullyQualifiedDomainName': 'bcr01a.fra02.softlayer.com',
186+
'id': 462912
187+
},
188+
'tagReferences': ''}
189+
gpods_mock.return_value = [{'backendRouterId': 462912,
190+
'backendRouterName': 'bcr01a.fra02',
191+
'datacenterId': 449506,
192+
'datacenterLongName': 'Frankfurt 2',
193+
'frontendRouterId': 335916,
194+
'frontendRouterName': 'fcr01a.fra02',
195+
'name': 'fra02.pod01',
196+
'capabilities': ['SUPPORTS_SECURITY_GROUP']}]
197+
result = self.run_command(['vlan', 'list'])
198+
self.assert_no_fail(result)
199+
200+
@mock.patch('SoftLayer.CLI.formatting.no_going_back')
201+
def test_vlan_details_no_vs_no_hard_no_trunck(self, ngb_mock):
202+
ngb_mock.return_value = True
203+
vlan_mock = self.set_mock('SoftLayer_Network_Vlan', 'getObject')
204+
get_object = {'primaryRouter': {'fullyQualifiedDomainName': 'bcr02a.fra02.softlayer.com',
205+
'id': 1186647,
206+
'datacenter': {'id': 449506,
207+
'longName': 'Frankfurt 2',
208+
'name': 'fra02'}
209+
},
210+
'id': 1186647,
211+
'vlanNumber': 932,
212+
'networkVlanFirewall': {
213+
'datacenter': {'id': 449506, 'longName': 'Frankfurt 2'},
214+
'fullyQualifiedDomainName': 'bcr02a.fra02.softlayer.com'
215+
},
216+
'subnets': [
217+
{'gateway': '10.85.154.1',
218+
'id': 1688651,
219+
'netmask': '255.255.255.192',
220+
'networkIdentifier': '10.85.154.0',
221+
'subnetType': 'ADDITIONAL_PRIMARY',
222+
'usableIpAddressCount': '61'}],
223+
'hardware': [
224+
{'domain': 'vmware.chechu.com',
225+
'hostname': 'host15',
226+
'primaryBackendIpAddress': '10.177.122.170',
227+
'primaryIpAddress': '169.46.48.107'}],
228+
'virtualGuests': [
229+
{'domain': 'ocp-virt.chechu.me',
230+
'hostname': 'haproxy',
231+
'primaryBackendIpAddress': '10.85.154.44',
232+
'primaryIpAddress': '158.177.72.67'}],
233+
'networkComponentTrunks': [
234+
{'networkComponent': {'hardwareId': 1483895, 'networkVlanId': 3285524,
235+
'port': 12,
236+
'downlinkComponent': {
237+
'networkVlanId': '', 'port': 0,
238+
'primaryIpAddress': '10.194.250.148',
239+
'hardware': {
240+
'domain': 'chechu.me',
241+
'fullyQualifiedDomainName': 'fra02-ocp-virt.chechu.me',
242+
'hostname': 'fra02-ocp-virt',
243+
'networkManagementIpAddress': '10.194.250.150',
244+
'tagReferences': []
245+
},
246+
'networkComponentGroup': {
247+
'groupTypeId': 1,
248+
'membersDescription': 'eth0/2'}}}}],
249+
'tagReferences': []}
250+
251+
vlan_mock.return_value = get_object
252+
result = self.run_command(['vlan', 'detail', '3284824'])
253+
self.assert_no_fail(result)
254+
96255
@mock.patch('SoftLayer.CLI.vlan.edit.click')
97256
def test_vlan_edit_failure(self, click):
98257
mock = self.set_mock('SoftLayer_Network_Vlan', 'editObject')
@@ -114,7 +273,7 @@ def test_vlan_detail_firewall(self):
114273
'networkVlanFirewall': {
115274
'datacenter': {'id': 1234, 'longName': 'TestDC'},
116275
'fullyQualifiedDomainName': 'fcr01.TestDC'
117-
},
276+
}
118277
}
119278
vlan_mock.return_value = get_object
120279
result = self.run_command(['vlan', 'detail', '1234'])
@@ -132,7 +291,7 @@ def test_vlan_detail_gateway(self):
132291
'attachedNetworkGateway': {
133292
'id': 54321,
134293
"name": 'support'
135-
},
294+
}
136295
}
137296
vlan_mock.return_value = get_object
138297
result = self.run_command(['vlan', 'detail', '1234'])
@@ -164,8 +323,7 @@ def test_create_vlan(self):
164323
])
165324

166325
self.assert_no_fail(result)
167-
self.assertEqual(json.loads(result.output),
168-
{'id': 123456, 'created': '2021-06-02 15:23:47', 'name': 'test'})
326+
self.assertEqual(json.loads(result.output), {'id': 123456, 'created': '2021-06-02 15:23:47', 'name': 'test'})
169327

170328
def test_create_vlan_pod(self):
171329
_mock = self.set_mock('SoftLayer_Product_Package', 'getItems')
@@ -182,8 +340,7 @@ def test_create_vlan_pod(self):
182340
])
183341

184342
self.assert_no_fail(result)
185-
self.assertEqual(json.loads(result.output),
186-
{'id': 123456, 'created': '2021-06-02 15:23:47', 'name': 'test'})
343+
self.assertEqual(json.loads(result.output), {'id': 123456, 'created': '2021-06-02 15:23:47', 'name': 'test'})
187344

188345
@mock.patch('SoftLayer.CLI.formatting.no_going_back')
189346
def test_vlan_cancel(self, confirm_mock):
@@ -204,3 +361,16 @@ def test_vlan_cancel_fail(self, confirm_mock):
204361
confirm_mock.return_value = False
205362
result = self.run_command(['vlan', 'cancel', '1234'])
206363
self.assertTrue(result.exit_code, 2)
364+
365+
@mock.patch('SoftLayer.CLI.formatting.no_going_back')
366+
def test_vlan_cancel_exception(self, confirm_mock):
367+
confirm_mock.return_value = True
368+
cancel_failure_mock = self.set_mock('SoftLayer_Network_Vlan', 'getCancelFailureReasons')
369+
cancel_failure_mock.return_value = []
370+
vlan_mock = self.set_mock('SoftLayer_Network_Vlan', 'getObject')
371+
vlan_mock.return_value = {}
372+
result = self.run_command(['vlan', 'cancel', '1234'])
373+
self.assertEqual(result.exit_code, 2)
374+
print(result.exception)
375+
self.assertIsInstance(result.exception, exceptions.CLIAbort)
376+
self.assertIn("VLAN is an automatically assigned", result.exception.message)

0 commit comments

Comments
 (0)