forked from softlayer/softlayer-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnetwork_tests.py
More file actions
298 lines (235 loc) · 10.8 KB
/
network_tests.py
File metadata and controls
298 lines (235 loc) · 10.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
"""
SoftLayer.tests.managers.network_tests
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:license: MIT, see LICENSE for more details.
"""
import SoftLayer
from SoftLayer import fixtures
from SoftLayer.managers import network
from SoftLayer import testing
class NetworkTests(testing.TestCase):
def set_up(self):
self.network = SoftLayer.NetworkManager(self.client)
def test_ip_lookup(self):
result = self.network.ip_lookup('10.0.1.37')
expected = fixtures.SoftLayer_Network_Subnet_IpAddress.getByIpAddress
self.assertEqual(result, expected)
self.assert_called_with('SoftLayer_Network_Subnet_IpAddress',
'getByIpAddress',
args=('10.0.1.37',))
def test_add_subnet_raises_exception_on_failure(self):
self.assertRaises(TypeError, self.network.add_subnet, ('bad'))
def test_add_global_ip(self):
# Test a global IPv4 order
result = self.network.add_global_ip(test_order=True)
self.assertEqual(fixtures.SoftLayer_Product_Order.verifyOrder, result)
def test_add_subnet_for_ipv4(self):
# Test a four public address IPv4 order
result = self.network.add_subnet('public',
quantity=4,
vlan_id=1234,
version=4,
test_order=True)
self.assertEqual(fixtures.SoftLayer_Product_Order.verifyOrder, result)
result = self.network.add_subnet('public',
quantity=4,
vlan_id=1234,
version=4,
test_order=False)
self.assertEqual(fixtures.SoftLayer_Product_Order.verifyOrder, result)
result = self.network.add_subnet('global',
test_order=True)
self.assertEqual(fixtures.SoftLayer_Product_Order.verifyOrder, result)
def test_add_subnet_for_ipv6(self):
# Test a public IPv6 order
result = self.network.add_subnet('public',
quantity=64,
vlan_id=45678,
version=6,
test_order=True)
self.assertEqual(fixtures.SoftLayer_Product_Order.verifyOrder, result)
# Test a global IPv6 order
result = self.network.add_subnet('global',
version=6,
test_order=True)
self.assertEqual(fixtures.SoftLayer_Product_Order.verifyOrder, result)
def test_assign_global_ip(self):
result = self.network.assign_global_ip(9876, '172.16.24.76')
self.assertEqual(result, True)
self.assert_called_with('SoftLayer_Network_Subnet_IpAddress_Global',
'route',
identifier=9876,
args=('172.16.24.76',))
def test_cancel_global_ip(self):
result = self.network.cancel_global_ip(1234)
self.assertEqual(result, True)
self.assert_called_with('SoftLayer_Billing_Item', 'cancelService',
identifier=1234)
def test_cancel_subnet(self):
result = self.network.cancel_subnet(1234)
self.assertEqual(result, True)
self.assert_called_with('SoftLayer_Billing_Item', 'cancelService',
identifier=1056)
def test_edit_rwhois(self):
result = self.network.edit_rwhois(
address1='123 Test Street',
address2='Apt. #31',
city='Anywhere',
company_name='TestLayer',
country='US',
first_name='Bob',
last_name='Bobinson',
postal_code='9ba62',
private_residence=False,
state='TX')
self.assertEqual(result, True)
expected = {
'abuseEmail': '[email protected]',
'address1': '123 Test Street',
'address2': 'Apt. #31',
'city': 'Anywhere',
'companyName': 'TestLayer',
'country': 'US',
'firstName': 'Bob',
'lastName': 'Bobinson',
'postalCode': '9ba62',
'privateResidenceFlag': False,
'state': 'TX',
}
self.assert_called_with('SoftLayer_Network_Subnet_Rwhois_Data',
'editObject',
identifier='id',
args=(expected,))
def test_get_rwhois(self):
result = self.network.get_rwhois()
self.assertEqual(result, fixtures.SoftLayer_Account.getRwhoisData)
self.assert_called_with('SoftLayer_Account', 'getRwhoisData')
def test_get_subnet(self):
result = self.network.get_subnet(9876)
self.assertEqual(result, fixtures.SoftLayer_Network_Subnet.getObject)
self.assert_called_with('SoftLayer_Network_Subnet', 'getObject',
identifier=9876)
def test_get_vlan(self):
result = self.network.get_vlan(1234)
self.assertEqual(result, fixtures.SoftLayer_Network_Vlan.getObject)
self.assert_called_with('SoftLayer_Network_Vlan', 'getObject',
identifier=1234)
def test_list_global_ips_default(self):
result = self.network.list_global_ips()
self.assertEqual(result,
fixtures.SoftLayer_Account.getGlobalIpRecords)
mask = 'mask[destinationIpAddress[hardware, virtualGuest],ipAddress]'
self.assert_called_with('SoftLayer_Account', 'getGlobalIpRecords',
mask=mask)
def test_list_global_ips_with_filter(self):
result = self.network.list_global_ips(version=4)
self.assertEqual(result,
fixtures.SoftLayer_Account.getGlobalIpRecords)
mask = 'mask[destinationIpAddress[hardware, virtualGuest],ipAddress]'
_filter = {
'globalIpRecords': {
'ipAddress': {
'subnet': {
'version': {'operation': 4},
}
}
}
}
mask = 'mask[destinationIpAddress[hardware, virtualGuest],ipAddress]'
self.assert_called_with('SoftLayer_Account', 'getGlobalIpRecords',
mask=mask,
filter=_filter)
def test_list_subnets_default(self):
result = self.network.list_subnets()
self.assertEqual(result, fixtures.SoftLayer_Account.getSubnets)
_filter = {'subnets': {'subnetType': {'operation': '!= GLOBAL_IP'}}}
self.assert_called_with('SoftLayer_Account', 'getSubnets',
mask='mask[%s]' % network.DEFAULT_SUBNET_MASK,
filter=_filter)
def test_list_subnets_with_filters(self):
result = self.network.list_subnets(
identifier='10.0.0.1',
datacenter='dal00',
version=4,
subnet_type='PRIMARY',
network_space='PUBLIC',
)
self.assertEqual(result, fixtures.SoftLayer_Account.getSubnets)
_filter = {
'subnets': {
'networkIdentifier': {'operation': '_= 10.0.0.1'},
'datacenter': {
'name': {'operation': '_= dal00'}
},
'version': {'operation': 4},
'subnetType': {'operation': '_= PRIMARY'},
'networkVlan': {'networkSpace': {'operation': '_= PUBLIC'}},
}
}
self.assert_called_with('SoftLayer_Account', 'getSubnets',
mask='mask[%s]' % network.DEFAULT_SUBNET_MASK,
filter=_filter)
def test_list_vlans_default(self):
result = self.network.list_vlans()
self.assertEqual(result, fixtures.SoftLayer_Account.getNetworkVlans)
self.assert_called_with('SoftLayer_Account', 'getNetworkVlans')
def test_list_vlans_with_filters(self):
result = self.network.list_vlans(
vlan_number=5,
datacenter='dal00',
name='primary-vlan',
)
self.assertEqual(result, fixtures.SoftLayer_Account.getNetworkVlans)
_filter = {
'networkVlans': {
'primaryRouter': {
'datacenter': {
'name': {'operation': '_= dal00'}},
},
'vlanNumber': {'operation': 5},
'name': {'operation': '_= primary-vlan'},
},
}
self.assert_called_with('SoftLayer_Account', 'getNetworkVlans',
filter=_filter)
def test_summary_by_datacenter(self):
result = self.network.summary_by_datacenter()
expected = {'dal00': {'hardware_count': 1,
'virtual_guest_count': 1,
'subnet_count': 0,
'public_ip_count': 6,
'vlan_count': 3}}
self.assertEqual(expected, result)
def test_resolve_global_ip_ids(self):
_id = self.network.resolve_global_ip_ids('10.0.0.1')
self.assertEqual(_id, ['200', '201'])
def test_resolve_global_ip_ids_no_results(self):
mock = self.set_mock('SoftLayer_Account', 'getGlobalIpRecords')
mock.return_value = []
_id = self.network.resolve_global_ip_ids('nope')
self.assertEqual(_id, [])
def test_resolve_subnet_ids(self):
_id = self.network.resolve_subnet_ids('10.0.0.1/29')
self.assertEqual(_id, ['100'])
def test_resolve_subnet_ids_no_results(self):
mock = self.set_mock('SoftLayer_Account', 'getSubnets')
mock.return_value = []
_id = self.network.resolve_subnet_ids('nope')
self.assertEqual(_id, [])
def test_resolve_vlan_ids(self):
mock = self.set_mock('SoftLayer_Account', 'getNetworkVlans')
mock.return_value = [{'id': '100'}]
_id = self.network.resolve_vlan_ids('vlan_name')
self.assertEqual(_id, ['100'])
def test_resolve_vlan_ids_no_results(self):
mock = self.set_mock('SoftLayer_Account', 'getNetworkVlans')
mock.return_value = []
_id = self.network.resolve_vlan_ids('nope')
self.assertEqual(_id, [])
def test_unassign_global_ip(self):
result = self.network.unassign_global_ip(9876)
self.assertEqual(result, True)
self.assert_called_with('SoftLayer_Network_Subnet_IpAddress_Global',
'unroute',
identifier=9876)