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 |
Jay Pipes | f4dad39 | 2012-06-05 16:03:58 -0400 | [diff] [blame] | 17 | |
Matthew Treinish | 481466b | 2012-12-20 17:16:01 -0500 | [diff] [blame] | 18 | from tempest import clients |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [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 |
Anju Tiwari | 860097d | 2013-10-17 11:10:39 +0530 | [diff] [blame] | 22 | from tempest.openstack.common import log as logging |
Attila Fazekas | dc21642 | 2013-01-29 15:12:14 +0100 | [diff] [blame] | 23 | import tempest.test |
Jay Pipes | f4dad39 | 2012-06-05 16:03:58 -0400 | [diff] [blame] | 24 | |
Matthew Treinish | 03b48df | 2014-01-29 16:59:49 +0000 | [diff] [blame] | 25 | CONF = config.CONF |
| 26 | |
Anju Tiwari | 860097d | 2013-10-17 11:10:39 +0530 | [diff] [blame] | 27 | LOG = logging.getLogger(__name__) |
| 28 | |
Jay Pipes | f4dad39 | 2012-06-05 16:03:58 -0400 | [diff] [blame] | 29 | |
Attila Fazekas | dc21642 | 2013-01-29 15:12:14 +0100 | [diff] [blame] | 30 | class BaseNetworkTest(tempest.test.BaseTestCase): |
Jay Pipes | f4dad39 | 2012-06-05 16:03:58 -0400 | [diff] [blame] | 31 | |
Miguel Lavalle | cc93961 | 2013-02-22 17:27:20 -0600 | [diff] [blame] | 32 | """ |
Mark McClain | f2982e8 | 2013-07-06 17:48:03 -0400 | [diff] [blame] | 33 | Base class for the Neutron tests that use the Tempest Neutron REST client |
Miguel Lavalle | cc93961 | 2013-02-22 17:27:20 -0600 | [diff] [blame] | 34 | |
Mark McClain | f2982e8 | 2013-07-06 17:48:03 -0400 | [diff] [blame] | 35 | 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] | 36 | (docs.openstack.org/api/openstack-network/2.0/content/Overview-d1e71.html) |
Mark McClain | f2982e8 | 2013-07-06 17:48:03 -0400 | [diff] [blame] | 37 | 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] | 38 | 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 Lavalle | 2492d78 | 2013-06-16 15:04:15 -0500 | [diff] [blame] | 45 | |
| 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 Lavalle | cc93961 | 2013-02-22 17:27:20 -0600 | [diff] [blame] | 50 | """ |
| 51 | |
JordanP | 5ef2bcf | 2014-08-22 16:55:46 +0200 | [diff] [blame] | 52 | _interface = 'json' |
Matthew Treinish | 2f6628c | 2013-10-21 21:06:27 +0000 | [diff] [blame] | 53 | force_tenant_isolation = False |
| 54 | |
Henry Gessau | ffda37a | 2014-01-16 11:17:55 -0500 | [diff] [blame] | 55 | # Default to ipv4. |
| 56 | _ip_version = 4 |
Henry Gessau | ffda37a | 2014-01-16 11:17:55 -0500 | [diff] [blame] | 57 | |
Jay Pipes | f4dad39 | 2012-06-05 16:03:58 -0400 | [diff] [blame] | 58 | @classmethod |
Andrea Frittoli | da4a245 | 2014-09-15 13:12:08 +0100 | [diff] [blame] | 59 | def resource_setup(cls): |
Salvatore Orlando | 5a33724 | 2014-01-15 22:49:22 +0000 | [diff] [blame] | 60 | # Create no network resources for these test. |
| 61 | cls.set_network_resources() |
Andrea Frittoli | da4a245 | 2014-09-15 13:12:08 +0100 | [diff] [blame] | 62 | super(BaseNetworkTest, cls).resource_setup() |
Matthew Treinish | 03b48df | 2014-01-29 16:59:49 +0000 | [diff] [blame] | 63 | if not CONF.service_available.neutron: |
Mark McClain | f2982e8 | 2013-07-06 17:48:03 -0400 | [diff] [blame] | 64 | raise cls.skipException("Neutron support is required") |
Mark McClain | 6e07c0d | 2014-10-10 11:25:03 -0400 | [diff] [blame] | 65 | if getattr(cls, '_interface', None) == 'xml': |
| 66 | if not CONF.network_feature_enabled.xml_api: |
| 67 | raise cls.skipException('XML API is not enabled') |
Sergey Shnaidman | 97e6a0f | 2014-11-12 20:00:53 +0300 | [diff] [blame^] | 68 | if cls._ip_version == 6 and not CONF.network_feature_enabled.ipv6: |
| 69 | raise cls.skipException("IPv6 Tests are disabled.") |
Matthew Treinish | 2f6628c | 2013-10-21 21:06:27 +0000 | [diff] [blame] | 70 | |
| 71 | os = cls.get_client_manager() |
| 72 | |
| 73 | cls.network_cfg = CONF.network |
Miguel Lavalle | cc93961 | 2013-02-22 17:27:20 -0600 | [diff] [blame] | 74 | cls.client = os.network_client |
| 75 | cls.networks = [] |
| 76 | cls.subnets = [] |
raiesmh08 | e1aad98 | 2013-08-05 14:19:36 +0530 | [diff] [blame] | 77 | cls.ports = [] |
Salvatore Orlando | a85e8fe | 2013-09-20 03:48:02 -0700 | [diff] [blame] | 78 | cls.routers = [] |
raiesmh08 | 0fe7685 | 2013-09-13 11:52:56 +0530 | [diff] [blame] | 79 | cls.pools = [] |
| 80 | cls.vips = [] |
raiesmh08 | f8437ed | 2013-09-17 10:59:38 +0530 | [diff] [blame] | 81 | cls.members = [] |
raiesmh08 | 32580d0 | 2013-09-17 13:11:34 +0530 | [diff] [blame] | 82 | cls.health_monitors = [] |
Anju Tiwari | 860097d | 2013-10-17 11:10:39 +0530 | [diff] [blame] | 83 | cls.vpnservices = [] |
raiesmh08 | bd6070d | 2013-12-06 15:13:38 +0530 | [diff] [blame] | 84 | cls.ikepolicies = [] |
rossella | dd68b23 | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 85 | cls.floating_ips = [] |
Emilien Macchi | 0d0b7cc | 2014-01-11 12:30:21 -0500 | [diff] [blame] | 86 | cls.metering_labels = [] |
| 87 | cls.metering_label_rules = [] |
Mh Raies | 96594fc | 2014-03-26 16:34:18 +0530 | [diff] [blame] | 88 | cls.fw_rules = [] |
| 89 | cls.fw_policies = [] |
raiesmh08 | df3fac4 | 2014-06-02 15:42:18 +0530 | [diff] [blame] | 90 | cls.ipsecpolicies = [] |
sridhargaddam | 510f896 | 2014-09-08 23:37:16 +0530 | [diff] [blame] | 91 | cls.ethertype = "IPv" + str(cls._ip_version) |
Jay Pipes | f4dad39 | 2012-06-05 16:03:58 -0400 | [diff] [blame] | 92 | |
| 93 | @classmethod |
Andrea Frittoli | da4a245 | 2014-09-15 13:12:08 +0100 | [diff] [blame] | 94 | def resource_cleanup(cls): |
Daniel P. Berrange | 690c26a | 2014-07-01 12:51:36 +0100 | [diff] [blame] | 95 | if CONF.service_available.neutron: |
| 96 | # Clean up ipsec policies |
| 97 | for ipsecpolicy in cls.ipsecpolicies: |
| 98 | cls.client.delete_ipsecpolicy(ipsecpolicy['id']) |
| 99 | # Clean up firewall policies |
| 100 | for fw_policy in cls.fw_policies: |
| 101 | cls.client.delete_firewall_policy(fw_policy['id']) |
| 102 | # Clean up firewall rules |
| 103 | for fw_rule in cls.fw_rules: |
| 104 | cls.client.delete_firewall_rule(fw_rule['id']) |
| 105 | # Clean up ike policies |
| 106 | for ikepolicy in cls.ikepolicies: |
| 107 | cls.client.delete_ikepolicy(ikepolicy['id']) |
| 108 | # Clean up vpn services |
| 109 | for vpnservice in cls.vpnservices: |
| 110 | cls.client.delete_vpnservice(vpnservice['id']) |
| 111 | # Clean up floating IPs |
| 112 | for floating_ip in cls.floating_ips: |
| 113 | cls.client.delete_floatingip(floating_ip['id']) |
| 114 | # Clean up routers |
| 115 | for router in cls.routers: |
| 116 | cls.delete_router(router) |
Adam Gandelman | 3e9d12b | 2014-04-02 17:04:19 -0700 | [diff] [blame] | 117 | |
Daniel P. Berrange | 690c26a | 2014-07-01 12:51:36 +0100 | [diff] [blame] | 118 | # Clean up health monitors |
| 119 | for health_monitor in cls.health_monitors: |
| 120 | cls.client.delete_health_monitor(health_monitor['id']) |
| 121 | # Clean up members |
| 122 | for member in cls.members: |
| 123 | cls.client.delete_member(member['id']) |
| 124 | # Clean up vips |
| 125 | for vip in cls.vips: |
| 126 | cls.client.delete_vip(vip['id']) |
| 127 | # Clean up pools |
| 128 | for pool in cls.pools: |
| 129 | cls.client.delete_pool(pool['id']) |
| 130 | # Clean up metering label rules |
| 131 | for metering_label_rule in cls.metering_label_rules: |
| 132 | cls.admin_client.delete_metering_label_rule( |
| 133 | metering_label_rule['id']) |
| 134 | # Clean up metering labels |
| 135 | for metering_label in cls.metering_labels: |
| 136 | cls.admin_client.delete_metering_label(metering_label['id']) |
| 137 | # Clean up ports |
| 138 | for port in cls.ports: |
| 139 | cls.client.delete_port(port['id']) |
| 140 | # Clean up subnets |
| 141 | for subnet in cls.subnets: |
| 142 | cls.client.delete_subnet(subnet['id']) |
| 143 | # Clean up networks |
| 144 | for network in cls.networks: |
| 145 | cls.client.delete_network(network['id']) |
| 146 | cls.clear_isolated_creds() |
Andrea Frittoli | da4a245 | 2014-09-15 13:12:08 +0100 | [diff] [blame] | 147 | super(BaseNetworkTest, cls).resource_cleanup() |
Jay Pipes | f4dad39 | 2012-06-05 16:03:58 -0400 | [diff] [blame] | 148 | |
Miguel Lavalle | cc93961 | 2013-02-22 17:27:20 -0600 | [diff] [blame] | 149 | @classmethod |
| 150 | def create_network(cls, network_name=None): |
Sean Dague | f237ccb | 2013-01-04 15:19:14 -0500 | [diff] [blame] | 151 | """Wrapper utility that returns a test network.""" |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 152 | network_name = network_name or data_utils.rand_name('test-network-') |
Jay Pipes | f4dad39 | 2012-06-05 16:03:58 -0400 | [diff] [blame] | 153 | |
Eugene Nikanorov | e9d255a | 2013-12-18 16:31:42 +0400 | [diff] [blame] | 154 | resp, body = cls.client.create_network(name=network_name) |
Jay Pipes | f4dad39 | 2012-06-05 16:03:58 -0400 | [diff] [blame] | 155 | network = body['network'] |
Miguel Lavalle | cc93961 | 2013-02-22 17:27:20 -0600 | [diff] [blame] | 156 | cls.networks.append(network) |
Jay Pipes | f4dad39 | 2012-06-05 16:03:58 -0400 | [diff] [blame] | 157 | return network |
Miguel Lavalle | cc93961 | 2013-02-22 17:27:20 -0600 | [diff] [blame] | 158 | |
| 159 | @classmethod |
Sergey Shnaidman | 18cf597 | 2014-09-02 22:05:00 +0400 | [diff] [blame] | 160 | def create_subnet(cls, network, gateway='', cidr=None, mask_bits=None, |
| 161 | ip_version=None, **kwargs): |
Miguel Lavalle | cc93961 | 2013-02-22 17:27:20 -0600 | [diff] [blame] | 162 | """Wrapper utility that returns a test subnet.""" |
Henry Gessau | ffda37a | 2014-01-16 11:17:55 -0500 | [diff] [blame] | 163 | # The cidr and mask_bits depend on the ip version. |
Sergey Shnaidman | 18cf597 | 2014-09-02 22:05:00 +0400 | [diff] [blame] | 164 | ip_version = ip_version if ip_version is not None else cls._ip_version |
| 165 | gateway_not_set = gateway == '' |
| 166 | if ip_version == 4: |
armando-migliaccio | ee90a4d | 2014-05-06 11:54:07 -0700 | [diff] [blame] | 167 | cidr = cidr or netaddr.IPNetwork(CONF.network.tenant_network_cidr) |
| 168 | mask_bits = mask_bits or CONF.network.tenant_network_mask_bits |
Sergey Shnaidman | 18cf597 | 2014-09-02 22:05:00 +0400 | [diff] [blame] | 169 | elif ip_version == 6: |
armando-migliaccio | ee90a4d | 2014-05-06 11:54:07 -0700 | [diff] [blame] | 170 | cidr = ( |
| 171 | cidr or netaddr.IPNetwork(CONF.network.tenant_network_v6_cidr)) |
| 172 | mask_bits = mask_bits or CONF.network.tenant_network_v6_mask_bits |
Miguel Lavalle | cc93961 | 2013-02-22 17:27:20 -0600 | [diff] [blame] | 173 | # Find a cidr that is not in use yet and create a subnet with it |
| 174 | for subnet_cidr in cidr.subnet(mask_bits): |
Sergey Shnaidman | 18cf597 | 2014-09-02 22:05:00 +0400 | [diff] [blame] | 175 | if gateway_not_set: |
| 176 | gateway_ip = str(netaddr.IPAddress(subnet_cidr) + 1) |
| 177 | else: |
| 178 | gateway_ip = gateway |
Miguel Lavalle | cc93961 | 2013-02-22 17:27:20 -0600 | [diff] [blame] | 179 | try: |
Eugene Nikanorov | e9d255a | 2013-12-18 16:31:42 +0400 | [diff] [blame] | 180 | resp, body = cls.client.create_subnet( |
| 181 | network_id=network['id'], |
| 182 | cidr=str(subnet_cidr), |
Sergey Shnaidman | 18cf597 | 2014-09-02 22:05:00 +0400 | [diff] [blame] | 183 | ip_version=ip_version, |
| 184 | gateway_ip=gateway_ip, |
Sean M. Collins | dd27a4d | 2014-05-13 10:33:15 -0400 | [diff] [blame] | 185 | **kwargs) |
Miguel Lavalle | cc93961 | 2013-02-22 17:27:20 -0600 | [diff] [blame] | 186 | break |
| 187 | except exceptions.BadRequest as e: |
| 188 | is_overlapping_cidr = 'overlaps with another subnet' in str(e) |
| 189 | if not is_overlapping_cidr: |
| 190 | raise |
Matthew Treinish | 6b8cd2a | 2014-03-03 20:45:56 +0000 | [diff] [blame] | 191 | else: |
| 192 | message = 'Available CIDR for subnet creation could not be found' |
| 193 | raise exceptions.BuildErrorException(message) |
Miguel Lavalle | cc93961 | 2013-02-22 17:27:20 -0600 | [diff] [blame] | 194 | subnet = body['subnet'] |
| 195 | cls.subnets.append(subnet) |
| 196 | return subnet |
raiesmh08 | e1aad98 | 2013-08-05 14:19:36 +0530 | [diff] [blame] | 197 | |
| 198 | @classmethod |
Dane LeBlanc | cbc4bc5 | 2014-03-19 16:03:23 -0400 | [diff] [blame] | 199 | def create_port(cls, network, **kwargs): |
raiesmh08 | e1aad98 | 2013-08-05 14:19:36 +0530 | [diff] [blame] | 200 | """Wrapper utility that returns a test port.""" |
Dane LeBlanc | cbc4bc5 | 2014-03-19 16:03:23 -0400 | [diff] [blame] | 201 | resp, body = cls.client.create_port(network_id=network['id'], |
| 202 | **kwargs) |
raiesmh08 | e1aad98 | 2013-08-05 14:19:36 +0530 | [diff] [blame] | 203 | port = body['port'] |
| 204 | cls.ports.append(port) |
| 205 | return port |
raiesmh08 | 0fe7685 | 2013-09-13 11:52:56 +0530 | [diff] [blame] | 206 | |
| 207 | @classmethod |
Dane LeBlanc | cbc4bc5 | 2014-03-19 16:03:23 -0400 | [diff] [blame] | 208 | def update_port(cls, port, **kwargs): |
| 209 | """Wrapper utility that updates a test port.""" |
| 210 | resp, body = cls.client.update_port(port['id'], |
| 211 | **kwargs) |
| 212 | return body['port'] |
| 213 | |
| 214 | @classmethod |
Salvatore Orlando | a85e8fe | 2013-09-20 03:48:02 -0700 | [diff] [blame] | 215 | def create_router(cls, router_name=None, admin_state_up=False, |
| 216 | external_network_id=None, enable_snat=None): |
| 217 | ext_gw_info = {} |
| 218 | if external_network_id: |
| 219 | ext_gw_info['network_id'] = external_network_id |
| 220 | if enable_snat: |
| 221 | ext_gw_info['enable_snat'] = enable_snat |
| 222 | resp, body = cls.client.create_router( |
| 223 | router_name, external_gateway_info=ext_gw_info, |
| 224 | admin_state_up=admin_state_up) |
| 225 | router = body['router'] |
| 226 | cls.routers.append(router) |
| 227 | return router |
| 228 | |
| 229 | @classmethod |
Ann Kamyshnikova | 47a4ff8 | 2014-03-17 12:48:57 +0400 | [diff] [blame] | 230 | def create_floatingip(cls, external_network_id): |
rossella | dd68b23 | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 231 | """Wrapper utility that returns a test floating IP.""" |
Ann Kamyshnikova | 47a4ff8 | 2014-03-17 12:48:57 +0400 | [diff] [blame] | 232 | resp, body = cls.client.create_floatingip( |
| 233 | floating_network_id=external_network_id) |
rossella | dd68b23 | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 234 | fip = body['floatingip'] |
| 235 | cls.floating_ips.append(fip) |
| 236 | return fip |
| 237 | |
| 238 | @classmethod |
raiesmh08 | 0fe7685 | 2013-09-13 11:52:56 +0530 | [diff] [blame] | 239 | def create_pool(cls, name, lb_method, protocol, subnet): |
| 240 | """Wrapper utility that returns a test pool.""" |
Eugene Nikanorov | 431e04a | 2013-12-17 15:44:27 +0400 | [diff] [blame] | 241 | resp, body = cls.client.create_pool( |
| 242 | name=name, |
| 243 | lb_method=lb_method, |
| 244 | protocol=protocol, |
| 245 | subnet_id=subnet['id']) |
raiesmh08 | 0fe7685 | 2013-09-13 11:52:56 +0530 | [diff] [blame] | 246 | pool = body['pool'] |
| 247 | cls.pools.append(pool) |
| 248 | return pool |
| 249 | |
| 250 | @classmethod |
Eugene Nikanorov | 431e04a | 2013-12-17 15:44:27 +0400 | [diff] [blame] | 251 | def update_pool(cls, name): |
| 252 | """Wrapper utility that returns a test pool.""" |
| 253 | resp, body = cls.client.update_pool(name=name) |
| 254 | pool = body['pool'] |
| 255 | return pool |
| 256 | |
| 257 | @classmethod |
raiesmh08 | 0fe7685 | 2013-09-13 11:52:56 +0530 | [diff] [blame] | 258 | def create_vip(cls, name, protocol, protocol_port, subnet, pool): |
| 259 | """Wrapper utility that returns a test vip.""" |
Elena Ezhova | 43c70a2 | 2014-01-14 12:42:51 +0400 | [diff] [blame] | 260 | resp, body = cls.client.create_vip(name=name, |
| 261 | protocol=protocol, |
| 262 | protocol_port=protocol_port, |
| 263 | subnet_id=subnet['id'], |
| 264 | pool_id=pool['id']) |
raiesmh08 | 0fe7685 | 2013-09-13 11:52:56 +0530 | [diff] [blame] | 265 | vip = body['vip'] |
| 266 | cls.vips.append(vip) |
| 267 | return vip |
raiesmh08 | f8437ed | 2013-09-17 10:59:38 +0530 | [diff] [blame] | 268 | |
| 269 | @classmethod |
Elena Ezhova | 43c70a2 | 2014-01-14 12:42:51 +0400 | [diff] [blame] | 270 | def update_vip(cls, name): |
| 271 | resp, body = cls.client.update_vip(name=name) |
| 272 | vip = body['vip'] |
| 273 | return vip |
| 274 | |
| 275 | @classmethod |
Sergey Shnaidman | 97e6a0f | 2014-11-12 20:00:53 +0300 | [diff] [blame^] | 276 | def create_member(cls, protocol_port, pool, ip_version=None): |
raiesmh08 | f8437ed | 2013-09-17 10:59:38 +0530 | [diff] [blame] | 277 | """Wrapper utility that returns a test member.""" |
Sergey Shnaidman | 97e6a0f | 2014-11-12 20:00:53 +0300 | [diff] [blame^] | 278 | ip_version = ip_version if ip_version is not None else cls._ip_version |
| 279 | member_address = "fd00::abcd" if ip_version == 6 else "10.0.9.46" |
| 280 | resp, body = cls.client.create_member(address=member_address, |
Ann Kamyshnikova | 2bc1c43 | 2013-12-10 17:31:50 +0400 | [diff] [blame] | 281 | protocol_port=protocol_port, |
| 282 | pool_id=pool['id']) |
raiesmh08 | f8437ed | 2013-09-17 10:59:38 +0530 | [diff] [blame] | 283 | member = body['member'] |
| 284 | cls.members.append(member) |
| 285 | return member |
raiesmh08 | 32580d0 | 2013-09-17 13:11:34 +0530 | [diff] [blame] | 286 | |
| 287 | @classmethod |
Ann Kamyshnikova | 2bc1c43 | 2013-12-10 17:31:50 +0400 | [diff] [blame] | 288 | def update_member(cls, admin_state_up): |
| 289 | resp, body = cls.client.update_member(admin_state_up=admin_state_up) |
| 290 | member = body['member'] |
| 291 | return member |
| 292 | |
| 293 | @classmethod |
raiesmh08 | 32580d0 | 2013-09-17 13:11:34 +0530 | [diff] [blame] | 294 | def create_health_monitor(cls, delay, max_retries, Type, timeout): |
| 295 | """Wrapper utility that returns a test health monitor.""" |
Elena Ezhova | 43c70a2 | 2014-01-14 12:42:51 +0400 | [diff] [blame] | 296 | resp, body = cls.client.create_health_monitor(delay=delay, |
| 297 | max_retries=max_retries, |
| 298 | type=Type, |
| 299 | timeout=timeout) |
raiesmh08 | 32580d0 | 2013-09-17 13:11:34 +0530 | [diff] [blame] | 300 | health_monitor = body['health_monitor'] |
| 301 | cls.health_monitors.append(health_monitor) |
| 302 | return health_monitor |
Anju Tiwari | 860097d | 2013-10-17 11:10:39 +0530 | [diff] [blame] | 303 | |
| 304 | @classmethod |
Elena Ezhova | 43c70a2 | 2014-01-14 12:42:51 +0400 | [diff] [blame] | 305 | def update_health_monitor(cls, admin_state_up): |
| 306 | resp, body = cls.client.update_vip(admin_state_up=admin_state_up) |
| 307 | health_monitor = body['health_monitor'] |
| 308 | return health_monitor |
| 309 | |
| 310 | @classmethod |
Anju Tiwari | 860097d | 2013-10-17 11:10:39 +0530 | [diff] [blame] | 311 | def create_router_interface(cls, router_id, subnet_id): |
| 312 | """Wrapper utility that returns a router interface.""" |
| 313 | resp, interface = cls.client.add_router_interface_with_subnet_id( |
| 314 | router_id, subnet_id) |
wanglianmin | 5e4b47a | 2014-03-12 18:16:18 +0800 | [diff] [blame] | 315 | return interface |
Anju Tiwari | 860097d | 2013-10-17 11:10:39 +0530 | [diff] [blame] | 316 | |
| 317 | @classmethod |
| 318 | def create_vpnservice(cls, subnet_id, router_id): |
| 319 | """Wrapper utility that returns a test vpn service.""" |
Eugene Nikanorov | 909ded1 | 2013-12-15 17:45:37 +0400 | [diff] [blame] | 320 | resp, body = cls.client.create_vpnservice( |
Eugene Nikanorov | f7e2fa4 | 2014-04-17 00:05:36 +0400 | [diff] [blame] | 321 | subnet_id=subnet_id, router_id=router_id, admin_state_up=True, |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 322 | name=data_utils.rand_name("vpnservice-")) |
Anju Tiwari | 860097d | 2013-10-17 11:10:39 +0530 | [diff] [blame] | 323 | vpnservice = body['vpnservice'] |
| 324 | cls.vpnservices.append(vpnservice) |
| 325 | return vpnservice |
Salvatore Orlando | ce22b49 | 2013-09-20 04:04:11 -0700 | [diff] [blame] | 326 | |
raiesmh08 | bd6070d | 2013-12-06 15:13:38 +0530 | [diff] [blame] | 327 | @classmethod |
Eugene Nikanorov | 909ded1 | 2013-12-15 17:45:37 +0400 | [diff] [blame] | 328 | def create_ikepolicy(cls, name): |
raiesmh08 | bd6070d | 2013-12-06 15:13:38 +0530 | [diff] [blame] | 329 | """Wrapper utility that returns a test ike policy.""" |
Eugene Nikanorov | f7e2fa4 | 2014-04-17 00:05:36 +0400 | [diff] [blame] | 330 | resp, body = cls.client.create_ikepolicy(name=name) |
raiesmh08 | bd6070d | 2013-12-06 15:13:38 +0530 | [diff] [blame] | 331 | ikepolicy = body['ikepolicy'] |
| 332 | cls.ikepolicies.append(ikepolicy) |
| 333 | return ikepolicy |
| 334 | |
Mh Raies | 96594fc | 2014-03-26 16:34:18 +0530 | [diff] [blame] | 335 | @classmethod |
| 336 | def create_firewall_rule(cls, action, protocol): |
| 337 | """Wrapper utility that returns a test firewall rule.""" |
| 338 | resp, body = cls.client.create_firewall_rule( |
| 339 | name=data_utils.rand_name("fw-rule"), |
| 340 | action=action, |
| 341 | protocol=protocol) |
| 342 | fw_rule = body['firewall_rule'] |
| 343 | cls.fw_rules.append(fw_rule) |
| 344 | return fw_rule |
| 345 | |
| 346 | @classmethod |
| 347 | def create_firewall_policy(cls): |
| 348 | """Wrapper utility that returns a test firewall policy.""" |
| 349 | resp, body = cls.client.create_firewall_policy( |
| 350 | name=data_utils.rand_name("fw-policy")) |
| 351 | fw_policy = body['firewall_policy'] |
| 352 | cls.fw_policies.append(fw_policy) |
| 353 | return fw_policy |
| 354 | |
Adam Gandelman | 3e9d12b | 2014-04-02 17:04:19 -0700 | [diff] [blame] | 355 | @classmethod |
| 356 | def delete_router(cls, router): |
| 357 | resp, body = cls.client.list_router_interfaces(router['id']) |
| 358 | interfaces = body['ports'] |
| 359 | for i in interfaces: |
| 360 | cls.client.remove_router_interface_with_subnet_id( |
| 361 | router['id'], i['fixed_ips'][0]['subnet_id']) |
| 362 | cls.client.delete_router(router['id']) |
| 363 | |
raiesmh08 | df3fac4 | 2014-06-02 15:42:18 +0530 | [diff] [blame] | 364 | @classmethod |
| 365 | def create_ipsecpolicy(cls, name): |
| 366 | """Wrapper utility that returns a test ipsec policy.""" |
| 367 | _, body = cls.client.create_ipsecpolicy(name=name) |
| 368 | ipsecpolicy = body['ipsecpolicy'] |
| 369 | cls.ipsecpolicies.append(ipsecpolicy) |
| 370 | return ipsecpolicy |
| 371 | |
Salvatore Orlando | ce22b49 | 2013-09-20 04:04:11 -0700 | [diff] [blame] | 372 | |
| 373 | class BaseAdminNetworkTest(BaseNetworkTest): |
| 374 | |
| 375 | @classmethod |
Andrea Frittoli | da4a245 | 2014-09-15 13:12:08 +0100 | [diff] [blame] | 376 | def resource_setup(cls): |
| 377 | super(BaseAdminNetworkTest, cls).resource_setup() |
Andrea Frittoli | 8283b4e | 2014-07-17 13:28:58 +0100 | [diff] [blame] | 378 | |
| 379 | try: |
| 380 | creds = cls.isolated_creds.get_admin_creds() |
| 381 | cls.os_adm = clients.Manager( |
| 382 | credentials=creds, interface=cls._interface) |
| 383 | except NotImplementedError: |
Salvatore Orlando | ce22b49 | 2013-09-20 04:04:11 -0700 | [diff] [blame] | 384 | msg = ("Missing Administrative Network API credentials " |
| 385 | "in configuration.") |
| 386 | raise cls.skipException(msg) |
Matthew Treinish | 2f6628c | 2013-10-21 21:06:27 +0000 | [diff] [blame] | 387 | cls.admin_client = cls.os_adm.network_client |
Emilien Macchi | 0d0b7cc | 2014-01-11 12:30:21 -0500 | [diff] [blame] | 388 | |
| 389 | @classmethod |
| 390 | def create_metering_label(cls, name, description): |
| 391 | """Wrapper utility that returns a test metering label.""" |
| 392 | resp, body = cls.admin_client.create_metering_label( |
| 393 | description=description, |
| 394 | name=data_utils.rand_name("metering-label")) |
| 395 | metering_label = body['metering_label'] |
| 396 | cls.metering_labels.append(metering_label) |
| 397 | return metering_label |
| 398 | |
| 399 | @classmethod |
| 400 | def create_metering_label_rule(cls, remote_ip_prefix, direction, |
| 401 | metering_label_id): |
| 402 | """Wrapper utility that returns a test metering label rule.""" |
| 403 | resp, body = cls.admin_client.create_metering_label_rule( |
| 404 | remote_ip_prefix=remote_ip_prefix, direction=direction, |
| 405 | metering_label_id=metering_label_id) |
| 406 | metering_label_rule = body['metering_label_rule'] |
| 407 | cls.metering_label_rules.append(metering_label_rule) |
| 408 | return metering_label_rule |