Skip to content

Commit 8a1dea6

Browse files
J JayasilanJ Jayasilan
authored andcommitted
Vlan unit test recommended changes
1 parent c78e79c commit 8a1dea6

File tree

2 files changed

+64
-84
lines changed

2 files changed

+64
-84
lines changed

SoftLayer/fixtures/SoftLayer_Network_Vlan.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,51 @@
4747
'tagReferences': [],
4848
}
4949

50+
getObject_no_hard_no_vs_no_trunk = {'primaryRouter': {'fullyQualifiedDomainName': 'bcr02a.fra02.softlayer.com',
51+
'id': 1186647,
52+
'datacenter': {'id': 449506,
53+
'longName': 'Frankfurt 2',
54+
'name': 'fra02'}
55+
},
56+
'id': 1186647,
57+
'vlanNumber': 932,
58+
'networkVlanFirewall': {
59+
'datacenter': {'id': 449506, 'longName': 'Frankfurt 2'},
60+
'fullyQualifiedDomainName': 'bcr02a.fra02.softlayer.com'
61+
},
62+
'subnets': [
63+
{'gateway': '10.85.154.1',
64+
'id': 1688651,
65+
'netmask': '255.255.255.192',
66+
'networkIdentifier': '10.85.154.0',
67+
'subnetType': 'ADDITIONAL_PRIMARY',
68+
'usableIpAddressCount': '61'}],
69+
'hardware': [
70+
{'domain': 'vmware.chechu.com',
71+
'hostname': 'host15',
72+
'primaryBackendIpAddress': '10.177.122.170',
73+
'primaryIpAddress': '169.46.48.107'}],
74+
'virtualGuests': [
75+
{'domain': 'ocp-virt.chechu.me',
76+
'hostname': 'haproxy',
77+
'primaryBackendIpAddress': '10.85.154.44',
78+
'primaryIpAddress': '158.177.72.67'}],
79+
'networkComponentTrunks': [
80+
{'networkComponent':
81+
{'hardwareId': 1483895, 'networkVlanId': 3285524, 'port': 12,
82+
'downlinkComponent': {'networkVlanId': '', 'port': 0,
83+
'primaryIpAddress': '10.194.250.148',
84+
'hardware':
85+
{
86+
'domain': 'chechu.me',
87+
'hostname': 'fra02-ocp-virt',
88+
'tagReferences': []
89+
},
90+
'networkComponentGroup': {
91+
'groupTypeId': 1,
92+
'membersDescription': 'eth0/2'}}}}],
93+
'tagReferences': []}
94+
5095
editObject = True
5196
setTags = True
5297
getList = [getObject]

tests/CLI/modules/vlan_tests.py

Lines changed: 19 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from SoftLayer.CLI import exceptions
1111
from SoftLayer import exceptions as ex
12+
from SoftLayer.fixtures import SoftLayer_Network_Vlan
1213
from SoftLayer.fixtures import SoftLayer_Product_Order
1314
from SoftLayer.fixtures import SoftLayer_Product_Package
1415
from SoftLayer import testing
@@ -34,27 +35,15 @@ def test_detail_no_hardware(self):
3435

3536
def test_subnet_list(self):
3637
vlan_mock = self.set_mock('SoftLayer_Network_Vlan', 'getObject')
37-
getObject = {
38-
'primaryRouter': {
39-
'datacenter': {'id': 1234, 'longName': 'TestDC'},
40-
'fullyQualifiedDomainName': 'fcr01.TestDC'
41-
},
42-
'id': 1234,
43-
'vlanNumber': 4444,
44-
'firewallInterfaces': None,
45-
'subnets': [
46-
{
47-
'id': 99,
48-
'networkIdentifier': 1111111,
49-
'netmask': '255.255.255.0',
50-
'gateway': '12.12.12.12',
51-
'subnetType': 'TEST',
52-
'usableIpAddressCount': 1
53-
54-
}
55-
56-
]
57-
}
38+
getObject = {'primaryRouter': {'datacenter': {'id': 1234, 'longName': 'TestDC'},
39+
'fullyQualifiedDomainName': 'fcr01.TestDC'},
40+
'id': 1234,
41+
'vlanNumber': 4444,
42+
'firewallInterfaces': None,
43+
'subnets': [{'id': 99, 'networkIdentifier': 1111111, 'netmask': '255.255.255.0',
44+
'gateway': '12.12.12.12', 'subnetType': 'TEST', 'usableIpAddressCount': 1}
45+
]
46+
}
5847
vlan_mock.return_value = getObject
5948
result = self.run_command(['vlan', 'detail', '1234'])
6049
self.assert_no_fail(result)
@@ -98,7 +87,7 @@ def test_vlan_edit(self, click):
9887
@mock.patch('SoftLayer.CLI.vlan.edit.click')
9988
def test_vlan_edit_not_any(self, click):
10089
result = self.run_command(['vlan', 'edit', '100'])
101-
self.assertTrue(result.exit_code, 2)
90+
self.assertEqual(result.exit_code, 2)
10291
self.assertEqual("At least one option is required", result.exception.message)
10392

10493
def test_vlan_create_not_data_pod(self):
@@ -147,23 +136,19 @@ def test_vlan_create_network_priv(self, confirm_mock):
147136
def test_vlan_create_option(self, confirm_mock):
148137
confirm_mock.return_value = True
149138
datacenter_mock = self.set_mock('SoftLayer_Location_Datacenter', 'getDatacenters')
150-
datacenter_mock.return_value = [{'id': 814994,
151-
'name': 'ams03'
152-
}]
139+
datacenter_mock.return_value = [{'id': 814994, 'name': 'ams03'}]
153140
router_mock = self.set_mock('SoftLayer_Location_Datacenter', 'getHardwareRouters')
154141
router_mock.return_value = [{'hostname': 'bcr01a.ams03'}]
155142
result = self.run_command(['vlan', 'create-options'])
156-
print(result.output)
157143
self.assert_no_fail(result)
158144

159145
@mock.patch('SoftLayer.CLI.formatting.no_going_back')
160146
def test_vlan_list_get_pod_with_closed_announcement(self, ngb_mock):
161147
ngb_mock.return_value = True
162148
vlan_mock = self.set_mock('SoftLayer_Account', 'getNetworkVlans')
163149
gpods_mock = self.set_mock('SoftLayer_Network_Pod', 'getAllObjects')
164-
vlan_mock.return_value = {'primaryRouter': {
165-
'fullyQualifiedDomainName': 'bcr01a.fra02.softlayer.com',
166-
'id': 462912},
150+
vlan_mock.return_value = {'primaryRouter': {'fullyQualifiedDomainName': 'bcr01a.fra02.softlayer.com',
151+
'id': 462912},
167152
'tagReferences': ''}
168153
gpods_mock.return_value = [{'backendRouterId': 462912,
169154
'backendRouterName': 'bcr01a.fra02',
@@ -181,11 +166,9 @@ def test_vlan_list_get_pod_with_closed_announcement_no_closure(self, ngb_mock):
181166
ngb_mock.return_value = True
182167
vlan_mock = self.set_mock('SoftLayer_Account', 'getNetworkVlans')
183168
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': ''}
169+
vlan_mock.return_value = {'primaryRouter': {'fullyQualifiedDomainName': 'bcr01a.fra02.softlayer.com',
170+
'id': 462912},
171+
'tagReferences': ''}
189172
gpods_mock.return_value = [{'backendRouterId': 462912,
190173
'backendRouterName': 'bcr01a.fra02',
191174
'datacenterId': 449506,
@@ -198,57 +181,10 @@ def test_vlan_list_get_pod_with_closed_announcement_no_closure(self, ngb_mock):
198181
self.assert_no_fail(result)
199182

200183
@mock.patch('SoftLayer.CLI.formatting.no_going_back')
201-
def test_vlan_details_no_vs_no_hard_no_trunck(self, ngb_mock):
184+
def test_vlan_details_no_vs_no_hard_no_trunk(self, ngb_mock):
202185
ngb_mock.return_value = True
203186
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
187+
vlan_mock.return_value = SoftLayer_Network_Vlan.getObject_no_hard_no_vs_no_trunk
252188
result = self.run_command(['vlan', 'detail', '3284824'])
253189
self.assert_no_fail(result)
254190

@@ -371,6 +307,5 @@ def test_vlan_cancel_exception(self, confirm_mock):
371307
vlan_mock.return_value = {}
372308
result = self.run_command(['vlan', 'cancel', '1234'])
373309
self.assertEqual(result.exit_code, 2)
374-
print(result.exception)
375310
self.assertIsInstance(result.exception, exceptions.CLIAbort)
376311
self.assertIn("VLAN is an automatically assigned", result.exception.message)

0 commit comments

Comments
 (0)