blob: d196886599bd5f41c51099ae5a9d177d1298ae04 [file] [log] [blame]
Anju Tiwari860097d2013-10-17 11:10:39 +05301# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
3# Copyright 2013 OpenStack Foundation
4# All Rights Reserved.
5#
6# Licensed under the Apache License, Version 2.0 (the "License"); you may
7# not use this file except in compliance with the License. You may obtain
8# a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15# License for the specific language governing permissions and limitations
16# under the License.
17
18from tempest.api.network import base
Masayuki Igawa259c1132013-10-31 17:48:44 +090019from tempest.common.utils import data_utils
mouad benchchaouiea2440d2013-12-22 00:38:06 +010020from tempest import test
Anju Tiwari860097d2013-10-17 11:10:39 +053021
22
23class VPNaaSJSON(base.BaseNetworkTest):
24 _interface = 'json'
25
26 """
27 Tests the following operations in the Neutron API using the REST client for
28 Neutron:
29
30 List VPN Services
31 Show VPN Services
32 Create VPN Services
33 Update VPN Services
34 Delete VPN Services
raiesmh08bd6070d2013-12-06 15:13:38 +053035 List, Show, Create, Delete, and Update IKE policy
Anju Tiwari860097d2013-10-17 11:10:39 +053036 """
37
38 @classmethod
39 def setUpClass(cls):
40 super(VPNaaSJSON, cls).setUpClass()
mouad benchchaouiea2440d2013-12-22 00:38:06 +010041 if not test.is_extension_enabled('vpnaas', 'network'):
42 msg = "vpnaas extension not enabled."
43 raise cls.skipException(msg)
Anju Tiwari860097d2013-10-17 11:10:39 +053044 cls.network = cls.create_network()
45 cls.subnet = cls.create_subnet(cls.network)
Nachi Ueno41ecf5b2013-12-10 13:26:33 -080046 cls.router = cls.create_router(
47 data_utils.rand_name("router-"),
48 external_network_id=cls.network_cfg.public_network_id)
Anju Tiwari860097d2013-10-17 11:10:39 +053049 cls.create_router_interface(cls.router['id'], cls.subnet['id'])
50 cls.vpnservice = cls.create_vpnservice(cls.subnet['id'],
51 cls.router['id'])
Eugene Nikanorov909ded12013-12-15 17:45:37 +040052 cls.ikepolicy = cls.create_ikepolicy(
53 data_utils.rand_name("ike-policy-"))
raiesmh08bd6070d2013-12-06 15:13:38 +053054
55 def _delete_ike_policy(self, ike_policy_id):
56 # Deletes a ike policy and verifies if it is deleted or not
57 ike_list = list()
Eugene Nikanorov909ded12013-12-15 17:45:37 +040058 resp, all_ike = self.client.list_ikepolicies()
raiesmh08bd6070d2013-12-06 15:13:38 +053059 for ike in all_ike['ikepolicies']:
60 ike_list.append(ike['id'])
61 if ike_policy_id in ike_list:
Eugene Nikanorov909ded12013-12-15 17:45:37 +040062 resp, _ = self.client.delete_ikepolicy(ike_policy_id)
raiesmh08bd6070d2013-12-06 15:13:38 +053063 self.assertEqual(204, resp.status)
64 # Asserting that the policy is not found in list after deletion
Eugene Nikanorov909ded12013-12-15 17:45:37 +040065 resp, ikepolicies = self.client.list_ikepolicies()
raiesmh08bd6070d2013-12-06 15:13:38 +053066 ike_id_list = list()
67 for i in ikepolicies['ikepolicies']:
68 ike_id_list.append(i['id'])
69 self.assertNotIn(ike_policy_id, ike_id_list)
Anju Tiwari860097d2013-10-17 11:10:39 +053070
mouad benchchaouiea2440d2013-12-22 00:38:06 +010071 @test.attr(type='smoke')
Anju Tiwari860097d2013-10-17 11:10:39 +053072 def test_list_vpn_services(self):
73 # Verify the VPN service exists in the list of all VPN services
Eugene Nikanorov909ded12013-12-15 17:45:37 +040074 resp, body = self.client.list_vpnservices()
Anju Tiwari860097d2013-10-17 11:10:39 +053075 self.assertEqual('200', resp['status'])
76 vpnservices = body['vpnservices']
77 self.assertIn(self.vpnservice['id'], [v['id'] for v in vpnservices])
78
mouad benchchaouiea2440d2013-12-22 00:38:06 +010079 @test.attr(type='smoke')
Anju Tiwari860097d2013-10-17 11:10:39 +053080 def test_create_update_delete_vpn_service(self):
81 # Creates a VPN service
Masayuki Igawa259c1132013-10-31 17:48:44 +090082 name = data_utils.rand_name('vpn-service-')
Eugene Nikanorov909ded12013-12-15 17:45:37 +040083 resp, body = self.client.create_vpnservice(self.subnet['id'],
84 self.router['id'],
85 name=name,
86 admin_state_up=True)
Anju Tiwari860097d2013-10-17 11:10:39 +053087 self.assertEqual('201', resp['status'])
88 vpnservice = body['vpnservice']
89 # Assert if created vpnservices are not found in vpnservices list
Eugene Nikanorov909ded12013-12-15 17:45:37 +040090 resp, body = self.client.list_vpnservices()
Anju Tiwari860097d2013-10-17 11:10:39 +053091 vpn_services = [vs['id'] for vs in body['vpnservices']]
92 self.assertIsNotNone(vpnservice['id'])
93 self.assertIn(vpnservice['id'], vpn_services)
94
95 # TODO(raies): implement logic to update vpnservice
96 # VPNaaS client function to update is implemented.
97 # But precondition is that current state of vpnservice
98 # should be "ACTIVE" not "PENDING*"
99
100 # Verification of vpn service delete
Eugene Nikanorov909ded12013-12-15 17:45:37 +0400101 resp, body = self.client.delete_vpnservice(vpnservice['id'])
Anju Tiwari860097d2013-10-17 11:10:39 +0530102 self.assertEqual('204', resp['status'])
103 # Asserting if vpn service is found in the list after deletion
Eugene Nikanorov909ded12013-12-15 17:45:37 +0400104 resp, body = self.client.list_vpnservices()
Anju Tiwari860097d2013-10-17 11:10:39 +0530105 vpn_services = [vs['id'] for vs in body['vpnservices']]
106 self.assertNotIn(vpnservice['id'], vpn_services)
107
mouad benchchaouiea2440d2013-12-22 00:38:06 +0100108 @test.attr(type='smoke')
Anju Tiwari860097d2013-10-17 11:10:39 +0530109 def test_show_vpn_service(self):
110 # Verifies the details of a vpn service
Eugene Nikanorov909ded12013-12-15 17:45:37 +0400111 resp, body = self.client.show_vpnservice(self.vpnservice['id'])
Anju Tiwari860097d2013-10-17 11:10:39 +0530112 self.assertEqual('200', resp['status'])
113 vpnservice = body['vpnservice']
114 self.assertEqual(self.vpnservice['id'], vpnservice['id'])
115 self.assertEqual(self.vpnservice['name'], vpnservice['name'])
116 self.assertEqual(self.vpnservice['description'],
117 vpnservice['description'])
118 self.assertEqual(self.vpnservice['router_id'], vpnservice['router_id'])
119 self.assertEqual(self.vpnservice['subnet_id'], vpnservice['subnet_id'])
120 self.assertEqual(self.vpnservice['tenant_id'], vpnservice['tenant_id'])
raiesmh08bd6070d2013-12-06 15:13:38 +0530121
mouad benchchaouiea2440d2013-12-22 00:38:06 +0100122 @test.attr(type='smoke')
raiesmh08bd6070d2013-12-06 15:13:38 +0530123 def test_list_ike_policies(self):
124 # Verify the ike policy exists in the list of all IKE policies
Eugene Nikanorov909ded12013-12-15 17:45:37 +0400125 resp, body = self.client.list_ikepolicies()
raiesmh08bd6070d2013-12-06 15:13:38 +0530126 self.assertEqual('200', resp['status'])
127 ikepolicies = body['ikepolicies']
128 self.assertIn(self.ikepolicy['id'], [i['id'] for i in ikepolicies])
129
mouad benchchaouiea2440d2013-12-22 00:38:06 +0100130 @test.attr(type='smoke')
raiesmh08bd6070d2013-12-06 15:13:38 +0530131 def test_create_update_delete_ike_policy(self):
132 # Creates a IKE policy
133 name = data_utils.rand_name('ike-policy-')
Eugene Nikanorov909ded12013-12-15 17:45:37 +0400134 resp, body = (self.client.create_ikepolicy(
raiesmh08bd6070d2013-12-06 15:13:38 +0530135 name,
136 ike_version="v1",
137 encryption_algorithm="aes-128",
138 auth_algorithm="sha1"))
139 self.assertEqual('201', resp['status'])
140 ikepolicy = body['ikepolicy']
141 self.addCleanup(self._delete_ike_policy, ikepolicy['id'])
142 # Verification of ike policy update
143 description = "Updated ike policy"
144 new_ike = {'description': description, 'pfs': 'group5',
145 'name': data_utils.rand_name("New-IKE-")}
Eugene Nikanorov909ded12013-12-15 17:45:37 +0400146 resp, body = self.client.update_ikepolicy(ikepolicy['id'],
147 **new_ike)
raiesmh08bd6070d2013-12-06 15:13:38 +0530148 self.assertEqual('200', resp['status'])
149 updated_ike_policy = body['ikepolicy']
150 self.assertEqual(updated_ike_policy['description'], description)
151 # Verification of ike policy delete
Eugene Nikanorov909ded12013-12-15 17:45:37 +0400152 resp, body = self.client.delete_ikepolicy(ikepolicy['id'])
raiesmh08bd6070d2013-12-06 15:13:38 +0530153 self.assertEqual('204', resp['status'])
154
mouad benchchaouiea2440d2013-12-22 00:38:06 +0100155 @test.attr(type='smoke')
raiesmh08bd6070d2013-12-06 15:13:38 +0530156 def test_show_ike_policy(self):
157 # Verifies the details of a ike policy
Eugene Nikanorov909ded12013-12-15 17:45:37 +0400158 resp, body = self.client.show_ikepolicy(self.ikepolicy['id'])
raiesmh08bd6070d2013-12-06 15:13:38 +0530159 self.assertEqual('200', resp['status'])
160 ikepolicy = body['ikepolicy']
161 self.assertEqual(self.ikepolicy['id'], ikepolicy['id'])
162 self.assertEqual(self.ikepolicy['name'], ikepolicy['name'])
163 self.assertEqual(self.ikepolicy['description'],
164 ikepolicy['description'])
165 self.assertEqual(self.ikepolicy['encryption_algorithm'],
166 ikepolicy['encryption_algorithm'])
167 self.assertEqual(self.ikepolicy['auth_algorithm'],
168 ikepolicy['auth_algorithm'])
169 self.assertEqual(self.ikepolicy['tenant_id'],
170 ikepolicy['tenant_id'])
171 self.assertEqual(self.ikepolicy['pfs'],
172 ikepolicy['pfs'])
173 self.assertEqual(self.ikepolicy['phase1_negotiation_mode'],
174 ikepolicy['phase1_negotiation_mode'])
175 self.assertEqual(self.ikepolicy['ike_version'],
176 ikepolicy['ike_version'])