blob: 4cb14859adcde355c2968d28c7687c11b0eb24dd [file] [log] [blame]
ZhiQiang Fan39f97222013-09-20 04:49:44 +08001# Copyright 2012 OpenStack Foundation
Jay Pipesf4dad392012-06-05 16:03:58 -04002# 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
Miguel Lavallecc939612013-02-22 17:27:20 -060016import netaddr
Masayuki Igawabfa07602015-01-20 18:47:17 +090017from tempest_lib import exceptions as lib_exc
Jay Pipesf4dad392012-06-05 16:03:58 -040018
Matthew Treinish481466b2012-12-20 17:16:01 -050019from tempest import clients
Masayuki Igawa259c1132013-10-31 17:48:44 +090020from tempest.common.utils import data_utils
Matthew Treinish03b48df2014-01-29 16:59:49 +000021from tempest import config
Miguel Lavallecc939612013-02-22 17:27:20 -060022from tempest import exceptions
Anju Tiwari860097d2013-10-17 11:10:39 +053023from tempest.openstack.common import log as logging
Attila Fazekasdc216422013-01-29 15:12:14 +010024import tempest.test
Jay Pipesf4dad392012-06-05 16:03:58 -040025
Matthew Treinish03b48df2014-01-29 16:59:49 +000026CONF = config.CONF
27
Anju Tiwari860097d2013-10-17 11:10:39 +053028LOG = logging.getLogger(__name__)
29
Jay Pipesf4dad392012-06-05 16:03:58 -040030
Attila Fazekasdc216422013-01-29 15:12:14 +010031class BaseNetworkTest(tempest.test.BaseTestCase):
Jay Pipesf4dad392012-06-05 16:03:58 -040032
Miguel Lavallecc939612013-02-22 17:27:20 -060033 """
Mark McClainf2982e82013-07-06 17:48:03 -040034 Base class for the Neutron tests that use the Tempest Neutron REST client
Miguel Lavallecc939612013-02-22 17:27:20 -060035
Mark McClainf2982e82013-07-06 17:48:03 -040036 Per the Neutron API Guide, API v1.x was removed from the source code tree
Miguel Lavallecc939612013-02-22 17:27:20 -060037 (docs.openstack.org/api/openstack-network/2.0/content/Overview-d1e71.html)
Mark McClainf2982e82013-07-06 17:48:03 -040038 Therefore, v2.x of the Neutron API is assumed. It is also assumed that the
Miguel Lavallecc939612013-02-22 17:27:20 -060039 following options are defined in the [network] section of etc/tempest.conf:
40
41 tenant_network_cidr with a block of cidr's from which smaller blocks
42 can be allocated for tenant networks
43
44 tenant_network_mask_bits with the mask bits to be used to partition the
45 block defined by tenant-network_cidr
Miguel Lavalle2492d782013-06-16 15:04:15 -050046
47 Finally, it is assumed that the following option is defined in the
48 [service_available] section of etc/tempest.conf
49
50 neutron as True
Miguel Lavallecc939612013-02-22 17:27:20 -060051 """
52
Matthew Treinish2f6628c2013-10-21 21:06:27 +000053 force_tenant_isolation = False
54
Henry Gessauffda37a2014-01-16 11:17:55 -050055 # Default to ipv4.
56 _ip_version = 4
Henry Gessauffda37a2014-01-16 11:17:55 -050057
Jay Pipesf4dad392012-06-05 16:03:58 -040058 @classmethod
Andrea Frittolida4a2452014-09-15 13:12:08 +010059 def resource_setup(cls):
Salvatore Orlando5a337242014-01-15 22:49:22 +000060 # Create no network resources for these test.
61 cls.set_network_resources()
Andrea Frittolida4a2452014-09-15 13:12:08 +010062 super(BaseNetworkTest, cls).resource_setup()
Matthew Treinish03b48df2014-01-29 16:59:49 +000063 if not CONF.service_available.neutron:
Mark McClainf2982e82013-07-06 17:48:03 -040064 raise cls.skipException("Neutron support is required")
Sergey Shnaidman97e6a0f2014-11-12 20:00:53 +030065 if cls._ip_version == 6 and not CONF.network_feature_enabled.ipv6:
66 raise cls.skipException("IPv6 Tests are disabled.")
Matthew Treinish2f6628c2013-10-21 21:06:27 +000067
68 os = cls.get_client_manager()
69
70 cls.network_cfg = CONF.network
Miguel Lavallecc939612013-02-22 17:27:20 -060071 cls.client = os.network_client
72 cls.networks = []
73 cls.subnets = []
raiesmh08e1aad982013-08-05 14:19:36 +053074 cls.ports = []
Salvatore Orlandoa85e8fe2013-09-20 03:48:02 -070075 cls.routers = []
raiesmh080fe76852013-09-13 11:52:56 +053076 cls.pools = []
77 cls.vips = []
raiesmh08f8437ed2013-09-17 10:59:38 +053078 cls.members = []
raiesmh0832580d02013-09-17 13:11:34 +053079 cls.health_monitors = []
Anju Tiwari860097d2013-10-17 11:10:39 +053080 cls.vpnservices = []
raiesmh08bd6070d2013-12-06 15:13:38 +053081 cls.ikepolicies = []
rosselladd68b232013-11-13 10:21:59 +010082 cls.floating_ips = []
Emilien Macchi0d0b7cc2014-01-11 12:30:21 -050083 cls.metering_labels = []
84 cls.metering_label_rules = []
Mh Raies96594fc2014-03-26 16:34:18 +053085 cls.fw_rules = []
86 cls.fw_policies = []
raiesmh08df3fac42014-06-02 15:42:18 +053087 cls.ipsecpolicies = []
sridhargaddam510f8962014-09-08 23:37:16 +053088 cls.ethertype = "IPv" + str(cls._ip_version)
Jay Pipesf4dad392012-06-05 16:03:58 -040089
90 @classmethod
Andrea Frittolida4a2452014-09-15 13:12:08 +010091 def resource_cleanup(cls):
Daniel P. Berrange690c26a2014-07-01 12:51:36 +010092 if CONF.service_available.neutron:
93 # Clean up ipsec policies
94 for ipsecpolicy in cls.ipsecpolicies:
Yair Fried4f923282014-11-19 10:55:57 +020095 cls._try_delete_resource(cls.client.delete_ipsecpolicy,
96 ipsecpolicy['id'])
Daniel P. Berrange690c26a2014-07-01 12:51:36 +010097 # Clean up firewall policies
98 for fw_policy in cls.fw_policies:
Yair Fried4f923282014-11-19 10:55:57 +020099 cls._try_delete_resource(cls.client.delete_firewall_policy,
100 fw_policy['id'])
Daniel P. Berrange690c26a2014-07-01 12:51:36 +0100101 # Clean up firewall rules
102 for fw_rule in cls.fw_rules:
Yair Fried4f923282014-11-19 10:55:57 +0200103 cls._try_delete_resource(cls.client.delete_firewall_rule,
104 fw_rule['id'])
Daniel P. Berrange690c26a2014-07-01 12:51:36 +0100105 # Clean up ike policies
106 for ikepolicy in cls.ikepolicies:
Yair Fried4f923282014-11-19 10:55:57 +0200107 cls._try_delete_resource(cls.client.delete_ikepolicy,
108 ikepolicy['id'])
Daniel P. Berrange690c26a2014-07-01 12:51:36 +0100109 # Clean up vpn services
110 for vpnservice in cls.vpnservices:
Yair Fried4f923282014-11-19 10:55:57 +0200111 cls._try_delete_resource(cls.client.delete_vpnservice,
112 vpnservice['id'])
Daniel P. Berrange690c26a2014-07-01 12:51:36 +0100113 # Clean up floating IPs
114 for floating_ip in cls.floating_ips:
Yair Fried4f923282014-11-19 10:55:57 +0200115 cls._try_delete_resource(cls.client.delete_floatingip,
116 floating_ip['id'])
Daniel P. Berrange690c26a2014-07-01 12:51:36 +0100117 # Clean up routers
118 for router in cls.routers:
Yair Fried4f923282014-11-19 10:55:57 +0200119 cls._try_delete_resource(cls.delete_router,
120 router)
Adam Gandelman3e9d12b2014-04-02 17:04:19 -0700121
Daniel P. Berrange690c26a2014-07-01 12:51:36 +0100122 # Clean up health monitors
123 for health_monitor in cls.health_monitors:
Yair Fried4f923282014-11-19 10:55:57 +0200124 cls._try_delete_resource(cls.client.delete_health_monitor,
125 health_monitor['id'])
Daniel P. Berrange690c26a2014-07-01 12:51:36 +0100126 # Clean up members
127 for member in cls.members:
Yair Fried4f923282014-11-19 10:55:57 +0200128 cls._try_delete_resource(cls.client.delete_member,
129 member['id'])
Daniel P. Berrange690c26a2014-07-01 12:51:36 +0100130 # Clean up vips
131 for vip in cls.vips:
Yair Fried4f923282014-11-19 10:55:57 +0200132 cls._try_delete_resource(cls.client.delete_vip,
133 vip['id'])
Daniel P. Berrange690c26a2014-07-01 12:51:36 +0100134 # Clean up pools
135 for pool in cls.pools:
Yair Fried4f923282014-11-19 10:55:57 +0200136 cls._try_delete_resource(cls.client.delete_pool,
137 pool['id'])
Daniel P. Berrange690c26a2014-07-01 12:51:36 +0100138 # Clean up metering label rules
139 for metering_label_rule in cls.metering_label_rules:
Yair Fried4f923282014-11-19 10:55:57 +0200140 cls._try_delete_resource(
141 cls.admin_client.delete_metering_label_rule,
Daniel P. Berrange690c26a2014-07-01 12:51:36 +0100142 metering_label_rule['id'])
143 # Clean up metering labels
144 for metering_label in cls.metering_labels:
Yair Fried4f923282014-11-19 10:55:57 +0200145 cls._try_delete_resource(
146 cls.admin_client.delete_metering_label,
147 metering_label['id'])
Daniel P. Berrange690c26a2014-07-01 12:51:36 +0100148 # Clean up ports
149 for port in cls.ports:
Yair Fried4f923282014-11-19 10:55:57 +0200150 cls._try_delete_resource(cls.client.delete_port,
151 port['id'])
Daniel P. Berrange690c26a2014-07-01 12:51:36 +0100152 # Clean up subnets
153 for subnet in cls.subnets:
Yair Fried4f923282014-11-19 10:55:57 +0200154 cls._try_delete_resource(cls.client.delete_subnet,
155 subnet['id'])
Daniel P. Berrange690c26a2014-07-01 12:51:36 +0100156 # Clean up networks
157 for network in cls.networks:
Yair Fried4f923282014-11-19 10:55:57 +0200158 cls._try_delete_resource(cls.client.delete_network,
159 network['id'])
Daniel P. Berrange690c26a2014-07-01 12:51:36 +0100160 cls.clear_isolated_creds()
Andrea Frittolida4a2452014-09-15 13:12:08 +0100161 super(BaseNetworkTest, cls).resource_cleanup()
Jay Pipesf4dad392012-06-05 16:03:58 -0400162
Miguel Lavallecc939612013-02-22 17:27:20 -0600163 @classmethod
Yair Fried4f923282014-11-19 10:55:57 +0200164 def _try_delete_resource(self, delete_callable, *args, **kwargs):
165 """Cleanup resources in case of test-failure
166
167 Some resources are explicitly deleted by the test.
168 If the test failed to delete a resource, this method will execute
169 the appropriate delete methods. Otherwise, the method ignores NotFound
170 exceptions thrown for resources that were correctly deleted by the
171 test.
172
173 :param delete_callable: delete method
174 :param args: arguments for delete method
175 :param kwargs: keyword arguments for delete method
176 """
177 try:
178 delete_callable(*args, **kwargs)
179 # if resource is not found, this means it was deleted in the test
Masayuki Igawabfa07602015-01-20 18:47:17 +0900180 except lib_exc.NotFound:
Yair Fried4f923282014-11-19 10:55:57 +0200181 pass
182
183 @classmethod
Miguel Lavallecc939612013-02-22 17:27:20 -0600184 def create_network(cls, network_name=None):
Sean Daguef237ccb2013-01-04 15:19:14 -0500185 """Wrapper utility that returns a test network."""
Masayuki Igawa259c1132013-10-31 17:48:44 +0900186 network_name = network_name or data_utils.rand_name('test-network-')
Jay Pipesf4dad392012-06-05 16:03:58 -0400187
David Kranz34e88122014-12-11 15:24:05 -0500188 body = cls.client.create_network(name=network_name)
Jay Pipesf4dad392012-06-05 16:03:58 -0400189 network = body['network']
Miguel Lavallecc939612013-02-22 17:27:20 -0600190 cls.networks.append(network)
Jay Pipesf4dad392012-06-05 16:03:58 -0400191 return network
Miguel Lavallecc939612013-02-22 17:27:20 -0600192
193 @classmethod
Sergey Shnaidman18cf5972014-09-02 22:05:00 +0400194 def create_subnet(cls, network, gateway='', cidr=None, mask_bits=None,
Yair Fried52ee1362014-09-29 14:47:03 +0300195 ip_version=None, client=None, **kwargs):
Miguel Lavallecc939612013-02-22 17:27:20 -0600196 """Wrapper utility that returns a test subnet."""
Yair Fried52ee1362014-09-29 14:47:03 +0300197
198 # allow tests to use admin client
199 if not client:
200 client = cls.client
201
Henry Gessauffda37a2014-01-16 11:17:55 -0500202 # The cidr and mask_bits depend on the ip version.
Sergey Shnaidman18cf5972014-09-02 22:05:00 +0400203 ip_version = ip_version if ip_version is not None else cls._ip_version
204 gateway_not_set = gateway == ''
205 if ip_version == 4:
armando-migliaccioee90a4d2014-05-06 11:54:07 -0700206 cidr = cidr or netaddr.IPNetwork(CONF.network.tenant_network_cidr)
207 mask_bits = mask_bits or CONF.network.tenant_network_mask_bits
Sergey Shnaidman18cf5972014-09-02 22:05:00 +0400208 elif ip_version == 6:
armando-migliaccioee90a4d2014-05-06 11:54:07 -0700209 cidr = (
210 cidr or netaddr.IPNetwork(CONF.network.tenant_network_v6_cidr))
211 mask_bits = mask_bits or CONF.network.tenant_network_v6_mask_bits
Miguel Lavallecc939612013-02-22 17:27:20 -0600212 # Find a cidr that is not in use yet and create a subnet with it
213 for subnet_cidr in cidr.subnet(mask_bits):
Sergey Shnaidman18cf5972014-09-02 22:05:00 +0400214 if gateway_not_set:
215 gateway_ip = str(netaddr.IPAddress(subnet_cidr) + 1)
216 else:
217 gateway_ip = gateway
Miguel Lavallecc939612013-02-22 17:27:20 -0600218 try:
David Kranz34e88122014-12-11 15:24:05 -0500219 body = client.create_subnet(
Eugene Nikanorove9d255a2013-12-18 16:31:42 +0400220 network_id=network['id'],
221 cidr=str(subnet_cidr),
Sergey Shnaidman18cf5972014-09-02 22:05:00 +0400222 ip_version=ip_version,
223 gateway_ip=gateway_ip,
Sean M. Collinsdd27a4d2014-05-13 10:33:15 -0400224 **kwargs)
Miguel Lavallecc939612013-02-22 17:27:20 -0600225 break
226 except exceptions.BadRequest as e:
227 is_overlapping_cidr = 'overlaps with another subnet' in str(e)
228 if not is_overlapping_cidr:
229 raise
Matthew Treinish6b8cd2a2014-03-03 20:45:56 +0000230 else:
231 message = 'Available CIDR for subnet creation could not be found'
232 raise exceptions.BuildErrorException(message)
Miguel Lavallecc939612013-02-22 17:27:20 -0600233 subnet = body['subnet']
234 cls.subnets.append(subnet)
235 return subnet
raiesmh08e1aad982013-08-05 14:19:36 +0530236
237 @classmethod
Dane LeBlanccbc4bc52014-03-19 16:03:23 -0400238 def create_port(cls, network, **kwargs):
raiesmh08e1aad982013-08-05 14:19:36 +0530239 """Wrapper utility that returns a test port."""
David Kranz34e88122014-12-11 15:24:05 -0500240 body = cls.client.create_port(network_id=network['id'],
241 **kwargs)
raiesmh08e1aad982013-08-05 14:19:36 +0530242 port = body['port']
243 cls.ports.append(port)
244 return port
raiesmh080fe76852013-09-13 11:52:56 +0530245
246 @classmethod
Dane LeBlanccbc4bc52014-03-19 16:03:23 -0400247 def update_port(cls, port, **kwargs):
248 """Wrapper utility that updates a test port."""
David Kranz34e88122014-12-11 15:24:05 -0500249 body = cls.client.update_port(port['id'],
250 **kwargs)
Dane LeBlanccbc4bc52014-03-19 16:03:23 -0400251 return body['port']
252
253 @classmethod
Salvatore Orlandoa85e8fe2013-09-20 03:48:02 -0700254 def create_router(cls, router_name=None, admin_state_up=False,
255 external_network_id=None, enable_snat=None):
256 ext_gw_info = {}
257 if external_network_id:
258 ext_gw_info['network_id'] = external_network_id
259 if enable_snat:
260 ext_gw_info['enable_snat'] = enable_snat
David Kranz34e88122014-12-11 15:24:05 -0500261 body = cls.client.create_router(
Salvatore Orlandoa85e8fe2013-09-20 03:48:02 -0700262 router_name, external_gateway_info=ext_gw_info,
263 admin_state_up=admin_state_up)
264 router = body['router']
265 cls.routers.append(router)
266 return router
267
268 @classmethod
Ann Kamyshnikova47a4ff82014-03-17 12:48:57 +0400269 def create_floatingip(cls, external_network_id):
rosselladd68b232013-11-13 10:21:59 +0100270 """Wrapper utility that returns a test floating IP."""
David Kranz34e88122014-12-11 15:24:05 -0500271 body = cls.client.create_floatingip(
Ann Kamyshnikova47a4ff82014-03-17 12:48:57 +0400272 floating_network_id=external_network_id)
rosselladd68b232013-11-13 10:21:59 +0100273 fip = body['floatingip']
274 cls.floating_ips.append(fip)
275 return fip
276
277 @classmethod
raiesmh080fe76852013-09-13 11:52:56 +0530278 def create_pool(cls, name, lb_method, protocol, subnet):
279 """Wrapper utility that returns a test pool."""
David Kranz34e88122014-12-11 15:24:05 -0500280 body = cls.client.create_pool(
Eugene Nikanorov431e04a2013-12-17 15:44:27 +0400281 name=name,
282 lb_method=lb_method,
283 protocol=protocol,
284 subnet_id=subnet['id'])
raiesmh080fe76852013-09-13 11:52:56 +0530285 pool = body['pool']
286 cls.pools.append(pool)
287 return pool
288
289 @classmethod
Eugene Nikanorov431e04a2013-12-17 15:44:27 +0400290 def update_pool(cls, name):
291 """Wrapper utility that returns a test pool."""
David Kranz34e88122014-12-11 15:24:05 -0500292 body = cls.client.update_pool(name=name)
Eugene Nikanorov431e04a2013-12-17 15:44:27 +0400293 pool = body['pool']
294 return pool
295
296 @classmethod
raiesmh080fe76852013-09-13 11:52:56 +0530297 def create_vip(cls, name, protocol, protocol_port, subnet, pool):
298 """Wrapper utility that returns a test vip."""
David Kranz34e88122014-12-11 15:24:05 -0500299 body = cls.client.create_vip(name=name,
300 protocol=protocol,
301 protocol_port=protocol_port,
302 subnet_id=subnet['id'],
303 pool_id=pool['id'])
raiesmh080fe76852013-09-13 11:52:56 +0530304 vip = body['vip']
305 cls.vips.append(vip)
306 return vip
raiesmh08f8437ed2013-09-17 10:59:38 +0530307
308 @classmethod
Elena Ezhova43c70a22014-01-14 12:42:51 +0400309 def update_vip(cls, name):
David Kranz34e88122014-12-11 15:24:05 -0500310 body = cls.client.update_vip(name=name)
Elena Ezhova43c70a22014-01-14 12:42:51 +0400311 vip = body['vip']
312 return vip
313
314 @classmethod
Sergey Shnaidman97e6a0f2014-11-12 20:00:53 +0300315 def create_member(cls, protocol_port, pool, ip_version=None):
raiesmh08f8437ed2013-09-17 10:59:38 +0530316 """Wrapper utility that returns a test member."""
Sergey Shnaidman97e6a0f2014-11-12 20:00:53 +0300317 ip_version = ip_version if ip_version is not None else cls._ip_version
318 member_address = "fd00::abcd" if ip_version == 6 else "10.0.9.46"
David Kranz34e88122014-12-11 15:24:05 -0500319 body = cls.client.create_member(address=member_address,
320 protocol_port=protocol_port,
321 pool_id=pool['id'])
raiesmh08f8437ed2013-09-17 10:59:38 +0530322 member = body['member']
323 cls.members.append(member)
324 return member
raiesmh0832580d02013-09-17 13:11:34 +0530325
326 @classmethod
Ann Kamyshnikova2bc1c432013-12-10 17:31:50 +0400327 def update_member(cls, admin_state_up):
David Kranz34e88122014-12-11 15:24:05 -0500328 body = cls.client.update_member(admin_state_up=admin_state_up)
Ann Kamyshnikova2bc1c432013-12-10 17:31:50 +0400329 member = body['member']
330 return member
331
332 @classmethod
raiesmh0832580d02013-09-17 13:11:34 +0530333 def create_health_monitor(cls, delay, max_retries, Type, timeout):
334 """Wrapper utility that returns a test health monitor."""
David Kranz34e88122014-12-11 15:24:05 -0500335 body = cls.client.create_health_monitor(delay=delay,
336 max_retries=max_retries,
337 type=Type,
338 timeout=timeout)
raiesmh0832580d02013-09-17 13:11:34 +0530339 health_monitor = body['health_monitor']
340 cls.health_monitors.append(health_monitor)
341 return health_monitor
Anju Tiwari860097d2013-10-17 11:10:39 +0530342
343 @classmethod
Elena Ezhova43c70a22014-01-14 12:42:51 +0400344 def update_health_monitor(cls, admin_state_up):
David Kranz34e88122014-12-11 15:24:05 -0500345 body = cls.client.update_vip(admin_state_up=admin_state_up)
Elena Ezhova43c70a22014-01-14 12:42:51 +0400346 health_monitor = body['health_monitor']
347 return health_monitor
348
349 @classmethod
Anju Tiwari860097d2013-10-17 11:10:39 +0530350 def create_router_interface(cls, router_id, subnet_id):
351 """Wrapper utility that returns a router interface."""
David Kranz34e88122014-12-11 15:24:05 -0500352 interface = cls.client.add_router_interface_with_subnet_id(
Anju Tiwari860097d2013-10-17 11:10:39 +0530353 router_id, subnet_id)
wanglianmin5e4b47a2014-03-12 18:16:18 +0800354 return interface
Anju Tiwari860097d2013-10-17 11:10:39 +0530355
356 @classmethod
357 def create_vpnservice(cls, subnet_id, router_id):
358 """Wrapper utility that returns a test vpn service."""
David Kranz34e88122014-12-11 15:24:05 -0500359 body = cls.client.create_vpnservice(
Eugene Nikanorovf7e2fa42014-04-17 00:05:36 +0400360 subnet_id=subnet_id, router_id=router_id, admin_state_up=True,
Masayuki Igawa259c1132013-10-31 17:48:44 +0900361 name=data_utils.rand_name("vpnservice-"))
Anju Tiwari860097d2013-10-17 11:10:39 +0530362 vpnservice = body['vpnservice']
363 cls.vpnservices.append(vpnservice)
364 return vpnservice
Salvatore Orlandoce22b492013-09-20 04:04:11 -0700365
raiesmh08bd6070d2013-12-06 15:13:38 +0530366 @classmethod
Eugene Nikanorov909ded12013-12-15 17:45:37 +0400367 def create_ikepolicy(cls, name):
raiesmh08bd6070d2013-12-06 15:13:38 +0530368 """Wrapper utility that returns a test ike policy."""
David Kranz34e88122014-12-11 15:24:05 -0500369 body = cls.client.create_ikepolicy(name=name)
raiesmh08bd6070d2013-12-06 15:13:38 +0530370 ikepolicy = body['ikepolicy']
371 cls.ikepolicies.append(ikepolicy)
372 return ikepolicy
373
Mh Raies96594fc2014-03-26 16:34:18 +0530374 @classmethod
375 def create_firewall_rule(cls, action, protocol):
376 """Wrapper utility that returns a test firewall rule."""
David Kranz34e88122014-12-11 15:24:05 -0500377 body = cls.client.create_firewall_rule(
Mh Raies96594fc2014-03-26 16:34:18 +0530378 name=data_utils.rand_name("fw-rule"),
379 action=action,
380 protocol=protocol)
381 fw_rule = body['firewall_rule']
382 cls.fw_rules.append(fw_rule)
383 return fw_rule
384
385 @classmethod
386 def create_firewall_policy(cls):
387 """Wrapper utility that returns a test firewall policy."""
David Kranz34e88122014-12-11 15:24:05 -0500388 body = cls.client.create_firewall_policy(
Mh Raies96594fc2014-03-26 16:34:18 +0530389 name=data_utils.rand_name("fw-policy"))
390 fw_policy = body['firewall_policy']
391 cls.fw_policies.append(fw_policy)
392 return fw_policy
393
Adam Gandelman3e9d12b2014-04-02 17:04:19 -0700394 @classmethod
395 def delete_router(cls, router):
David Kranz34e88122014-12-11 15:24:05 -0500396 body = cls.client.list_router_interfaces(router['id'])
Adam Gandelman3e9d12b2014-04-02 17:04:19 -0700397 interfaces = body['ports']
398 for i in interfaces:
Rohan Kanadef37eaef2014-12-26 10:02:04 +0100399 try:
400 cls.client.remove_router_interface_with_subnet_id(
401 router['id'], i['fixed_ips'][0]['subnet_id'])
Masayuki Igawabfa07602015-01-20 18:47:17 +0900402 except lib_exc.NotFound:
Rohan Kanadef37eaef2014-12-26 10:02:04 +0100403 pass
Adam Gandelman3e9d12b2014-04-02 17:04:19 -0700404 cls.client.delete_router(router['id'])
405
raiesmh08df3fac42014-06-02 15:42:18 +0530406 @classmethod
407 def create_ipsecpolicy(cls, name):
408 """Wrapper utility that returns a test ipsec policy."""
David Kranz34e88122014-12-11 15:24:05 -0500409 body = cls.client.create_ipsecpolicy(name=name)
raiesmh08df3fac42014-06-02 15:42:18 +0530410 ipsecpolicy = body['ipsecpolicy']
411 cls.ipsecpolicies.append(ipsecpolicy)
412 return ipsecpolicy
413
Salvatore Orlandoce22b492013-09-20 04:04:11 -0700414
415class BaseAdminNetworkTest(BaseNetworkTest):
416
417 @classmethod
Andrea Frittolida4a2452014-09-15 13:12:08 +0100418 def resource_setup(cls):
419 super(BaseAdminNetworkTest, cls).resource_setup()
Andrea Frittoli8283b4e2014-07-17 13:28:58 +0100420
421 try:
422 creds = cls.isolated_creds.get_admin_creds()
Andrea Frittolic0978352015-02-06 15:57:40 +0000423 cls.os_adm = clients.Manager(credentials=creds)
Andrea Frittoli8283b4e2014-07-17 13:28:58 +0100424 except NotImplementedError:
Salvatore Orlandoce22b492013-09-20 04:04:11 -0700425 msg = ("Missing Administrative Network API credentials "
426 "in configuration.")
427 raise cls.skipException(msg)
Matthew Treinish2f6628c2013-10-21 21:06:27 +0000428 cls.admin_client = cls.os_adm.network_client
Emilien Macchi0d0b7cc2014-01-11 12:30:21 -0500429
430 @classmethod
431 def create_metering_label(cls, name, description):
432 """Wrapper utility that returns a test metering label."""
David Kranz34e88122014-12-11 15:24:05 -0500433 body = cls.admin_client.create_metering_label(
Emilien Macchi0d0b7cc2014-01-11 12:30:21 -0500434 description=description,
435 name=data_utils.rand_name("metering-label"))
436 metering_label = body['metering_label']
437 cls.metering_labels.append(metering_label)
438 return metering_label
439
440 @classmethod
441 def create_metering_label_rule(cls, remote_ip_prefix, direction,
442 metering_label_id):
443 """Wrapper utility that returns a test metering label rule."""
David Kranz34e88122014-12-11 15:24:05 -0500444 body = cls.admin_client.create_metering_label_rule(
Emilien Macchi0d0b7cc2014-01-11 12:30:21 -0500445 remote_ip_prefix=remote_ip_prefix, direction=direction,
446 metering_label_id=metering_label_id)
447 metering_label_rule = body['metering_label_rule']
448 cls.metering_label_rules.append(metering_label_rule)
449 return metering_label_rule