blob: fc3b1d93c095bb935123f1c4f5728330c29844c0 [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
Anju Tiwari860097d2013-10-17 11:10:39 +053020from tempest.test import attr
21
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()
41 cls.network = cls.create_network()
42 cls.subnet = cls.create_subnet(cls.network)
Nachi Ueno41ecf5b2013-12-10 13:26:33 -080043 cls.router = cls.create_router(
44 data_utils.rand_name("router-"),
45 external_network_id=cls.network_cfg.public_network_id)
Anju Tiwari860097d2013-10-17 11:10:39 +053046 cls.create_router_interface(cls.router['id'], cls.subnet['id'])
47 cls.vpnservice = cls.create_vpnservice(cls.subnet['id'],
48 cls.router['id'])
Eugene Nikanorov909ded12013-12-15 17:45:37 +040049 cls.ikepolicy = cls.create_ikepolicy(
50 data_utils.rand_name("ike-policy-"))
raiesmh08bd6070d2013-12-06 15:13:38 +053051
52 def _delete_ike_policy(self, ike_policy_id):
53 # Deletes a ike policy and verifies if it is deleted or not
54 ike_list = list()
Eugene Nikanorov909ded12013-12-15 17:45:37 +040055 resp, all_ike = self.client.list_ikepolicies()
raiesmh08bd6070d2013-12-06 15:13:38 +053056 for ike in all_ike['ikepolicies']:
57 ike_list.append(ike['id'])
58 if ike_policy_id in ike_list:
Eugene Nikanorov909ded12013-12-15 17:45:37 +040059 resp, _ = self.client.delete_ikepolicy(ike_policy_id)
raiesmh08bd6070d2013-12-06 15:13:38 +053060 self.assertEqual(204, resp.status)
61 # Asserting that the policy is not found in list after deletion
Eugene Nikanorov909ded12013-12-15 17:45:37 +040062 resp, ikepolicies = self.client.list_ikepolicies()
raiesmh08bd6070d2013-12-06 15:13:38 +053063 ike_id_list = list()
64 for i in ikepolicies['ikepolicies']:
65 ike_id_list.append(i['id'])
66 self.assertNotIn(ike_policy_id, ike_id_list)
Anju Tiwari860097d2013-10-17 11:10:39 +053067
68 @attr(type='smoke')
69 def test_list_vpn_services(self):
70 # Verify the VPN service exists in the list of all VPN services
Eugene Nikanorov909ded12013-12-15 17:45:37 +040071 resp, body = self.client.list_vpnservices()
Anju Tiwari860097d2013-10-17 11:10:39 +053072 self.assertEqual('200', resp['status'])
73 vpnservices = body['vpnservices']
74 self.assertIn(self.vpnservice['id'], [v['id'] for v in vpnservices])
75
76 @attr(type='smoke')
77 def test_create_update_delete_vpn_service(self):
78 # Creates a VPN service
Masayuki Igawa259c1132013-10-31 17:48:44 +090079 name = data_utils.rand_name('vpn-service-')
Eugene Nikanorov909ded12013-12-15 17:45:37 +040080 resp, body = self.client.create_vpnservice(self.subnet['id'],
81 self.router['id'],
82 name=name,
83 admin_state_up=True)
Anju Tiwari860097d2013-10-17 11:10:39 +053084 self.assertEqual('201', resp['status'])
85 vpnservice = body['vpnservice']
86 # Assert if created vpnservices are not found in vpnservices list
Eugene Nikanorov909ded12013-12-15 17:45:37 +040087 resp, body = self.client.list_vpnservices()
Anju Tiwari860097d2013-10-17 11:10:39 +053088 vpn_services = [vs['id'] for vs in body['vpnservices']]
89 self.assertIsNotNone(vpnservice['id'])
90 self.assertIn(vpnservice['id'], vpn_services)
91
92 # TODO(raies): implement logic to update vpnservice
93 # VPNaaS client function to update is implemented.
94 # But precondition is that current state of vpnservice
95 # should be "ACTIVE" not "PENDING*"
96
97 # Verification of vpn service delete
Eugene Nikanorov909ded12013-12-15 17:45:37 +040098 resp, body = self.client.delete_vpnservice(vpnservice['id'])
Anju Tiwari860097d2013-10-17 11:10:39 +053099 self.assertEqual('204', resp['status'])
100 # Asserting if vpn service is found in the list after deletion
Eugene Nikanorov909ded12013-12-15 17:45:37 +0400101 resp, body = self.client.list_vpnservices()
Anju Tiwari860097d2013-10-17 11:10:39 +0530102 vpn_services = [vs['id'] for vs in body['vpnservices']]
103 self.assertNotIn(vpnservice['id'], vpn_services)
104
105 @attr(type='smoke')
106 def test_show_vpn_service(self):
107 # Verifies the details of a vpn service
Eugene Nikanorov909ded12013-12-15 17:45:37 +0400108 resp, body = self.client.show_vpnservice(self.vpnservice['id'])
Anju Tiwari860097d2013-10-17 11:10:39 +0530109 self.assertEqual('200', resp['status'])
110 vpnservice = body['vpnservice']
111 self.assertEqual(self.vpnservice['id'], vpnservice['id'])
112 self.assertEqual(self.vpnservice['name'], vpnservice['name'])
113 self.assertEqual(self.vpnservice['description'],
114 vpnservice['description'])
115 self.assertEqual(self.vpnservice['router_id'], vpnservice['router_id'])
116 self.assertEqual(self.vpnservice['subnet_id'], vpnservice['subnet_id'])
117 self.assertEqual(self.vpnservice['tenant_id'], vpnservice['tenant_id'])
raiesmh08bd6070d2013-12-06 15:13:38 +0530118
119 @attr(type='smoke')
120 def test_list_ike_policies(self):
121 # Verify the ike policy exists in the list of all IKE policies
Eugene Nikanorov909ded12013-12-15 17:45:37 +0400122 resp, body = self.client.list_ikepolicies()
raiesmh08bd6070d2013-12-06 15:13:38 +0530123 self.assertEqual('200', resp['status'])
124 ikepolicies = body['ikepolicies']
125 self.assertIn(self.ikepolicy['id'], [i['id'] for i in ikepolicies])
126
127 @attr(type='smoke')
128 def test_create_update_delete_ike_policy(self):
129 # Creates a IKE policy
130 name = data_utils.rand_name('ike-policy-')
Eugene Nikanorov909ded12013-12-15 17:45:37 +0400131 resp, body = (self.client.create_ikepolicy(
raiesmh08bd6070d2013-12-06 15:13:38 +0530132 name,
133 ike_version="v1",
134 encryption_algorithm="aes-128",
135 auth_algorithm="sha1"))
136 self.assertEqual('201', resp['status'])
137 ikepolicy = body['ikepolicy']
138 self.addCleanup(self._delete_ike_policy, ikepolicy['id'])
139 # Verification of ike policy update
140 description = "Updated ike policy"
141 new_ike = {'description': description, 'pfs': 'group5',
142 'name': data_utils.rand_name("New-IKE-")}
Eugene Nikanorov909ded12013-12-15 17:45:37 +0400143 resp, body = self.client.update_ikepolicy(ikepolicy['id'],
144 **new_ike)
raiesmh08bd6070d2013-12-06 15:13:38 +0530145 self.assertEqual('200', resp['status'])
146 updated_ike_policy = body['ikepolicy']
147 self.assertEqual(updated_ike_policy['description'], description)
148 # Verification of ike policy delete
Eugene Nikanorov909ded12013-12-15 17:45:37 +0400149 resp, body = self.client.delete_ikepolicy(ikepolicy['id'])
raiesmh08bd6070d2013-12-06 15:13:38 +0530150 self.assertEqual('204', resp['status'])
151
152 @attr(type='smoke')
153 def test_show_ike_policy(self):
154 # Verifies the details of a ike policy
Eugene Nikanorov909ded12013-12-15 17:45:37 +0400155 resp, body = self.client.show_ikepolicy(self.ikepolicy['id'])
raiesmh08bd6070d2013-12-06 15:13:38 +0530156 self.assertEqual('200', resp['status'])
157 ikepolicy = body['ikepolicy']
158 self.assertEqual(self.ikepolicy['id'], ikepolicy['id'])
159 self.assertEqual(self.ikepolicy['name'], ikepolicy['name'])
160 self.assertEqual(self.ikepolicy['description'],
161 ikepolicy['description'])
162 self.assertEqual(self.ikepolicy['encryption_algorithm'],
163 ikepolicy['encryption_algorithm'])
164 self.assertEqual(self.ikepolicy['auth_algorithm'],
165 ikepolicy['auth_algorithm'])
166 self.assertEqual(self.ikepolicy['tenant_id'],
167 ikepolicy['tenant_id'])
168 self.assertEqual(self.ikepolicy['pfs'],
169 ikepolicy['pfs'])
170 self.assertEqual(self.ikepolicy['phase1_negotiation_mode'],
171 ikepolicy['phase1_negotiation_mode'])
172 self.assertEqual(self.ikepolicy['ike_version'],
173 ikepolicy['ike_version'])