ZhiQiang Fan | 39f9722 | 2013-09-20 04:49:44 +0800 | [diff] [blame] | 1 | # Copyright 2012 OpenStack Foundation |
Jay Pipes | f4dad39 | 2012-06-05 16:03:58 -0400 | [diff] [blame] | 2 | # 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 Lavalle | cc93961 | 2013-02-22 17:27:20 -0600 | [diff] [blame] | 16 | import netaddr |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 17 | from tempest_lib import exceptions as lib_exc |
Jay Pipes | f4dad39 | 2012-06-05 16:03:58 -0400 | [diff] [blame] | 18 | |
Fei Long Wang | d39431f | 2015-05-14 11:30:48 +1200 | [diff] [blame] | 19 | from tempest.common.utils import data_utils |
Matthew Treinish | 03b48df | 2014-01-29 16:59:49 +0000 | [diff] [blame] | 20 | from tempest import config |
Miguel Lavalle | cc93961 | 2013-02-22 17:27:20 -0600 | [diff] [blame] | 21 | from tempest import exceptions |
Attila Fazekas | dc21642 | 2013-01-29 15:12:14 +0100 | [diff] [blame] | 22 | import tempest.test |
Jay Pipes | f4dad39 | 2012-06-05 16:03:58 -0400 | [diff] [blame] | 23 | |
Matthew Treinish | 03b48df | 2014-01-29 16:59:49 +0000 | [diff] [blame] | 24 | CONF = config.CONF |
| 25 | |
Jay Pipes | f4dad39 | 2012-06-05 16:03:58 -0400 | [diff] [blame] | 26 | |
Attila Fazekas | dc21642 | 2013-01-29 15:12:14 +0100 | [diff] [blame] | 27 | class BaseNetworkTest(tempest.test.BaseTestCase): |
Ken'ichi Ohmichi | e03bea9 | 2015-11-19 07:45:58 +0000 | [diff] [blame] | 28 | """Base class for the Neutron tests |
Miguel Lavalle | cc93961 | 2013-02-22 17:27:20 -0600 | [diff] [blame] | 29 | |
Mark McClain | f2982e8 | 2013-07-06 17:48:03 -0400 | [diff] [blame] | 30 | Per the Neutron API Guide, API v1.x was removed from the source code tree |
Miguel Lavalle | cc93961 | 2013-02-22 17:27:20 -0600 | [diff] [blame] | 31 | (docs.openstack.org/api/openstack-network/2.0/content/Overview-d1e71.html) |
Mark McClain | f2982e8 | 2013-07-06 17:48:03 -0400 | [diff] [blame] | 32 | Therefore, v2.x of the Neutron API is assumed. It is also assumed that the |
Miguel Lavalle | cc93961 | 2013-02-22 17:27:20 -0600 | [diff] [blame] | 33 | following options are defined in the [network] section of etc/tempest.conf: |
| 34 | |
| 35 | tenant_network_cidr with a block of cidr's from which smaller blocks |
| 36 | can be allocated for tenant networks |
| 37 | |
| 38 | tenant_network_mask_bits with the mask bits to be used to partition the |
| 39 | block defined by tenant-network_cidr |
Miguel Lavalle | 2492d78 | 2013-06-16 15:04:15 -0500 | [diff] [blame] | 40 | |
| 41 | Finally, it is assumed that the following option is defined in the |
| 42 | [service_available] section of etc/tempest.conf |
| 43 | |
| 44 | neutron as True |
Miguel Lavalle | cc93961 | 2013-02-22 17:27:20 -0600 | [diff] [blame] | 45 | """ |
| 46 | |
Matthew Treinish | 2f6628c | 2013-10-21 21:06:27 +0000 | [diff] [blame] | 47 | force_tenant_isolation = False |
Andrea Frittoli | b21de6c | 2015-02-06 20:12:38 +0000 | [diff] [blame] | 48 | credentials = ['primary'] |
Matthew Treinish | 2f6628c | 2013-10-21 21:06:27 +0000 | [diff] [blame] | 49 | |
Henry Gessau | ffda37a | 2014-01-16 11:17:55 -0500 | [diff] [blame] | 50 | # Default to ipv4. |
| 51 | _ip_version = 4 |
Henry Gessau | ffda37a | 2014-01-16 11:17:55 -0500 | [diff] [blame] | 52 | |
Jay Pipes | f4dad39 | 2012-06-05 16:03:58 -0400 | [diff] [blame] | 53 | @classmethod |
Rohan Kanade | a565e45 | 2015-01-27 14:00:13 +0530 | [diff] [blame] | 54 | def skip_checks(cls): |
| 55 | super(BaseNetworkTest, cls).skip_checks() |
Matthew Treinish | 03b48df | 2014-01-29 16:59:49 +0000 | [diff] [blame] | 56 | if not CONF.service_available.neutron: |
Mark McClain | f2982e8 | 2013-07-06 17:48:03 -0400 | [diff] [blame] | 57 | raise cls.skipException("Neutron support is required") |
Sergey Shnaidman | 97e6a0f | 2014-11-12 20:00:53 +0300 | [diff] [blame] | 58 | if cls._ip_version == 6 and not CONF.network_feature_enabled.ipv6: |
| 59 | raise cls.skipException("IPv6 Tests are disabled.") |
Matthew Treinish | 2f6628c | 2013-10-21 21:06:27 +0000 | [diff] [blame] | 60 | |
Rohan Kanade | a565e45 | 2015-01-27 14:00:13 +0530 | [diff] [blame] | 61 | @classmethod |
| 62 | def setup_credentials(cls): |
| 63 | # Create no network resources for these test. |
| 64 | cls.set_network_resources() |
| 65 | super(BaseNetworkTest, cls).setup_credentials() |
Rohan Kanade | a565e45 | 2015-01-27 14:00:13 +0530 | [diff] [blame] | 66 | |
| 67 | @classmethod |
| 68 | def setup_clients(cls): |
| 69 | super(BaseNetworkTest, cls).setup_clients() |
| 70 | cls.client = cls.os.network_client |
Ken'ichi Ohmichi | 7186006 | 2015-12-15 08:20:13 +0000 | [diff] [blame] | 71 | cls.agents_client = cls.os.network_agents_client |
John Warren | 94d8faf | 2015-09-15 12:22:24 -0400 | [diff] [blame] | 72 | cls.networks_client = cls.os.networks_client |
Ken'ichi Ohmichi | f3f8aba | 2015-12-15 08:11:00 +0000 | [diff] [blame] | 73 | cls.subnetpools_client = cls.os.subnetpools_client |
John Warren | 3961acd | 2015-10-02 14:38:53 -0400 | [diff] [blame] | 74 | cls.subnets_client = cls.os.subnets_client |
John Warren | 49c0fe5 | 2015-10-22 12:35:54 -0400 | [diff] [blame] | 75 | cls.ports_client = cls.os.ports_client |
Ken'ichi Ohmichi | 756d8ff | 2015-12-15 09:47:54 +0000 | [diff] [blame] | 76 | cls.quotas_client = cls.os.network_quotas_client |
John Warren | fbf2a89 | 2015-11-17 12:36:14 -0500 | [diff] [blame] | 77 | cls.floating_ips_client = cls.os.floating_ips_client |
John Warren | f9606e9 | 2015-12-10 12:12:42 -0500 | [diff] [blame] | 78 | cls.security_groups_client = cls.os.security_groups_client |
John Warren | 456d9ae | 2016-01-12 15:36:33 -0500 | [diff] [blame^] | 79 | cls.security_group_rules_client = ( |
| 80 | cls.os.security_group_rules_client) |
Rohan Kanade | a565e45 | 2015-01-27 14:00:13 +0530 | [diff] [blame] | 81 | |
| 82 | @classmethod |
| 83 | def resource_setup(cls): |
| 84 | super(BaseNetworkTest, cls).resource_setup() |
Miguel Lavalle | cc93961 | 2013-02-22 17:27:20 -0600 | [diff] [blame] | 85 | cls.networks = [] |
| 86 | cls.subnets = [] |
raiesmh08 | e1aad98 | 2013-08-05 14:19:36 +0530 | [diff] [blame] | 87 | cls.ports = [] |
Salvatore Orlando | a85e8fe | 2013-09-20 03:48:02 -0700 | [diff] [blame] | 88 | cls.routers = [] |
rossella | dd68b23 | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 89 | cls.floating_ips = [] |
Emilien Macchi | 0d0b7cc | 2014-01-11 12:30:21 -0500 | [diff] [blame] | 90 | cls.metering_labels = [] |
| 91 | cls.metering_label_rules = [] |
sridhargaddam | 510f896 | 2014-09-08 23:37:16 +0530 | [diff] [blame] | 92 | cls.ethertype = "IPv" + str(cls._ip_version) |
Jay Pipes | f4dad39 | 2012-06-05 16:03:58 -0400 | [diff] [blame] | 93 | |
| 94 | @classmethod |
Andrea Frittoli | da4a245 | 2014-09-15 13:12:08 +0100 | [diff] [blame] | 95 | def resource_cleanup(cls): |
Daniel P. Berrange | 690c26a | 2014-07-01 12:51:36 +0100 | [diff] [blame] | 96 | if CONF.service_available.neutron: |
Daniel P. Berrange | 690c26a | 2014-07-01 12:51:36 +0100 | [diff] [blame] | 97 | # Clean up floating IPs |
| 98 | for floating_ip in cls.floating_ips: |
John Warren | fbf2a89 | 2015-11-17 12:36:14 -0500 | [diff] [blame] | 99 | cls._try_delete_resource( |
| 100 | cls.floating_ips_client.delete_floatingip, |
| 101 | floating_ip['id']) |
Adam Gandelman | 3e9d12b | 2014-04-02 17:04:19 -0700 | [diff] [blame] | 102 | |
Daniel P. Berrange | 690c26a | 2014-07-01 12:51:36 +0100 | [diff] [blame] | 103 | # Clean up metering label rules |
John Warren | dd20b3e | 2015-12-03 13:11:28 -0500 | [diff] [blame] | 104 | # Not all classes in the hierarchy have the client class variable |
| 105 | if len(cls.metering_label_rules) > 0: |
| 106 | label_rules_client = cls.admin_metering_label_rules_client |
Daniel P. Berrange | 690c26a | 2014-07-01 12:51:36 +0100 | [diff] [blame] | 107 | for metering_label_rule in cls.metering_label_rules: |
Yair Fried | 4f92328 | 2014-11-19 10:55:57 +0200 | [diff] [blame] | 108 | cls._try_delete_resource( |
John Warren | dd20b3e | 2015-12-03 13:11:28 -0500 | [diff] [blame] | 109 | label_rules_client.delete_metering_label_rule, |
Daniel P. Berrange | 690c26a | 2014-07-01 12:51:36 +0100 | [diff] [blame] | 110 | metering_label_rule['id']) |
| 111 | # Clean up metering labels |
| 112 | for metering_label in cls.metering_labels: |
Yair Fried | 4f92328 | 2014-11-19 10:55:57 +0200 | [diff] [blame] | 113 | cls._try_delete_resource( |
John Warren | 6d0083a | 2015-11-30 18:12:30 -0500 | [diff] [blame] | 114 | cls.admin_metering_labels_client.delete_metering_label, |
Yair Fried | 4f92328 | 2014-11-19 10:55:57 +0200 | [diff] [blame] | 115 | metering_label['id']) |
Daniel P. Berrange | 690c26a | 2014-07-01 12:51:36 +0100 | [diff] [blame] | 116 | # Clean up ports |
| 117 | for port in cls.ports: |
John Warren | 49c0fe5 | 2015-10-22 12:35:54 -0400 | [diff] [blame] | 118 | cls._try_delete_resource(cls.ports_client.delete_port, |
Yair Fried | 4f92328 | 2014-11-19 10:55:57 +0200 | [diff] [blame] | 119 | port['id']) |
PrinikaSN | e46fbd1 | 2015-05-29 16:41:30 -0700 | [diff] [blame] | 120 | # Clean up routers |
| 121 | for router in cls.routers: |
| 122 | cls._try_delete_resource(cls.delete_router, |
| 123 | router) |
Daniel P. Berrange | 690c26a | 2014-07-01 12:51:36 +0100 | [diff] [blame] | 124 | # Clean up subnets |
| 125 | for subnet in cls.subnets: |
John Warren | 3961acd | 2015-10-02 14:38:53 -0400 | [diff] [blame] | 126 | cls._try_delete_resource(cls.subnets_client.delete_subnet, |
Yair Fried | 4f92328 | 2014-11-19 10:55:57 +0200 | [diff] [blame] | 127 | subnet['id']) |
Daniel P. Berrange | 690c26a | 2014-07-01 12:51:36 +0100 | [diff] [blame] | 128 | # Clean up networks |
| 129 | for network in cls.networks: |
John Warren | 94d8faf | 2015-09-15 12:22:24 -0400 | [diff] [blame] | 130 | cls._try_delete_resource(cls.networks_client.delete_network, |
Yair Fried | 4f92328 | 2014-11-19 10:55:57 +0200 | [diff] [blame] | 131 | network['id']) |
Andrea Frittoli | da4a245 | 2014-09-15 13:12:08 +0100 | [diff] [blame] | 132 | super(BaseNetworkTest, cls).resource_cleanup() |
Jay Pipes | f4dad39 | 2012-06-05 16:03:58 -0400 | [diff] [blame] | 133 | |
Miguel Lavalle | cc93961 | 2013-02-22 17:27:20 -0600 | [diff] [blame] | 134 | @classmethod |
Yair Fried | 4f92328 | 2014-11-19 10:55:57 +0200 | [diff] [blame] | 135 | def _try_delete_resource(self, delete_callable, *args, **kwargs): |
| 136 | """Cleanup resources in case of test-failure |
| 137 | |
| 138 | Some resources are explicitly deleted by the test. |
| 139 | If the test failed to delete a resource, this method will execute |
| 140 | the appropriate delete methods. Otherwise, the method ignores NotFound |
| 141 | exceptions thrown for resources that were correctly deleted by the |
| 142 | test. |
| 143 | |
| 144 | :param delete_callable: delete method |
| 145 | :param args: arguments for delete method |
| 146 | :param kwargs: keyword arguments for delete method |
| 147 | """ |
| 148 | try: |
| 149 | delete_callable(*args, **kwargs) |
| 150 | # if resource is not found, this means it was deleted in the test |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 151 | except lib_exc.NotFound: |
Yair Fried | 4f92328 | 2014-11-19 10:55:57 +0200 | [diff] [blame] | 152 | pass |
| 153 | |
| 154 | @classmethod |
Miguel Lavalle | cc93961 | 2013-02-22 17:27:20 -0600 | [diff] [blame] | 155 | def create_network(cls, network_name=None): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 156 | """Wrapper utility that returns a test network.""" |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 157 | network_name = network_name or data_utils.rand_name('test-network-') |
Jay Pipes | f4dad39 | 2012-06-05 16:03:58 -0400 | [diff] [blame] | 158 | |
John Warren | 94d8faf | 2015-09-15 12:22:24 -0400 | [diff] [blame] | 159 | body = cls.networks_client.create_network(name=network_name) |
Jay Pipes | f4dad39 | 2012-06-05 16:03:58 -0400 | [diff] [blame] | 160 | network = body['network'] |
Miguel Lavalle | cc93961 | 2013-02-22 17:27:20 -0600 | [diff] [blame] | 161 | cls.networks.append(network) |
Jay Pipes | f4dad39 | 2012-06-05 16:03:58 -0400 | [diff] [blame] | 162 | return network |
Miguel Lavalle | cc93961 | 2013-02-22 17:27:20 -0600 | [diff] [blame] | 163 | |
| 164 | @classmethod |
Sergey Shnaidman | 18cf597 | 2014-09-02 22:05:00 +0400 | [diff] [blame] | 165 | def create_subnet(cls, network, gateway='', cidr=None, mask_bits=None, |
Yair Fried | 52ee136 | 2014-09-29 14:47:03 +0300 | [diff] [blame] | 166 | ip_version=None, client=None, **kwargs): |
Miguel Lavalle | cc93961 | 2013-02-22 17:27:20 -0600 | [diff] [blame] | 167 | """Wrapper utility that returns a test subnet.""" |
Yair Fried | 52ee136 | 2014-09-29 14:47:03 +0300 | [diff] [blame] | 168 | |
| 169 | # allow tests to use admin client |
| 170 | if not client: |
John Warren | 3961acd | 2015-10-02 14:38:53 -0400 | [diff] [blame] | 171 | client = cls.subnets_client |
Yair Fried | 52ee136 | 2014-09-29 14:47:03 +0300 | [diff] [blame] | 172 | |
Henry Gessau | ffda37a | 2014-01-16 11:17:55 -0500 | [diff] [blame] | 173 | # The cidr and mask_bits depend on the ip version. |
Sergey Shnaidman | 18cf597 | 2014-09-02 22:05:00 +0400 | [diff] [blame] | 174 | ip_version = ip_version if ip_version is not None else cls._ip_version |
| 175 | gateway_not_set = gateway == '' |
| 176 | if ip_version == 4: |
armando-migliaccio | ee90a4d | 2014-05-06 11:54:07 -0700 | [diff] [blame] | 177 | cidr = cidr or netaddr.IPNetwork(CONF.network.tenant_network_cidr) |
| 178 | mask_bits = mask_bits or CONF.network.tenant_network_mask_bits |
Sergey Shnaidman | 18cf597 | 2014-09-02 22:05:00 +0400 | [diff] [blame] | 179 | elif ip_version == 6: |
armando-migliaccio | ee90a4d | 2014-05-06 11:54:07 -0700 | [diff] [blame] | 180 | cidr = ( |
| 181 | cidr or netaddr.IPNetwork(CONF.network.tenant_network_v6_cidr)) |
| 182 | mask_bits = mask_bits or CONF.network.tenant_network_v6_mask_bits |
Miguel Lavalle | cc93961 | 2013-02-22 17:27:20 -0600 | [diff] [blame] | 183 | # Find a cidr that is not in use yet and create a subnet with it |
| 184 | for subnet_cidr in cidr.subnet(mask_bits): |
Sergey Shnaidman | 18cf597 | 2014-09-02 22:05:00 +0400 | [diff] [blame] | 185 | if gateway_not_set: |
| 186 | gateway_ip = str(netaddr.IPAddress(subnet_cidr) + 1) |
| 187 | else: |
| 188 | gateway_ip = gateway |
Miguel Lavalle | cc93961 | 2013-02-22 17:27:20 -0600 | [diff] [blame] | 189 | try: |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 190 | body = client.create_subnet( |
Eugene Nikanorov | e9d255a | 2013-12-18 16:31:42 +0400 | [diff] [blame] | 191 | network_id=network['id'], |
| 192 | cidr=str(subnet_cidr), |
Sergey Shnaidman | 18cf597 | 2014-09-02 22:05:00 +0400 | [diff] [blame] | 193 | ip_version=ip_version, |
| 194 | gateway_ip=gateway_ip, |
Sean M. Collins | dd27a4d | 2014-05-13 10:33:15 -0400 | [diff] [blame] | 195 | **kwargs) |
Miguel Lavalle | cc93961 | 2013-02-22 17:27:20 -0600 | [diff] [blame] | 196 | break |
Masayuki Igawa | 4b29e47 | 2015-02-16 10:41:54 +0900 | [diff] [blame] | 197 | except lib_exc.BadRequest as e: |
Miguel Lavalle | cc93961 | 2013-02-22 17:27:20 -0600 | [diff] [blame] | 198 | is_overlapping_cidr = 'overlaps with another subnet' in str(e) |
| 199 | if not is_overlapping_cidr: |
| 200 | raise |
Matthew Treinish | 6b8cd2a | 2014-03-03 20:45:56 +0000 | [diff] [blame] | 201 | else: |
| 202 | message = 'Available CIDR for subnet creation could not be found' |
| 203 | raise exceptions.BuildErrorException(message) |
Miguel Lavalle | cc93961 | 2013-02-22 17:27:20 -0600 | [diff] [blame] | 204 | subnet = body['subnet'] |
| 205 | cls.subnets.append(subnet) |
| 206 | return subnet |
raiesmh08 | e1aad98 | 2013-08-05 14:19:36 +0530 | [diff] [blame] | 207 | |
| 208 | @classmethod |
Dane LeBlanc | cbc4bc5 | 2014-03-19 16:03:23 -0400 | [diff] [blame] | 209 | def create_port(cls, network, **kwargs): |
raiesmh08 | e1aad98 | 2013-08-05 14:19:36 +0530 | [diff] [blame] | 210 | """Wrapper utility that returns a test port.""" |
John Warren | 49c0fe5 | 2015-10-22 12:35:54 -0400 | [diff] [blame] | 211 | body = cls.ports_client.create_port(network_id=network['id'], |
| 212 | **kwargs) |
raiesmh08 | e1aad98 | 2013-08-05 14:19:36 +0530 | [diff] [blame] | 213 | port = body['port'] |
| 214 | cls.ports.append(port) |
| 215 | return port |
raiesmh08 | 0fe7685 | 2013-09-13 11:52:56 +0530 | [diff] [blame] | 216 | |
| 217 | @classmethod |
Dane LeBlanc | cbc4bc5 | 2014-03-19 16:03:23 -0400 | [diff] [blame] | 218 | def update_port(cls, port, **kwargs): |
| 219 | """Wrapper utility that updates a test port.""" |
John Warren | 49c0fe5 | 2015-10-22 12:35:54 -0400 | [diff] [blame] | 220 | body = cls.ports_client.update_port(port['id'], |
| 221 | **kwargs) |
Dane LeBlanc | cbc4bc5 | 2014-03-19 16:03:23 -0400 | [diff] [blame] | 222 | return body['port'] |
| 223 | |
| 224 | @classmethod |
Salvatore Orlando | a85e8fe | 2013-09-20 03:48:02 -0700 | [diff] [blame] | 225 | def create_router(cls, router_name=None, admin_state_up=False, |
armando-migliaccio | 88f7b70 | 2014-06-05 12:59:09 -0700 | [diff] [blame] | 226 | external_network_id=None, enable_snat=None, |
| 227 | **kwargs): |
Salvatore Orlando | a85e8fe | 2013-09-20 03:48:02 -0700 | [diff] [blame] | 228 | ext_gw_info = {} |
| 229 | if external_network_id: |
| 230 | ext_gw_info['network_id'] = external_network_id |
Shuquan Huang | 813362a | 2015-09-18 08:24:13 +0000 | [diff] [blame] | 231 | if enable_snat is not None: |
Salvatore Orlando | a85e8fe | 2013-09-20 03:48:02 -0700 | [diff] [blame] | 232 | ext_gw_info['enable_snat'] = enable_snat |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 233 | body = cls.client.create_router( |
Salvatore Orlando | a85e8fe | 2013-09-20 03:48:02 -0700 | [diff] [blame] | 234 | router_name, external_gateway_info=ext_gw_info, |
armando-migliaccio | 88f7b70 | 2014-06-05 12:59:09 -0700 | [diff] [blame] | 235 | admin_state_up=admin_state_up, **kwargs) |
Salvatore Orlando | a85e8fe | 2013-09-20 03:48:02 -0700 | [diff] [blame] | 236 | router = body['router'] |
| 237 | cls.routers.append(router) |
| 238 | return router |
| 239 | |
| 240 | @classmethod |
Ann Kamyshnikova | 47a4ff8 | 2014-03-17 12:48:57 +0400 | [diff] [blame] | 241 | def create_floatingip(cls, external_network_id): |
rossella | dd68b23 | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 242 | """Wrapper utility that returns a test floating IP.""" |
John Warren | fbf2a89 | 2015-11-17 12:36:14 -0500 | [diff] [blame] | 243 | body = cls.floating_ips_client.create_floatingip( |
Ann Kamyshnikova | 47a4ff8 | 2014-03-17 12:48:57 +0400 | [diff] [blame] | 244 | floating_network_id=external_network_id) |
rossella | dd68b23 | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 245 | fip = body['floatingip'] |
| 246 | cls.floating_ips.append(fip) |
| 247 | return fip |
| 248 | |
| 249 | @classmethod |
Anju Tiwari | 860097d | 2013-10-17 11:10:39 +0530 | [diff] [blame] | 250 | def create_router_interface(cls, router_id, subnet_id): |
| 251 | """Wrapper utility that returns a router interface.""" |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 252 | interface = cls.client.add_router_interface_with_subnet_id( |
Anju Tiwari | 860097d | 2013-10-17 11:10:39 +0530 | [diff] [blame] | 253 | router_id, subnet_id) |
wanglianmin | 5e4b47a | 2014-03-12 18:16:18 +0800 | [diff] [blame] | 254 | return interface |
Anju Tiwari | 860097d | 2013-10-17 11:10:39 +0530 | [diff] [blame] | 255 | |
| 256 | @classmethod |
Adam Gandelman | 3e9d12b | 2014-04-02 17:04:19 -0700 | [diff] [blame] | 257 | def delete_router(cls, router): |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 258 | body = cls.client.list_router_interfaces(router['id']) |
Adam Gandelman | 3e9d12b | 2014-04-02 17:04:19 -0700 | [diff] [blame] | 259 | interfaces = body['ports'] |
| 260 | for i in interfaces: |
Rohan Kanade | f37eaef | 2014-12-26 10:02:04 +0100 | [diff] [blame] | 261 | try: |
| 262 | cls.client.remove_router_interface_with_subnet_id( |
| 263 | router['id'], i['fixed_ips'][0]['subnet_id']) |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 264 | except lib_exc.NotFound: |
Rohan Kanade | f37eaef | 2014-12-26 10:02:04 +0100 | [diff] [blame] | 265 | pass |
Adam Gandelman | 3e9d12b | 2014-04-02 17:04:19 -0700 | [diff] [blame] | 266 | cls.client.delete_router(router['id']) |
| 267 | |
Salvatore Orlando | ce22b49 | 2013-09-20 04:04:11 -0700 | [diff] [blame] | 268 | |
| 269 | class BaseAdminNetworkTest(BaseNetworkTest): |
| 270 | |
Andrea Frittoli | b21de6c | 2015-02-06 20:12:38 +0000 | [diff] [blame] | 271 | credentials = ['primary', 'admin'] |
Rohan Kanade | a565e45 | 2015-01-27 14:00:13 +0530 | [diff] [blame] | 272 | |
| 273 | @classmethod |
| 274 | def setup_clients(cls): |
| 275 | super(BaseAdminNetworkTest, cls).setup_clients() |
Matthew Treinish | 2f6628c | 2013-10-21 21:06:27 +0000 | [diff] [blame] | 276 | cls.admin_client = cls.os_adm.network_client |
Ken'ichi Ohmichi | 7186006 | 2015-12-15 08:20:13 +0000 | [diff] [blame] | 277 | cls.admin_agents_client = cls.os_adm.network_agents_client |
John Warren | 94d8faf | 2015-09-15 12:22:24 -0400 | [diff] [blame] | 278 | cls.admin_networks_client = cls.os_adm.networks_client |
John Warren | 3961acd | 2015-10-02 14:38:53 -0400 | [diff] [blame] | 279 | cls.admin_subnets_client = cls.os_adm.subnets_client |
John Warren | 49c0fe5 | 2015-10-22 12:35:54 -0400 | [diff] [blame] | 280 | cls.admin_ports_client = cls.os_adm.ports_client |
Ken'ichi Ohmichi | 756d8ff | 2015-12-15 09:47:54 +0000 | [diff] [blame] | 281 | cls.admin_quotas_client = cls.os_adm.network_quotas_client |
John Warren | fbf2a89 | 2015-11-17 12:36:14 -0500 | [diff] [blame] | 282 | cls.admin_floating_ips_client = cls.os_adm.floating_ips_client |
John Warren | 6d0083a | 2015-11-30 18:12:30 -0500 | [diff] [blame] | 283 | cls.admin_metering_labels_client = cls.os_adm.metering_labels_client |
John Warren | dd20b3e | 2015-12-03 13:11:28 -0500 | [diff] [blame] | 284 | cls.admin_metering_label_rules_client = ( |
| 285 | cls.os_adm.metering_label_rules_client) |
Emilien Macchi | 0d0b7cc | 2014-01-11 12:30:21 -0500 | [diff] [blame] | 286 | |
| 287 | @classmethod |
| 288 | def create_metering_label(cls, name, description): |
| 289 | """Wrapper utility that returns a test metering label.""" |
John Warren | 6d0083a | 2015-11-30 18:12:30 -0500 | [diff] [blame] | 290 | body = cls.admin_metering_labels_client.create_metering_label( |
Emilien Macchi | 0d0b7cc | 2014-01-11 12:30:21 -0500 | [diff] [blame] | 291 | description=description, |
| 292 | name=data_utils.rand_name("metering-label")) |
| 293 | metering_label = body['metering_label'] |
| 294 | cls.metering_labels.append(metering_label) |
| 295 | return metering_label |
| 296 | |
| 297 | @classmethod |
| 298 | def create_metering_label_rule(cls, remote_ip_prefix, direction, |
| 299 | metering_label_id): |
| 300 | """Wrapper utility that returns a test metering label rule.""" |
John Warren | dd20b3e | 2015-12-03 13:11:28 -0500 | [diff] [blame] | 301 | client = cls.admin_metering_label_rules_client |
| 302 | body = client.create_metering_label_rule( |
Emilien Macchi | 0d0b7cc | 2014-01-11 12:30:21 -0500 | [diff] [blame] | 303 | remote_ip_prefix=remote_ip_prefix, direction=direction, |
| 304 | metering_label_id=metering_label_id) |
| 305 | metering_label_rule = body['metering_label_rule'] |
| 306 | cls.metering_label_rules.append(metering_label_rule) |
| 307 | return metering_label_rule |