blob: f864f957590b43c1b723f1c226b6c58571a41965 [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
Doug Hellmann583ce2c2015-03-11 14:55:46 +000017from oslo_log import log as logging
Matthew Treinish01472ff2015-02-20 17:26:52 -050018from tempest_lib.common.utils import data_utils
Masayuki Igawabfa07602015-01-20 18:47:17 +090019from tempest_lib import exceptions as lib_exc
Jay Pipesf4dad392012-06-05 16:03:58 -040020
Matthew Treinish03b48df2014-01-29 16:59:49 +000021from tempest import config
Miguel Lavallecc939612013-02-22 17:27:20 -060022from tempest import exceptions
Attila Fazekasdc216422013-01-29 15:12:14 +010023import tempest.test
Jay Pipesf4dad392012-06-05 16:03:58 -040024
Matthew Treinish03b48df2014-01-29 16:59:49 +000025CONF = config.CONF
26
Anju Tiwari860097d2013-10-17 11:10:39 +053027LOG = logging.getLogger(__name__)
28
Jay Pipesf4dad392012-06-05 16:03:58 -040029
Attila Fazekasdc216422013-01-29 15:12:14 +010030class BaseNetworkTest(tempest.test.BaseTestCase):
Jay Pipesf4dad392012-06-05 16:03:58 -040031
Miguel Lavallecc939612013-02-22 17:27:20 -060032 """
Mark McClainf2982e82013-07-06 17:48:03 -040033 Base class for the Neutron tests that use the Tempest Neutron REST client
Miguel Lavallecc939612013-02-22 17:27:20 -060034
Mark McClainf2982e82013-07-06 17:48:03 -040035 Per the Neutron API Guide, API v1.x was removed from the source code tree
Miguel Lavallecc939612013-02-22 17:27:20 -060036 (docs.openstack.org/api/openstack-network/2.0/content/Overview-d1e71.html)
Mark McClainf2982e82013-07-06 17:48:03 -040037 Therefore, v2.x of the Neutron API is assumed. It is also assumed that the
Miguel Lavallecc939612013-02-22 17:27:20 -060038 following options are defined in the [network] section of etc/tempest.conf:
39
40 tenant_network_cidr with a block of cidr's from which smaller blocks
41 can be allocated for tenant networks
42
43 tenant_network_mask_bits with the mask bits to be used to partition the
44 block defined by tenant-network_cidr
Miguel Lavalle2492d782013-06-16 15:04:15 -050045
46 Finally, it is assumed that the following option is defined in the
47 [service_available] section of etc/tempest.conf
48
49 neutron as True
Miguel Lavallecc939612013-02-22 17:27:20 -060050 """
51
Matthew Treinish2f6628c2013-10-21 21:06:27 +000052 force_tenant_isolation = False
Andrea Frittolib21de6c2015-02-06 20:12:38 +000053 credentials = ['primary']
Matthew Treinish2f6628c2013-10-21 21:06:27 +000054
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
Rohan Kanadea565e452015-01-27 14:00:13 +053059 def skip_checks(cls):
60 super(BaseNetworkTest, cls).skip_checks()
Matthew Treinish03b48df2014-01-29 16:59:49 +000061 if not CONF.service_available.neutron:
Mark McClainf2982e82013-07-06 17:48:03 -040062 raise cls.skipException("Neutron support is required")
Sergey Shnaidman97e6a0f2014-11-12 20:00:53 +030063 if cls._ip_version == 6 and not CONF.network_feature_enabled.ipv6:
64 raise cls.skipException("IPv6 Tests are disabled.")
Matthew Treinish2f6628c2013-10-21 21:06:27 +000065
Rohan Kanadea565e452015-01-27 14:00:13 +053066 @classmethod
67 def setup_credentials(cls):
68 # Create no network resources for these test.
69 cls.set_network_resources()
70 super(BaseNetworkTest, cls).setup_credentials()
Rohan Kanadea565e452015-01-27 14:00:13 +053071
72 @classmethod
73 def setup_clients(cls):
74 super(BaseNetworkTest, cls).setup_clients()
75 cls.client = cls.os.network_client
76
77 @classmethod
78 def resource_setup(cls):
79 super(BaseNetworkTest, cls).resource_setup()
Matthew Treinish2f6628c2013-10-21 21:06:27 +000080 cls.network_cfg = CONF.network
Miguel Lavallecc939612013-02-22 17:27:20 -060081 cls.networks = []
82 cls.subnets = []
raiesmh08e1aad982013-08-05 14:19:36 +053083 cls.ports = []
Salvatore Orlandoa85e8fe2013-09-20 03:48:02 -070084 cls.routers = []
raiesmh080fe76852013-09-13 11:52:56 +053085 cls.pools = []
86 cls.vips = []
raiesmh08f8437ed2013-09-17 10:59:38 +053087 cls.members = []
raiesmh0832580d02013-09-17 13:11:34 +053088 cls.health_monitors = []
Anju Tiwari860097d2013-10-17 11:10:39 +053089 cls.vpnservices = []
raiesmh08bd6070d2013-12-06 15:13:38 +053090 cls.ikepolicies = []
rosselladd68b232013-11-13 10:21:59 +010091 cls.floating_ips = []
Emilien Macchi0d0b7cc2014-01-11 12:30:21 -050092 cls.metering_labels = []
93 cls.metering_label_rules = []
Mh Raies96594fc2014-03-26 16:34:18 +053094 cls.fw_rules = []
95 cls.fw_policies = []
raiesmh08df3fac42014-06-02 15:42:18 +053096 cls.ipsecpolicies = []
sridhargaddam510f8962014-09-08 23:37:16 +053097 cls.ethertype = "IPv" + str(cls._ip_version)
Jay Pipesf4dad392012-06-05 16:03:58 -040098
99 @classmethod
Andrea Frittolida4a2452014-09-15 13:12:08 +0100100 def resource_cleanup(cls):
Daniel P. Berrange690c26a2014-07-01 12:51:36 +0100101 if CONF.service_available.neutron:
102 # Clean up ipsec policies
103 for ipsecpolicy in cls.ipsecpolicies:
Yair Fried4f923282014-11-19 10:55:57 +0200104 cls._try_delete_resource(cls.client.delete_ipsecpolicy,
105 ipsecpolicy['id'])
Daniel P. Berrange690c26a2014-07-01 12:51:36 +0100106 # Clean up firewall policies
107 for fw_policy in cls.fw_policies:
Yair Fried4f923282014-11-19 10:55:57 +0200108 cls._try_delete_resource(cls.client.delete_firewall_policy,
109 fw_policy['id'])
Daniel P. Berrange690c26a2014-07-01 12:51:36 +0100110 # Clean up firewall rules
111 for fw_rule in cls.fw_rules:
Yair Fried4f923282014-11-19 10:55:57 +0200112 cls._try_delete_resource(cls.client.delete_firewall_rule,
113 fw_rule['id'])
Daniel P. Berrange690c26a2014-07-01 12:51:36 +0100114 # Clean up ike policies
115 for ikepolicy in cls.ikepolicies:
Yair Fried4f923282014-11-19 10:55:57 +0200116 cls._try_delete_resource(cls.client.delete_ikepolicy,
117 ikepolicy['id'])
Daniel P. Berrange690c26a2014-07-01 12:51:36 +0100118 # Clean up vpn services
119 for vpnservice in cls.vpnservices:
Yair Fried4f923282014-11-19 10:55:57 +0200120 cls._try_delete_resource(cls.client.delete_vpnservice,
121 vpnservice['id'])
Daniel P. Berrange690c26a2014-07-01 12:51:36 +0100122 # Clean up floating IPs
123 for floating_ip in cls.floating_ips:
Yair Fried4f923282014-11-19 10:55:57 +0200124 cls._try_delete_resource(cls.client.delete_floatingip,
125 floating_ip['id'])
Adam Gandelman3e9d12b2014-04-02 17:04:19 -0700126
Daniel P. Berrange690c26a2014-07-01 12:51:36 +0100127 # Clean up health monitors
128 for health_monitor in cls.health_monitors:
Yair Fried4f923282014-11-19 10:55:57 +0200129 cls._try_delete_resource(cls.client.delete_health_monitor,
130 health_monitor['id'])
Daniel P. Berrange690c26a2014-07-01 12:51:36 +0100131 # Clean up members
132 for member in cls.members:
Yair Fried4f923282014-11-19 10:55:57 +0200133 cls._try_delete_resource(cls.client.delete_member,
134 member['id'])
Daniel P. Berrange690c26a2014-07-01 12:51:36 +0100135 # Clean up vips
136 for vip in cls.vips:
Yair Fried4f923282014-11-19 10:55:57 +0200137 cls._try_delete_resource(cls.client.delete_vip,
138 vip['id'])
Daniel P. Berrange690c26a2014-07-01 12:51:36 +0100139 # Clean up pools
140 for pool in cls.pools:
Yair Fried4f923282014-11-19 10:55:57 +0200141 cls._try_delete_resource(cls.client.delete_pool,
142 pool['id'])
Daniel P. Berrange690c26a2014-07-01 12:51:36 +0100143 # Clean up metering label rules
144 for metering_label_rule in cls.metering_label_rules:
Yair Fried4f923282014-11-19 10:55:57 +0200145 cls._try_delete_resource(
146 cls.admin_client.delete_metering_label_rule,
Daniel P. Berrange690c26a2014-07-01 12:51:36 +0100147 metering_label_rule['id'])
148 # Clean up metering labels
149 for metering_label in cls.metering_labels:
Yair Fried4f923282014-11-19 10:55:57 +0200150 cls._try_delete_resource(
151 cls.admin_client.delete_metering_label,
152 metering_label['id'])
Daniel P. Berrange690c26a2014-07-01 12:51:36 +0100153 # Clean up ports
154 for port in cls.ports:
Yair Fried4f923282014-11-19 10:55:57 +0200155 cls._try_delete_resource(cls.client.delete_port,
156 port['id'])
PrinikaSNe46fbd12015-05-29 16:41:30 -0700157 # Clean up routers
158 for router in cls.routers:
159 cls._try_delete_resource(cls.delete_router,
160 router)
Daniel P. Berrange690c26a2014-07-01 12:51:36 +0100161 # Clean up subnets
162 for subnet in cls.subnets:
Yair Fried4f923282014-11-19 10:55:57 +0200163 cls._try_delete_resource(cls.client.delete_subnet,
164 subnet['id'])
Daniel P. Berrange690c26a2014-07-01 12:51:36 +0100165 # Clean up networks
166 for network in cls.networks:
Yair Fried4f923282014-11-19 10:55:57 +0200167 cls._try_delete_resource(cls.client.delete_network,
168 network['id'])
Andrea Frittolida4a2452014-09-15 13:12:08 +0100169 super(BaseNetworkTest, cls).resource_cleanup()
Jay Pipesf4dad392012-06-05 16:03:58 -0400170
Miguel Lavallecc939612013-02-22 17:27:20 -0600171 @classmethod
Yair Fried4f923282014-11-19 10:55:57 +0200172 def _try_delete_resource(self, delete_callable, *args, **kwargs):
173 """Cleanup resources in case of test-failure
174
175 Some resources are explicitly deleted by the test.
176 If the test failed to delete a resource, this method will execute
177 the appropriate delete methods. Otherwise, the method ignores NotFound
178 exceptions thrown for resources that were correctly deleted by the
179 test.
180
181 :param delete_callable: delete method
182 :param args: arguments for delete method
183 :param kwargs: keyword arguments for delete method
184 """
185 try:
186 delete_callable(*args, **kwargs)
187 # if resource is not found, this means it was deleted in the test
Masayuki Igawabfa07602015-01-20 18:47:17 +0900188 except lib_exc.NotFound:
Yair Fried4f923282014-11-19 10:55:57 +0200189 pass
190
191 @classmethod
Miguel Lavallecc939612013-02-22 17:27:20 -0600192 def create_network(cls, network_name=None):
Sean Daguef237ccb2013-01-04 15:19:14 -0500193 """Wrapper utility that returns a test network."""
Masayuki Igawa259c1132013-10-31 17:48:44 +0900194 network_name = network_name or data_utils.rand_name('test-network-')
Jay Pipesf4dad392012-06-05 16:03:58 -0400195
David Kranz34e88122014-12-11 15:24:05 -0500196 body = cls.client.create_network(name=network_name)
Jay Pipesf4dad392012-06-05 16:03:58 -0400197 network = body['network']
Miguel Lavallecc939612013-02-22 17:27:20 -0600198 cls.networks.append(network)
Jay Pipesf4dad392012-06-05 16:03:58 -0400199 return network
Miguel Lavallecc939612013-02-22 17:27:20 -0600200
201 @classmethod
Sergey Shnaidman18cf5972014-09-02 22:05:00 +0400202 def create_subnet(cls, network, gateway='', cidr=None, mask_bits=None,
Yair Fried52ee1362014-09-29 14:47:03 +0300203 ip_version=None, client=None, **kwargs):
Miguel Lavallecc939612013-02-22 17:27:20 -0600204 """Wrapper utility that returns a test subnet."""
Yair Fried52ee1362014-09-29 14:47:03 +0300205
206 # allow tests to use admin client
207 if not client:
208 client = cls.client
209
Henry Gessauffda37a2014-01-16 11:17:55 -0500210 # The cidr and mask_bits depend on the ip version.
Sergey Shnaidman18cf5972014-09-02 22:05:00 +0400211 ip_version = ip_version if ip_version is not None else cls._ip_version
212 gateway_not_set = gateway == ''
213 if ip_version == 4:
armando-migliaccioee90a4d2014-05-06 11:54:07 -0700214 cidr = cidr or netaddr.IPNetwork(CONF.network.tenant_network_cidr)
215 mask_bits = mask_bits or CONF.network.tenant_network_mask_bits
Sergey Shnaidman18cf5972014-09-02 22:05:00 +0400216 elif ip_version == 6:
armando-migliaccioee90a4d2014-05-06 11:54:07 -0700217 cidr = (
218 cidr or netaddr.IPNetwork(CONF.network.tenant_network_v6_cidr))
219 mask_bits = mask_bits or CONF.network.tenant_network_v6_mask_bits
Miguel Lavallecc939612013-02-22 17:27:20 -0600220 # Find a cidr that is not in use yet and create a subnet with it
221 for subnet_cidr in cidr.subnet(mask_bits):
Sergey Shnaidman18cf5972014-09-02 22:05:00 +0400222 if gateway_not_set:
223 gateway_ip = str(netaddr.IPAddress(subnet_cidr) + 1)
224 else:
225 gateway_ip = gateway
Miguel Lavallecc939612013-02-22 17:27:20 -0600226 try:
David Kranz34e88122014-12-11 15:24:05 -0500227 body = client.create_subnet(
Eugene Nikanorove9d255a2013-12-18 16:31:42 +0400228 network_id=network['id'],
229 cidr=str(subnet_cidr),
Sergey Shnaidman18cf5972014-09-02 22:05:00 +0400230 ip_version=ip_version,
231 gateway_ip=gateway_ip,
Sean M. Collinsdd27a4d2014-05-13 10:33:15 -0400232 **kwargs)
Miguel Lavallecc939612013-02-22 17:27:20 -0600233 break
Masayuki Igawa4b29e472015-02-16 10:41:54 +0900234 except lib_exc.BadRequest as e:
Miguel Lavallecc939612013-02-22 17:27:20 -0600235 is_overlapping_cidr = 'overlaps with another subnet' in str(e)
236 if not is_overlapping_cidr:
237 raise
Matthew Treinish6b8cd2a2014-03-03 20:45:56 +0000238 else:
239 message = 'Available CIDR for subnet creation could not be found'
240 raise exceptions.BuildErrorException(message)
Miguel Lavallecc939612013-02-22 17:27:20 -0600241 subnet = body['subnet']
242 cls.subnets.append(subnet)
243 return subnet
raiesmh08e1aad982013-08-05 14:19:36 +0530244
245 @classmethod
Dane LeBlanccbc4bc52014-03-19 16:03:23 -0400246 def create_port(cls, network, **kwargs):
raiesmh08e1aad982013-08-05 14:19:36 +0530247 """Wrapper utility that returns a test port."""
David Kranz34e88122014-12-11 15:24:05 -0500248 body = cls.client.create_port(network_id=network['id'],
249 **kwargs)
raiesmh08e1aad982013-08-05 14:19:36 +0530250 port = body['port']
251 cls.ports.append(port)
252 return port
raiesmh080fe76852013-09-13 11:52:56 +0530253
254 @classmethod
Dane LeBlanccbc4bc52014-03-19 16:03:23 -0400255 def update_port(cls, port, **kwargs):
256 """Wrapper utility that updates a test port."""
David Kranz34e88122014-12-11 15:24:05 -0500257 body = cls.client.update_port(port['id'],
258 **kwargs)
Dane LeBlanccbc4bc52014-03-19 16:03:23 -0400259 return body['port']
260
261 @classmethod
Salvatore Orlandoa85e8fe2013-09-20 03:48:02 -0700262 def create_router(cls, router_name=None, admin_state_up=False,
armando-migliaccio88f7b702014-06-05 12:59:09 -0700263 external_network_id=None, enable_snat=None,
264 **kwargs):
Salvatore Orlandoa85e8fe2013-09-20 03:48:02 -0700265 ext_gw_info = {}
266 if external_network_id:
267 ext_gw_info['network_id'] = external_network_id
268 if enable_snat:
269 ext_gw_info['enable_snat'] = enable_snat
David Kranz34e88122014-12-11 15:24:05 -0500270 body = cls.client.create_router(
Salvatore Orlandoa85e8fe2013-09-20 03:48:02 -0700271 router_name, external_gateway_info=ext_gw_info,
armando-migliaccio88f7b702014-06-05 12:59:09 -0700272 admin_state_up=admin_state_up, **kwargs)
Salvatore Orlandoa85e8fe2013-09-20 03:48:02 -0700273 router = body['router']
274 cls.routers.append(router)
275 return router
276
277 @classmethod
Ann Kamyshnikova47a4ff82014-03-17 12:48:57 +0400278 def create_floatingip(cls, external_network_id):
rosselladd68b232013-11-13 10:21:59 +0100279 """Wrapper utility that returns a test floating IP."""
David Kranz34e88122014-12-11 15:24:05 -0500280 body = cls.client.create_floatingip(
Ann Kamyshnikova47a4ff82014-03-17 12:48:57 +0400281 floating_network_id=external_network_id)
rosselladd68b232013-11-13 10:21:59 +0100282 fip = body['floatingip']
283 cls.floating_ips.append(fip)
284 return fip
285
286 @classmethod
raiesmh080fe76852013-09-13 11:52:56 +0530287 def create_pool(cls, name, lb_method, protocol, subnet):
288 """Wrapper utility that returns a test pool."""
David Kranz34e88122014-12-11 15:24:05 -0500289 body = cls.client.create_pool(
Eugene Nikanorov431e04a2013-12-17 15:44:27 +0400290 name=name,
291 lb_method=lb_method,
292 protocol=protocol,
293 subnet_id=subnet['id'])
raiesmh080fe76852013-09-13 11:52:56 +0530294 pool = body['pool']
295 cls.pools.append(pool)
296 return pool
297
298 @classmethod
Eugene Nikanorov431e04a2013-12-17 15:44:27 +0400299 def update_pool(cls, name):
300 """Wrapper utility that returns a test pool."""
David Kranz34e88122014-12-11 15:24:05 -0500301 body = cls.client.update_pool(name=name)
Eugene Nikanorov431e04a2013-12-17 15:44:27 +0400302 pool = body['pool']
303 return pool
304
305 @classmethod
raiesmh080fe76852013-09-13 11:52:56 +0530306 def create_vip(cls, name, protocol, protocol_port, subnet, pool):
307 """Wrapper utility that returns a test vip."""
David Kranz34e88122014-12-11 15:24:05 -0500308 body = cls.client.create_vip(name=name,
309 protocol=protocol,
310 protocol_port=protocol_port,
311 subnet_id=subnet['id'],
312 pool_id=pool['id'])
raiesmh080fe76852013-09-13 11:52:56 +0530313 vip = body['vip']
314 cls.vips.append(vip)
315 return vip
raiesmh08f8437ed2013-09-17 10:59:38 +0530316
317 @classmethod
Elena Ezhova43c70a22014-01-14 12:42:51 +0400318 def update_vip(cls, name):
David Kranz34e88122014-12-11 15:24:05 -0500319 body = cls.client.update_vip(name=name)
Elena Ezhova43c70a22014-01-14 12:42:51 +0400320 vip = body['vip']
321 return vip
322
323 @classmethod
Sergey Shnaidman97e6a0f2014-11-12 20:00:53 +0300324 def create_member(cls, protocol_port, pool, ip_version=None):
raiesmh08f8437ed2013-09-17 10:59:38 +0530325 """Wrapper utility that returns a test member."""
Sergey Shnaidman97e6a0f2014-11-12 20:00:53 +0300326 ip_version = ip_version if ip_version is not None else cls._ip_version
327 member_address = "fd00::abcd" if ip_version == 6 else "10.0.9.46"
David Kranz34e88122014-12-11 15:24:05 -0500328 body = cls.client.create_member(address=member_address,
329 protocol_port=protocol_port,
330 pool_id=pool['id'])
raiesmh08f8437ed2013-09-17 10:59:38 +0530331 member = body['member']
332 cls.members.append(member)
333 return member
raiesmh0832580d02013-09-17 13:11:34 +0530334
335 @classmethod
Ann Kamyshnikova2bc1c432013-12-10 17:31:50 +0400336 def update_member(cls, admin_state_up):
David Kranz34e88122014-12-11 15:24:05 -0500337 body = cls.client.update_member(admin_state_up=admin_state_up)
Ann Kamyshnikova2bc1c432013-12-10 17:31:50 +0400338 member = body['member']
339 return member
340
341 @classmethod
raiesmh0832580d02013-09-17 13:11:34 +0530342 def create_health_monitor(cls, delay, max_retries, Type, timeout):
343 """Wrapper utility that returns a test health monitor."""
David Kranz34e88122014-12-11 15:24:05 -0500344 body = cls.client.create_health_monitor(delay=delay,
345 max_retries=max_retries,
346 type=Type,
347 timeout=timeout)
raiesmh0832580d02013-09-17 13:11:34 +0530348 health_monitor = body['health_monitor']
349 cls.health_monitors.append(health_monitor)
350 return health_monitor
Anju Tiwari860097d2013-10-17 11:10:39 +0530351
352 @classmethod
Elena Ezhova43c70a22014-01-14 12:42:51 +0400353 def update_health_monitor(cls, admin_state_up):
David Kranz34e88122014-12-11 15:24:05 -0500354 body = cls.client.update_vip(admin_state_up=admin_state_up)
Elena Ezhova43c70a22014-01-14 12:42:51 +0400355 health_monitor = body['health_monitor']
356 return health_monitor
357
358 @classmethod
Anju Tiwari860097d2013-10-17 11:10:39 +0530359 def create_router_interface(cls, router_id, subnet_id):
360 """Wrapper utility that returns a router interface."""
David Kranz34e88122014-12-11 15:24:05 -0500361 interface = cls.client.add_router_interface_with_subnet_id(
Anju Tiwari860097d2013-10-17 11:10:39 +0530362 router_id, subnet_id)
wanglianmin5e4b47a2014-03-12 18:16:18 +0800363 return interface
Anju Tiwari860097d2013-10-17 11:10:39 +0530364
365 @classmethod
366 def create_vpnservice(cls, subnet_id, router_id):
367 """Wrapper utility that returns a test vpn service."""
David Kranz34e88122014-12-11 15:24:05 -0500368 body = cls.client.create_vpnservice(
Eugene Nikanorovf7e2fa42014-04-17 00:05:36 +0400369 subnet_id=subnet_id, router_id=router_id, admin_state_up=True,
Masayuki Igawa259c1132013-10-31 17:48:44 +0900370 name=data_utils.rand_name("vpnservice-"))
Anju Tiwari860097d2013-10-17 11:10:39 +0530371 vpnservice = body['vpnservice']
372 cls.vpnservices.append(vpnservice)
373 return vpnservice
Salvatore Orlandoce22b492013-09-20 04:04:11 -0700374
raiesmh08bd6070d2013-12-06 15:13:38 +0530375 @classmethod
Eugene Nikanorov909ded12013-12-15 17:45:37 +0400376 def create_ikepolicy(cls, name):
raiesmh08bd6070d2013-12-06 15:13:38 +0530377 """Wrapper utility that returns a test ike policy."""
David Kranz34e88122014-12-11 15:24:05 -0500378 body = cls.client.create_ikepolicy(name=name)
raiesmh08bd6070d2013-12-06 15:13:38 +0530379 ikepolicy = body['ikepolicy']
380 cls.ikepolicies.append(ikepolicy)
381 return ikepolicy
382
Mh Raies96594fc2014-03-26 16:34:18 +0530383 @classmethod
384 def create_firewall_rule(cls, action, protocol):
385 """Wrapper utility that returns a test firewall rule."""
David Kranz34e88122014-12-11 15:24:05 -0500386 body = cls.client.create_firewall_rule(
Mh Raies96594fc2014-03-26 16:34:18 +0530387 name=data_utils.rand_name("fw-rule"),
388 action=action,
389 protocol=protocol)
390 fw_rule = body['firewall_rule']
391 cls.fw_rules.append(fw_rule)
392 return fw_rule
393
394 @classmethod
395 def create_firewall_policy(cls):
396 """Wrapper utility that returns a test firewall policy."""
David Kranz34e88122014-12-11 15:24:05 -0500397 body = cls.client.create_firewall_policy(
Mh Raies96594fc2014-03-26 16:34:18 +0530398 name=data_utils.rand_name("fw-policy"))
399 fw_policy = body['firewall_policy']
400 cls.fw_policies.append(fw_policy)
401 return fw_policy
402
Adam Gandelman3e9d12b2014-04-02 17:04:19 -0700403 @classmethod
404 def delete_router(cls, router):
David Kranz34e88122014-12-11 15:24:05 -0500405 body = cls.client.list_router_interfaces(router['id'])
Adam Gandelman3e9d12b2014-04-02 17:04:19 -0700406 interfaces = body['ports']
407 for i in interfaces:
Rohan Kanadef37eaef2014-12-26 10:02:04 +0100408 try:
409 cls.client.remove_router_interface_with_subnet_id(
410 router['id'], i['fixed_ips'][0]['subnet_id'])
Masayuki Igawabfa07602015-01-20 18:47:17 +0900411 except lib_exc.NotFound:
Rohan Kanadef37eaef2014-12-26 10:02:04 +0100412 pass
Adam Gandelman3e9d12b2014-04-02 17:04:19 -0700413 cls.client.delete_router(router['id'])
414
raiesmh08df3fac42014-06-02 15:42:18 +0530415 @classmethod
416 def create_ipsecpolicy(cls, name):
417 """Wrapper utility that returns a test ipsec policy."""
David Kranz34e88122014-12-11 15:24:05 -0500418 body = cls.client.create_ipsecpolicy(name=name)
raiesmh08df3fac42014-06-02 15:42:18 +0530419 ipsecpolicy = body['ipsecpolicy']
420 cls.ipsecpolicies.append(ipsecpolicy)
421 return ipsecpolicy
422
Salvatore Orlandoce22b492013-09-20 04:04:11 -0700423
424class BaseAdminNetworkTest(BaseNetworkTest):
425
Andrea Frittolib21de6c2015-02-06 20:12:38 +0000426 credentials = ['primary', 'admin']
Rohan Kanadea565e452015-01-27 14:00:13 +0530427
428 @classmethod
429 def setup_clients(cls):
430 super(BaseAdminNetworkTest, cls).setup_clients()
Matthew Treinish2f6628c2013-10-21 21:06:27 +0000431 cls.admin_client = cls.os_adm.network_client
Emilien Macchi0d0b7cc2014-01-11 12:30:21 -0500432
433 @classmethod
434 def create_metering_label(cls, name, description):
435 """Wrapper utility that returns a test metering label."""
David Kranz34e88122014-12-11 15:24:05 -0500436 body = cls.admin_client.create_metering_label(
Emilien Macchi0d0b7cc2014-01-11 12:30:21 -0500437 description=description,
438 name=data_utils.rand_name("metering-label"))
439 metering_label = body['metering_label']
440 cls.metering_labels.append(metering_label)
441 return metering_label
442
443 @classmethod
444 def create_metering_label_rule(cls, remote_ip_prefix, direction,
445 metering_label_id):
446 """Wrapper utility that returns a test metering label rule."""
David Kranz34e88122014-12-11 15:24:05 -0500447 body = cls.admin_client.create_metering_label_rule(
Emilien Macchi0d0b7cc2014-01-11 12:30:21 -0500448 remote_ip_prefix=remote_ip_prefix, direction=direction,
449 metering_label_id=metering_label_id)
450 metering_label_rule = body['metering_label_rule']
451 cls.metering_label_rules.append(metering_label_rule)
452 return metering_label_rule