blob: 09a5555d29901facb8ff63132694ed3f4c9609b2 [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 Treinish481466b2012-12-20 17:16:01 -050021from tempest import clients
Rohan Kanadea565e452015-01-27 14:00:13 +053022from tempest.common import credentials
Matthew Treinish03b48df2014-01-29 16:59:49 +000023from tempest import config
Miguel Lavallecc939612013-02-22 17:27:20 -060024from tempest import exceptions
Attila Fazekasdc216422013-01-29 15:12:14 +010025import tempest.test
Jay Pipesf4dad392012-06-05 16:03:58 -040026
Matthew Treinish03b48df2014-01-29 16:59:49 +000027CONF = config.CONF
28
Anju Tiwari860097d2013-10-17 11:10:39 +053029LOG = logging.getLogger(__name__)
30
Jay Pipesf4dad392012-06-05 16:03:58 -040031
Attila Fazekasdc216422013-01-29 15:12:14 +010032class BaseNetworkTest(tempest.test.BaseTestCase):
Jay Pipesf4dad392012-06-05 16:03:58 -040033
Miguel Lavallecc939612013-02-22 17:27:20 -060034 """
Mark McClainf2982e82013-07-06 17:48:03 -040035 Base class for the Neutron tests that use the Tempest Neutron REST client
Miguel Lavallecc939612013-02-22 17:27:20 -060036
Mark McClainf2982e82013-07-06 17:48:03 -040037 Per the Neutron API Guide, API v1.x was removed from the source code tree
Miguel Lavallecc939612013-02-22 17:27:20 -060038 (docs.openstack.org/api/openstack-network/2.0/content/Overview-d1e71.html)
Mark McClainf2982e82013-07-06 17:48:03 -040039 Therefore, v2.x of the Neutron API is assumed. It is also assumed that the
Miguel Lavallecc939612013-02-22 17:27:20 -060040 following options are defined in the [network] section of etc/tempest.conf:
41
42 tenant_network_cidr with a block of cidr's from which smaller blocks
43 can be allocated for tenant networks
44
45 tenant_network_mask_bits with the mask bits to be used to partition the
46 block defined by tenant-network_cidr
Miguel Lavalle2492d782013-06-16 15:04:15 -050047
48 Finally, it is assumed that the following option is defined in the
49 [service_available] section of etc/tempest.conf
50
51 neutron as True
Miguel Lavallecc939612013-02-22 17:27:20 -060052 """
53
Matthew Treinish2f6628c2013-10-21 21:06:27 +000054 force_tenant_isolation = False
55
Henry Gessauffda37a2014-01-16 11:17:55 -050056 # Default to ipv4.
57 _ip_version = 4
Henry Gessauffda37a2014-01-16 11:17:55 -050058
Jay Pipesf4dad392012-06-05 16:03:58 -040059 @classmethod
Rohan Kanadea565e452015-01-27 14:00:13 +053060 def skip_checks(cls):
61 super(BaseNetworkTest, cls).skip_checks()
Matthew Treinish03b48df2014-01-29 16:59:49 +000062 if not CONF.service_available.neutron:
Mark McClainf2982e82013-07-06 17:48:03 -040063 raise cls.skipException("Neutron support is required")
Sergey Shnaidman97e6a0f2014-11-12 20:00:53 +030064 if cls._ip_version == 6 and not CONF.network_feature_enabled.ipv6:
65 raise cls.skipException("IPv6 Tests are disabled.")
Matthew Treinish2f6628c2013-10-21 21:06:27 +000066
Rohan Kanadea565e452015-01-27 14:00:13 +053067 @classmethod
68 def setup_credentials(cls):
69 # Create no network resources for these test.
70 cls.set_network_resources()
71 super(BaseNetworkTest, cls).setup_credentials()
72 cls.os = cls.get_client_manager()
73
74 @classmethod
75 def setup_clients(cls):
76 super(BaseNetworkTest, cls).setup_clients()
77 cls.client = cls.os.network_client
78
79 @classmethod
80 def resource_setup(cls):
81 super(BaseNetworkTest, cls).resource_setup()
Matthew Treinish2f6628c2013-10-21 21:06:27 +000082
83 cls.network_cfg = CONF.network
Miguel Lavallecc939612013-02-22 17:27:20 -060084 cls.networks = []
85 cls.subnets = []
raiesmh08e1aad982013-08-05 14:19:36 +053086 cls.ports = []
Salvatore Orlandoa85e8fe2013-09-20 03:48:02 -070087 cls.routers = []
raiesmh080fe76852013-09-13 11:52:56 +053088 cls.pools = []
89 cls.vips = []
raiesmh08f8437ed2013-09-17 10:59:38 +053090 cls.members = []
raiesmh0832580d02013-09-17 13:11:34 +053091 cls.health_monitors = []
Anju Tiwari860097d2013-10-17 11:10:39 +053092 cls.vpnservices = []
raiesmh08bd6070d2013-12-06 15:13:38 +053093 cls.ikepolicies = []
rosselladd68b232013-11-13 10:21:59 +010094 cls.floating_ips = []
Emilien Macchi0d0b7cc2014-01-11 12:30:21 -050095 cls.metering_labels = []
96 cls.metering_label_rules = []
Mh Raies96594fc2014-03-26 16:34:18 +053097 cls.fw_rules = []
98 cls.fw_policies = []
raiesmh08df3fac42014-06-02 15:42:18 +053099 cls.ipsecpolicies = []
sridhargaddam510f8962014-09-08 23:37:16 +0530100 cls.ethertype = "IPv" + str(cls._ip_version)
Jay Pipesf4dad392012-06-05 16:03:58 -0400101
102 @classmethod
Andrea Frittolida4a2452014-09-15 13:12:08 +0100103 def resource_cleanup(cls):
Daniel P. Berrange690c26a2014-07-01 12:51:36 +0100104 if CONF.service_available.neutron:
105 # Clean up ipsec policies
106 for ipsecpolicy in cls.ipsecpolicies:
Yair Fried4f923282014-11-19 10:55:57 +0200107 cls._try_delete_resource(cls.client.delete_ipsecpolicy,
108 ipsecpolicy['id'])
Daniel P. Berrange690c26a2014-07-01 12:51:36 +0100109 # Clean up firewall policies
110 for fw_policy in cls.fw_policies:
Yair Fried4f923282014-11-19 10:55:57 +0200111 cls._try_delete_resource(cls.client.delete_firewall_policy,
112 fw_policy['id'])
Daniel P. Berrange690c26a2014-07-01 12:51:36 +0100113 # Clean up firewall rules
114 for fw_rule in cls.fw_rules:
Yair Fried4f923282014-11-19 10:55:57 +0200115 cls._try_delete_resource(cls.client.delete_firewall_rule,
116 fw_rule['id'])
Daniel P. Berrange690c26a2014-07-01 12:51:36 +0100117 # Clean up ike policies
118 for ikepolicy in cls.ikepolicies:
Yair Fried4f923282014-11-19 10:55:57 +0200119 cls._try_delete_resource(cls.client.delete_ikepolicy,
120 ikepolicy['id'])
Daniel P. Berrange690c26a2014-07-01 12:51:36 +0100121 # Clean up vpn services
122 for vpnservice in cls.vpnservices:
Yair Fried4f923282014-11-19 10:55:57 +0200123 cls._try_delete_resource(cls.client.delete_vpnservice,
124 vpnservice['id'])
Daniel P. Berrange690c26a2014-07-01 12:51:36 +0100125 # Clean up floating IPs
126 for floating_ip in cls.floating_ips:
Yair Fried4f923282014-11-19 10:55:57 +0200127 cls._try_delete_resource(cls.client.delete_floatingip,
128 floating_ip['id'])
Daniel P. Berrange690c26a2014-07-01 12:51:36 +0100129 # Clean up routers
130 for router in cls.routers:
Yair Fried4f923282014-11-19 10:55:57 +0200131 cls._try_delete_resource(cls.delete_router,
132 router)
Adam Gandelman3e9d12b2014-04-02 17:04:19 -0700133
Daniel P. Berrange690c26a2014-07-01 12:51:36 +0100134 # Clean up health monitors
135 for health_monitor in cls.health_monitors:
Yair Fried4f923282014-11-19 10:55:57 +0200136 cls._try_delete_resource(cls.client.delete_health_monitor,
137 health_monitor['id'])
Daniel P. Berrange690c26a2014-07-01 12:51:36 +0100138 # Clean up members
139 for member in cls.members:
Yair Fried4f923282014-11-19 10:55:57 +0200140 cls._try_delete_resource(cls.client.delete_member,
141 member['id'])
Daniel P. Berrange690c26a2014-07-01 12:51:36 +0100142 # Clean up vips
143 for vip in cls.vips:
Yair Fried4f923282014-11-19 10:55:57 +0200144 cls._try_delete_resource(cls.client.delete_vip,
145 vip['id'])
Daniel P. Berrange690c26a2014-07-01 12:51:36 +0100146 # Clean up pools
147 for pool in cls.pools:
Yair Fried4f923282014-11-19 10:55:57 +0200148 cls._try_delete_resource(cls.client.delete_pool,
149 pool['id'])
Daniel P. Berrange690c26a2014-07-01 12:51:36 +0100150 # Clean up metering label rules
151 for metering_label_rule in cls.metering_label_rules:
Yair Fried4f923282014-11-19 10:55:57 +0200152 cls._try_delete_resource(
153 cls.admin_client.delete_metering_label_rule,
Daniel P. Berrange690c26a2014-07-01 12:51:36 +0100154 metering_label_rule['id'])
155 # Clean up metering labels
156 for metering_label in cls.metering_labels:
Yair Fried4f923282014-11-19 10:55:57 +0200157 cls._try_delete_resource(
158 cls.admin_client.delete_metering_label,
159 metering_label['id'])
Daniel P. Berrange690c26a2014-07-01 12:51:36 +0100160 # Clean up ports
161 for port in cls.ports:
Yair Fried4f923282014-11-19 10:55:57 +0200162 cls._try_delete_resource(cls.client.delete_port,
163 port['id'])
Daniel P. Berrange690c26a2014-07-01 12:51:36 +0100164 # Clean up subnets
165 for subnet in cls.subnets:
Yair Fried4f923282014-11-19 10:55:57 +0200166 cls._try_delete_resource(cls.client.delete_subnet,
167 subnet['id'])
Daniel P. Berrange690c26a2014-07-01 12:51:36 +0100168 # Clean up networks
169 for network in cls.networks:
Yair Fried4f923282014-11-19 10:55:57 +0200170 cls._try_delete_resource(cls.client.delete_network,
171 network['id'])
Andrea Frittolida4a2452014-09-15 13:12:08 +0100172 super(BaseNetworkTest, cls).resource_cleanup()
Jay Pipesf4dad392012-06-05 16:03:58 -0400173
Miguel Lavallecc939612013-02-22 17:27:20 -0600174 @classmethod
Yair Fried4f923282014-11-19 10:55:57 +0200175 def _try_delete_resource(self, delete_callable, *args, **kwargs):
176 """Cleanup resources in case of test-failure
177
178 Some resources are explicitly deleted by the test.
179 If the test failed to delete a resource, this method will execute
180 the appropriate delete methods. Otherwise, the method ignores NotFound
181 exceptions thrown for resources that were correctly deleted by the
182 test.
183
184 :param delete_callable: delete method
185 :param args: arguments for delete method
186 :param kwargs: keyword arguments for delete method
187 """
188 try:
189 delete_callable(*args, **kwargs)
190 # if resource is not found, this means it was deleted in the test
Masayuki Igawabfa07602015-01-20 18:47:17 +0900191 except lib_exc.NotFound:
Yair Fried4f923282014-11-19 10:55:57 +0200192 pass
193
194 @classmethod
Miguel Lavallecc939612013-02-22 17:27:20 -0600195 def create_network(cls, network_name=None):
Sean Daguef237ccb2013-01-04 15:19:14 -0500196 """Wrapper utility that returns a test network."""
Masayuki Igawa259c1132013-10-31 17:48:44 +0900197 network_name = network_name or data_utils.rand_name('test-network-')
Jay Pipesf4dad392012-06-05 16:03:58 -0400198
David Kranz34e88122014-12-11 15:24:05 -0500199 body = cls.client.create_network(name=network_name)
Jay Pipesf4dad392012-06-05 16:03:58 -0400200 network = body['network']
Miguel Lavallecc939612013-02-22 17:27:20 -0600201 cls.networks.append(network)
Jay Pipesf4dad392012-06-05 16:03:58 -0400202 return network
Miguel Lavallecc939612013-02-22 17:27:20 -0600203
204 @classmethod
Sergey Shnaidman18cf5972014-09-02 22:05:00 +0400205 def create_subnet(cls, network, gateway='', cidr=None, mask_bits=None,
Yair Fried52ee1362014-09-29 14:47:03 +0300206 ip_version=None, client=None, **kwargs):
Miguel Lavallecc939612013-02-22 17:27:20 -0600207 """Wrapper utility that returns a test subnet."""
Yair Fried52ee1362014-09-29 14:47:03 +0300208
209 # allow tests to use admin client
210 if not client:
211 client = cls.client
212
Henry Gessauffda37a2014-01-16 11:17:55 -0500213 # The cidr and mask_bits depend on the ip version.
Sergey Shnaidman18cf5972014-09-02 22:05:00 +0400214 ip_version = ip_version if ip_version is not None else cls._ip_version
215 gateway_not_set = gateway == ''
216 if ip_version == 4:
armando-migliaccioee90a4d2014-05-06 11:54:07 -0700217 cidr = cidr or netaddr.IPNetwork(CONF.network.tenant_network_cidr)
218 mask_bits = mask_bits or CONF.network.tenant_network_mask_bits
Sergey Shnaidman18cf5972014-09-02 22:05:00 +0400219 elif ip_version == 6:
armando-migliaccioee90a4d2014-05-06 11:54:07 -0700220 cidr = (
221 cidr or netaddr.IPNetwork(CONF.network.tenant_network_v6_cidr))
222 mask_bits = mask_bits or CONF.network.tenant_network_v6_mask_bits
Miguel Lavallecc939612013-02-22 17:27:20 -0600223 # Find a cidr that is not in use yet and create a subnet with it
224 for subnet_cidr in cidr.subnet(mask_bits):
Sergey Shnaidman18cf5972014-09-02 22:05:00 +0400225 if gateway_not_set:
226 gateway_ip = str(netaddr.IPAddress(subnet_cidr) + 1)
227 else:
228 gateway_ip = gateway
Miguel Lavallecc939612013-02-22 17:27:20 -0600229 try:
David Kranz34e88122014-12-11 15:24:05 -0500230 body = client.create_subnet(
Eugene Nikanorove9d255a2013-12-18 16:31:42 +0400231 network_id=network['id'],
232 cidr=str(subnet_cidr),
Sergey Shnaidman18cf5972014-09-02 22:05:00 +0400233 ip_version=ip_version,
234 gateway_ip=gateway_ip,
Sean M. Collinsdd27a4d2014-05-13 10:33:15 -0400235 **kwargs)
Miguel Lavallecc939612013-02-22 17:27:20 -0600236 break
Masayuki Igawa4b29e472015-02-16 10:41:54 +0900237 except lib_exc.BadRequest as e:
Miguel Lavallecc939612013-02-22 17:27:20 -0600238 is_overlapping_cidr = 'overlaps with another subnet' in str(e)
239 if not is_overlapping_cidr:
240 raise
Matthew Treinish6b8cd2a2014-03-03 20:45:56 +0000241 else:
242 message = 'Available CIDR for subnet creation could not be found'
243 raise exceptions.BuildErrorException(message)
Miguel Lavallecc939612013-02-22 17:27:20 -0600244 subnet = body['subnet']
245 cls.subnets.append(subnet)
246 return subnet
raiesmh08e1aad982013-08-05 14:19:36 +0530247
248 @classmethod
Dane LeBlanccbc4bc52014-03-19 16:03:23 -0400249 def create_port(cls, network, **kwargs):
raiesmh08e1aad982013-08-05 14:19:36 +0530250 """Wrapper utility that returns a test port."""
David Kranz34e88122014-12-11 15:24:05 -0500251 body = cls.client.create_port(network_id=network['id'],
252 **kwargs)
raiesmh08e1aad982013-08-05 14:19:36 +0530253 port = body['port']
254 cls.ports.append(port)
255 return port
raiesmh080fe76852013-09-13 11:52:56 +0530256
257 @classmethod
Dane LeBlanccbc4bc52014-03-19 16:03:23 -0400258 def update_port(cls, port, **kwargs):
259 """Wrapper utility that updates a test port."""
David Kranz34e88122014-12-11 15:24:05 -0500260 body = cls.client.update_port(port['id'],
261 **kwargs)
Dane LeBlanccbc4bc52014-03-19 16:03:23 -0400262 return body['port']
263
264 @classmethod
Salvatore Orlandoa85e8fe2013-09-20 03:48:02 -0700265 def create_router(cls, router_name=None, admin_state_up=False,
266 external_network_id=None, enable_snat=None):
267 ext_gw_info = {}
268 if external_network_id:
269 ext_gw_info['network_id'] = external_network_id
270 if enable_snat:
271 ext_gw_info['enable_snat'] = enable_snat
David Kranz34e88122014-12-11 15:24:05 -0500272 body = cls.client.create_router(
Salvatore Orlandoa85e8fe2013-09-20 03:48:02 -0700273 router_name, external_gateway_info=ext_gw_info,
274 admin_state_up=admin_state_up)
275 router = body['router']
276 cls.routers.append(router)
277 return router
278
279 @classmethod
Ann Kamyshnikova47a4ff82014-03-17 12:48:57 +0400280 def create_floatingip(cls, external_network_id):
rosselladd68b232013-11-13 10:21:59 +0100281 """Wrapper utility that returns a test floating IP."""
David Kranz34e88122014-12-11 15:24:05 -0500282 body = cls.client.create_floatingip(
Ann Kamyshnikova47a4ff82014-03-17 12:48:57 +0400283 floating_network_id=external_network_id)
rosselladd68b232013-11-13 10:21:59 +0100284 fip = body['floatingip']
285 cls.floating_ips.append(fip)
286 return fip
287
288 @classmethod
raiesmh080fe76852013-09-13 11:52:56 +0530289 def create_pool(cls, name, lb_method, protocol, subnet):
290 """Wrapper utility that returns a test pool."""
David Kranz34e88122014-12-11 15:24:05 -0500291 body = cls.client.create_pool(
Eugene Nikanorov431e04a2013-12-17 15:44:27 +0400292 name=name,
293 lb_method=lb_method,
294 protocol=protocol,
295 subnet_id=subnet['id'])
raiesmh080fe76852013-09-13 11:52:56 +0530296 pool = body['pool']
297 cls.pools.append(pool)
298 return pool
299
300 @classmethod
Eugene Nikanorov431e04a2013-12-17 15:44:27 +0400301 def update_pool(cls, name):
302 """Wrapper utility that returns a test pool."""
David Kranz34e88122014-12-11 15:24:05 -0500303 body = cls.client.update_pool(name=name)
Eugene Nikanorov431e04a2013-12-17 15:44:27 +0400304 pool = body['pool']
305 return pool
306
307 @classmethod
raiesmh080fe76852013-09-13 11:52:56 +0530308 def create_vip(cls, name, protocol, protocol_port, subnet, pool):
309 """Wrapper utility that returns a test vip."""
David Kranz34e88122014-12-11 15:24:05 -0500310 body = cls.client.create_vip(name=name,
311 protocol=protocol,
312 protocol_port=protocol_port,
313 subnet_id=subnet['id'],
314 pool_id=pool['id'])
raiesmh080fe76852013-09-13 11:52:56 +0530315 vip = body['vip']
316 cls.vips.append(vip)
317 return vip
raiesmh08f8437ed2013-09-17 10:59:38 +0530318
319 @classmethod
Elena Ezhova43c70a22014-01-14 12:42:51 +0400320 def update_vip(cls, name):
David Kranz34e88122014-12-11 15:24:05 -0500321 body = cls.client.update_vip(name=name)
Elena Ezhova43c70a22014-01-14 12:42:51 +0400322 vip = body['vip']
323 return vip
324
325 @classmethod
Sergey Shnaidman97e6a0f2014-11-12 20:00:53 +0300326 def create_member(cls, protocol_port, pool, ip_version=None):
raiesmh08f8437ed2013-09-17 10:59:38 +0530327 """Wrapper utility that returns a test member."""
Sergey Shnaidman97e6a0f2014-11-12 20:00:53 +0300328 ip_version = ip_version if ip_version is not None else cls._ip_version
329 member_address = "fd00::abcd" if ip_version == 6 else "10.0.9.46"
David Kranz34e88122014-12-11 15:24:05 -0500330 body = cls.client.create_member(address=member_address,
331 protocol_port=protocol_port,
332 pool_id=pool['id'])
raiesmh08f8437ed2013-09-17 10:59:38 +0530333 member = body['member']
334 cls.members.append(member)
335 return member
raiesmh0832580d02013-09-17 13:11:34 +0530336
337 @classmethod
Ann Kamyshnikova2bc1c432013-12-10 17:31:50 +0400338 def update_member(cls, admin_state_up):
David Kranz34e88122014-12-11 15:24:05 -0500339 body = cls.client.update_member(admin_state_up=admin_state_up)
Ann Kamyshnikova2bc1c432013-12-10 17:31:50 +0400340 member = body['member']
341 return member
342
343 @classmethod
raiesmh0832580d02013-09-17 13:11:34 +0530344 def create_health_monitor(cls, delay, max_retries, Type, timeout):
345 """Wrapper utility that returns a test health monitor."""
David Kranz34e88122014-12-11 15:24:05 -0500346 body = cls.client.create_health_monitor(delay=delay,
347 max_retries=max_retries,
348 type=Type,
349 timeout=timeout)
raiesmh0832580d02013-09-17 13:11:34 +0530350 health_monitor = body['health_monitor']
351 cls.health_monitors.append(health_monitor)
352 return health_monitor
Anju Tiwari860097d2013-10-17 11:10:39 +0530353
354 @classmethod
Elena Ezhova43c70a22014-01-14 12:42:51 +0400355 def update_health_monitor(cls, admin_state_up):
David Kranz34e88122014-12-11 15:24:05 -0500356 body = cls.client.update_vip(admin_state_up=admin_state_up)
Elena Ezhova43c70a22014-01-14 12:42:51 +0400357 health_monitor = body['health_monitor']
358 return health_monitor
359
360 @classmethod
Anju Tiwari860097d2013-10-17 11:10:39 +0530361 def create_router_interface(cls, router_id, subnet_id):
362 """Wrapper utility that returns a router interface."""
David Kranz34e88122014-12-11 15:24:05 -0500363 interface = cls.client.add_router_interface_with_subnet_id(
Anju Tiwari860097d2013-10-17 11:10:39 +0530364 router_id, subnet_id)
wanglianmin5e4b47a2014-03-12 18:16:18 +0800365 return interface
Anju Tiwari860097d2013-10-17 11:10:39 +0530366
367 @classmethod
368 def create_vpnservice(cls, subnet_id, router_id):
369 """Wrapper utility that returns a test vpn service."""
David Kranz34e88122014-12-11 15:24:05 -0500370 body = cls.client.create_vpnservice(
Eugene Nikanorovf7e2fa42014-04-17 00:05:36 +0400371 subnet_id=subnet_id, router_id=router_id, admin_state_up=True,
Masayuki Igawa259c1132013-10-31 17:48:44 +0900372 name=data_utils.rand_name("vpnservice-"))
Anju Tiwari860097d2013-10-17 11:10:39 +0530373 vpnservice = body['vpnservice']
374 cls.vpnservices.append(vpnservice)
375 return vpnservice
Salvatore Orlandoce22b492013-09-20 04:04:11 -0700376
raiesmh08bd6070d2013-12-06 15:13:38 +0530377 @classmethod
Eugene Nikanorov909ded12013-12-15 17:45:37 +0400378 def create_ikepolicy(cls, name):
raiesmh08bd6070d2013-12-06 15:13:38 +0530379 """Wrapper utility that returns a test ike policy."""
David Kranz34e88122014-12-11 15:24:05 -0500380 body = cls.client.create_ikepolicy(name=name)
raiesmh08bd6070d2013-12-06 15:13:38 +0530381 ikepolicy = body['ikepolicy']
382 cls.ikepolicies.append(ikepolicy)
383 return ikepolicy
384
Mh Raies96594fc2014-03-26 16:34:18 +0530385 @classmethod
386 def create_firewall_rule(cls, action, protocol):
387 """Wrapper utility that returns a test firewall rule."""
David Kranz34e88122014-12-11 15:24:05 -0500388 body = cls.client.create_firewall_rule(
Mh Raies96594fc2014-03-26 16:34:18 +0530389 name=data_utils.rand_name("fw-rule"),
390 action=action,
391 protocol=protocol)
392 fw_rule = body['firewall_rule']
393 cls.fw_rules.append(fw_rule)
394 return fw_rule
395
396 @classmethod
397 def create_firewall_policy(cls):
398 """Wrapper utility that returns a test firewall policy."""
David Kranz34e88122014-12-11 15:24:05 -0500399 body = cls.client.create_firewall_policy(
Mh Raies96594fc2014-03-26 16:34:18 +0530400 name=data_utils.rand_name("fw-policy"))
401 fw_policy = body['firewall_policy']
402 cls.fw_policies.append(fw_policy)
403 return fw_policy
404
Adam Gandelman3e9d12b2014-04-02 17:04:19 -0700405 @classmethod
406 def delete_router(cls, router):
David Kranz34e88122014-12-11 15:24:05 -0500407 body = cls.client.list_router_interfaces(router['id'])
Adam Gandelman3e9d12b2014-04-02 17:04:19 -0700408 interfaces = body['ports']
409 for i in interfaces:
Rohan Kanadef37eaef2014-12-26 10:02:04 +0100410 try:
411 cls.client.remove_router_interface_with_subnet_id(
412 router['id'], i['fixed_ips'][0]['subnet_id'])
Masayuki Igawabfa07602015-01-20 18:47:17 +0900413 except lib_exc.NotFound:
Rohan Kanadef37eaef2014-12-26 10:02:04 +0100414 pass
Adam Gandelman3e9d12b2014-04-02 17:04:19 -0700415 cls.client.delete_router(router['id'])
416
raiesmh08df3fac42014-06-02 15:42:18 +0530417 @classmethod
418 def create_ipsecpolicy(cls, name):
419 """Wrapper utility that returns a test ipsec policy."""
David Kranz34e88122014-12-11 15:24:05 -0500420 body = cls.client.create_ipsecpolicy(name=name)
raiesmh08df3fac42014-06-02 15:42:18 +0530421 ipsecpolicy = body['ipsecpolicy']
422 cls.ipsecpolicies.append(ipsecpolicy)
423 return ipsecpolicy
424
Salvatore Orlandoce22b492013-09-20 04:04:11 -0700425
426class BaseAdminNetworkTest(BaseNetworkTest):
427
428 @classmethod
Rohan Kanadea565e452015-01-27 14:00:13 +0530429 def skip_checks(cls):
430 super(BaseAdminNetworkTest, cls).skip_checks()
431 if not credentials.is_admin_available():
Salvatore Orlandoce22b492013-09-20 04:04:11 -0700432 msg = ("Missing Administrative Network API credentials "
433 "in configuration.")
434 raise cls.skipException(msg)
Rohan Kanadea565e452015-01-27 14:00:13 +0530435
436 @classmethod
437 def setup_credentials(cls):
438 super(BaseAdminNetworkTest, cls).setup_credentials()
439 creds = cls.isolated_creds.get_admin_creds()
440 cls.os_adm = clients.Manager(credentials=creds)
441
442 @classmethod
443 def setup_clients(cls):
444 super(BaseAdminNetworkTest, cls).setup_clients()
Matthew Treinish2f6628c2013-10-21 21:06:27 +0000445 cls.admin_client = cls.os_adm.network_client
Emilien Macchi0d0b7cc2014-01-11 12:30:21 -0500446
447 @classmethod
448 def create_metering_label(cls, name, description):
449 """Wrapper utility that returns a test metering label."""
David Kranz34e88122014-12-11 15:24:05 -0500450 body = cls.admin_client.create_metering_label(
Emilien Macchi0d0b7cc2014-01-11 12:30:21 -0500451 description=description,
452 name=data_utils.rand_name("metering-label"))
453 metering_label = body['metering_label']
454 cls.metering_labels.append(metering_label)
455 return metering_label
456
457 @classmethod
458 def create_metering_label_rule(cls, remote_ip_prefix, direction,
459 metering_label_id):
460 """Wrapper utility that returns a test metering label rule."""
David Kranz34e88122014-12-11 15:24:05 -0500461 body = cls.admin_client.create_metering_label_rule(
Emilien Macchi0d0b7cc2014-01-11 12:30:21 -0500462 remote_ip_prefix=remote_ip_prefix, direction=direction,
463 metering_label_id=metering_label_id)
464 metering_label_rule = body['metering_label_rule']
465 cls.metering_label_rules.append(metering_label_rule)
466 return metering_label_rule