Debian Codegraph @

neutron_tempest_plugin/vpnaas/api/base_vpnaas.py

raw
1 # Copyright 2012 OpenStack Foundation
2 # Copyright 2016 Hewlett Packard Enterprise Development Company LP
3 # All Rights Reserved.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License"); you may
6 # not use this file except in compliance with the License. You may obtain
7 # a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 # License for the specific language governing permissions and limitations
15 # under the License.
16
17 from tempest.lib.common.utils import data_utils
18
19 from neutron_tempest_plugin.api import base
20 from neutron_tempest_plugin import config
21 from neutron_tempest_plugin.vpnaas.services import clients_vpnaas
22
23 CONF = config.CONF
24
25
26 class BaseNetworkTest(base.BaseNetworkTest):
27 @classmethod
28 def resource_setup(cls):
29 super(BaseNetworkTest, cls).resource_setup()
30 cls.vpnservices = []
31 cls.ikepolicies = []
32 cls.ipsecpolicies = []
33 cls.ipsec_site_connections = []
34 cls.endpoint_groups = []
35
36 @classmethod
37 def get_client_manager(cls, credential_type=None, roles=None,
38 force_new=None):
39 manager = super(BaseNetworkTest, cls).get_client_manager(
40 credential_type=credential_type,
41 roles=roles,
42 force_new=force_new)
43 # Neutron uses a different clients manager than the one in the Tempest
44 return clients_vpnaas.Manager(manager.credentials)
45
46 @classmethod
47 def resource_cleanup(cls):
48 if CONF.service_available.neutron:
49 # Clean up ipsec connections
50 for ipsec_site_connection in cls.ipsec_site_connections:
51 cls._try_delete_resource(
52 cls.client.delete_ipsec_site_connection,
53 ipsec_site_connection['id'])
54
55 # Clean up ipsec endpoint group
56 for endpoint_group in cls.endpoint_groups:
57 cls._try_delete_resource(cls.client.delete_endpoint_group,
58 endpoint_group['id'])
59
60 # Clean up ipsec policies
61 for ipsecpolicy in cls.ipsecpolicies:
62 cls._try_delete_resource(cls.client.delete_ipsecpolicy,
63 ipsecpolicy['id'])
64 # Clean up ike policies
65 for ikepolicy in cls.ikepolicies:
66 cls._try_delete_resource(cls.client.delete_ikepolicy,
67 ikepolicy['id'])
68 # Clean up vpn services
69 for vpnservice in cls.vpnservices:
70 cls._try_delete_resource(cls.client.delete_vpnservice,
71 vpnservice['id'])
72 super(BaseNetworkTest, cls).resource_cleanup()
73
74 @classmethod
75 def create_vpnservice(cls, subnet_id, router_id, name=None):
76 """Wrapper utility that returns a test vpn service."""
77 if name is None:
78 name = data_utils.rand_name("vpnservice-")
79 body = cls.client.create_vpnservice(
80 subnet_id=subnet_id, router_id=router_id, admin_state_up=True,
81 name=name)
82 vpnservice = body['vpnservice']
83 cls.vpnservices.append(vpnservice)
84 return vpnservice
85
86 @classmethod
87 def create_vpnservice_no_subnet(cls, router_id):
88 """Wrapper utility that returns a test vpn service."""
89 body = cls.client.create_vpnservice(
90 router_id=router_id, admin_state_up=True,
91 name=data_utils.rand_name("vpnservice-"))
92 vpnservice = body['vpnservice']
93 cls.vpnservices.append(vpnservice)
94 return vpnservice
95
96 @classmethod
97 def create_ikepolicy(cls, name):
98 """Wrapper utility that returns a test ike policy."""
99 body = cls.client.create_ikepolicy(name=name)
100 ikepolicy = body['ikepolicy']
101 cls.ikepolicies.append(ikepolicy)
102 return ikepolicy
103
104 @classmethod
105 def create_ipsecpolicy(cls, name):
106 """Wrapper utility that returns a test ipsec policy."""
107 body = cls.client.create_ipsecpolicy(name=name)
108 ipsecpolicy = body['ipsecpolicy']
109 cls.ipsecpolicies.append(ipsecpolicy)
110 return ipsecpolicy
111
112 @classmethod
113 def create_ipsec_site_connection(cls, ikepolicy_id, ipsecpolicy_id,
114 vpnservice_id, psk="secret",
115 peer_address="172.24.4.233",
116 peer_id="172.24.4.233",
117 peer_cidrs=None,
118 name=None):
119 """Wrapper utility that returns a test vpn connection."""
120 if peer_cidrs is None:
121 peer_cidrs = ['1.1.1.0/24', '2.2.2.0/24']
122 if name is None:
123 name = data_utils.rand_name("ipsec_site_connection-")
124 body = cls.client.create_ipsec_site_connection(
125 psk=psk,
126 initiator="bi-directional",
127 ipsecpolicy_id=ipsecpolicy_id,
128 admin_state_up=True,
129 mtu=1500,
130 ikepolicy_id=ikepolicy_id,
131 vpnservice_id=vpnservice_id,
132 peer_address=peer_address,
133 peer_id=peer_id,
134 peer_cidrs=peer_cidrs,
135 name=name)
136 ipsec_site_connection = body['ipsec_site_connection']
137 cls.ipsec_site_connections.append(ipsec_site_connection)
138 return ipsec_site_connection
139
140 @classmethod
141 def create_endpoint_group(cls, name, type, endpoints):
142 """Wrapper utility that returns a test ipsec policy."""
143 body = cls.client.create_endpoint_group(
144 endpoints=endpoints,
145 type=type,
146 description='endpoint type:' + type,
147 name=name)
148 endpoint_group = body['endpoint_group']
149 cls.endpoint_groups.append(endpoint_group)
150 return endpoint_group
151
152
153 class BaseAdminNetworkTest(BaseNetworkTest):
154 credentials = ['primary', 'admin']
155
156 @classmethod
157 def setup_clients(cls):
158 super(BaseAdminNetworkTest, cls).setup_clients()
159 cls.admin_client = cls.os_admin.network_client
160 cls.identity_admin_client = cls.os_admin.tenants_client