blob: 09e9640c551fd477e834bfe44586dac0b1b1bb37 [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
16from tempest.api.network import base
Masayuki Igawa259c1132013-10-31 17:48:44 +090017from tempest.common.utils import data_utils
Matthew Treinish03b48df2014-01-29 16:59:49 +000018from tempest import config
raiesmh08df3fac42014-06-02 15:42:18 +053019from tempest import exceptions
mouad benchchaouiea2440d2013-12-22 00:38:06 +010020from tempest import test
Anju Tiwari860097d2013-10-17 11:10:39 +053021
Matthew Treinish03b48df2014-01-29 16:59:49 +000022CONF = config.CONF
23
Anju Tiwari860097d2013-10-17 11:10:39 +053024
Miguel Lavalle3581e462014-03-27 19:01:46 -050025class VPNaaSTestJSON(base.BaseAdminNetworkTest):
Anju Tiwari860097d2013-10-17 11:10:39 +053026 _interface = 'json'
27
28 """
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
Masayuki Igawa6d495d62014-03-19 16:38:57 +090037 @test.safe_setup
Anju Tiwari860097d2013-10-17 11:10:39 +053038 def setUpClass(cls):
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)
Mh Raiesc440bca2014-04-04 12:05:48 +053042 super(VPNaaSTestJSON, cls).setUpClass()
Anju Tiwari860097d2013-10-17 11:10:39 +053043 cls.network = cls.create_network()
44 cls.subnet = cls.create_subnet(cls.network)
Nachi Ueno41ecf5b2013-12-10 13:26:33 -080045 cls.router = cls.create_router(
Miguel Lavalle3581e462014-03-27 19:01:46 -050046 data_utils.rand_name("router"),
Matthew Treinish03b48df2014-01-29 16:59:49 +000047 external_network_id=CONF.network.public_network_id)
Anju Tiwari860097d2013-10-17 11:10:39 +053048 cls.create_router_interface(cls.router['id'], cls.subnet['id'])
49 cls.vpnservice = cls.create_vpnservice(cls.subnet['id'],
50 cls.router['id'])
Miguel Lavalle3581e462014-03-27 19:01:46 -050051
Eugene Nikanorov909ded12013-12-15 17:45:37 +040052 cls.ikepolicy = cls.create_ikepolicy(
53 data_utils.rand_name("ike-policy-"))
raiesmh08df3fac42014-06-02 15:42:18 +053054 cls.ipsecpolicy = cls.create_ipsecpolicy(
55 data_utils.rand_name("ipsec-policy-"))
raiesmh08bd6070d2013-12-06 15:13:38 +053056
57 def _delete_ike_policy(self, ike_policy_id):
58 # Deletes a ike policy and verifies if it is deleted or not
59 ike_list = list()
Eugene Nikanorov909ded12013-12-15 17:45:37 +040060 resp, all_ike = self.client.list_ikepolicies()
raiesmh08bd6070d2013-12-06 15:13:38 +053061 for ike in all_ike['ikepolicies']:
62 ike_list.append(ike['id'])
63 if ike_policy_id in ike_list:
Rohan Kanadeeeb21642014-08-14 12:00:26 +020064 self.client.delete_ikepolicy(ike_policy_id)
raiesmh08bd6070d2013-12-06 15:13:38 +053065 # Asserting that the policy is not found in list after deletion
Eugene Nikanorov909ded12013-12-15 17:45:37 +040066 resp, ikepolicies = self.client.list_ikepolicies()
raiesmh08bd6070d2013-12-06 15:13:38 +053067 ike_id_list = list()
68 for i in ikepolicies['ikepolicies']:
69 ike_id_list.append(i['id'])
70 self.assertNotIn(ike_policy_id, ike_id_list)
Anju Tiwari860097d2013-10-17 11:10:39 +053071
raiesmh08df3fac42014-06-02 15:42:18 +053072 def _delete_ipsec_policy(self, ipsec_policy_id):
73 # Deletes an ike policy if it exists
74 try:
75 self.client.delete_ipsecpolicy(ipsec_policy_id)
76
77 except exceptions.NotFound:
78 pass
79
80 def _assertExpected(self, expected, actual):
81 # Check if not expected keys/values exists in actual response body
82 for key, value in expected.iteritems():
83 self.assertIn(key, actual)
84 self.assertEqual(value, actual[key])
85
Miguel Lavalle3581e462014-03-27 19:01:46 -050086 def _delete_vpn_service(self, vpn_service_id):
Rohan Kanadeeeb21642014-08-14 12:00:26 +020087 self.client.delete_vpnservice(vpn_service_id)
Miguel Lavalle3581e462014-03-27 19:01:46 -050088 # Asserting if vpn service is found in the list after deletion
89 _, body = self.client.list_vpnservices()
90 vpn_services = [vs['id'] for vs in body['vpnservices']]
91 self.assertNotIn(vpn_service_id, vpn_services)
92
93 def _get_tenant_id(self):
94 """
95 Returns the tenant_id of the client current user
96 """
97 # TODO(jroovers) This is a temporary workaround to get the tenant_id
98 # of the the current client. Replace this once tenant_isolation for
99 # neutron is fixed.
100 _, body = self.client.show_network(self.network['id'])
101 return body['network']['tenant_id']
102
103 @test.attr(type='smoke')
104 def test_admin_create_ipsec_policy_for_tenant(self):
105 tenant_id = self._get_tenant_id()
106 # Create IPSec policy for the newly created tenant
107 name = data_utils.rand_name('ipsec-policy')
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200108 _, body = (self.admin_client.
109 create_ipsecpolicy(name=name, tenant_id=tenant_id))
Miguel Lavalle3581e462014-03-27 19:01:46 -0500110 ipsecpolicy = body['ipsecpolicy']
111 self.assertIsNotNone(ipsecpolicy['id'])
112 self.addCleanup(self.admin_client.delete_ipsecpolicy,
113 ipsecpolicy['id'])
114
115 # Assert that created ipsec policy is found in API list call
116 _, body = self.client.list_ipsecpolicies()
117 ipsecpolicies = [policy['id'] for policy in body['ipsecpolicies']]
118 self.assertIn(ipsecpolicy['id'], ipsecpolicies)
119
120 @test.attr(type='smoke')
121 def test_admin_create_vpn_service_for_tenant(self):
122 tenant_id = self._get_tenant_id()
123
124 # Create vpn service for the newly created tenant
125 name = data_utils.rand_name('vpn-service')
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200126 _, body = self.admin_client.create_vpnservice(
Miguel Lavalle3581e462014-03-27 19:01:46 -0500127 subnet_id=self.subnet['id'],
128 router_id=self.router['id'],
129 name=name,
130 admin_state_up=True,
131 tenant_id=tenant_id)
Miguel Lavalle3581e462014-03-27 19:01:46 -0500132 vpnservice = body['vpnservice']
133 self.assertIsNotNone(vpnservice['id'])
134 self.addCleanup(self.admin_client.delete_vpnservice, vpnservice['id'])
135
136 # Assert that created vpnservice is found in API list call
137 _, body = self.client.list_vpnservices()
138 vpn_services = [vs['id'] for vs in body['vpnservices']]
139 self.assertIn(vpnservice['id'], vpn_services)
140
141 @test.attr(type='smoke')
142 def test_admin_create_ike_policy_for_tenant(self):
143 tenant_id = self._get_tenant_id()
144
145 # Create IKE policy for the newly created tenant
146 name = data_utils.rand_name('ike-policy')
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200147 _, body = (self.admin_client.
148 create_ikepolicy(name=name, ike_version="v1",
149 encryption_algorithm="aes-128",
150 auth_algorithm="sha1",
151 tenant_id=tenant_id))
Miguel Lavalle3581e462014-03-27 19:01:46 -0500152 ikepolicy = body['ikepolicy']
153 self.assertIsNotNone(ikepolicy['id'])
154 self.addCleanup(self.admin_client.delete_ikepolicy, ikepolicy['id'])
155
156 # Assert that created ike policy is found in API list call
157 _, body = self.client.list_ikepolicies()
158 ikepolicies = [ikp['id'] for ikp in body['ikepolicies']]
159 self.assertIn(ikepolicy['id'], ikepolicies)
160
mouad benchchaouiea2440d2013-12-22 00:38:06 +0100161 @test.attr(type='smoke')
Anju Tiwari860097d2013-10-17 11:10:39 +0530162 def test_list_vpn_services(self):
163 # Verify the VPN service exists in the list of all VPN services
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200164 _, body = self.client.list_vpnservices()
Anju Tiwari860097d2013-10-17 11:10:39 +0530165 vpnservices = body['vpnservices']
166 self.assertIn(self.vpnservice['id'], [v['id'] for v in vpnservices])
167
mouad benchchaouiea2440d2013-12-22 00:38:06 +0100168 @test.attr(type='smoke')
Anju Tiwari860097d2013-10-17 11:10:39 +0530169 def test_create_update_delete_vpn_service(self):
Miguel Lavalle3581e462014-03-27 19:01:46 -0500170 # Creates a VPN service and sets up deletion
171 name = data_utils.rand_name('vpn-service')
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200172 _, body = self.client.create_vpnservice(subnet_id=self.subnet['id'],
173 router_id=self.router['id'],
174 name=name,
175 admin_state_up=True)
Anju Tiwari860097d2013-10-17 11:10:39 +0530176 vpnservice = body['vpnservice']
Miguel Lavalle3581e462014-03-27 19:01:46 -0500177 self.addCleanup(self._delete_vpn_service, vpnservice['id'])
Anju Tiwari860097d2013-10-17 11:10:39 +0530178 # Assert if created vpnservices are not found in vpnservices list
Eugene Nikanorov909ded12013-12-15 17:45:37 +0400179 resp, body = self.client.list_vpnservices()
Anju Tiwari860097d2013-10-17 11:10:39 +0530180 vpn_services = [vs['id'] for vs in body['vpnservices']]
181 self.assertIsNotNone(vpnservice['id'])
182 self.assertIn(vpnservice['id'], vpn_services)
183
184 # TODO(raies): implement logic to update vpnservice
185 # VPNaaS client function to update is implemented.
186 # But precondition is that current state of vpnservice
187 # should be "ACTIVE" not "PENDING*"
188
mouad benchchaouiea2440d2013-12-22 00:38:06 +0100189 @test.attr(type='smoke')
Anju Tiwari860097d2013-10-17 11:10:39 +0530190 def test_show_vpn_service(self):
191 # Verifies the details of a vpn service
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200192 _, body = self.client.show_vpnservice(self.vpnservice['id'])
Anju Tiwari860097d2013-10-17 11:10:39 +0530193 vpnservice = body['vpnservice']
194 self.assertEqual(self.vpnservice['id'], vpnservice['id'])
195 self.assertEqual(self.vpnservice['name'], vpnservice['name'])
196 self.assertEqual(self.vpnservice['description'],
197 vpnservice['description'])
198 self.assertEqual(self.vpnservice['router_id'], vpnservice['router_id'])
199 self.assertEqual(self.vpnservice['subnet_id'], vpnservice['subnet_id'])
200 self.assertEqual(self.vpnservice['tenant_id'], vpnservice['tenant_id'])
Miguel Lavalle3581e462014-03-27 19:01:46 -0500201 valid_status = ["ACTIVE", "DOWN", "BUILD", "ERROR", "PENDING_CREATE",
202 "PENDING_UPDATE", "PENDING_DELETE"]
203 self.assertIn(vpnservice['status'], valid_status)
raiesmh08bd6070d2013-12-06 15:13:38 +0530204
mouad benchchaouiea2440d2013-12-22 00:38:06 +0100205 @test.attr(type='smoke')
raiesmh08bd6070d2013-12-06 15:13:38 +0530206 def test_list_ike_policies(self):
207 # Verify the ike policy exists in the list of all IKE policies
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200208 _, body = self.client.list_ikepolicies()
raiesmh08bd6070d2013-12-06 15:13:38 +0530209 ikepolicies = body['ikepolicies']
210 self.assertIn(self.ikepolicy['id'], [i['id'] for i in ikepolicies])
211
mouad benchchaouiea2440d2013-12-22 00:38:06 +0100212 @test.attr(type='smoke')
raiesmh08bd6070d2013-12-06 15:13:38 +0530213 def test_create_update_delete_ike_policy(self):
214 # Creates a IKE policy
Miguel Lavalle3581e462014-03-27 19:01:46 -0500215 name = data_utils.rand_name('ike-policy')
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200216 _, body = (self.client.create_ikepolicy(
217 name=name,
218 ike_version="v1",
219 encryption_algorithm="aes-128",
220 auth_algorithm="sha1"))
raiesmh08bd6070d2013-12-06 15:13:38 +0530221 ikepolicy = body['ikepolicy']
Miguel Lavalle3581e462014-03-27 19:01:46 -0500222 self.assertIsNotNone(ikepolicy['id'])
raiesmh08bd6070d2013-12-06 15:13:38 +0530223 self.addCleanup(self._delete_ike_policy, ikepolicy['id'])
Miguel Lavalle3581e462014-03-27 19:01:46 -0500224
225 # Update IKE Policy
226 new_ike = {'name': data_utils.rand_name("New-IKE"),
227 'description': "Updated ike policy",
228 'encryption_algorithm': "aes-256",
229 'ike_version': "v2",
230 'pfs': "group14",
231 'lifetime': {'units': "seconds", 'value': 2000}}
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200232 self.client.update_ikepolicy(ikepolicy['id'], **new_ike)
Miguel Lavalle3581e462014-03-27 19:01:46 -0500233 # Confirm that update was successful by verifying using 'show'
234 _, body = self.client.show_ikepolicy(ikepolicy['id'])
235 ike_policy = body['ikepolicy']
236 for key, value in new_ike.iteritems():
237 self.assertIn(key, ike_policy)
238 self.assertEqual(value, ike_policy[key])
239
raiesmh08bd6070d2013-12-06 15:13:38 +0530240 # Verification of ike policy delete
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200241 self.client.delete_ikepolicy(ikepolicy['id'])
Miguel Lavalle3581e462014-03-27 19:01:46 -0500242 _, body = self.client.list_ikepolicies()
243 ikepolicies = [ikp['id'] for ikp in body['ikepolicies']]
244 self.assertNotIn(ike_policy['id'], ikepolicies)
raiesmh08bd6070d2013-12-06 15:13:38 +0530245
mouad benchchaouiea2440d2013-12-22 00:38:06 +0100246 @test.attr(type='smoke')
raiesmh08bd6070d2013-12-06 15:13:38 +0530247 def test_show_ike_policy(self):
248 # Verifies the details of a ike policy
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200249 _, body = self.client.show_ikepolicy(self.ikepolicy['id'])
raiesmh08bd6070d2013-12-06 15:13:38 +0530250 ikepolicy = body['ikepolicy']
251 self.assertEqual(self.ikepolicy['id'], ikepolicy['id'])
252 self.assertEqual(self.ikepolicy['name'], ikepolicy['name'])
253 self.assertEqual(self.ikepolicy['description'],
254 ikepolicy['description'])
255 self.assertEqual(self.ikepolicy['encryption_algorithm'],
256 ikepolicy['encryption_algorithm'])
257 self.assertEqual(self.ikepolicy['auth_algorithm'],
258 ikepolicy['auth_algorithm'])
259 self.assertEqual(self.ikepolicy['tenant_id'],
260 ikepolicy['tenant_id'])
261 self.assertEqual(self.ikepolicy['pfs'],
262 ikepolicy['pfs'])
263 self.assertEqual(self.ikepolicy['phase1_negotiation_mode'],
264 ikepolicy['phase1_negotiation_mode'])
265 self.assertEqual(self.ikepolicy['ike_version'],
266 ikepolicy['ike_version'])
Mh Raiesc440bca2014-04-04 12:05:48 +0530267
raiesmh08df3fac42014-06-02 15:42:18 +0530268 @test.attr(type='smoke')
269 def test_list_ipsec_policies(self):
270 # Verify the ipsec policy exists in the list of all ipsec policies
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200271 _, body = self.client.list_ipsecpolicies()
raiesmh08df3fac42014-06-02 15:42:18 +0530272 ipsecpolicies = body['ipsecpolicies']
273 self.assertIn(self.ipsecpolicy['id'], [i['id'] for i in ipsecpolicies])
274
275 @test.attr(type='smoke')
276 def test_create_update_delete_ipsec_policy(self):
277 # Creates an ipsec policy
278 ipsec_policy_body = {'name': data_utils.rand_name('ipsec-policy'),
279 'pfs': 'group5',
280 'encryption_algorithm': "aes-128",
281 'auth_algorithm': 'sha1'}
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200282 _, resp_body = self.client.create_ipsecpolicy(**ipsec_policy_body)
raiesmh08df3fac42014-06-02 15:42:18 +0530283 ipsecpolicy = resp_body['ipsecpolicy']
284 self.addCleanup(self._delete_ipsec_policy, ipsecpolicy['id'])
285 self._assertExpected(ipsec_policy_body, ipsecpolicy)
286 # Verification of ipsec policy update
287 new_ipsec = {'description': 'Updated ipsec policy',
288 'pfs': 'group2',
289 'name': data_utils.rand_name("New-IPSec"),
290 'encryption_algorithm': "aes-256",
291 'lifetime': {'units': "seconds", 'value': '2000'}}
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200292 _, body = self.client.update_ipsecpolicy(ipsecpolicy['id'],
293 **new_ipsec)
raiesmh08df3fac42014-06-02 15:42:18 +0530294 updated_ipsec_policy = body['ipsecpolicy']
295 self._assertExpected(new_ipsec, updated_ipsec_policy)
296 # Verification of ipsec policy delete
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200297 self.client.delete_ipsecpolicy(ipsecpolicy['id'])
raiesmh08df3fac42014-06-02 15:42:18 +0530298 self.assertRaises(exceptions.NotFound,
299 self.client.delete_ipsecpolicy, ipsecpolicy['id'])
300
301 @test.attr(type='smoke')
302 def test_show_ipsec_policy(self):
303 # Verifies the details of an ipsec policy
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200304 _, body = self.client.show_ipsecpolicy(self.ipsecpolicy['id'])
raiesmh08df3fac42014-06-02 15:42:18 +0530305 ipsecpolicy = body['ipsecpolicy']
306 self._assertExpected(self.ipsecpolicy, ipsecpolicy)
307
Mh Raiesc440bca2014-04-04 12:05:48 +0530308
309class VPNaaSTestXML(VPNaaSTestJSON):
310 _interface = 'xml'