blob: 4ab69e0bd1cd99c1c7e6313cd6a759aaa3b17917 [file] [log] [blame]
Anju Tiwari860097d2013-10-17 11:10:39 +05301# Copyright 2013 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
Matthew Treinish01472ff2015-02-20 17:26:52 -050016from tempest_lib.common.utils import data_utils
Masayuki Igawabfa07602015-01-20 18:47:17 +090017from tempest_lib import exceptions as lib_exc
18
Anju Tiwari860097d2013-10-17 11:10:39 +053019from tempest.api.network import base
Matthew Treinish03b48df2014-01-29 16:59:49 +000020from tempest import config
mouad benchchaouiea2440d2013-12-22 00:38:06 +010021from tempest import test
Anju Tiwari860097d2013-10-17 11:10:39 +053022
Matthew Treinish03b48df2014-01-29 16:59:49 +000023CONF = config.CONF
24
Anju Tiwari860097d2013-10-17 11:10:39 +053025
Miguel Lavalle3581e462014-03-27 19:01:46 -050026class VPNaaSTestJSON(base.BaseAdminNetworkTest):
Anju Tiwari860097d2013-10-17 11:10:39 +053027 """
28 Tests the following operations in the Neutron API using the REST client for
29 Neutron:
Miguel Lavalle3581e462014-03-27 19:01:46 -050030 List, Show, Create, Delete, and Update VPN Service
raiesmh08bd6070d2013-12-06 15:13:38 +053031 List, Show, Create, Delete, and Update IKE policy
Miguel Lavalle3581e462014-03-27 19:01:46 -050032 List, Show, Create, Delete, and Update IPSec policy
Anju Tiwari860097d2013-10-17 11:10:39 +053033 """
34
35 @classmethod
Rohan Kanadea565e452015-01-27 14:00:13 +053036 def skip_checks(cls):
37 super(VPNaaSTestJSON, cls).skip_checks()
mouad benchchaouiea2440d2013-12-22 00:38:06 +010038 if not test.is_extension_enabled('vpnaas', 'network'):
39 msg = "vpnaas extension not enabled."
40 raise cls.skipException(msg)
Rohan Kanadea565e452015-01-27 14:00:13 +053041
42 @classmethod
43 def resource_setup(cls):
Andrea Frittolida4a2452014-09-15 13:12:08 +010044 super(VPNaaSTestJSON, cls).resource_setup()
vikasa347ffd2014-09-30 23:19:10 -070045 cls.ext_net_id = CONF.network.public_network_id
Anju Tiwari860097d2013-10-17 11:10:39 +053046 cls.network = cls.create_network()
47 cls.subnet = cls.create_subnet(cls.network)
Nachi Ueno41ecf5b2013-12-10 13:26:33 -080048 cls.router = cls.create_router(
Miguel Lavalle3581e462014-03-27 19:01:46 -050049 data_utils.rand_name("router"),
Matthew Treinish03b48df2014-01-29 16:59:49 +000050 external_network_id=CONF.network.public_network_id)
Anju Tiwari860097d2013-10-17 11:10:39 +053051 cls.create_router_interface(cls.router['id'], cls.subnet['id'])
52 cls.vpnservice = cls.create_vpnservice(cls.subnet['id'],
53 cls.router['id'])
Miguel Lavalle3581e462014-03-27 19:01:46 -050054
Eugene Nikanorov909ded12013-12-15 17:45:37 +040055 cls.ikepolicy = cls.create_ikepolicy(
56 data_utils.rand_name("ike-policy-"))
raiesmh08df3fac42014-06-02 15:42:18 +053057 cls.ipsecpolicy = cls.create_ipsecpolicy(
58 data_utils.rand_name("ipsec-policy-"))
raiesmh08bd6070d2013-12-06 15:13:38 +053059
60 def _delete_ike_policy(self, ike_policy_id):
61 # Deletes a ike policy and verifies if it is deleted or not
62 ike_list = list()
David Kranz34e88122014-12-11 15:24:05 -050063 all_ike = self.client.list_ikepolicies()
raiesmh08bd6070d2013-12-06 15:13:38 +053064 for ike in all_ike['ikepolicies']:
65 ike_list.append(ike['id'])
66 if ike_policy_id in ike_list:
Rohan Kanadeeeb21642014-08-14 12:00:26 +020067 self.client.delete_ikepolicy(ike_policy_id)
raiesmh08bd6070d2013-12-06 15:13:38 +053068 # Asserting that the policy is not found in list after deletion
David Kranz34e88122014-12-11 15:24:05 -050069 ikepolicies = self.client.list_ikepolicies()
raiesmh08bd6070d2013-12-06 15:13:38 +053070 ike_id_list = list()
71 for i in ikepolicies['ikepolicies']:
72 ike_id_list.append(i['id'])
73 self.assertNotIn(ike_policy_id, ike_id_list)
Anju Tiwari860097d2013-10-17 11:10:39 +053074
raiesmh08df3fac42014-06-02 15:42:18 +053075 def _delete_ipsec_policy(self, ipsec_policy_id):
76 # Deletes an ike policy if it exists
77 try:
78 self.client.delete_ipsecpolicy(ipsec_policy_id)
79
Masayuki Igawabfa07602015-01-20 18:47:17 +090080 except lib_exc.NotFound:
raiesmh08df3fac42014-06-02 15:42:18 +053081 pass
82
83 def _assertExpected(self, expected, actual):
84 # Check if not expected keys/values exists in actual response body
85 for key, value in expected.iteritems():
86 self.assertIn(key, actual)
87 self.assertEqual(value, actual[key])
88
Miguel Lavalle3581e462014-03-27 19:01:46 -050089 def _delete_vpn_service(self, vpn_service_id):
Rohan Kanadeeeb21642014-08-14 12:00:26 +020090 self.client.delete_vpnservice(vpn_service_id)
Miguel Lavalle3581e462014-03-27 19:01:46 -050091 # Asserting if vpn service is found in the list after deletion
David Kranz34e88122014-12-11 15:24:05 -050092 body = self.client.list_vpnservices()
Miguel Lavalle3581e462014-03-27 19:01:46 -050093 vpn_services = [vs['id'] for vs in body['vpnservices']]
94 self.assertNotIn(vpn_service_id, vpn_services)
95
96 def _get_tenant_id(self):
97 """
98 Returns the tenant_id of the client current user
99 """
100 # TODO(jroovers) This is a temporary workaround to get the tenant_id
101 # of the the current client. Replace this once tenant_isolation for
102 # neutron is fixed.
David Kranz34e88122014-12-11 15:24:05 -0500103 body = self.client.show_network(self.network['id'])
Miguel Lavalle3581e462014-03-27 19:01:46 -0500104 return body['network']['tenant_id']
105
106 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800107 @test.idempotent_id('14311574-0737-4e53-ac05-f7ae27742eed')
Miguel Lavalle3581e462014-03-27 19:01:46 -0500108 def test_admin_create_ipsec_policy_for_tenant(self):
109 tenant_id = self._get_tenant_id()
110 # Create IPSec policy for the newly created tenant
111 name = data_utils.rand_name('ipsec-policy')
David Kranz34e88122014-12-11 15:24:05 -0500112 body = (self.admin_client.
113 create_ipsecpolicy(name=name, tenant_id=tenant_id))
Miguel Lavalle3581e462014-03-27 19:01:46 -0500114 ipsecpolicy = body['ipsecpolicy']
115 self.assertIsNotNone(ipsecpolicy['id'])
116 self.addCleanup(self.admin_client.delete_ipsecpolicy,
117 ipsecpolicy['id'])
118
119 # Assert that created ipsec policy is found in API list call
David Kranz34e88122014-12-11 15:24:05 -0500120 body = self.client.list_ipsecpolicies()
Miguel Lavalle3581e462014-03-27 19:01:46 -0500121 ipsecpolicies = [policy['id'] for policy in body['ipsecpolicies']]
122 self.assertIn(ipsecpolicy['id'], ipsecpolicies)
123
124 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800125 @test.idempotent_id('b62acdc6-0c53-4d84-84aa-859b22b79799')
Miguel Lavalle3581e462014-03-27 19:01:46 -0500126 def test_admin_create_vpn_service_for_tenant(self):
127 tenant_id = self._get_tenant_id()
128
129 # Create vpn service for the newly created tenant
vikasa347ffd2014-09-30 23:19:10 -0700130 network2 = self.create_network()
131 subnet2 = self.create_subnet(network2)
132 router2 = self.create_router(data_utils.rand_name('router-'),
133 external_network_id=self.ext_net_id)
134 self.create_router_interface(router2['id'], subnet2['id'])
Miguel Lavalle3581e462014-03-27 19:01:46 -0500135 name = data_utils.rand_name('vpn-service')
David Kranz34e88122014-12-11 15:24:05 -0500136 body = self.admin_client.create_vpnservice(
vikasa347ffd2014-09-30 23:19:10 -0700137 subnet_id=subnet2['id'],
138 router_id=router2['id'],
Miguel Lavalle3581e462014-03-27 19:01:46 -0500139 name=name,
140 admin_state_up=True,
141 tenant_id=tenant_id)
Miguel Lavalle3581e462014-03-27 19:01:46 -0500142 vpnservice = body['vpnservice']
143 self.assertIsNotNone(vpnservice['id'])
144 self.addCleanup(self.admin_client.delete_vpnservice, vpnservice['id'])
Miguel Lavalle3581e462014-03-27 19:01:46 -0500145 # Assert that created vpnservice is found in API list call
David Kranz34e88122014-12-11 15:24:05 -0500146 body = self.client.list_vpnservices()
Miguel Lavalle3581e462014-03-27 19:01:46 -0500147 vpn_services = [vs['id'] for vs in body['vpnservices']]
148 self.assertIn(vpnservice['id'], vpn_services)
149
150 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800151 @test.idempotent_id('58cc4a1c-443b-4f39-8fb6-c19d39f343ab')
Miguel Lavalle3581e462014-03-27 19:01:46 -0500152 def test_admin_create_ike_policy_for_tenant(self):
153 tenant_id = self._get_tenant_id()
154
155 # Create IKE policy for the newly created tenant
156 name = data_utils.rand_name('ike-policy')
David Kranz34e88122014-12-11 15:24:05 -0500157 body = (self.admin_client.
158 create_ikepolicy(name=name, ike_version="v1",
159 encryption_algorithm="aes-128",
160 auth_algorithm="sha1",
161 tenant_id=tenant_id))
Miguel Lavalle3581e462014-03-27 19:01:46 -0500162 ikepolicy = body['ikepolicy']
163 self.assertIsNotNone(ikepolicy['id'])
164 self.addCleanup(self.admin_client.delete_ikepolicy, ikepolicy['id'])
165
166 # Assert that created ike policy is found in API list call
David Kranz34e88122014-12-11 15:24:05 -0500167 body = self.client.list_ikepolicies()
Miguel Lavalle3581e462014-03-27 19:01:46 -0500168 ikepolicies = [ikp['id'] for ikp in body['ikepolicies']]
169 self.assertIn(ikepolicy['id'], ikepolicies)
170
mouad benchchaouiea2440d2013-12-22 00:38:06 +0100171 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800172 @test.idempotent_id('de5bb04c-3a1f-46b1-b329-7a8abba5c7f1')
Anju Tiwari860097d2013-10-17 11:10:39 +0530173 def test_list_vpn_services(self):
174 # Verify the VPN service exists in the list of all VPN services
David Kranz34e88122014-12-11 15:24:05 -0500175 body = self.client.list_vpnservices()
Anju Tiwari860097d2013-10-17 11:10:39 +0530176 vpnservices = body['vpnservices']
177 self.assertIn(self.vpnservice['id'], [v['id'] for v in vpnservices])
178
mouad benchchaouiea2440d2013-12-22 00:38:06 +0100179 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800180 @test.idempotent_id('aacb13b1-fdc7-41fd-bab2-32621aee1878')
Anju Tiwari860097d2013-10-17 11:10:39 +0530181 def test_create_update_delete_vpn_service(self):
Miguel Lavalle3581e462014-03-27 19:01:46 -0500182 # Creates a VPN service and sets up deletion
vikasa347ffd2014-09-30 23:19:10 -0700183 network1 = self.create_network()
184 subnet1 = self.create_subnet(network1)
185 router1 = self.create_router(data_utils.rand_name('router-'),
186 external_network_id=self.ext_net_id)
187 self.create_router_interface(router1['id'], subnet1['id'])
188 name = data_utils.rand_name('vpn-service1')
David Kranz34e88122014-12-11 15:24:05 -0500189 body = self.client.create_vpnservice(subnet_id=subnet1['id'],
190 router_id=router1['id'],
191 name=name,
192 admin_state_up=True)
Anju Tiwari860097d2013-10-17 11:10:39 +0530193 vpnservice = body['vpnservice']
Miguel Lavalle3581e462014-03-27 19:01:46 -0500194 self.addCleanup(self._delete_vpn_service, vpnservice['id'])
Anju Tiwari860097d2013-10-17 11:10:39 +0530195 # Assert if created vpnservices are not found in vpnservices list
David Kranz34e88122014-12-11 15:24:05 -0500196 body = self.client.list_vpnservices()
Anju Tiwari860097d2013-10-17 11:10:39 +0530197 vpn_services = [vs['id'] for vs in body['vpnservices']]
198 self.assertIsNotNone(vpnservice['id'])
199 self.assertIn(vpnservice['id'], vpn_services)
200
201 # TODO(raies): implement logic to update vpnservice
202 # VPNaaS client function to update is implemented.
203 # But precondition is that current state of vpnservice
204 # should be "ACTIVE" not "PENDING*"
205
mouad benchchaouiea2440d2013-12-22 00:38:06 +0100206 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800207 @test.idempotent_id('0dedfc1d-f8ee-4e2a-bfd4-7997b9dc17ff')
Anju Tiwari860097d2013-10-17 11:10:39 +0530208 def test_show_vpn_service(self):
209 # Verifies the details of a vpn service
David Kranz34e88122014-12-11 15:24:05 -0500210 body = self.client.show_vpnservice(self.vpnservice['id'])
Anju Tiwari860097d2013-10-17 11:10:39 +0530211 vpnservice = body['vpnservice']
212 self.assertEqual(self.vpnservice['id'], vpnservice['id'])
213 self.assertEqual(self.vpnservice['name'], vpnservice['name'])
214 self.assertEqual(self.vpnservice['description'],
215 vpnservice['description'])
216 self.assertEqual(self.vpnservice['router_id'], vpnservice['router_id'])
217 self.assertEqual(self.vpnservice['subnet_id'], vpnservice['subnet_id'])
218 self.assertEqual(self.vpnservice['tenant_id'], vpnservice['tenant_id'])
Miguel Lavalle3581e462014-03-27 19:01:46 -0500219 valid_status = ["ACTIVE", "DOWN", "BUILD", "ERROR", "PENDING_CREATE",
220 "PENDING_UPDATE", "PENDING_DELETE"]
221 self.assertIn(vpnservice['status'], valid_status)
raiesmh08bd6070d2013-12-06 15:13:38 +0530222
mouad benchchaouiea2440d2013-12-22 00:38:06 +0100223 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800224 @test.idempotent_id('e0fb6200-da3d-4869-8340-a8c1956ca618')
raiesmh08bd6070d2013-12-06 15:13:38 +0530225 def test_list_ike_policies(self):
226 # Verify the ike policy exists in the list of all IKE policies
David Kranz34e88122014-12-11 15:24:05 -0500227 body = self.client.list_ikepolicies()
raiesmh08bd6070d2013-12-06 15:13:38 +0530228 ikepolicies = body['ikepolicies']
229 self.assertIn(self.ikepolicy['id'], [i['id'] for i in ikepolicies])
230
mouad benchchaouiea2440d2013-12-22 00:38:06 +0100231 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800232 @test.idempotent_id('d61f29a5-160c-487d-bc0d-22e32e731b44')
raiesmh08bd6070d2013-12-06 15:13:38 +0530233 def test_create_update_delete_ike_policy(self):
234 # Creates a IKE policy
Miguel Lavalle3581e462014-03-27 19:01:46 -0500235 name = data_utils.rand_name('ike-policy')
David Kranz34e88122014-12-11 15:24:05 -0500236 body = (self.client.create_ikepolicy(
237 name=name,
238 ike_version="v1",
239 encryption_algorithm="aes-128",
240 auth_algorithm="sha1"))
raiesmh08bd6070d2013-12-06 15:13:38 +0530241 ikepolicy = body['ikepolicy']
Miguel Lavalle3581e462014-03-27 19:01:46 -0500242 self.assertIsNotNone(ikepolicy['id'])
raiesmh08bd6070d2013-12-06 15:13:38 +0530243 self.addCleanup(self._delete_ike_policy, ikepolicy['id'])
Miguel Lavalle3581e462014-03-27 19:01:46 -0500244
245 # Update IKE Policy
246 new_ike = {'name': data_utils.rand_name("New-IKE"),
247 'description': "Updated ike policy",
248 'encryption_algorithm': "aes-256",
249 'ike_version': "v2",
250 'pfs': "group14",
251 'lifetime': {'units': "seconds", 'value': 2000}}
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200252 self.client.update_ikepolicy(ikepolicy['id'], **new_ike)
Miguel Lavalle3581e462014-03-27 19:01:46 -0500253 # Confirm that update was successful by verifying using 'show'
David Kranz34e88122014-12-11 15:24:05 -0500254 body = self.client.show_ikepolicy(ikepolicy['id'])
Miguel Lavalle3581e462014-03-27 19:01:46 -0500255 ike_policy = body['ikepolicy']
256 for key, value in new_ike.iteritems():
257 self.assertIn(key, ike_policy)
258 self.assertEqual(value, ike_policy[key])
259
raiesmh08bd6070d2013-12-06 15:13:38 +0530260 # Verification of ike policy delete
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200261 self.client.delete_ikepolicy(ikepolicy['id'])
David Kranz34e88122014-12-11 15:24:05 -0500262 body = self.client.list_ikepolicies()
Miguel Lavalle3581e462014-03-27 19:01:46 -0500263 ikepolicies = [ikp['id'] for ikp in body['ikepolicies']]
264 self.assertNotIn(ike_policy['id'], ikepolicies)
raiesmh08bd6070d2013-12-06 15:13:38 +0530265
mouad benchchaouiea2440d2013-12-22 00:38:06 +0100266 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800267 @test.idempotent_id('b5fcf3a3-9407-452d-b8a8-e7c6c32baea8')
raiesmh08bd6070d2013-12-06 15:13:38 +0530268 def test_show_ike_policy(self):
269 # Verifies the details of a ike policy
David Kranz34e88122014-12-11 15:24:05 -0500270 body = self.client.show_ikepolicy(self.ikepolicy['id'])
raiesmh08bd6070d2013-12-06 15:13:38 +0530271 ikepolicy = body['ikepolicy']
272 self.assertEqual(self.ikepolicy['id'], ikepolicy['id'])
273 self.assertEqual(self.ikepolicy['name'], ikepolicy['name'])
274 self.assertEqual(self.ikepolicy['description'],
275 ikepolicy['description'])
276 self.assertEqual(self.ikepolicy['encryption_algorithm'],
277 ikepolicy['encryption_algorithm'])
278 self.assertEqual(self.ikepolicy['auth_algorithm'],
279 ikepolicy['auth_algorithm'])
280 self.assertEqual(self.ikepolicy['tenant_id'],
281 ikepolicy['tenant_id'])
282 self.assertEqual(self.ikepolicy['pfs'],
283 ikepolicy['pfs'])
284 self.assertEqual(self.ikepolicy['phase1_negotiation_mode'],
285 ikepolicy['phase1_negotiation_mode'])
286 self.assertEqual(self.ikepolicy['ike_version'],
287 ikepolicy['ike_version'])
Mh Raiesc440bca2014-04-04 12:05:48 +0530288
raiesmh08df3fac42014-06-02 15:42:18 +0530289 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800290 @test.idempotent_id('19ea0a2f-add9-44be-b732-ffd8a7b42f37')
raiesmh08df3fac42014-06-02 15:42:18 +0530291 def test_list_ipsec_policies(self):
292 # Verify the ipsec policy exists in the list of all ipsec policies
David Kranz34e88122014-12-11 15:24:05 -0500293 body = self.client.list_ipsecpolicies()
raiesmh08df3fac42014-06-02 15:42:18 +0530294 ipsecpolicies = body['ipsecpolicies']
295 self.assertIn(self.ipsecpolicy['id'], [i['id'] for i in ipsecpolicies])
296
297 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800298 @test.idempotent_id('9c1701c9-329a-4e5d-930a-1ead1b3f86ad')
raiesmh08df3fac42014-06-02 15:42:18 +0530299 def test_create_update_delete_ipsec_policy(self):
300 # Creates an ipsec policy
301 ipsec_policy_body = {'name': data_utils.rand_name('ipsec-policy'),
302 'pfs': 'group5',
303 'encryption_algorithm': "aes-128",
304 'auth_algorithm': 'sha1'}
David Kranz34e88122014-12-11 15:24:05 -0500305 resp_body = self.client.create_ipsecpolicy(**ipsec_policy_body)
raiesmh08df3fac42014-06-02 15:42:18 +0530306 ipsecpolicy = resp_body['ipsecpolicy']
307 self.addCleanup(self._delete_ipsec_policy, ipsecpolicy['id'])
308 self._assertExpected(ipsec_policy_body, ipsecpolicy)
309 # Verification of ipsec policy update
310 new_ipsec = {'description': 'Updated ipsec policy',
311 'pfs': 'group2',
312 'name': data_utils.rand_name("New-IPSec"),
313 'encryption_algorithm': "aes-256",
314 'lifetime': {'units': "seconds", 'value': '2000'}}
David Kranz34e88122014-12-11 15:24:05 -0500315 body = self.client.update_ipsecpolicy(ipsecpolicy['id'],
316 **new_ipsec)
raiesmh08df3fac42014-06-02 15:42:18 +0530317 updated_ipsec_policy = body['ipsecpolicy']
318 self._assertExpected(new_ipsec, updated_ipsec_policy)
319 # Verification of ipsec policy delete
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200320 self.client.delete_ipsecpolicy(ipsecpolicy['id'])
Masayuki Igawabfa07602015-01-20 18:47:17 +0900321 self.assertRaises(lib_exc.NotFound,
raiesmh08df3fac42014-06-02 15:42:18 +0530322 self.client.delete_ipsecpolicy, ipsecpolicy['id'])
323
324 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800325 @test.idempotent_id('601f8a05-9d3c-4539-a400-1c4b3a21b03b')
raiesmh08df3fac42014-06-02 15:42:18 +0530326 def test_show_ipsec_policy(self):
327 # Verifies the details of an ipsec policy
David Kranz34e88122014-12-11 15:24:05 -0500328 body = self.client.show_ipsecpolicy(self.ipsecpolicy['id'])
raiesmh08df3fac42014-06-02 15:42:18 +0530329 ipsecpolicy = body['ipsecpolicy']
330 self._assertExpected(self.ipsecpolicy, ipsecpolicy)