Anju Tiwari | 860097d | 2013-10-17 11:10:39 +0530 | [diff] [blame] | 1 | # 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 | |
| 18 | from tempest.api.network import base |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 19 | from tempest.common.utils import data_utils |
mouad benchchaoui | ea2440d | 2013-12-22 00:38:06 +0100 | [diff] [blame] | 20 | from tempest import test |
Anju Tiwari | 860097d | 2013-10-17 11:10:39 +0530 | [diff] [blame] | 21 | |
| 22 | |
| 23 | class 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 |
raiesmh08 | bd6070d | 2013-12-06 15:13:38 +0530 | [diff] [blame] | 35 | List, Show, Create, Delete, and Update IKE policy |
Anju Tiwari | 860097d | 2013-10-17 11:10:39 +0530 | [diff] [blame] | 36 | """ |
| 37 | |
| 38 | @classmethod |
| 39 | def setUpClass(cls): |
| 40 | super(VPNaaSJSON, cls).setUpClass() |
mouad benchchaoui | ea2440d | 2013-12-22 00:38:06 +0100 | [diff] [blame] | 41 | if not test.is_extension_enabled('vpnaas', 'network'): |
| 42 | msg = "vpnaas extension not enabled." |
| 43 | raise cls.skipException(msg) |
Anju Tiwari | 860097d | 2013-10-17 11:10:39 +0530 | [diff] [blame] | 44 | cls.network = cls.create_network() |
| 45 | cls.subnet = cls.create_subnet(cls.network) |
Nachi Ueno | 41ecf5b | 2013-12-10 13:26:33 -0800 | [diff] [blame] | 46 | cls.router = cls.create_router( |
| 47 | data_utils.rand_name("router-"), |
| 48 | external_network_id=cls.network_cfg.public_network_id) |
Anju Tiwari | 860097d | 2013-10-17 11:10:39 +0530 | [diff] [blame] | 49 | cls.create_router_interface(cls.router['id'], cls.subnet['id']) |
| 50 | cls.vpnservice = cls.create_vpnservice(cls.subnet['id'], |
| 51 | cls.router['id']) |
Eugene Nikanorov | 909ded1 | 2013-12-15 17:45:37 +0400 | [diff] [blame] | 52 | cls.ikepolicy = cls.create_ikepolicy( |
| 53 | data_utils.rand_name("ike-policy-")) |
raiesmh08 | bd6070d | 2013-12-06 15:13:38 +0530 | [diff] [blame] | 54 | |
| 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 Nikanorov | 909ded1 | 2013-12-15 17:45:37 +0400 | [diff] [blame] | 58 | resp, all_ike = self.client.list_ikepolicies() |
raiesmh08 | bd6070d | 2013-12-06 15:13:38 +0530 | [diff] [blame] | 59 | for ike in all_ike['ikepolicies']: |
| 60 | ike_list.append(ike['id']) |
| 61 | if ike_policy_id in ike_list: |
Eugene Nikanorov | 909ded1 | 2013-12-15 17:45:37 +0400 | [diff] [blame] | 62 | resp, _ = self.client.delete_ikepolicy(ike_policy_id) |
raiesmh08 | bd6070d | 2013-12-06 15:13:38 +0530 | [diff] [blame] | 63 | self.assertEqual(204, resp.status) |
| 64 | # Asserting that the policy is not found in list after deletion |
Eugene Nikanorov | 909ded1 | 2013-12-15 17:45:37 +0400 | [diff] [blame] | 65 | resp, ikepolicies = self.client.list_ikepolicies() |
raiesmh08 | bd6070d | 2013-12-06 15:13:38 +0530 | [diff] [blame] | 66 | 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 Tiwari | 860097d | 2013-10-17 11:10:39 +0530 | [diff] [blame] | 70 | |
mouad benchchaoui | ea2440d | 2013-12-22 00:38:06 +0100 | [diff] [blame] | 71 | @test.attr(type='smoke') |
Anju Tiwari | 860097d | 2013-10-17 11:10:39 +0530 | [diff] [blame] | 72 | def test_list_vpn_services(self): |
| 73 | # Verify the VPN service exists in the list of all VPN services |
Eugene Nikanorov | 909ded1 | 2013-12-15 17:45:37 +0400 | [diff] [blame] | 74 | resp, body = self.client.list_vpnservices() |
Anju Tiwari | 860097d | 2013-10-17 11:10:39 +0530 | [diff] [blame] | 75 | self.assertEqual('200', resp['status']) |
| 76 | vpnservices = body['vpnservices'] |
| 77 | self.assertIn(self.vpnservice['id'], [v['id'] for v in vpnservices]) |
| 78 | |
mouad benchchaoui | ea2440d | 2013-12-22 00:38:06 +0100 | [diff] [blame] | 79 | @test.attr(type='smoke') |
Anju Tiwari | 860097d | 2013-10-17 11:10:39 +0530 | [diff] [blame] | 80 | def test_create_update_delete_vpn_service(self): |
| 81 | # Creates a VPN service |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 82 | name = data_utils.rand_name('vpn-service-') |
Eugene Nikanorov | 909ded1 | 2013-12-15 17:45:37 +0400 | [diff] [blame] | 83 | resp, body = self.client.create_vpnservice(self.subnet['id'], |
| 84 | self.router['id'], |
| 85 | name=name, |
| 86 | admin_state_up=True) |
Anju Tiwari | 860097d | 2013-10-17 11:10:39 +0530 | [diff] [blame] | 87 | self.assertEqual('201', resp['status']) |
| 88 | vpnservice = body['vpnservice'] |
| 89 | # Assert if created vpnservices are not found in vpnservices list |
Eugene Nikanorov | 909ded1 | 2013-12-15 17:45:37 +0400 | [diff] [blame] | 90 | resp, body = self.client.list_vpnservices() |
Anju Tiwari | 860097d | 2013-10-17 11:10:39 +0530 | [diff] [blame] | 91 | 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 Nikanorov | 909ded1 | 2013-12-15 17:45:37 +0400 | [diff] [blame] | 101 | resp, body = self.client.delete_vpnservice(vpnservice['id']) |
Anju Tiwari | 860097d | 2013-10-17 11:10:39 +0530 | [diff] [blame] | 102 | self.assertEqual('204', resp['status']) |
| 103 | # Asserting if vpn service is found in the list after deletion |
Eugene Nikanorov | 909ded1 | 2013-12-15 17:45:37 +0400 | [diff] [blame] | 104 | resp, body = self.client.list_vpnservices() |
Anju Tiwari | 860097d | 2013-10-17 11:10:39 +0530 | [diff] [blame] | 105 | vpn_services = [vs['id'] for vs in body['vpnservices']] |
| 106 | self.assertNotIn(vpnservice['id'], vpn_services) |
| 107 | |
mouad benchchaoui | ea2440d | 2013-12-22 00:38:06 +0100 | [diff] [blame] | 108 | @test.attr(type='smoke') |
Anju Tiwari | 860097d | 2013-10-17 11:10:39 +0530 | [diff] [blame] | 109 | def test_show_vpn_service(self): |
| 110 | # Verifies the details of a vpn service |
Eugene Nikanorov | 909ded1 | 2013-12-15 17:45:37 +0400 | [diff] [blame] | 111 | resp, body = self.client.show_vpnservice(self.vpnservice['id']) |
Anju Tiwari | 860097d | 2013-10-17 11:10:39 +0530 | [diff] [blame] | 112 | 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']) |
raiesmh08 | bd6070d | 2013-12-06 15:13:38 +0530 | [diff] [blame] | 121 | |
mouad benchchaoui | ea2440d | 2013-12-22 00:38:06 +0100 | [diff] [blame] | 122 | @test.attr(type='smoke') |
raiesmh08 | bd6070d | 2013-12-06 15:13:38 +0530 | [diff] [blame] | 123 | def test_list_ike_policies(self): |
| 124 | # Verify the ike policy exists in the list of all IKE policies |
Eugene Nikanorov | 909ded1 | 2013-12-15 17:45:37 +0400 | [diff] [blame] | 125 | resp, body = self.client.list_ikepolicies() |
raiesmh08 | bd6070d | 2013-12-06 15:13:38 +0530 | [diff] [blame] | 126 | self.assertEqual('200', resp['status']) |
| 127 | ikepolicies = body['ikepolicies'] |
| 128 | self.assertIn(self.ikepolicy['id'], [i['id'] for i in ikepolicies]) |
| 129 | |
mouad benchchaoui | ea2440d | 2013-12-22 00:38:06 +0100 | [diff] [blame] | 130 | @test.attr(type='smoke') |
raiesmh08 | bd6070d | 2013-12-06 15:13:38 +0530 | [diff] [blame] | 131 | def test_create_update_delete_ike_policy(self): |
| 132 | # Creates a IKE policy |
| 133 | name = data_utils.rand_name('ike-policy-') |
Eugene Nikanorov | 909ded1 | 2013-12-15 17:45:37 +0400 | [diff] [blame] | 134 | resp, body = (self.client.create_ikepolicy( |
raiesmh08 | bd6070d | 2013-12-06 15:13:38 +0530 | [diff] [blame] | 135 | 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 Nikanorov | 909ded1 | 2013-12-15 17:45:37 +0400 | [diff] [blame] | 146 | resp, body = self.client.update_ikepolicy(ikepolicy['id'], |
| 147 | **new_ike) |
raiesmh08 | bd6070d | 2013-12-06 15:13:38 +0530 | [diff] [blame] | 148 | 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 Nikanorov | 909ded1 | 2013-12-15 17:45:37 +0400 | [diff] [blame] | 152 | resp, body = self.client.delete_ikepolicy(ikepolicy['id']) |
raiesmh08 | bd6070d | 2013-12-06 15:13:38 +0530 | [diff] [blame] | 153 | self.assertEqual('204', resp['status']) |
| 154 | |
mouad benchchaoui | ea2440d | 2013-12-22 00:38:06 +0100 | [diff] [blame] | 155 | @test.attr(type='smoke') |
raiesmh08 | bd6070d | 2013-12-06 15:13:38 +0530 | [diff] [blame] | 156 | def test_show_ike_policy(self): |
| 157 | # Verifies the details of a ike policy |
Eugene Nikanorov | 909ded1 | 2013-12-15 17:45:37 +0400 | [diff] [blame] | 158 | resp, body = self.client.show_ikepolicy(self.ikepolicy['id']) |
raiesmh08 | bd6070d | 2013-12-06 15:13:38 +0530 | [diff] [blame] | 159 | 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']) |