blob: 9fe2a56483bc34d0ea76bc5a9ddbad027599bea5 [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 Treinish71426682015-04-23 11:19:38 -040016import six
Matthew Treinish01472ff2015-02-20 17:26:52 -050017from tempest_lib.common.utils import data_utils
Masayuki Igawabfa07602015-01-20 18:47:17 +090018from tempest_lib import exceptions as lib_exc
19
Anju Tiwari860097d2013-10-17 11:10:39 +053020from tempest.api.network import base
Matthew Treinish03b48df2014-01-29 16:59:49 +000021from tempest import config
mouad benchchaouiea2440d2013-12-22 00:38:06 +010022from tempest import test
Anju Tiwari860097d2013-10-17 11:10:39 +053023
Matthew Treinish03b48df2014-01-29 16:59:49 +000024CONF = config.CONF
25
Anju Tiwari860097d2013-10-17 11:10:39 +053026
Miguel Lavalle3581e462014-03-27 19:01:46 -050027class VPNaaSTestJSON(base.BaseAdminNetworkTest):
Anju Tiwari860097d2013-10-17 11:10:39 +053028 """
29 Tests the following operations in the Neutron API using the REST client for
30 Neutron:
Miguel Lavalle3581e462014-03-27 19:01:46 -050031 List, Show, Create, Delete, and Update VPN Service
raiesmh08bd6070d2013-12-06 15:13:38 +053032 List, Show, Create, Delete, and Update IKE policy
Miguel Lavalle3581e462014-03-27 19:01:46 -050033 List, Show, Create, Delete, and Update IPSec policy
Anju Tiwari860097d2013-10-17 11:10:39 +053034 """
35
36 @classmethod
Rohan Kanadea565e452015-01-27 14:00:13 +053037 def skip_checks(cls):
38 super(VPNaaSTestJSON, cls).skip_checks()
mouad benchchaouiea2440d2013-12-22 00:38:06 +010039 if not test.is_extension_enabled('vpnaas', 'network'):
40 msg = "vpnaas extension not enabled."
41 raise cls.skipException(msg)
Rohan Kanadea565e452015-01-27 14:00:13 +053042
43 @classmethod
44 def resource_setup(cls):
Andrea Frittolida4a2452014-09-15 13:12:08 +010045 super(VPNaaSTestJSON, cls).resource_setup()
vikasa347ffd2014-09-30 23:19:10 -070046 cls.ext_net_id = CONF.network.public_network_id
Anju Tiwari860097d2013-10-17 11:10:39 +053047 cls.network = cls.create_network()
48 cls.subnet = cls.create_subnet(cls.network)
Nachi Ueno41ecf5b2013-12-10 13:26:33 -080049 cls.router = cls.create_router(
Miguel Lavalle3581e462014-03-27 19:01:46 -050050 data_utils.rand_name("router"),
Matthew Treinish03b48df2014-01-29 16:59:49 +000051 external_network_id=CONF.network.public_network_id)
Anju Tiwari860097d2013-10-17 11:10:39 +053052 cls.create_router_interface(cls.router['id'], cls.subnet['id'])
53 cls.vpnservice = cls.create_vpnservice(cls.subnet['id'],
54 cls.router['id'])
Miguel Lavalle3581e462014-03-27 19:01:46 -050055
Eugene Nikanorov909ded12013-12-15 17:45:37 +040056 cls.ikepolicy = cls.create_ikepolicy(
57 data_utils.rand_name("ike-policy-"))
raiesmh08df3fac42014-06-02 15:42:18 +053058 cls.ipsecpolicy = cls.create_ipsecpolicy(
59 data_utils.rand_name("ipsec-policy-"))
raiesmh08bd6070d2013-12-06 15:13:38 +053060
61 def _delete_ike_policy(self, ike_policy_id):
62 # Deletes a ike policy and verifies if it is deleted or not
63 ike_list = list()
David Kranz34e88122014-12-11 15:24:05 -050064 all_ike = self.client.list_ikepolicies()
raiesmh08bd6070d2013-12-06 15:13:38 +053065 for ike in all_ike['ikepolicies']:
66 ike_list.append(ike['id'])
67 if ike_policy_id in ike_list:
Rohan Kanadeeeb21642014-08-14 12:00:26 +020068 self.client.delete_ikepolicy(ike_policy_id)
raiesmh08bd6070d2013-12-06 15:13:38 +053069 # Asserting that the policy is not found in list after deletion
David Kranz34e88122014-12-11 15:24:05 -050070 ikepolicies = self.client.list_ikepolicies()
raiesmh08bd6070d2013-12-06 15:13:38 +053071 ike_id_list = list()
72 for i in ikepolicies['ikepolicies']:
73 ike_id_list.append(i['id'])
74 self.assertNotIn(ike_policy_id, ike_id_list)
Anju Tiwari860097d2013-10-17 11:10:39 +053075
raiesmh08df3fac42014-06-02 15:42:18 +053076 def _delete_ipsec_policy(self, ipsec_policy_id):
77 # Deletes an ike policy if it exists
78 try:
79 self.client.delete_ipsecpolicy(ipsec_policy_id)
80
Masayuki Igawabfa07602015-01-20 18:47:17 +090081 except lib_exc.NotFound:
raiesmh08df3fac42014-06-02 15:42:18 +053082 pass
83
84 def _assertExpected(self, expected, actual):
85 # Check if not expected keys/values exists in actual response body
Matthew Treinish71426682015-04-23 11:19:38 -040086 for key, value in six.iteritems(expected):
raiesmh08df3fac42014-06-02 15:42:18 +053087 self.assertIn(key, actual)
88 self.assertEqual(value, actual[key])
89
Miguel Lavalle3581e462014-03-27 19:01:46 -050090 def _delete_vpn_service(self, vpn_service_id):
Rohan Kanadeeeb21642014-08-14 12:00:26 +020091 self.client.delete_vpnservice(vpn_service_id)
Miguel Lavalle3581e462014-03-27 19:01:46 -050092 # Asserting if vpn service is found in the list after deletion
David Kranz34e88122014-12-11 15:24:05 -050093 body = self.client.list_vpnservices()
Miguel Lavalle3581e462014-03-27 19:01:46 -050094 vpn_services = [vs['id'] for vs in body['vpnservices']]
95 self.assertNotIn(vpn_service_id, vpn_services)
96
97 def _get_tenant_id(self):
98 """
99 Returns the tenant_id of the client current user
100 """
101 # TODO(jroovers) This is a temporary workaround to get the tenant_id
102 # of the the current client. Replace this once tenant_isolation for
103 # neutron is fixed.
David Kranz34e88122014-12-11 15:24:05 -0500104 body = self.client.show_network(self.network['id'])
Miguel Lavalle3581e462014-03-27 19:01:46 -0500105 return body['network']['tenant_id']
106
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
Chris Hoge7579c1a2015-02-26 14:12:15 -0800124 @test.idempotent_id('b62acdc6-0c53-4d84-84aa-859b22b79799')
Miguel Lavalle3581e462014-03-27 19:01:46 -0500125 def test_admin_create_vpn_service_for_tenant(self):
126 tenant_id = self._get_tenant_id()
127
128 # Create vpn service for the newly created tenant
vikasa347ffd2014-09-30 23:19:10 -0700129 network2 = self.create_network()
130 subnet2 = self.create_subnet(network2)
131 router2 = self.create_router(data_utils.rand_name('router-'),
132 external_network_id=self.ext_net_id)
133 self.create_router_interface(router2['id'], subnet2['id'])
Miguel Lavalle3581e462014-03-27 19:01:46 -0500134 name = data_utils.rand_name('vpn-service')
David Kranz34e88122014-12-11 15:24:05 -0500135 body = self.admin_client.create_vpnservice(
vikasa347ffd2014-09-30 23:19:10 -0700136 subnet_id=subnet2['id'],
137 router_id=router2['id'],
Miguel Lavalle3581e462014-03-27 19:01:46 -0500138 name=name,
139 admin_state_up=True,
140 tenant_id=tenant_id)
Miguel Lavalle3581e462014-03-27 19:01:46 -0500141 vpnservice = body['vpnservice']
142 self.assertIsNotNone(vpnservice['id'])
143 self.addCleanup(self.admin_client.delete_vpnservice, vpnservice['id'])
Miguel Lavalle3581e462014-03-27 19:01:46 -0500144 # Assert that created vpnservice is found in API list call
David Kranz34e88122014-12-11 15:24:05 -0500145 body = self.client.list_vpnservices()
Miguel Lavalle3581e462014-03-27 19:01:46 -0500146 vpn_services = [vs['id'] for vs in body['vpnservices']]
147 self.assertIn(vpnservice['id'], vpn_services)
148
Chris Hoge7579c1a2015-02-26 14:12:15 -0800149 @test.idempotent_id('58cc4a1c-443b-4f39-8fb6-c19d39f343ab')
Miguel Lavalle3581e462014-03-27 19:01:46 -0500150 def test_admin_create_ike_policy_for_tenant(self):
151 tenant_id = self._get_tenant_id()
152
153 # Create IKE policy for the newly created tenant
154 name = data_utils.rand_name('ike-policy')
David Kranz34e88122014-12-11 15:24:05 -0500155 body = (self.admin_client.
156 create_ikepolicy(name=name, ike_version="v1",
157 encryption_algorithm="aes-128",
158 auth_algorithm="sha1",
159 tenant_id=tenant_id))
Miguel Lavalle3581e462014-03-27 19:01:46 -0500160 ikepolicy = body['ikepolicy']
161 self.assertIsNotNone(ikepolicy['id'])
162 self.addCleanup(self.admin_client.delete_ikepolicy, ikepolicy['id'])
163
164 # Assert that created ike policy is found in API list call
David Kranz34e88122014-12-11 15:24:05 -0500165 body = self.client.list_ikepolicies()
Miguel Lavalle3581e462014-03-27 19:01:46 -0500166 ikepolicies = [ikp['id'] for ikp in body['ikepolicies']]
167 self.assertIn(ikepolicy['id'], ikepolicies)
168
Chris Hoge7579c1a2015-02-26 14:12:15 -0800169 @test.idempotent_id('de5bb04c-3a1f-46b1-b329-7a8abba5c7f1')
Anju Tiwari860097d2013-10-17 11:10:39 +0530170 def test_list_vpn_services(self):
171 # Verify the VPN service exists in the list of all VPN services
David Kranz34e88122014-12-11 15:24:05 -0500172 body = self.client.list_vpnservices()
Anju Tiwari860097d2013-10-17 11:10:39 +0530173 vpnservices = body['vpnservices']
174 self.assertIn(self.vpnservice['id'], [v['id'] for v in vpnservices])
175
Chris Hoge7579c1a2015-02-26 14:12:15 -0800176 @test.idempotent_id('aacb13b1-fdc7-41fd-bab2-32621aee1878')
Anju Tiwari860097d2013-10-17 11:10:39 +0530177 def test_create_update_delete_vpn_service(self):
Miguel Lavalle3581e462014-03-27 19:01:46 -0500178 # Creates a VPN service and sets up deletion
vikasa347ffd2014-09-30 23:19:10 -0700179 network1 = self.create_network()
180 subnet1 = self.create_subnet(network1)
181 router1 = self.create_router(data_utils.rand_name('router-'),
182 external_network_id=self.ext_net_id)
183 self.create_router_interface(router1['id'], subnet1['id'])
184 name = data_utils.rand_name('vpn-service1')
David Kranz34e88122014-12-11 15:24:05 -0500185 body = self.client.create_vpnservice(subnet_id=subnet1['id'],
186 router_id=router1['id'],
187 name=name,
188 admin_state_up=True)
Anju Tiwari860097d2013-10-17 11:10:39 +0530189 vpnservice = body['vpnservice']
Miguel Lavalle3581e462014-03-27 19:01:46 -0500190 self.addCleanup(self._delete_vpn_service, vpnservice['id'])
Anju Tiwari860097d2013-10-17 11:10:39 +0530191 # Assert if created vpnservices are not found in vpnservices list
David Kranz34e88122014-12-11 15:24:05 -0500192 body = self.client.list_vpnservices()
Anju Tiwari860097d2013-10-17 11:10:39 +0530193 vpn_services = [vs['id'] for vs in body['vpnservices']]
194 self.assertIsNotNone(vpnservice['id'])
195 self.assertIn(vpnservice['id'], vpn_services)
196
197 # TODO(raies): implement logic to update vpnservice
198 # VPNaaS client function to update is implemented.
199 # But precondition is that current state of vpnservice
200 # should be "ACTIVE" not "PENDING*"
201
Chris Hoge7579c1a2015-02-26 14:12:15 -0800202 @test.idempotent_id('0dedfc1d-f8ee-4e2a-bfd4-7997b9dc17ff')
Anju Tiwari860097d2013-10-17 11:10:39 +0530203 def test_show_vpn_service(self):
204 # Verifies the details of a vpn service
David Kranz34e88122014-12-11 15:24:05 -0500205 body = self.client.show_vpnservice(self.vpnservice['id'])
Anju Tiwari860097d2013-10-17 11:10:39 +0530206 vpnservice = body['vpnservice']
207 self.assertEqual(self.vpnservice['id'], vpnservice['id'])
208 self.assertEqual(self.vpnservice['name'], vpnservice['name'])
209 self.assertEqual(self.vpnservice['description'],
210 vpnservice['description'])
211 self.assertEqual(self.vpnservice['router_id'], vpnservice['router_id'])
212 self.assertEqual(self.vpnservice['subnet_id'], vpnservice['subnet_id'])
213 self.assertEqual(self.vpnservice['tenant_id'], vpnservice['tenant_id'])
Miguel Lavalle3581e462014-03-27 19:01:46 -0500214 valid_status = ["ACTIVE", "DOWN", "BUILD", "ERROR", "PENDING_CREATE",
215 "PENDING_UPDATE", "PENDING_DELETE"]
216 self.assertIn(vpnservice['status'], valid_status)
raiesmh08bd6070d2013-12-06 15:13:38 +0530217
Chris Hoge7579c1a2015-02-26 14:12:15 -0800218 @test.idempotent_id('e0fb6200-da3d-4869-8340-a8c1956ca618')
raiesmh08bd6070d2013-12-06 15:13:38 +0530219 def test_list_ike_policies(self):
220 # Verify the ike policy exists in the list of all IKE policies
David Kranz34e88122014-12-11 15:24:05 -0500221 body = self.client.list_ikepolicies()
raiesmh08bd6070d2013-12-06 15:13:38 +0530222 ikepolicies = body['ikepolicies']
223 self.assertIn(self.ikepolicy['id'], [i['id'] for i in ikepolicies])
224
Chris Hoge7579c1a2015-02-26 14:12:15 -0800225 @test.idempotent_id('d61f29a5-160c-487d-bc0d-22e32e731b44')
raiesmh08bd6070d2013-12-06 15:13:38 +0530226 def test_create_update_delete_ike_policy(self):
227 # Creates a IKE policy
Miguel Lavalle3581e462014-03-27 19:01:46 -0500228 name = data_utils.rand_name('ike-policy')
David Kranz34e88122014-12-11 15:24:05 -0500229 body = (self.client.create_ikepolicy(
230 name=name,
231 ike_version="v1",
232 encryption_algorithm="aes-128",
233 auth_algorithm="sha1"))
raiesmh08bd6070d2013-12-06 15:13:38 +0530234 ikepolicy = body['ikepolicy']
Miguel Lavalle3581e462014-03-27 19:01:46 -0500235 self.assertIsNotNone(ikepolicy['id'])
raiesmh08bd6070d2013-12-06 15:13:38 +0530236 self.addCleanup(self._delete_ike_policy, ikepolicy['id'])
Miguel Lavalle3581e462014-03-27 19:01:46 -0500237
238 # Update IKE Policy
239 new_ike = {'name': data_utils.rand_name("New-IKE"),
240 'description': "Updated ike policy",
241 'encryption_algorithm': "aes-256",
242 'ike_version': "v2",
243 'pfs': "group14",
244 'lifetime': {'units': "seconds", 'value': 2000}}
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200245 self.client.update_ikepolicy(ikepolicy['id'], **new_ike)
Miguel Lavalle3581e462014-03-27 19:01:46 -0500246 # Confirm that update was successful by verifying using 'show'
David Kranz34e88122014-12-11 15:24:05 -0500247 body = self.client.show_ikepolicy(ikepolicy['id'])
Miguel Lavalle3581e462014-03-27 19:01:46 -0500248 ike_policy = body['ikepolicy']
Matthew Treinish71426682015-04-23 11:19:38 -0400249 for key, value in six.iteritems(new_ike):
Miguel Lavalle3581e462014-03-27 19:01:46 -0500250 self.assertIn(key, ike_policy)
251 self.assertEqual(value, ike_policy[key])
252
raiesmh08bd6070d2013-12-06 15:13:38 +0530253 # Verification of ike policy delete
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200254 self.client.delete_ikepolicy(ikepolicy['id'])
David Kranz34e88122014-12-11 15:24:05 -0500255 body = self.client.list_ikepolicies()
Miguel Lavalle3581e462014-03-27 19:01:46 -0500256 ikepolicies = [ikp['id'] for ikp in body['ikepolicies']]
257 self.assertNotIn(ike_policy['id'], ikepolicies)
raiesmh08bd6070d2013-12-06 15:13:38 +0530258
Chris Hoge7579c1a2015-02-26 14:12:15 -0800259 @test.idempotent_id('b5fcf3a3-9407-452d-b8a8-e7c6c32baea8')
raiesmh08bd6070d2013-12-06 15:13:38 +0530260 def test_show_ike_policy(self):
261 # Verifies the details of a ike policy
David Kranz34e88122014-12-11 15:24:05 -0500262 body = self.client.show_ikepolicy(self.ikepolicy['id'])
raiesmh08bd6070d2013-12-06 15:13:38 +0530263 ikepolicy = body['ikepolicy']
264 self.assertEqual(self.ikepolicy['id'], ikepolicy['id'])
265 self.assertEqual(self.ikepolicy['name'], ikepolicy['name'])
266 self.assertEqual(self.ikepolicy['description'],
267 ikepolicy['description'])
268 self.assertEqual(self.ikepolicy['encryption_algorithm'],
269 ikepolicy['encryption_algorithm'])
270 self.assertEqual(self.ikepolicy['auth_algorithm'],
271 ikepolicy['auth_algorithm'])
272 self.assertEqual(self.ikepolicy['tenant_id'],
273 ikepolicy['tenant_id'])
274 self.assertEqual(self.ikepolicy['pfs'],
275 ikepolicy['pfs'])
276 self.assertEqual(self.ikepolicy['phase1_negotiation_mode'],
277 ikepolicy['phase1_negotiation_mode'])
278 self.assertEqual(self.ikepolicy['ike_version'],
279 ikepolicy['ike_version'])
Mh Raiesc440bca2014-04-04 12:05:48 +0530280
Chris Hoge7579c1a2015-02-26 14:12:15 -0800281 @test.idempotent_id('19ea0a2f-add9-44be-b732-ffd8a7b42f37')
raiesmh08df3fac42014-06-02 15:42:18 +0530282 def test_list_ipsec_policies(self):
283 # Verify the ipsec policy exists in the list of all ipsec policies
David Kranz34e88122014-12-11 15:24:05 -0500284 body = self.client.list_ipsecpolicies()
raiesmh08df3fac42014-06-02 15:42:18 +0530285 ipsecpolicies = body['ipsecpolicies']
286 self.assertIn(self.ipsecpolicy['id'], [i['id'] for i in ipsecpolicies])
287
Chris Hoge7579c1a2015-02-26 14:12:15 -0800288 @test.idempotent_id('9c1701c9-329a-4e5d-930a-1ead1b3f86ad')
raiesmh08df3fac42014-06-02 15:42:18 +0530289 def test_create_update_delete_ipsec_policy(self):
290 # Creates an ipsec policy
291 ipsec_policy_body = {'name': data_utils.rand_name('ipsec-policy'),
292 'pfs': 'group5',
293 'encryption_algorithm': "aes-128",
294 'auth_algorithm': 'sha1'}
David Kranz34e88122014-12-11 15:24:05 -0500295 resp_body = self.client.create_ipsecpolicy(**ipsec_policy_body)
raiesmh08df3fac42014-06-02 15:42:18 +0530296 ipsecpolicy = resp_body['ipsecpolicy']
297 self.addCleanup(self._delete_ipsec_policy, ipsecpolicy['id'])
298 self._assertExpected(ipsec_policy_body, ipsecpolicy)
299 # Verification of ipsec policy update
300 new_ipsec = {'description': 'Updated ipsec policy',
301 'pfs': 'group2',
302 'name': data_utils.rand_name("New-IPSec"),
303 'encryption_algorithm': "aes-256",
304 'lifetime': {'units': "seconds", 'value': '2000'}}
David Kranz34e88122014-12-11 15:24:05 -0500305 body = self.client.update_ipsecpolicy(ipsecpolicy['id'],
306 **new_ipsec)
raiesmh08df3fac42014-06-02 15:42:18 +0530307 updated_ipsec_policy = body['ipsecpolicy']
308 self._assertExpected(new_ipsec, updated_ipsec_policy)
309 # Verification of ipsec policy delete
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200310 self.client.delete_ipsecpolicy(ipsecpolicy['id'])
Masayuki Igawabfa07602015-01-20 18:47:17 +0900311 self.assertRaises(lib_exc.NotFound,
raiesmh08df3fac42014-06-02 15:42:18 +0530312 self.client.delete_ipsecpolicy, ipsecpolicy['id'])
313
Chris Hoge7579c1a2015-02-26 14:12:15 -0800314 @test.idempotent_id('601f8a05-9d3c-4539-a400-1c4b3a21b03b')
raiesmh08df3fac42014-06-02 15:42:18 +0530315 def test_show_ipsec_policy(self):
316 # Verifies the details of an ipsec policy
David Kranz34e88122014-12-11 15:24:05 -0500317 body = self.client.show_ipsecpolicy(self.ipsecpolicy['id'])
raiesmh08df3fac42014-06-02 15:42:18 +0530318 ipsecpolicy = body['ipsecpolicy']
319 self._assertExpected(self.ipsecpolicy, ipsecpolicy)