Debian Codegraph @

neutron_tempest_plugin/vpnaas/api/test_vpnaas.py

raw
1 # Copyright 2012,2016 OpenStack Foundation
2 # All Rights Reserved.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License"); you may
5 # not use this file except in compliance with the License. You may obtain
6 # a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 # License for the specific language governing permissions and limitations
14 # under the License.
15
16 from neutron_lib.db import constants as db_const
17 from tempest.common import utils
18 from tempest.lib.common.utils import data_utils
19 from tempest.lib import decorators
20 from tempest.lib import exceptions as lib_exc
21
22 from neutron_tempest_plugin import config
23 from neutron_tempest_plugin.vpnaas.api import base_vpnaas as base
24
25 CONF = config.CONF
26
27 _LONG_NAME = 'x' * (db_const.NAME_FIELD_SIZE + 1)
28 _LONG_DESCRIPTION = 'y' * (db_const.DESCRIPTION_FIELD_SIZE + 1)
29
30
31 class VPNaaSTestJSON(base.BaseAdminNetworkTest):
32
33 """VPNaaS API tests.
34
35 Tests the following operations in the Neutron API using the REST client for
36 Neutron:
37
38 * List, Show, Create, Delete, and Update VPN Service
39 * List, Show, Create, Delete, and Update IKE policy
40 * List, Show, Create, Delete, and Update IPSec policy
41 """
42
43 @classmethod
44 def resource_setup(cls):
45 if not utils.is_extension_enabled('vpnaas', 'network'):
46 msg = "vpnaas extension not enabled."
47 raise cls.skipException(msg)
48 super(VPNaaSTestJSON, cls).resource_setup()
49 cls.ext_net_id = CONF.network.public_network_id
50 network_name = data_utils.rand_name('network-')
51 cls.network = cls.create_network(network_name)
52 cls.subnet = cls.create_subnet(cls.network)
53 cls.router = cls.create_router(
54 data_utils.rand_name("router"),
55 external_network_id=CONF.network.public_network_id)
56 cls.create_router_interface(cls.router['id'], cls.subnet['id'])
57 cls.vpnservice = cls.create_vpnservice(cls.subnet['id'],
58 cls.router['id'])
59 vpnservice2 = cls.create_vpnservice_no_subnet(cls.router['id'])
60 cls.vpnservice_no_subnet = vpnservice2
61
62 cls.ikepolicy = cls.create_ikepolicy(
63 data_utils.rand_name("ike-policy-"))
64 cls.ipsecpolicy = cls.create_ipsecpolicy(
65 data_utils.rand_name("ipsec-policy-"))
66
67 cls.endpoint_group_local = cls.create_endpoint_group(
68 data_utils.rand_name("endpoint-group-local-"),
69 'subnet',
70 cls.subnet['id'])
71
72 cls.endpoint_group_remote = cls.create_endpoint_group(
73 data_utils.rand_name("endpoint-group-remote-"),
74 'cidr',
75 ["10.101.0.0/24", "10.102.0.0/24"])
76
77 cls.ipsec_site_connection = cls.create_ipsec_site_connection(
78 cls.ikepolicy['id'],
79 cls.ipsecpolicy['id'],
80 cls.vpnservice['id'])
81
82 def _delete_ike_policy(self, ike_policy_id):
83 # Deletes a ike policy and verifies if it is deleted or not
84 ike_list = list()
85 all_ike = self.client.list_ikepolicies()
86 for ike in all_ike['ikepolicies']:
87 ike_list.append(ike['id'])
88 if ike_policy_id in ike_list:
89 self.client.delete_ikepolicy(ike_policy_id)
90 # Asserting that the policy is not found in list after deletion
91 ikepolicies = self.client.list_ikepolicies()
92 ike_id_list = list()
93 for i in ikepolicies['ikepolicies']:
94 ike_id_list.append(i['id'])
95 self.assertNotIn(ike_policy_id, ike_id_list)
96
97 def _delete_ipsec_policy(self, ipsec_policy_id):
98 # Deletes an ike policy if it exists
99 try:
100 self.client.delete_ipsecpolicy(ipsec_policy_id)
101
102 except lib_exc.NotFound:
103 pass
104
105 def _delete_ipsec_site_connection(self, conn_id):
106 # Deletes an ipsec site connection if it exists
107 try:
108 self.client.delete_ipsec_site_connection(conn_id)
109 except lib_exc.NotFound:
110 pass
111
112 def _assertExpected(self, expected, actual):
113 # Check if not expected keys/values exists in actual response body
114 for key, value in expected.items():
115 self.assertIn(key, actual)
116 self.assertEqual(value, actual[key])
117
118 def _delete_vpn_service(self, vpn_service_id):
119 self.client.delete_vpnservice(vpn_service_id)
120 # Asserting if vpn service is found in the list after deletion
121 body = self.client.list_vpnservices()
122 vpn_services = [vs['id'] for vs in body['vpnservices']]
123 self.assertNotIn(vpn_service_id, vpn_services)
124
125 def _delete_endpoint_group(self, endpoint_group_id):
126 # Delete a endpoint-group and verifies if it is deleted or not
127 endpoint_group_list = list()
128 all_endpoint = self.client.list_endpoint_groups()
129 for endpoint in all_endpoint['endpoint_groups']:
130 endpoint_group_list.append(endpoint['id'])
131 if endpoint_group_id in endpoint_group_list:
132 self.client.delete_endpoint_group(endpoint_group_id)
133 # Asserting that the endpoint is not found in list after deletion
134 endpoint_group = self.client.list_endpoint_groups()
135 for e in endpoint_group['endpoint_groups']:
136 endpoint_group_list.append(e['id'])
137 self.assertNotIn(endpoint_group_list, endpoint_group_id)
138
139 def _get_tenant_id(self):
140 """Returns the tenant_id of the client current user"""
141 return self.client.project_id
142
143 @decorators.attr(type='smoke')
144 @decorators.idempotent_id('74dcf2d3-a40e-4a6c-a25a-747d764bee81')
145 def test_admin_create_ipsec_policy_for_tenant(self):
146 tenant_id = self._get_tenant_id()
147 # Create IPSec policy for the newly created tenant
148 name = data_utils.rand_name('ipsec-policy')
149 body = (self.admin_client.
150 create_ipsecpolicy(name=name, tenant_id=tenant_id))
151 ipsecpolicy = body['ipsecpolicy']
152 self.assertIsNotNone(ipsecpolicy['id'])
153 self.addCleanup(self.admin_client.delete_ipsecpolicy,
154 ipsecpolicy['id'])
155
156 # Assert that created ipsec policy is found in API list call
157 body = self.client.list_ipsecpolicies()
158 ipsecpolicies = [policy['id'] for policy in body['ipsecpolicies']]
159 self.assertIn(ipsecpolicy['id'], ipsecpolicies)
160
161 @decorators.attr(type='smoke')
162 @decorators.idempotent_id('016b1861-fe55-4184-ba3c-e049ebbeb570')
163 def test_admin_create_vpn_service_for_tenant(self):
164 tenant_id = self._get_tenant_id()
165
166 # Create vpn service for the newly created tenant
167 network2 = self.create_network()
168 subnet2 = self.create_subnet(network2)
169 router2 = self.create_router(data_utils.rand_name('router-'),
170 external_network_id=self.ext_net_id)
171 self.create_router_interface(router2['id'], subnet2['id'])
172 name = data_utils.rand_name('vpn-service')
173 body = self.admin_client.create_vpnservice(
174 subnet_id=subnet2['id'],
175 router_id=router2['id'],
176 name=name,
177 admin_state_up=True,
178 tenant_id=tenant_id)
179 vpnservice = body['vpnservice']
180 self.assertIsNotNone(vpnservice['id'])
181 self.addCleanup(self.admin_client.delete_vpnservice, vpnservice['id'])
182 # Assert that created vpnservice is found in API list call
183 body = self.client.list_vpnservices()
184 vpn_services = [vs['id'] for vs in body['vpnservices']]
185 self.assertIn(vpnservice['id'], vpn_services)
186
187 @decorators.attr(type='smoke')
188 @decorators.idempotent_id('8f33c292-558d-4fdb-b32c-ab1677e8bdc8')
189 def test_admin_create_ike_policy_for_tenant(self):
190 tenant_id = self._get_tenant_id()
191
192 # Create IKE policy for the newly created tenant
193 name = data_utils.rand_name('ike-policy')
194 body = (self.admin_client.
195 create_ikepolicy(name=name, ike_version="v1",
196 encryption_algorithm="aes-128",
197 auth_algorithm="sha1",
198 tenant_id=tenant_id))
199 ikepolicy = body['ikepolicy']
200 self.assertIsNotNone(ikepolicy['id'])
201 self.addCleanup(self.admin_client.delete_ikepolicy, ikepolicy['id'])
202
203 # Assert that created ike policy is found in API list call
204 body = self.client.list_ikepolicies()
205 ikepolicies = [ikp['id'] for ikp in body['ikepolicies']]
206 self.assertIn(ikepolicy['id'], ikepolicies)
207
208 @decorators.attr(type='smoke')
209 @decorators.idempotent_id('2997641b-3f2f-4fdf-9af6-bfb9997ecd3b')
210 def test_list_vpn_services(self):
211 # Verify the VPN service exists in the list of all VPN services
212 body = self.client.list_vpnservices()
213 vpnservices = body['vpnservices']
214 self.assertIn(self.vpnservice['id'], [v['id'] for v in vpnservices])
215
216 @decorators.attr(type='smoke')
217 @decorators.idempotent_id('8780a28a-deb2-40b0-8433-66f37005c058')
218 def test_create_update_delete_vpn_service(self):
219 # Creates a VPN service and sets up deletion
220 network1 = self.create_network()
221 subnet1 = self.create_subnet(network1)
222 router1 = self.create_router(data_utils.rand_name('router-'),
223 external_network_id=self.ext_net_id)
224 self.create_router_interface(router1['id'], subnet1['id'])
225 name = data_utils.rand_name('vpn-service1')
226 body = self.client.create_vpnservice(subnet_id=subnet1['id'],
227 router_id=router1['id'],
228 name=name,
229 admin_state_up=True)
230 vpnservice = body['vpnservice']
231 self.addCleanup(self._delete_vpn_service, vpnservice['id'])
232 # Assert if created vpnservices are not found in vpnservices list
233 body = self.client.list_vpnservices()
234 vpn_services = [vs['id'] for vs in body['vpnservices']]
235 self.assertIsNotNone(vpnservice['id'])
236 self.assertIn(vpnservice['id'], vpn_services)
237
238 # TODO(raies): implement logic to update vpnservice
239 # VPNaaS client function to update is implemented.
240 # But precondition is that current state of vpnservice
241 # should be "ACTIVE" not "PENDING*"
242
243 @decorators.attr(type='smoke')
244 @decorators.idempotent_id('631d33ec-8d34-49e1-9e53-576959ea2c57')
245 def test_show_vpn_service(self):
246 # Verifies the details of a vpn service
247 body = self.client.show_vpnservice(self.vpnservice['id'])
248 vpnservice = body['vpnservice']
249 self.assertEqual(self.vpnservice['id'], vpnservice['id'])
250 self.assertEqual(self.vpnservice['name'], vpnservice['name'])
251 self.assertEqual(self.vpnservice['description'],
252 vpnservice['description'])
253 self.assertEqual(self.vpnservice['router_id'], vpnservice['router_id'])
254 self.assertEqual(self.vpnservice['subnet_id'], vpnservice['subnet_id'])
255 self.assertEqual(self.vpnservice['tenant_id'], vpnservice['tenant_id'])
256 valid_status = ["ACTIVE", "DOWN", "BUILD", "ERROR", "PENDING_CREATE",
257 "PENDING_UPDATE", "PENDING_DELETE"]
258 self.assertIn(vpnservice['status'], valid_status)
259
260 @decorators.attr(type='smoke')
261 @decorators.idempotent_id('b6a665cf-d3df-417f-9477-bd0ef2c56c36')
262 def test_list_ike_policies(self):
263 # Verify the ike policy exists in the list of all IKE policies
264 body = self.client.list_ikepolicies()
265 ikepolicies = body['ikepolicies']
266 self.assertIn(self.ikepolicy['id'], [i['id'] for i in ikepolicies])
267
268 @decorators.attr(type='smoke')
269 @decorators.idempotent_id('d9ecb858-7136-4ef5-abba-325c84c57d78')
270 def test_create_update_delete_ike_policy(self):
271 # Creates a IKE policy
272 name = data_utils.rand_name('ike-policy')
273 body = (self.client.create_ikepolicy(
274 name=name,
275 ike_version="v1",
276 encryption_algorithm="aes-128",
277 auth_algorithm="sha1"))
278 ikepolicy = body['ikepolicy']
279 self.assertIsNotNone(ikepolicy['id'])
280 self.addCleanup(self._delete_ike_policy, ikepolicy['id'])
281
282 # Update IKE Policy
283 new_ike = {'name': data_utils.rand_name("New-IKE"),
284 'description': "Updated ike policy",
285 'encryption_algorithm': "aes-256",
286 'ike_version': "v2",
287 'pfs': "group14",
288 'lifetime': {'units': "seconds", 'value': 2000}}
289 self.client.update_ikepolicy(ikepolicy['id'], **new_ike)
290 # Confirm that update was successful by verifying using 'show'
291 body = self.client.show_ikepolicy(ikepolicy['id'])
292 ike_policy = body['ikepolicy']
293 for key, value in new_ike.items():
294 self.assertIn(key, ike_policy)
295 self.assertEqual(value, ike_policy[key])
296
297 # Verification of ike policy delete
298 self.client.delete_ikepolicy(ikepolicy['id'])
299 body = self.client.list_ikepolicies()
300 ikepolicies = [ikp['id'] for ikp in body['ikepolicies']]
301 self.assertNotIn(ike_policy['id'], ikepolicies)
302
303 @decorators.attr(type='smoke')
304 @decorators.idempotent_id('5efd625b-41f2-4b80-90e0-81786f3e3309')
305 def test_show_ike_policy(self):
306 # Verifies the details of a ike policy
307 body = self.client.show_ikepolicy(self.ikepolicy['id'])
308 ikepolicy = body['ikepolicy']
309 self.assertEqual(self.ikepolicy['id'], ikepolicy['id'])
310 self.assertEqual(self.ikepolicy['name'], ikepolicy['name'])
311 self.assertEqual(self.ikepolicy['description'],
312 ikepolicy['description'])
313 self.assertEqual(self.ikepolicy['encryption_algorithm'],
314 ikepolicy['encryption_algorithm'])
315 self.assertEqual(self.ikepolicy['auth_algorithm'],
316 ikepolicy['auth_algorithm'])
317 self.assertEqual(self.ikepolicy['tenant_id'],
318 ikepolicy['tenant_id'])
319 self.assertEqual(self.ikepolicy['pfs'],
320 ikepolicy['pfs'])
321 self.assertEqual(self.ikepolicy['phase1_negotiation_mode'],
322 ikepolicy['phase1_negotiation_mode'])
323 self.assertEqual(self.ikepolicy['ike_version'],
324 ikepolicy['ike_version'])
325
326 @decorators.attr(type='smoke')
327 @decorators.idempotent_id('c3f7a459-3ccb-42b3-8fab-5ad7a5a791b1')
328 def test_list_ipsec_policies(self):
329 # Verify the ipsec policy exists in the list of all ipsec policies
330 body = self.client.list_ipsecpolicies()
331 ipsecpolicies = body['ipsecpolicies']
332 self.assertIn(self.ipsecpolicy['id'], [i['id'] for i in ipsecpolicies])
333
334 @decorators.attr(type='smoke')
335 @decorators.idempotent_id('e3952941-9b9e-48fc-9f36-fc41707a16b4')
336 def test_create_update_delete_ipsec_policy(self):
337 # Creates an ipsec policy
338 ipsec_policy_body = {'name': data_utils.rand_name('ipsec-policy'),
339 'pfs': 'group5',
340 'encryption_algorithm': "aes-128",
341 'auth_algorithm': 'sha1'}
342 resp_body = self.client.create_ipsecpolicy(**ipsec_policy_body)
343 ipsecpolicy = resp_body['ipsecpolicy']
344 self.addCleanup(self._delete_ipsec_policy, ipsecpolicy['id'])
345 self._assertExpected(ipsec_policy_body, ipsecpolicy)
346 # Verification of ipsec policy update
347 new_ipsec = {'description': 'Updated ipsec policy',
348 'pfs': 'group2',
349 'name': data_utils.rand_name("New-IPSec"),
350 'encryption_algorithm': "aes-256",
351 'lifetime': {'units': "seconds", 'value': '2000'}}
352 body = self.client.update_ipsecpolicy(ipsecpolicy['id'],
353 **new_ipsec)
354 updated_ipsec_policy = body['ipsecpolicy']
355 self._assertExpected(new_ipsec, updated_ipsec_policy)
356 # Verification of ipsec policy delete
357 self.client.delete_ipsecpolicy(ipsecpolicy['id'])
358 self.assertRaises(lib_exc.NotFound,
359 self.client.delete_ipsecpolicy, ipsecpolicy['id'])
360
361 @decorators.attr(type='smoke')
362 @decorators.idempotent_id('86d68b8d-5935-46db-b096-235f70825678')
363 def test_show_ipsec_policy(self):
364 # Verifies the details of an ipsec policy
365 body = self.client.show_ipsecpolicy(self.ipsecpolicy['id'])
366 ipsecpolicy = body['ipsecpolicy']
367 self._assertExpected(self.ipsecpolicy, ipsecpolicy)
368
369 @decorators.attr(type=['negative', 'smoke'])
370 @decorators.idempotent_id('95a4a55a-3a10-4f53-9e8a-45be359a245e')
371 def test_create_vpnservice_long_name(self):
372 """Test excessively long name.
373
374 Without REST checks, this call would return 500 INTERNAL SERVER
375 error on internal db failure instead.
376 """
377 name = _LONG_NAME
378 self.assertRaises(
379 lib_exc.BadRequest, self.client.create_vpnservice,
380 subnet_id=self.subnet['id'], router_id=self.router['id'],
381 name=name, admin_state_up=True)
382
383 @decorators.attr(type=['negative', 'smoke'])
384 @decorators.idempotent_id('6e88b4fb-de5e-464e-97db-a04c68070589')
385 def test_create_vpnservice_long_description(self):
386 name = data_utils.rand_name('vpn-service1')
387 description = _LONG_DESCRIPTION
388 self.assertRaises(
389 lib_exc.BadRequest, self.client.create_vpnservice,
390 subnet_id=self.subnet['id'], router_id=self.router['id'],
391 name=name, description=description, admin_state_up=True)
392
393 @decorators.attr(type='smoke')
394 @decorators.idempotent_id('fdb5a215-0671-449b-91e4-dd58fb223947')
395 def test_list_vpn_connections(self):
396 # Verify the VPN service exists in the list of all VPN services
397 body = self.client.list_ipsec_site_connections()
398 ipsec_site_connections = body['ipsec_site_connections']
399 self.assertIn(self.ipsec_site_connection['id'],
400 [v['id'] for v in ipsec_site_connections])
401
402 @decorators.attr(type='smoke')
403 @decorators.idempotent_id('92cfbb15-4299-4fe9-a4e1-f11167e3b057')
404 def test_create_delete_vpn_connection_with_legacy_mode(self):
405 # Verify create VPN connection
406 name = data_utils.rand_name("ipsec_site_connection-")
407 body = self.client.create_ipsec_site_connection(
408 ipsecpolicy_id=self.ipsecpolicy['id'],
409 ikepolicy_id=self.ikepolicy['id'],
410 vpnservice_id=self.vpnservice['id'],
411 peer_address="172.24.4.233",
412 peer_id="172.24.4.233",
413 peer_cidrs=['10.1.1.0/24', '10.2.2.0/24'],
414 name=name,
415 mtu=1500,
416 admin_state_up=True,
417 initiator="bi-directional",
418 psk="secret")
419 ipsec_site_connection = body['ipsec_site_connection']
420 self.assertEqual(ipsec_site_connection['name'], name)
421 self.assertEqual(ipsec_site_connection['mtu'], 1500)
422 self.addCleanup(self._delete_ipsec_site_connection,
423 ipsec_site_connection['id'])
424
425 # Verification of IPsec connection delete
426 self.client.delete_ipsec_site_connection(ipsec_site_connection['id'])
427 body = self.client.list_ipsec_site_connections()
428 ipsec_site_connections = body['ipsec_site_connections']
429 self.assertNotIn(ipsec_site_connection['id'],
430 [v['id'] for v in ipsec_site_connections])
431
432 @decorators.attr(type=['negative', 'smoke'])
433 @decorators.idempotent_id('e9977b38-9cd8-4aa6-8bd5-ba15f41c368c')
434 def test_create_vpn_connection_missing_peer_cidr(self):
435 # Verify create VPN connection with JSON missing peer cidr
436 # in legacy mode
437 name = data_utils.rand_name("ipsec_site_connection-")
438 self.assertRaises(
439 lib_exc.BadRequest,
440 self.client.create_ipsec_site_connection,
441 ipsecpolicy_id=self.ipsecpolicy['id'],
442 ikepolicy_id=self.ikepolicy['id'],
443 vpnservice_id=self.vpnservice['id'],
444 peer_address="172.24.4.233",
445 peer_id="172.24.4.233",
446 name=name,
447 mtu=1500,
448 admin_state_up=True,
449 initiator="bi-directional",
450 psk="secret")
451
452 @decorators.attr(type=['negative', 'smoke'])
453 @decorators.idempotent_id('06a268fa-c53b-4cd1-9350-b83892e4a394')
454 def test_create_vpn_service_subnet_not_on_router(self):
455 # Verify create VPN service with a subnet not on router
456 tenant_id = self._get_tenant_id()
457
458 # Create vpn service for the newly created tenant
459 network2 = self.create_network()
460 subnet2 = self.create_subnet(network2)
461 router2 = self.create_router(data_utils.rand_name('router-'),
462 external_network_id=self.ext_net_id)
463 self.addCleanup(self.admin_client.delete_router, router2['id'])
464 self.addCleanup(self.admin_client.delete_network, network2['id'])
465 name = data_utils.rand_name('vpn-service')
466 self.assertRaises(
467 lib_exc.BadRequest,
468 self.admin_client.create_vpnservice,
469 subnet_id=subnet2['id'],
470 router_id=router2['id'],
471 name=name,
472 admin_state_up=True,
473 tenant_id=tenant_id)
474
475 @decorators.attr(type=['negative', 'smoke'])
476 @decorators.idempotent_id('7678798a-fc20-46cd-ad78-b6b3d599de18')
477 def test_create_vpn_connection_small_MTU(self):
478 # Verify create VPN connection with small MTU
479 name = data_utils.rand_name("ipsec_site_connection-")
480 self.assertRaises(
481 lib_exc.BadRequest,
482 self.client.create_ipsec_site_connection,
483 ipsecpolicy_id=self.ipsecpolicy['id'],
484 ikepolicy_id=self.ikepolicy['id'],
485 vpnservice_id=self.vpnservice['id'],
486 peer_address="172.24.4.233",
487 peer_id="172.24.4.233",
488 peer_cidrs=['10.1.1.0/24', '10.2.2.0/24'],
489 name=name,
490 mtu=63,
491 admin_state_up=True,
492 initiator="bi-directional",
493 psk="secret")
494
495 @decorators.attr(type=['negative', 'smoke'])
496 @decorators.idempotent_id('d9e1af94-1fbf-4183-b857-82328d4f4b97')
497 def test_create_vpn_connection_small_dpd(self):
498 # Verify create VPN connection with small dpd
499 name = data_utils.rand_name("ipsec_site_connection-")
500 self.assertRaises(
501 lib_exc.BadRequest,
502 self.client.create_ipsec_site_connection,
503 ipsecpolicy_id=self.ipsecpolicy['id'],
504 ikepolicy_id=self.ikepolicy['id'],
505 vpnservice_id=self.vpnservice['id'],
506 peer_address="172.24.4.233",
507 peer_id="172.24.4.233",
508 peer_cidrs=['10.1.1.0/24', '10.2.2.0/24'],
509 name=name,
510 dpd=59,
511 admin_state_up=True,
512 initiator="bi-directional",
513 psk="secret")
514
515 @decorators.attr(type=['negative', 'smoke'])
516 @decorators.idempotent_id('ea6ae270-9ea4-4446-9022-b7ef7d986762')
517 def test_create_vpn_connection_wrong_peer_cidr(self):
518 # Verify create VPN connection with wrong peer cidr
519 name = data_utils.rand_name("ipsec_site_connection-")
520 self.assertRaises(
521 lib_exc.BadRequest,
522 self.client.create_ipsec_site_connection,
523 ipsecpolicy_id=self.ipsecpolicy['id'],
524 ikepolicy_id=self.ikepolicy['id'],
525 vpnservice_id=self.vpnservice['id'],
526 peer_address="172.24.4.233",
527 peer_id="172.24.4.233",
528 peer_cidrs=['1.0.0.0/33'],
529 name=name,
530 mtu=1500,
531 admin_state_up=True,
532 initiator="bi-directional",
533 psk="secret")
534
535 @decorators.attr(type=['negative', 'smoke'])
536 @decorators.idempotent_id('68e17a9b-5b33-4d3e-90f2-01a6728d2c26')
537 def test_create_connection_with_cidr_and_endpoint_group(self):
538 tenant_id = self._get_tenant_id()
539 # Create endpoint group for the newly created tenant
540 name = data_utils.rand_name('endpoint_group')
541 subnet_id = self.subnet['id']
542 body = self.client.create_endpoint_group(
543 tenant_id=tenant_id,
544 name=name,
545 type='subnet',
546 endpoints=subnet_id)
547 endpoint_group_local = body['endpoint_group']
548 self.addCleanup(self._delete_endpoint_group,
549 endpoint_group_local['id'])
550 name = data_utils.rand_name('endpoint_group')
551 body = self.client.create_endpoint_group(
552 tenant_id=tenant_id,
553 name=name,
554 type='cidr',
555 endpoints=["10.103.0.0/24", "10.104.0.0/24"])
556 endpoint_group_remote = body['endpoint_group']
557 self.addCleanup(self._delete_endpoint_group,
558 endpoint_group_remote['id'])
559 # Create connections
560 name = data_utils.rand_name("ipsec_site_connection-")
561 self.assertRaises(
562 lib_exc.BadRequest,
563 self.client.create_ipsec_site_connection,
564 ipsecpolicy_id=self.ipsecpolicy['id'],
565 ikepolicy_id=self.ikepolicy['id'],
566 vpnservice_id=self.vpnservice_no_subnet['id'],
567 peer_address="172.24.4.233",
568 peer_id="172.24.4.233",
569 peer_cidr="10.1.0.0/24",
570 peer_ep_group_id=endpoint_group_local['id'],
571 local_ep_group_id=endpoint_group_remote['id'],
572 name=name,
573 admin_state_up=True,
574 initiator="bi-directional",
575 psk="secret")
576
577 @decorators.attr(type=['negative', 'smoke'])
578 @decorators.idempotent_id('d101a6a7-67d3-4418-9d9e-65c4507a9148')
579 def test_create_vpn_connection_with_missing_remote_endpoint_group(self):
580 # Verify create VPN connection without subnet in vpnservice
581 # and has only local endpoint group
582 tenant_id = self._get_tenant_id()
583 # Create endpoint group for the newly created tenant
584 tenant_id = self._get_tenant_id()
585 name = data_utils.rand_name('endpoint_group')
586 subnet_id = self.subnet['id']
587 body = self.client.create_endpoint_group(
588 tenant_id=tenant_id,
589 name=name,
590 type='subnet',
591 endpoints=subnet_id)
592 endpoint_group = body['endpoint_group']
593 self.addCleanup(self._delete_endpoint_group, endpoint_group['id'])
594 # Create connections
595 name = data_utils.rand_name("ipsec_site_connection-")
596 self.assertRaises(
597 lib_exc.BadRequest,
598 self.client.create_ipsec_site_connection,
599 ipsecpolicy_id=self.ipsecpolicy['id'],
600 ikepolicy_id=self.ikepolicy['id'],
601 vpnservice_id=self.vpnservice_no_subnet['id'],
602 peer_address="172.24.4.233",
603 peer_id="172.24.4.233",
604 local_ep_group_id=endpoint_group['id'],
605 name=name,
606 admin_state_up=True,
607 initiator="bi-directional",
608 psk="secret")
609
610 @decorators.attr(type=['negative', 'smoke'])
611 @decorators.idempotent_id('b5dd8d1e-587b-4e26-84f0-dcb814c65e57')
612 def test_create_vpn_connection_with_missing_local_endpoint_group(self):
613 # Verify create VPN connection without subnet in vpnservice
614 # and only have only local endpoint group
615 tenant_id = self._get_tenant_id()
616 # Create endpoint group for the newly created tenant
617 tenant_id = self._get_tenant_id()
618 name = data_utils.rand_name('endpoint_group')
619 body = self.client.create_endpoint_group(
620 tenant_id=tenant_id,
621 name=name,
622 type='cidr',
623 endpoints=["10.101.0.0/24", "10.102.0.0/24"])
624 endpoint_group = body['endpoint_group']
625 self.addCleanup(self._delete_endpoint_group, endpoint_group['id'])
626 # Create connections
627 name = data_utils.rand_name("ipsec_site_connection-")
628 self.assertRaises(
629 lib_exc.BadRequest,
630 self.client.create_ipsec_site_connection,
631 ipsecpolicy_id=self.ipsecpolicy['id'],
632 ikepolicy_id=self.ikepolicy['id'],
633 vpnservice_id=self.vpnservice_no_subnet['id'],
634 peer_address="172.24.4.233",
635 peer_id="172.24.4.233",
636 peer_ep_group_id=endpoint_group['id'],
637 name=name,
638 admin_state_up=True,
639 initiator="bi-directional",
640 psk="secret")
641
642 @decorators.attr(type=['negative', 'smoke'])
643 @decorators.idempotent_id('427bbc1b-4040-42e4-b661-6395a0bd8762')
644 def test_create_connection_with_mix_ip_endpoint_group(self):
645 tenant_id = self._get_tenant_id()
646 # Create endpoint group for the newly created tenant
647 name = data_utils.rand_name('endpoint_group')
648 subnet_id = self.subnet['id']
649 body = self.client.create_endpoint_group(
650 tenant_id=tenant_id,
651 name=name,
652 type='subnet',
653 endpoints=subnet_id)
654 endpoint_group_local = body['endpoint_group']
655 self.addCleanup(self._delete_endpoint_group,
656 endpoint_group_local['id'])
657 name_v6 = data_utils.rand_name('endpoint_group')
658 body_v6 = self.client.create_endpoint_group(
659 tenant_id=tenant_id,
660 name=name_v6,
661 type='cidr',
662 endpoints=["fec0:101::/64", "fec0:102::/64"])
663 endpoint_group_remote = body_v6['endpoint_group']
664 self.addCleanup(self._delete_endpoint_group,
665 endpoint_group_remote['id'])
666 # Create connections
667 name = data_utils.rand_name("ipsec_site_connection-")
668 self.assertEqual(endpoint_group_local['type'], 'subnet')
669 self.assertEqual(endpoint_group_remote['type'], 'cidr')
670 self.assertRaises(
671 lib_exc.BadRequest,
672 self.client.create_ipsec_site_connection,
673 ipsecpolicy_id=self.ipsecpolicy['id'],
674 ikepolicy_id=self.ikepolicy['id'],
675 vpnservice_id=self.vpnservice_no_subnet['id'],
676 peer_address="172.24.4.233",
677 peer_id="172.24.4.233",
678 peer_ep_group_id=endpoint_group_local['id'],
679 local_ep_group_id=endpoint_group_remote['id'],
680 name=name,
681 admin_state_up=True,
682 initiator="bi-directional",
683 psk="secret")
684
685 @decorators.attr(type=['negative', 'smoke'])
686 @decorators.idempotent_id('eac56769-ec2d-4817-ba45-ca101d676bfc')
687 def test_create_connection_with_subnet_and_remote_endpoint_group(self):
688 tenant_id = self._get_tenant_id()
689 # Create endpoint group for the newly created tenant
690 name = data_utils.rand_name('endpoint_group')
691 body = self.client.create_endpoint_group(
692 tenant_id=tenant_id,
693 name=name,
694 type='cidr',
695 endpoints=["10.101.0.0/24", "10.102.0.0/24"])
696 endpoint_group = body['endpoint_group']
697 self.addCleanup(self._delete_endpoint_group, endpoint_group['id'])
698 # Create connections
699 name = data_utils.rand_name("ipsec_site_connection-")
700 self.assertRaises(
701 lib_exc.BadRequest,
702 self.client.create_ipsec_site_connection,
703 ipsecpolicy_id=self.ipsecpolicy['id'],
704 ikepolicy_id=self.ikepolicy['id'],
705 vpnservice_id=self.vpnservice['id'],
706 peer_address="172.24.4.233",
707 peer_ep_group_id=endpoint_group['id'],
708 name=name,
709 admin_state_up=True,
710 initiator="bi-directional",
711 psk="secret")
712
713 @decorators.attr(type=['negative', 'smoke'])
714 @decorators.idempotent_id('92cd1221-3c7c-47ea-adad-8d8c2fc0f247')
715 def test_create_connection_with_subnet_and_local_endpoint_group(self):
716 tenant_id = self._get_tenant_id()
717 # Create endpoint group for the newly created tenant
718 name = data_utils.rand_name('endpoint_group')
719 subnet_id = self.subnet['id']
720 body = self.client.create_endpoint_group(
721 tenant_id=tenant_id,
722 name=name,
723 type='subnet',
724 endpoints=subnet_id)
725 endpoint_group = body['endpoint_group']
726 self.addCleanup(self._delete_endpoint_group, endpoint_group['id'])
727 # Create connections
728 name = data_utils.rand_name("ipsec_site_connection-")
729 self.assertRaises(
730 lib_exc.BadRequest,
731 self.client.create_ipsec_site_connection,
732 ipsecpolicy_id=self.ipsecpolicy['id'],
733 ikepolicy_id=self.ikepolicy['id'],
734 vpnservice_id=self.vpnservice['id'],
735 peer_address="172.24.4.233",
736 local_ep_group_id=endpoint_group['id'],
737 name=name,
738 admin_state_up=True,
739 initiator="bi-directional",
740 psk="secret")
741
742 @decorators.attr(type='smoke')
743 @decorators.idempotent_id('e0cb784d-ebd9-4ad1-84e1-0cba915784d0')
744 def test_create_update_delete_endpoint_group(self):
745 # Creates a endpoint-group
746 name = data_utils.rand_name('endpoint_group')
747 body = (self.client.create_endpoint_group(
748 name=name,
749 type='cidr',
750 endpoints=["10.2.0.0/24", "10.3.0.0/24"]))
751 endpoint_group = body['endpoint_group']
752 self.assertIsNotNone(endpoint_group['id'])
753 self.addCleanup(self._delete_endpoint_group, endpoint_group['id'])
754 # Update endpoint-group
755 body = {'name': data_utils.rand_name("new_endpoint_group")}
756 self.client.update_endpoint_group(endpoint_group['id'],
757 name=name)
758 # Confirm that update was successful by verifying using 'show'
759 body = self.client.show_endpoint_group(endpoint_group['id'])
760 endpoint_group = body['endpoint_group']
761 self.assertEqual(name, endpoint_group['name'])
762 # Verification of endpoint-group delete
763 endpoint_group_id = endpoint_group['id']
764 self.client.delete_endpoint_group(endpoint_group['id'])
765 body = self.client.list_endpoint_groups()
766 endpoint_group = [enp['id'] for enp in body['endpoint_groups']]
767 self.assertNotIn(endpoint_group_id, endpoint_group)
768
769 @decorators.attr(type='smoke')
770 @decorators.idempotent_id('69ee29e9-f72c-4d84-b6ab-c3f5576440fc')
771 def test_admin_create_endpoint_group_for_tenant(self):
772 # Create endpoint group for the newly created tenant
773 tenant_id = self._get_tenant_id()
774 name = data_utils.rand_name('endpoint_group')
775 body = (self.client.
776 create_endpoint_group(
777 name=name,
778 type='cidr',
779 endpoints=["10.2.0.0/24", "10.3.0.0/24"],
780 tenant_id=tenant_id))
781 endpoint_group = body['endpoint_group']
782 self.assertIsNotNone(endpoint_group['id'])
783 self.addCleanup(self._delete_endpoint_group, endpoint_group['id'])
784 # Assert that created endpoint group is found in API list call
785 endpoint_group_id = endpoint_group['id']
786 self.client.delete_endpoint_group(endpoint_group['id'])
787 body = self.client.list_endpoint_groups()
788 endpoint_group = [enp['id'] for enp in body['endpoint_groups']]
789 self.assertNotIn(endpoint_group_id, endpoint_group)
790
791 @decorators.attr(type='smoke')
792 @decorators.idempotent_id('7a584d9c-0f64-4d39-a66c-261bfa46e369')
793 def test_show_endpoint_group(self):
794 # Verifies the details of an endpoint group
795 body = self.client.show_endpoint_group(self.endpoint_group_local['id'])
796 endpoint_group = body['endpoint_group']
797 self.assertEqual(self.endpoint_group_local['id'], endpoint_group['id'])
798 self.assertEqual(self.endpoint_group_local['name'],
799 endpoint_group['name'])
800 self.assertEqual(self.endpoint_group_local['description'],
801 endpoint_group['description'])
802 self.assertEqual(self.endpoint_group_local['tenant_id'],
803 endpoint_group['tenant_id'])
804 self.assertEqual(self.endpoint_group_local['type'],
805 endpoint_group['type'])
806 self.assertEqual(self.endpoint_group_local['endpoints'],
807 endpoint_group['endpoints'])
808 # Verifies the details of an endpoint group
809 body = self.client.show_endpoint_group(
810 self.endpoint_group_remote['id'])
811 endpoint_group = body['endpoint_group']
812 # endpoint_group_remote = endpoint_group['id']
813 self.assertEqual(self.endpoint_group_remote['id'],
814 endpoint_group['id'])
815 self.assertEqual(self.endpoint_group_remote['name'],
816 endpoint_group['name'])
817 self.assertEqual(self.endpoint_group_remote['description'],
818 endpoint_group['description'])
819 self.assertEqual(self.endpoint_group_remote['tenant_id'],
820 endpoint_group['tenant_id'])
821 self.assertEqual(self.endpoint_group_remote['type'],
822 endpoint_group['type'])
823 self.assertEqual(self.endpoint_group_remote['endpoints'],
824 endpoint_group['endpoints'])
825
826 @decorators.attr(type='smoke')
827 @decorators.idempotent_id('386f703e-445e-4208-abd2-df66066fd876')
828 def test_create_delete_vpn_connection_with_ep_group(self):
829 # Creates a endpoint-group with type cidr
830 name = data_utils.rand_name('endpoint_group')
831 body = self.client.create_endpoint_group(
832 name=name,
833 type='cidr',
834 endpoints=["10.2.0.0/24", "10.3.0.0/24"])
835 endpoint_group_remote = body['endpoint_group']
836 self.addCleanup(self._delete_endpoint_group,
837 endpoint_group_remote['id'])
838 # Creates a endpoint-group with type subnet
839 name = data_utils.rand_name('endpoint_group')
840 subnet_id = self.subnet['id']
841 body2 = self.client.create_endpoint_group(
842 name=name,
843 type='subnet',
844 endpoints=subnet_id)
845 endpoint_group_local = body2['endpoint_group']
846 self.addCleanup(self._delete_endpoint_group,
847 endpoint_group_local['id'])
848 # Verify create VPN connection
849 name = data_utils.rand_name("ipsec_site_connection-")
850 body = self.client.create_ipsec_site_connection(
851 ipsecpolicy_id=self.ipsecpolicy['id'],
852 ikepolicy_id=self.ikepolicy['id'],
853 vpnservice_id=self.vpnservice_no_subnet['id'],
854 peer_ep_group_id=endpoint_group_remote['id'],
855 local_ep_group_id=endpoint_group_local['id'],
856 name=name,
857 mtu=1500,
858 admin_state_up=True,
859 initiator="bi-directional",
860 peer_address="172.24.4.233",
861 peer_id="172.24.4.233",
862 psk="secret")
863 ipsec_site_connection = body['ipsec_site_connection']
864 self.assertEqual(ipsec_site_connection['name'], name)
865 self.assertEqual(ipsec_site_connection['mtu'], 1500)
866 self.addCleanup(self._delete_ipsec_site_connection,
867 ipsec_site_connection['id'])
868
869 # Verification of IPsec connection delete
870 self.client.delete_ipsec_site_connection(ipsec_site_connection['id'])
871 body = self.client.list_ipsec_site_connections()
872 ipsec_site_connections = body['ipsec_site_connections']
873 self.assertNotIn(ipsec_site_connection['id'],
874 [v['id'] for v in ipsec_site_connections])
875
876 @decorators.attr(type=['negative', 'smoke'])
877 @decorators.idempotent_id('0ef1b2b0-9b4b-49f1-9473-cb4a0b625543')
878 def test_fail_create_endpoint_group_when_wrong_type(self):
879 # Creates a endpoint-group with wrong type
880 name = data_utils.rand_name('endpoint_group')
881 self.assertRaises(
882 lib_exc.BadRequest,
883 self.client.create_endpoint_group,
884 name=name,
885 type='subnet',
886 endpoints=["10.2.0.0/24", "10.3.0.0/24"])
887
888 @decorators.attr(type=['negative', 'smoke'])
889 @decorators.idempotent_id('670844d2-f7b0-466c-8fd7-7d2ad6e832ee')
890 def test_fail_create_endpoint_group_when_provide_subnet_id_with_cidr(self):
891 # Creates a endpoint-group when provide subnet id with type cidr
892 name = data_utils.rand_name('endpoint_group')
893 subnet_id = self.subnet['id']
894 self.assertRaises(
895 lib_exc.BadRequest,
896 self.client.create_endpoint_group,
897 name=name,
898 type='cidr',
899 endpoints=subnet_id)
900
901 @decorators.attr(type=['negative', 'smoke'])
902 @decorators.idempotent_id('d7516513-f2a2-42bd-8cea-baba73b93a22')
903 def test_fail_create_endpoint_group_with_mixed_IP_version(self):
904 # Creates a endpoint-group with mixed IP version
905 name = data_utils.rand_name('endpoint_group')
906 self.assertRaises(
907 lib_exc.BadRequest,
908 self.client.create_endpoint_group,
909 name=name,
910 type='cidr',
911 endpoints=["10.2.0.0/24", "2000::1"])