blob: 7646b63e13829898352b68fae4f19178caedb271 [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.
Miguel Lavallecc939612013-02-22 17:27:20 -060015import netaddr
Matthew Treinish71426682015-04-23 11:19:38 -040016import six
Kevin Benton6919da42016-03-05 18:00:03 -080017import testtools
Jay Pipesf4dad392012-06-05 16:03:58 -040018
Sean Dague1937d092013-05-17 16:36:38 -040019from tempest.api.network import base
Rohan Kanade35589aa2014-08-19 14:56:12 +020020from tempest.common import custom_matchers
Andrea Frittolicd368412017-08-14 21:37:56 +010021from tempest.common import utils
Matthew Treinish03b48df2014-01-29 16:59:49 +000022from tempest import config
Ken'ichi Ohmichif50e4df2017-03-10 10:52:53 -080023from tempest.lib.common.utils import data_utils
Jordan Pittier9e227c52016-02-09 14:35:18 +010024from tempest.lib.common.utils import test_utils
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -080025from tempest.lib import decorators
Andrea Frittoli (andreaf)db9672e2016-02-23 14:07:24 -050026from tempest.lib import exceptions as lib_exc
Unmesh Gurjar44986832012-05-08 19:57:10 +053027
Matthew Treinish03b48df2014-01-29 16:59:49 +000028CONF = config.CONF
29
Unmesh Gurjar44986832012-05-08 19:57:10 +053030
Jonte Watford871547c2016-10-10 20:11:04 +000031class BaseNetworkTestResources(base.BaseNetworkTest):
zhufl0abb76f2020-04-26 14:37:47 +080032 """Test networks"""
Miguel Lavallecc939612013-02-22 17:27:20 -060033
Unmesh Gurjar44986832012-05-08 19:57:10 +053034 @classmethod
Andrea Frittolida4a2452014-09-15 13:12:08 +010035 def resource_setup(cls):
Jonte Watford871547c2016-10-10 20:11:04 +000036 super(BaseNetworkTestResources, cls).resource_setup()
Jay Pipesf4dad392012-06-05 16:03:58 -040037 cls.network = cls.create_network()
zhuflec61bac2017-09-01 15:59:50 +080038 cls.subnet = cls._create_subnet_with_last_subnet_block(cls.network)
Rohan Kanade35589aa2014-08-19 14:56:12 +020039 cls._subnet_data = {6: {'gateway':
40 str(cls._get_gateway_from_tempest_conf(6)),
41 'allocation_pools':
42 cls._get_allocation_pools_from_gateway(6),
43 'dns_nameservers': ['2001:4860:4860::8844',
44 '2001:4860:4860::8888'],
45 'host_routes': [{'destination': '2001::/64',
46 'nexthop': '2003::1'}],
47 'new_host_routes': [{'destination':
48 '2001::/64',
49 'nexthop': '2005::1'}],
50 'new_dns_nameservers':
51 ['2001:4860:4860::7744',
52 '2001:4860:4860::7888']},
53 4: {'gateway':
54 str(cls._get_gateway_from_tempest_conf(4)),
55 'allocation_pools':
56 cls._get_allocation_pools_from_gateway(4),
57 'dns_nameservers': ['8.8.4.4', '8.8.8.8'],
58 'host_routes': [{'destination': '10.20.0.0/32',
59 'nexthop': '10.100.1.1'}],
60 'new_host_routes': [{'destination':
61 '10.20.0.0/32',
62 'nexthop':
63 '10.100.1.2'}],
64 'new_dns_nameservers': ['7.8.8.8', '7.8.4.4']}}
65
66 @classmethod
zhuflec61bac2017-09-01 15:59:50 +080067 def _create_subnet_with_last_subnet_block(cls, network):
Sean Dagueed6e5862016-04-04 10:49:13 -040068 # Derive last subnet CIDR block from project CIDR and
Ken'ichi Ohmichie03bea92015-11-19 07:45:58 +000069 # create the subnet with that derived CIDR
zhuflec61bac2017-09-01 15:59:50 +080070 subnet_cidr = list(cls.cidr.subnet(cls.mask_bits))[-1]
venakata anil1a2a64a2014-12-02 07:25:59 +000071 gateway_ip = str(netaddr.IPAddress(subnet_cidr) + 1)
72 return cls.create_subnet(network, gateway=gateway_ip,
zhuflec61bac2017-09-01 15:59:50 +080073 cidr=subnet_cidr, mask_bits=cls.mask_bits)
venakata anil1a2a64a2014-12-02 07:25:59 +000074
75 @classmethod
Rohan Kanade35589aa2014-08-19 14:56:12 +020076 def _get_gateway_from_tempest_conf(cls, ip_version):
77 """Return first subnet gateway for configured CIDR """
78 if ip_version == 4:
Sean Dagueed6e5862016-04-04 10:49:13 -040079 cidr = netaddr.IPNetwork(CONF.network.project_network_cidr)
80 mask_bits = CONF.network.project_network_mask_bits
Rohan Kanade35589aa2014-08-19 14:56:12 +020081 elif ip_version == 6:
Sean Dagueed6e5862016-04-04 10:49:13 -040082 cidr = netaddr.IPNetwork(CONF.network.project_network_v6_cidr)
83 mask_bits = CONF.network.project_network_v6_mask_bits
Rohan Kanade35589aa2014-08-19 14:56:12 +020084
85 if mask_bits >= cidr.prefixlen:
86 return netaddr.IPAddress(cidr) + 1
87 else:
88 for subnet in cidr.subnet(mask_bits):
89 return netaddr.IPAddress(subnet) + 1
90
91 @classmethod
92 def _get_allocation_pools_from_gateway(cls, ip_version):
93 """Return allocation range for subnet of given gateway"""
94 gateway = cls._get_gateway_from_tempest_conf(ip_version)
Hynek Mlnarikbe634fc2016-06-27 09:34:15 +020095 return [{'start': str(gateway + 2), 'end': str(gateway + 6)}]
Rohan Kanade35589aa2014-08-19 14:56:12 +020096
97 def subnet_dict(self, include_keys):
Ken'ichi Ohmichie03bea92015-11-19 07:45:58 +000098 # Return a subnet dict which has include_keys and their corresponding
99 # value from self._subnet_data
Rohan Kanade35589aa2014-08-19 14:56:12 +0200100 return dict((key, self._subnet_data[self._ip_version][key])
101 for key in include_keys)
102
103 def _compare_resource_attrs(self, actual, expected):
104 exclude_keys = set(actual).symmetric_difference(expected)
105 self.assertThat(actual, custom_matchers.MatchesDictExceptForKeys(
106 expected, exclude_keys))
107
108 def _create_verify_delete_subnet(self, cidr=None, mask_bits=None,
109 **kwargs):
110 network = self.create_network()
111 net_id = network['id']
112 gateway = kwargs.pop('gateway', None)
113 subnet = self.create_subnet(network, gateway, cidr, mask_bits,
114 **kwargs)
115 compare_args_full = dict(gateway_ip=gateway, cidr=cidr,
116 mask_bits=mask_bits, **kwargs)
guo yunxian7bbbec12016-08-21 20:03:10 +0800117 compare_args = dict((k, v) for k, v in compare_args_full.items()
Rohan Kanade35589aa2014-08-19 14:56:12 +0200118 if v is not None)
119
120 if 'dns_nameservers' in set(subnet).intersection(compare_args):
121 self.assertEqual(sorted(compare_args['dns_nameservers']),
122 sorted(subnet['dns_nameservers']))
123 del subnet['dns_nameservers'], compare_args['dns_nameservers']
124
125 self._compare_resource_attrs(subnet, compare_args)
John Warren94d8faf2015-09-15 12:22:24 -0400126 self.networks_client.delete_network(net_id)
Unmesh Gurjar44986832012-05-08 19:57:10 +0530127
Jonte Watford871547c2016-10-10 20:11:04 +0000128
129class NetworksTest(BaseNetworkTestResources):
130 """Tests the following operations in the Neutron API:
131
132 create a network for a project
133 list project's networks
134 show a project network details
135 create a subnet for a project
136 list project's subnets
137 show a project subnet details
138 network update
139 subnet update
140 delete a network also deletes its subnets
141 list external networks
142
143 All subnet tests are run once with ipv4 and once with ipv6.
144
145 v2.0 of the Neutron API is assumed. It is also assumed that the following
146 options are defined in the [network] section of etc/tempest.conf:
147
148 project_network_cidr with a block of cidr's from which smaller blocks
149 can be allocated for project ipv4 subnets
150
151 project_network_v6_cidr is the equivalent for ipv6 subnets
152
153 project_network_mask_bits with the mask bits to be used to partition
154 the block defined by project_network_cidr
155
156 project_network_v6_mask_bits is the equivalent for ipv6 subnets
157 """
158
Jordan Pittier3b46d272017-04-12 16:17:28 +0200159 @decorators.attr(type='smoke')
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800160 @decorators.idempotent_id('0e269138-0da6-4efc-a46d-578161e7b221')
raiesmh08e1aad982013-08-05 14:19:36 +0530161 def test_create_update_delete_network_subnet(self):
zhufl0abb76f2020-04-26 14:37:47 +0800162 """Verify creating, updating and deleting network subnet"""
Mark Maglana5885eb32014-02-28 10:57:34 -0800163 # Create a network
zhufld2c40ca2016-10-18 17:03:07 +0800164 network = self.create_network()
Slawek Kaplonski748dd8d2019-04-16 23:38:35 +0200165 self.addCleanup(test_utils.call_and_ignore_notfound_exc,
166 self.networks_client.delete_network, network['id'])
raiesmh08e1aad982013-08-05 14:19:36 +0530167 net_id = network['id']
Santosh Kumar42c94802014-08-08 04:31:42 -0700168 self.assertEqual('ACTIVE', network['status'])
Mark Maglana5885eb32014-02-28 10:57:34 -0800169 # Verify network update
raiesmh08e1aad982013-08-05 14:19:36 +0530170 new_name = "New_network"
John Warren94d8faf2015-09-15 12:22:24 -0400171 body = self.networks_client.update_network(net_id, name=new_name)
raiesmh08e1aad982013-08-05 14:19:36 +0530172 updated_net = body['network']
173 self.assertEqual(updated_net['name'], new_name)
Miguel Lavallecc939612013-02-22 17:27:20 -0600174 # Find a cidr that is not in use yet and create a subnet with it
Matthew Treinish6b8cd2a2014-03-03 20:45:56 +0000175 subnet = self.create_subnet(network)
raiesmh08e1aad982013-08-05 14:19:36 +0530176 subnet_id = subnet['id']
Mark Maglana5885eb32014-02-28 10:57:34 -0800177 # Verify subnet update
178 new_name = "New_subnet"
John Warren3961acd2015-10-02 14:38:53 -0400179 body = self.subnets_client.update_subnet(subnet_id, name=new_name)
raiesmh08e1aad982013-08-05 14:19:36 +0530180 updated_subnet = body['subnet']
Mark Maglana5885eb32014-02-28 10:57:34 -0800181 self.assertEqual(updated_subnet['name'], new_name)
Slawek Kaplonski748dd8d2019-04-16 23:38:35 +0200182 # Verify network delete
183 self.networks_client.delete_network(network['id'])
Unmesh Gurjar44986832012-05-08 19:57:10 +0530184
Jordan Pittier3b46d272017-04-12 16:17:28 +0200185 @decorators.attr(type='smoke')
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800186 @decorators.idempotent_id('2bf13842-c93f-4a69-83ed-717d2ec3b44e')
Unmesh Gurjar44986832012-05-08 19:57:10 +0530187 def test_show_network(self):
zhufl0abb76f2020-04-26 14:37:47 +0800188 """Verify the details of a network"""
John Warren94d8faf2015-09-15 12:22:24 -0400189 body = self.networks_client.show_network(self.network['id'])
Unmesh Gurjar44986832012-05-08 19:57:10 +0530190 network = body['network']
Mark Maglana5885eb32014-02-28 10:57:34 -0800191 for key in ['id', 'name']:
192 self.assertEqual(network[key], self.network[key])
Unmesh Gurjar44986832012-05-08 19:57:10 +0530193
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800194 @decorators.idempotent_id('867819bb-c4b6-45f7-acf9-90edcf70aa5e')
jun xied557d9b2014-01-09 14:00:36 +0800195 def test_show_network_fields(self):
zhufl0abb76f2020-04-26 14:37:47 +0800196 """Verify specific fields of a network"""
Zhi Kun Liu903596c2014-04-11 08:55:53 -0500197 fields = ['id', 'name']
Andrea Frittolicd368412017-08-14 21:37:56 +0100198 if utils.is_extension_enabled('net-mtu', 'network'):
Bruce Tand3e9b4a2016-09-22 09:17:06 +0000199 fields.append('mtu')
John Warren94d8faf2015-09-15 12:22:24 -0400200 body = self.networks_client.show_network(self.network['id'],
201 fields=fields)
jun xied557d9b2014-01-09 14:00:36 +0800202 network = body['network']
Zhi Kun Liu903596c2014-04-11 08:55:53 -0500203 self.assertEqual(sorted(network.keys()), sorted(fields))
204 for field_name in fields:
Mark Maglana5885eb32014-02-28 10:57:34 -0800205 self.assertEqual(network[field_name], self.network[field_name])
Bruce Tand3e9b4a2016-09-22 09:17:06 +0000206 self.assertNotIn('tenant_id', network)
207 self.assertNotIn('project_id', network)
jun xied557d9b2014-01-09 14:00:36 +0800208
Jordan Pittier3b46d272017-04-12 16:17:28 +0200209 @decorators.attr(type='smoke')
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800210 @decorators.idempotent_id('f7ffdeda-e200-4a7a-bcbe-05716e86bf43')
Unmesh Gurjar44986832012-05-08 19:57:10 +0530211 def test_list_networks(self):
zhufl0abb76f2020-04-26 14:37:47 +0800212 """Verify the network exists in the list of all networks"""
John Warren94d8faf2015-09-15 12:22:24 -0400213 body = self.networks_client.list_networks()
Mark Maglana5885eb32014-02-28 10:57:34 -0800214 networks = [network['id'] for network in body['networks']
215 if network['id'] == self.network['id']]
216 self.assertNotEmpty(networks, "Created network not found in the list")
Unmesh Gurjar44986832012-05-08 19:57:10 +0530217
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800218 @decorators.idempotent_id('6ae6d24f-9194-4869-9c85-c313cb20e080')
jun xie0b4735d2014-01-07 15:42:58 +0800219 def test_list_networks_fields(self):
zhufl0abb76f2020-04-26 14:37:47 +0800220 """Verify specific fields of the networks"""
Zhi Kun Liu903596c2014-04-11 08:55:53 -0500221 fields = ['id', 'name']
Andrea Frittolicd368412017-08-14 21:37:56 +0100222 if utils.is_extension_enabled('net-mtu', 'network'):
Bruce Tand3e9b4a2016-09-22 09:17:06 +0000223 fields.append('mtu')
John Warren94d8faf2015-09-15 12:22:24 -0400224 body = self.networks_client.list_networks(fields=fields)
jun xie0b4735d2014-01-07 15:42:58 +0800225 networks = body['networks']
Mark Maglana5885eb32014-02-28 10:57:34 -0800226 self.assertNotEmpty(networks, "Network list returned is empty")
227 for network in networks:
Zhi Kun Liu903596c2014-04-11 08:55:53 -0500228 self.assertEqual(sorted(network.keys()), sorted(fields))
jun xie0b4735d2014-01-07 15:42:58 +0800229
Jordan Pittier3b46d272017-04-12 16:17:28 +0200230 @decorators.attr(type='smoke')
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800231 @decorators.idempotent_id('bd635d81-6030-4dd1-b3b9-31ba0cfdf6cc')
Miguel Lavallecc939612013-02-22 17:27:20 -0600232 def test_show_subnet(self):
zhufl0abb76f2020-04-26 14:37:47 +0800233 """Verify the details of a subnet"""
John Warren3961acd2015-10-02 14:38:53 -0400234 body = self.subnets_client.show_subnet(self.subnet['id'])
Miguel Lavallecc939612013-02-22 17:27:20 -0600235 subnet = body['subnet']
Mark Maglana5885eb32014-02-28 10:57:34 -0800236 self.assertNotEmpty(subnet, "Subnet returned has no fields")
237 for key in ['id', 'cidr']:
238 self.assertIn(key, subnet)
239 self.assertEqual(subnet[key], self.subnet[key])
Miguel Lavallecc939612013-02-22 17:27:20 -0600240
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800241 @decorators.idempotent_id('270fff0b-8bfc-411f-a184-1e8fd35286f0')
jun xied557d9b2014-01-09 14:00:36 +0800242 def test_show_subnet_fields(self):
zhufl0abb76f2020-04-26 14:37:47 +0800243 """Verify specific fields of a subnet"""
Zhi Kun Liu903596c2014-04-11 08:55:53 -0500244 fields = ['id', 'network_id']
John Warren3961acd2015-10-02 14:38:53 -0400245 body = self.subnets_client.show_subnet(self.subnet['id'],
246 fields=fields)
jun xied557d9b2014-01-09 14:00:36 +0800247 subnet = body['subnet']
Zhi Kun Liu903596c2014-04-11 08:55:53 -0500248 self.assertEqual(sorted(subnet.keys()), sorted(fields))
249 for field_name in fields:
Mark Maglana5885eb32014-02-28 10:57:34 -0800250 self.assertEqual(subnet[field_name], self.subnet[field_name])
jun xied557d9b2014-01-09 14:00:36 +0800251
Jordan Pittier3b46d272017-04-12 16:17:28 +0200252 @decorators.attr(type='smoke')
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800253 @decorators.idempotent_id('db68ba48-f4ea-49e9-81d1-e367f6d0b20a')
Miguel Lavallecc939612013-02-22 17:27:20 -0600254 def test_list_subnets(self):
zhufl0abb76f2020-04-26 14:37:47 +0800255 """Verify the subnet exists in the list of all subnets"""
John Warren3961acd2015-10-02 14:38:53 -0400256 body = self.subnets_client.list_subnets()
Mark Maglana5885eb32014-02-28 10:57:34 -0800257 subnets = [subnet['id'] for subnet in body['subnets']
258 if subnet['id'] == self.subnet['id']]
259 self.assertNotEmpty(subnets, "Created subnet not found in the list")
raiesmh08e1aad982013-08-05 14:19:36 +0530260
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800261 @decorators.idempotent_id('842589e3-9663-46b0-85e4-7f01273b0412')
jun xie0b4735d2014-01-07 15:42:58 +0800262 def test_list_subnets_fields(self):
zhufl0abb76f2020-04-26 14:37:47 +0800263 """Verify specific fields of subnets"""
Zhi Kun Liu903596c2014-04-11 08:55:53 -0500264 fields = ['id', 'network_id']
John Warren3961acd2015-10-02 14:38:53 -0400265 body = self.subnets_client.list_subnets(fields=fields)
jun xie0b4735d2014-01-07 15:42:58 +0800266 subnets = body['subnets']
Mark Maglana5885eb32014-02-28 10:57:34 -0800267 self.assertNotEmpty(subnets, "Subnet list returned is empty")
268 for subnet in subnets:
Zhi Kun Liu903596c2014-04-11 08:55:53 -0500269 self.assertEqual(sorted(subnet.keys()), sorted(fields))
jun xie0b4735d2014-01-07 15:42:58 +0800270
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800271 @decorators.idempotent_id('f04f61a9-b7f3-4194-90b2-9bcf660d1bfe')
sukhdevc704a702014-01-15 11:50:56 -0800272 def test_delete_network_with_subnet(self):
zhufl0abb76f2020-04-26 14:37:47 +0800273 """Verify deleting network with subnet"""
sukhdevc704a702014-01-15 11:50:56 -0800274 # Creates a network
Tianbiao Qi309ac412016-10-31 19:42:37 +0800275 network = self.create_network()
sukhdevc704a702014-01-15 11:50:56 -0800276 net_id = network['id']
Jordan Pittier9e227c52016-02-09 14:35:18 +0100277 self.addCleanup(test_utils.call_and_ignore_notfound_exc,
zhufl587efc02017-11-28 09:52:50 +0800278 self.networks_client.delete_network, network['id'])
sukhdevc704a702014-01-15 11:50:56 -0800279
280 # Find a cidr that is not in use yet and create a subnet with it
281 subnet = self.create_subnet(network)
282 subnet_id = subnet['id']
283
284 # Delete network while the subnet still exists
Tianbiao Qi309ac412016-10-31 19:42:37 +0800285 self.networks_client.delete_network(net_id)
sukhdevc704a702014-01-15 11:50:56 -0800286
287 # Verify that the subnet got automatically deleted.
John Warren3961acd2015-10-02 14:38:53 -0400288 self.assertRaises(lib_exc.NotFound, self.subnets_client.show_subnet,
sukhdevc704a702014-01-15 11:50:56 -0800289 subnet_id)
290
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800291 @decorators.idempotent_id('d2d596e2-8e76-47a9-ac51-d4648009f4d3')
Sergey Shnaidman18cf5972014-09-02 22:05:00 +0400292 def test_create_delete_subnet_without_gateway(self):
zhufl0abb76f2020-04-26 14:37:47 +0800293 """Verify creating and deleting subnet without gateway"""
Sergey Shnaidman18cf5972014-09-02 22:05:00 +0400294 self._create_verify_delete_subnet()
295
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800296 @decorators.idempotent_id('9393b468-186d-496d-aa36-732348cd76e7')
Edgar Magana6a9ac342014-01-16 13:52:49 -0800297 def test_create_delete_subnet_with_gw(self):
zhufl0abb76f2020-04-26 14:37:47 +0800298 """Verify creating and deleting subnet with gateway"""
Rohan Kanade35589aa2014-08-19 14:56:12 +0200299 self._create_verify_delete_subnet(
300 **self.subnet_dict(['gateway']))
Edgar Magana6a9ac342014-01-16 13:52:49 -0800301
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800302 @decorators.idempotent_id('bec949c4-3147-4ba6-af5f-cd2306118404')
Rohan Kanade35589aa2014-08-19 14:56:12 +0200303 def test_create_delete_subnet_with_allocation_pools(self):
zhufl0abb76f2020-04-26 14:37:47 +0800304 """Verify creating and deleting subnet with allocation pools"""
Rohan Kanade35589aa2014-08-19 14:56:12 +0200305 self._create_verify_delete_subnet(
306 **self.subnet_dict(['allocation_pools']))
307
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800308 @decorators.idempotent_id('8217a149-0c6c-4cfb-93db-0486f707d13f')
Rohan Kanade35589aa2014-08-19 14:56:12 +0200309 def test_create_delete_subnet_with_gw_and_allocation_pools(self):
zhufl0abb76f2020-04-26 14:37:47 +0800310 """Verify create/delete subnet with gateway and allocation pools"""
Rohan Kanade35589aa2014-08-19 14:56:12 +0200311 self._create_verify_delete_subnet(**self.subnet_dict(
312 ['gateway', 'allocation_pools']))
313
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800314 @decorators.idempotent_id('d830de0a-be47-468f-8f02-1fd996118289')
Rohan Kanade35589aa2014-08-19 14:56:12 +0200315 def test_create_delete_subnet_with_host_routes_and_dns_nameservers(self):
zhufl0abb76f2020-04-26 14:37:47 +0800316 """Verify create/delete subnet with host routes and name servers"""
Rohan Kanade35589aa2014-08-19 14:56:12 +0200317 self._create_verify_delete_subnet(
318 **self.subnet_dict(['host_routes', 'dns_nameservers']))
319
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800320 @decorators.idempotent_id('94ce038d-ff0a-4a4c-a56b-09da3ca0b55d')
Rohan Kanade35589aa2014-08-19 14:56:12 +0200321 def test_create_delete_subnet_with_dhcp_enabled(self):
zhufl0abb76f2020-04-26 14:37:47 +0800322 """Verify create/delete subnet with dhcp enabled"""
Rohan Kanade35589aa2014-08-19 14:56:12 +0200323 self._create_verify_delete_subnet(enable_dhcp=True)
324
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800325 @decorators.idempotent_id('3d3852eb-3009-49ec-97ac-5ce83b73010a')
Rohan Kanade35589aa2014-08-19 14:56:12 +0200326 def test_update_subnet_gw_dns_host_routes_dhcp(self):
zhufl0abb76f2020-04-26 14:37:47 +0800327 """Verify updating subnet's gateway/nameserver/routes/dhcp"""
Rohan Kanade35589aa2014-08-19 14:56:12 +0200328 network = self.create_network()
Slawek Kaplonski748dd8d2019-04-16 23:38:35 +0200329 self.addCleanup(test_utils.call_and_ignore_notfound_exc,
330 self.networks_client.delete_network, network['id'])
Rohan Kanade35589aa2014-08-19 14:56:12 +0200331
332 subnet = self.create_subnet(
333 network, **self.subnet_dict(['gateway', 'host_routes',
afazekas40fcb9b2019-03-08 11:25:11 +0100334 'dns_nameservers',
Rohan Kanade35589aa2014-08-19 14:56:12 +0200335 'allocation_pools']))
336 subnet_id = subnet['id']
337 new_gateway = str(netaddr.IPAddress(
338 self._subnet_data[self._ip_version]['gateway']) + 1)
339 # Verify subnet update
340 new_host_routes = self._subnet_data[self._ip_version][
341 'new_host_routes']
342
343 new_dns_nameservers = self._subnet_data[self._ip_version][
344 'new_dns_nameservers']
345 kwargs = {'host_routes': new_host_routes,
346 'dns_nameservers': new_dns_nameservers,
347 'gateway_ip': new_gateway, 'enable_dhcp': True}
348
349 new_name = "New_subnet"
John Warren3961acd2015-10-02 14:38:53 -0400350 body = self.subnets_client.update_subnet(subnet_id, name=new_name,
351 **kwargs)
Rohan Kanade35589aa2014-08-19 14:56:12 +0200352 updated_subnet = body['subnet']
353 kwargs['name'] = new_name
354 self.assertEqual(sorted(updated_subnet['dns_nameservers']),
355 sorted(kwargs['dns_nameservers']))
356 del subnet['dns_nameservers'], kwargs['dns_nameservers']
357
358 self._compare_resource_attrs(updated_subnet, kwargs)
359
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800360 @decorators.idempotent_id('a4d9ec4c-0306-4111-a75c-db01a709030b')
Rohan Kanade35589aa2014-08-19 14:56:12 +0200361 def test_create_delete_subnet_all_attributes(self):
zhufl0abb76f2020-04-26 14:37:47 +0800362 """Verify create/delete subnet's all attributes"""
Rohan Kanade35589aa2014-08-19 14:56:12 +0200363 self._create_verify_delete_subnet(
364 enable_dhcp=True,
365 **self.subnet_dict(['gateway', 'host_routes', 'dns_nameservers']))
Edgar Magana6a9ac342014-01-16 13:52:49 -0800366
Jordan Pittier3b46d272017-04-12 16:17:28 +0200367 @decorators.attr(type='smoke')
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800368 @decorators.idempotent_id('af774677-42a9-4e4b-bb58-16fe6a5bc1ec')
Andrea Frittolicd368412017-08-14 21:37:56 +0100369 @utils.requires_ext(extension='external-net', service='network')
Kevin Benton6919da42016-03-05 18:00:03 -0800370 @testtools.skipUnless(CONF.network.public_network_id,
371 'The public_network_id option must be specified.')
Yair Friedbfdfc752014-09-28 13:56:45 +0300372 def test_external_network_visibility(self):
zhufl0abb76f2020-04-26 14:37:47 +0800373 """Verify external network's visibility"""
Duc Truongded59722017-07-18 14:33:24 -0700374 public_network_id = CONF.network.public_network_id
375
376 # find external network matching public_network_id
John Warren94d8faf2015-09-15 12:22:24 -0400377 body = self.networks_client.list_networks(**{'router:external': True})
Duc Truongded59722017-07-18 14:33:24 -0700378 external_network = next((network for network in body['networks']
379 if network['id'] == public_network_id), None)
380 self.assertIsNotNone(external_network, "Public network %s not found "
381 "in external network list"
382 % public_network_id)
Yair Friedbfdfc752014-09-28 13:56:45 +0300383
384 nonexternal = [net for net in body['networks'] if
385 not net['router:external']]
386 self.assertEmpty(nonexternal, "Found non-external networks"
387 " in filtered list (%s)." % nonexternal)
Duc Truongded59722017-07-18 14:33:24 -0700388
Kevin Benton6919da42016-03-05 18:00:03 -0800389 # only check the public network ID because the other networks may
390 # belong to other tests and their state may have changed during this
391 # test
Duc Truongded59722017-07-18 14:33:24 -0700392 body = self.subnets_client.list_subnets(network_id=public_network_id)
393
394 # check subnet visibility of external_network
395 if external_network['shared']:
396 self.assertNotEmpty(body['subnets'], "Subnets should be visible "
397 "for shared public network %s"
398 % public_network_id)
399 else:
400 self.assertEmpty(body['subnets'], "Subnets should not be visible "
401 "for non-shared public "
402 "network %s"
403 % public_network_id)
Yair Friedbfdfc752014-09-28 13:56:45 +0300404
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800405 @decorators.idempotent_id('c72c1c0c-2193-4aca-ccc4-b1442640bbbb')
Andrea Frittolicd368412017-08-14 21:37:56 +0100406 @utils.requires_ext(extension="standard-attr-description",
407 service="network")
Bruce Tand3e9b4a2016-09-22 09:17:06 +0000408 def test_create_update_network_description(self):
zhufl0abb76f2020-04-26 14:37:47 +0800409 """Verify creating and updating network's description"""
Bruce Tand3e9b4a2016-09-22 09:17:06 +0000410 body = self.create_network(description='d1')
411 self.assertEqual('d1', body['description'])
412 net_id = body['id']
413 body = self.networks_client.list_networks(id=net_id)['networks'][0]
414 self.assertEqual('d1', body['description'])
415 body = self.networks_client.update_network(body['id'],
416 description='d2')
417 self.assertEqual('d2', body['network']['description'])
418 body = self.networks_client.list_networks(id=net_id)['networks'][0]
419 self.assertEqual('d2', body['description'])
420
raiesmh086b055e22013-09-16 12:59:57 +0530421
Tong Liu7012c862016-04-11 22:32:05 +0000422class BulkNetworkOpsTest(base.BaseNetworkTest):
Ken'ichi Ohmichie03bea92015-11-19 07:45:58 +0000423 """Tests the following operations in the Neutron API:
raiesmh086b055e22013-09-16 12:59:57 +0530424
425 bulk network creation
426 bulk subnet creation
Eugene Nikanorove9d255a2013-12-18 16:31:42 +0400427 bulk port creation
Sean Dagueed6e5862016-04-04 10:49:13 -0400428 list project's networks
raiesmh086b055e22013-09-16 12:59:57 +0530429
430 v2.0 of the Neutron API is assumed. It is also assumed that the following
431 options are defined in the [network] section of etc/tempest.conf:
432
Sean Dagueed6e5862016-04-04 10:49:13 -0400433 project_network_cidr with a block of cidr's from which smaller blocks
434 can be allocated for project networks
raiesmh086b055e22013-09-16 12:59:57 +0530435
Sean Dagueed6e5862016-04-04 10:49:13 -0400436 project_network_mask_bits with the mask bits to be used to partition
437 the block defined by project-network_cidr
raiesmh086b055e22013-09-16 12:59:57 +0530438 """
439
raiesmh086b055e22013-09-16 12:59:57 +0530440 def _delete_networks(self, created_networks):
441 for n in created_networks:
John Warren94d8faf2015-09-15 12:22:24 -0400442 self.networks_client.delete_network(n['id'])
raiesmh086b055e22013-09-16 12:59:57 +0530443 # Asserting that the networks are not found in the list after deletion
John Warren94d8faf2015-09-15 12:22:24 -0400444 body = self.networks_client.list_networks()
Mark Maglana5885eb32014-02-28 10:57:34 -0800445 networks_list = [network['id'] for network in body['networks']]
raiesmh086b055e22013-09-16 12:59:57 +0530446 for n in created_networks:
447 self.assertNotIn(n['id'], networks_list)
448
449 def _delete_subnets(self, created_subnets):
450 for n in created_subnets:
John Warren3961acd2015-10-02 14:38:53 -0400451 self.subnets_client.delete_subnet(n['id'])
raiesmh086b055e22013-09-16 12:59:57 +0530452 # Asserting that the subnets are not found in the list after deletion
John Warren3961acd2015-10-02 14:38:53 -0400453 body = self.subnets_client.list_subnets()
Mark Maglana5885eb32014-02-28 10:57:34 -0800454 subnets_list = [subnet['id'] for subnet in body['subnets']]
raiesmh086b055e22013-09-16 12:59:57 +0530455 for n in created_subnets:
456 self.assertNotIn(n['id'], subnets_list)
457
458 def _delete_ports(self, created_ports):
459 for n in created_ports:
John Warren49c0fe52015-10-22 12:35:54 -0400460 self.ports_client.delete_port(n['id'])
raiesmh086b055e22013-09-16 12:59:57 +0530461 # Asserting that the ports are not found in the list after deletion
John Warren49c0fe52015-10-22 12:35:54 -0400462 body = self.ports_client.list_ports()
Mark Maglana5885eb32014-02-28 10:57:34 -0800463 ports_list = [port['id'] for port in body['ports']]
raiesmh086b055e22013-09-16 12:59:57 +0530464 for n in created_ports:
465 self.assertNotIn(n['id'], ports_list)
466
Jordan Pittier3b46d272017-04-12 16:17:28 +0200467 @decorators.attr(type='smoke')
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800468 @decorators.idempotent_id('d4f9024d-1e28-4fc1-a6b1-25dbc6fa11e2')
Nayna Patelb03eab42013-08-08 08:58:48 +0000469 def test_bulk_create_delete_network(self):
zhufl0abb76f2020-04-26 14:37:47 +0800470 """Verify creating and deleting multiple networks in one request"""
Nayna Patelb03eab42013-08-08 08:58:48 +0000471 # Creates 2 networks in one request
piyush1107867584aa72015-12-15 18:46:38 +0530472 network_list = [{'name': data_utils.rand_name('network-')},
473 {'name': data_utils.rand_name('network-')}]
Ken'ichi Ohmichi1f52fd92016-03-03 12:24:12 -0800474 body = self.networks_client.create_bulk_networks(networks=network_list)
Nayna Patelb03eab42013-08-08 08:58:48 +0000475 created_networks = body['networks']
Nayna Patelb03eab42013-08-08 08:58:48 +0000476 self.addCleanup(self._delete_networks, created_networks)
477 # Asserting that the networks are found in the list after creation
John Warren94d8faf2015-09-15 12:22:24 -0400478 body = self.networks_client.list_networks()
Mark Maglana5885eb32014-02-28 10:57:34 -0800479 networks_list = [network['id'] for network in body['networks']]
Nayna Patelb03eab42013-08-08 08:58:48 +0000480 for n in created_networks:
481 self.assertIsNotNone(n['id'])
482 self.assertIn(n['id'], networks_list)
raiesmh0867698322013-08-20 13:09:01 +0530483
Jordan Pittier3b46d272017-04-12 16:17:28 +0200484 @decorators.attr(type='smoke')
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800485 @decorators.idempotent_id('8936533b-c0aa-4f29-8e53-6cc873aec489')
raiesmh082d5c6512013-09-06 15:35:05 +0530486 def test_bulk_create_delete_subnet(self):
zhufl0abb76f2020-04-26 14:37:47 +0800487 """Verify creating and deleting multiple subnets in one request"""
Assaf Mullere4f78992014-06-19 17:32:14 +0300488 networks = [self.create_network(), self.create_network()]
raiesmh082d5c6512013-09-06 15:35:05 +0530489 # Creates 2 subnets in one request
zhuflec61bac2017-09-01 15:59:50 +0800490 cidrs = [subnet_cidr
491 for subnet_cidr in self.cidr.subnet(self.mask_bits)]
Rohan Kanade0efb0232015-02-19 13:33:31 +0530492
Mark Maglana5885eb32014-02-28 10:57:34 -0800493 names = [data_utils.rand_name('subnet-') for i in range(len(networks))]
494 subnets_list = []
raiesmh082d5c6512013-09-06 15:35:05 +0530495 for i in range(len(names)):
496 p1 = {
Assaf Mullere4f78992014-06-19 17:32:14 +0300497 'network_id': networks[i]['id'],
raiesmh082d5c6512013-09-06 15:35:05 +0530498 'cidr': str(cidrs[(i)]),
499 'name': names[i],
Rohan Kanade0efb0232015-02-19 13:33:31 +0530500 'ip_version': self._ip_version
raiesmh082d5c6512013-09-06 15:35:05 +0530501 }
Mark Maglana5885eb32014-02-28 10:57:34 -0800502 subnets_list.append(p1)
503 del subnets_list[1]['name']
Ken'ichi Ohmichi1f52fd92016-03-03 12:24:12 -0800504 body = self.subnets_client.create_bulk_subnets(subnets=subnets_list)
raiesmh082d5c6512013-09-06 15:35:05 +0530505 created_subnets = body['subnets']
506 self.addCleanup(self._delete_subnets, created_subnets)
raiesmh082d5c6512013-09-06 15:35:05 +0530507 # Asserting that the subnets are found in the list after creation
John Warren3961acd2015-10-02 14:38:53 -0400508 body = self.subnets_client.list_subnets()
Mark Maglana5885eb32014-02-28 10:57:34 -0800509 subnets_list = [subnet['id'] for subnet in body['subnets']]
raiesmh082d5c6512013-09-06 15:35:05 +0530510 for n in created_subnets:
511 self.assertIsNotNone(n['id'])
512 self.assertIn(n['id'], subnets_list)
513
Jordan Pittier3b46d272017-04-12 16:17:28 +0200514 @decorators.attr(type='smoke')
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800515 @decorators.idempotent_id('48037ff2-e889-4c3b-b86a-8e3f34d2d060')
raiesmh082d5c6512013-09-06 15:35:05 +0530516 def test_bulk_create_delete_port(self):
zhufl0abb76f2020-04-26 14:37:47 +0800517 """Verify creating and deleting multiple ports in one request"""
Assaf Mullere4f78992014-06-19 17:32:14 +0300518 networks = [self.create_network(), self.create_network()]
raiesmh082d5c6512013-09-06 15:35:05 +0530519 # Creates 2 ports in one request
Mark Maglana5885eb32014-02-28 10:57:34 -0800520 names = [data_utils.rand_name('port-') for i in range(len(networks))]
raiesmh082d5c6512013-09-06 15:35:05 +0530521 port_list = []
522 state = [True, False]
523 for i in range(len(names)):
524 p1 = {
Assaf Mullere4f78992014-06-19 17:32:14 +0300525 'network_id': networks[i]['id'],
raiesmh082d5c6512013-09-06 15:35:05 +0530526 'name': names[i],
527 'admin_state_up': state[i],
528 }
529 port_list.append(p1)
530 del port_list[1]['name']
Ken'ichi Ohmichi1f52fd92016-03-03 12:24:12 -0800531 body = self.ports_client.create_bulk_ports(ports=port_list)
raiesmh082d5c6512013-09-06 15:35:05 +0530532 created_ports = body['ports']
533 self.addCleanup(self._delete_ports, created_ports)
raiesmh082d5c6512013-09-06 15:35:05 +0530534 # Asserting that the ports are found in the list after creation
John Warren49c0fe52015-10-22 12:35:54 -0400535 body = self.ports_client.list_ports()
Mark Maglana5885eb32014-02-28 10:57:34 -0800536 ports_list = [port['id'] for port in body['ports']]
raiesmh082d5c6512013-09-06 15:35:05 +0530537 for n in created_ports:
538 self.assertIsNotNone(n['id'])
539 self.assertIn(n['id'], ports_list)
540
raiesmh0867698322013-08-20 13:09:01 +0530541
Tong Liu7012c862016-04-11 22:32:05 +0000542class BulkNetworkOpsIpV6Test(BulkNetworkOpsTest):
Rohan Kanade0efb0232015-02-19 13:33:31 +0530543 _ip_version = 6
544
545
Tong Liu7012c862016-04-11 22:32:05 +0000546class NetworksIpV6Test(NetworksTest):
Henry Gessauffda37a2014-01-16 11:17:55 -0500547 _ip_version = 6
Henry Gessauffda37a2014-01-16 11:17:55 -0500548
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800549 @decorators.idempotent_id('e41a4888-65a6-418c-a095-f7c2ef4ad59a')
Edgar Magana6a9ac342014-01-16 13:52:49 -0800550 def test_create_delete_subnet_with_gw(self):
zhufl0abb76f2020-04-26 14:37:47 +0800551 """Verify creating and deleting subnet with gateway"""
Sean Dagueed6e5862016-04-04 10:49:13 -0400552 net = netaddr.IPNetwork(CONF.network.project_network_v6_cidr)
sridhargaddamea73d532014-05-13 14:48:30 +0530553 gateway = str(netaddr.IPAddress(net.first + 2))
zhufld2c40ca2016-10-18 17:03:07 +0800554 network = self.create_network()
Edgar Magana6a9ac342014-01-16 13:52:49 -0800555 subnet = self.create_subnet(network, gateway)
556 # Verifies Subnet GW in IPv6
557 self.assertEqual(subnet['gateway_ip'], gateway)
Edgar Magana6a9ac342014-01-16 13:52:49 -0800558
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800559 @decorators.idempotent_id('ebb4fd95-524f-46af-83c1-0305b239338f')
Sergey Shnaidman18cf5972014-09-02 22:05:00 +0400560 def test_create_delete_subnet_with_default_gw(self):
zhufl0abb76f2020-04-26 14:37:47 +0800561 """Verify creating and deleting subnet without specified gateway"""
Sean Dagueed6e5862016-04-04 10:49:13 -0400562 net = netaddr.IPNetwork(CONF.network.project_network_v6_cidr)
sridhargaddamea73d532014-05-13 14:48:30 +0530563 gateway_ip = str(netaddr.IPAddress(net.first + 1))
zhufld2c40ca2016-10-18 17:03:07 +0800564 network = self.create_network()
Edgar Magana6a9ac342014-01-16 13:52:49 -0800565 subnet = self.create_subnet(network)
566 # Verifies Subnet GW in IPv6
sridhargaddamea73d532014-05-13 14:48:30 +0530567 self.assertEqual(subnet['gateway_ip'], gateway_ip)
Edgar Magana6a9ac342014-01-16 13:52:49 -0800568
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800569 @decorators.idempotent_id('a9653883-b2a4-469b-8c3c-4518430a7e55')
Sergey Shnaidman18cf5972014-09-02 22:05:00 +0400570 def test_create_list_subnet_with_no_gw64_one_network(self):
zhufl0abb76f2020-04-26 14:37:47 +0800571 """Verify subnets with and without gateway are in one network
572
573 First we create a network, then we create one ipv6 subnet with
574 gateway and one ipv4 subnet without gateway, the two subnets
575 should be in the same network
576 """
zhufld2c40ca2016-10-18 17:03:07 +0800577 network = self.create_network()
Sergey Shnaidman18cf5972014-09-02 22:05:00 +0400578 ipv6_gateway = self.subnet_dict(['gateway'])['gateway']
579 subnet1 = self.create_subnet(network,
580 ip_version=6,
581 gateway=ipv6_gateway)
582 self.assertEqual(netaddr.IPNetwork(subnet1['cidr']).version, 6,
583 'The created subnet is not IPv6')
584 subnet2 = self.create_subnet(network,
585 gateway=None,
586 ip_version=4)
587 self.assertEqual(netaddr.IPNetwork(subnet2['cidr']).version, 4,
588 'The created subnet is not IPv4')
589 # Verifies Subnet GW is set in IPv6
590 self.assertEqual(subnet1['gateway_ip'], ipv6_gateway)
591 # Verifies Subnet GW is None in IPv4
guo yunxian0306a4a2016-07-29 16:32:28 +0800592 self.assertIsNone(subnet2['gateway_ip'])
Sergey Shnaidman18cf5972014-09-02 22:05:00 +0400593 # Verifies all 2 subnets in the same network
John Warren3961acd2015-10-02 14:38:53 -0400594 body = self.subnets_client.list_subnets()
Sergey Shnaidman18cf5972014-09-02 22:05:00 +0400595 subnets = [sub['id'] for sub in body['subnets']
596 if sub['network_id'] == network['id']]
597 test_subnet_ids = [sub['id'] for sub in (subnet1, subnet2)]
ghanshyam2dee5e32016-06-24 14:42:56 +0900598 six.assertCountEqual(self, subnets,
599 test_subnet_ids,
600 'Subnet are not in the same network')
Sergey Shnaidman18cf5972014-09-02 22:05:00 +0400601
Sergey She757c332014-11-25 01:16:32 +0300602
Jonte Watford871547c2016-10-10 20:11:04 +0000603class NetworksIpV6TestAttrs(BaseNetworkTestResources):
604
605 _ip_version = 6
Sergey She757c332014-11-25 01:16:32 +0300606
607 @classmethod
Rohan Kanadea565e452015-01-27 14:00:13 +0530608 def skip_checks(cls):
609 super(NetworksIpV6TestAttrs, cls).skip_checks()
Sergey She757c332014-11-25 01:16:32 +0300610 if not CONF.network_feature_enabled.ipv6_subnet_attributes:
611 raise cls.skipException("IPv6 extended attributes for "
612 "subnets not available")
Sergey She757c332014-11-25 01:16:32 +0300613
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800614 @decorators.idempotent_id('da40cd1b-a833-4354-9a85-cd9b8a3b74ca')
Sergey Shnaidman18cf5972014-09-02 22:05:00 +0400615 def test_create_delete_subnet_with_v6_attributes_stateful(self):
zhufl0abb76f2020-04-26 14:37:47 +0800616 """Test create/delete subnet with ipv6 attributes stateful"""
Rohan Kanade35589aa2014-08-19 14:56:12 +0200617 self._create_verify_delete_subnet(
618 gateway=self._subnet_data[self._ip_version]['gateway'],
Sergey Shnaidman18cf5972014-09-02 22:05:00 +0400619 ipv6_ra_mode='dhcpv6-stateful',
620 ipv6_address_mode='dhcpv6-stateful')
621
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800622 @decorators.idempotent_id('176b030f-a923-4040-a755-9dc94329e60c')
Sergey Shnaidman18cf5972014-09-02 22:05:00 +0400623 def test_create_delete_subnet_with_v6_attributes_slaac(self):
zhufl0abb76f2020-04-26 14:37:47 +0800624 """Test create/delete subnet with ipv6 attributes slaac"""
Sergey Shnaidman18cf5972014-09-02 22:05:00 +0400625 self._create_verify_delete_subnet(
Rohan Kanade35589aa2014-08-19 14:56:12 +0200626 ipv6_ra_mode='slaac',
627 ipv6_address_mode='slaac')
Sean M. Collinsdd27a4d2014-05-13 10:33:15 -0400628
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800629 @decorators.idempotent_id('7d410310-8c86-4902-adf9-865d08e31adb')
Sergey Shnaidman18cf5972014-09-02 22:05:00 +0400630 def test_create_delete_subnet_with_v6_attributes_stateless(self):
zhufl0abb76f2020-04-26 14:37:47 +0800631 """Test create/delete subnet with ipv6 attributes stateless"""
Sergey Shnaidman18cf5972014-09-02 22:05:00 +0400632 self._create_verify_delete_subnet(
633 ipv6_ra_mode='dhcpv6-stateless',
634 ipv6_address_mode='dhcpv6-stateless')
Sergey She757c332014-11-25 01:16:32 +0300635
636 def _test_delete_subnet_with_ports(self, mode):
637 """Create subnet and delete it with existing ports"""
638 slaac_network = self.create_network()
639 subnet_slaac = self.create_subnet(slaac_network,
640 **{'ipv6_ra_mode': mode,
641 'ipv6_address_mode': mode})
642 port = self.create_port(slaac_network)
643 self.assertIsNotNone(port['fixed_ips'][0]['ip_address'])
John Warren3961acd2015-10-02 14:38:53 -0400644 self.subnets_client.delete_subnet(subnet_slaac['id'])
John Warren3961acd2015-10-02 14:38:53 -0400645 subnets = self.subnets_client.list_subnets()
Sergey She757c332014-11-25 01:16:32 +0300646 subnet_ids = [subnet['id'] for subnet in subnets['subnets']]
647 self.assertNotIn(subnet_slaac['id'], subnet_ids,
648 "Subnet wasn't deleted")
reedip6fb7e1a2016-03-10 13:32:01 +0900649 self.assertRaisesRegex(
Masayuki Igawad9388762015-01-20 14:56:42 +0900650 lib_exc.Conflict,
Sergey She757c332014-11-25 01:16:32 +0300651 "There are one or more ports still in use on the network",
John Warren94d8faf2015-09-15 12:22:24 -0400652 self.networks_client.delete_network,
Sergey She757c332014-11-25 01:16:32 +0300653 slaac_network['id'])
654
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800655 @decorators.idempotent_id('88554555-ebf8-41ef-9300-4926d45e06e9')
Sergey She757c332014-11-25 01:16:32 +0300656 def test_create_delete_slaac_subnet_with_ports(self):
657 """Test deleting subnet with SLAAC ports
658
659 Create subnet with SLAAC, create ports in network
660 and then you shall be able to delete subnet without port
661 deletion. But you still can not delete the network.
662 """
663 self._test_delete_subnet_with_ports("slaac")
664
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800665 @decorators.idempotent_id('2de6ab5a-fcf0-4144-9813-f91a940291f1')
Sergey She757c332014-11-25 01:16:32 +0300666 def test_create_delete_stateless_subnet_with_ports(self):
667 """Test deleting subnet with DHCPv6 stateless ports
668
669 Create subnet with DHCPv6 stateless, create ports in network
670 and then you shall be able to delete subnet without port
671 deletion. But you still can not delete the network.
672 """
673 self._test_delete_subnet_with_ports("dhcpv6-stateless")