blob: b1fba2d78364fe1d3456f42a0d9af0cc6e8a645d [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
Kevin Benton6919da42016-03-05 18:00:03 -080016import testtools
Jay Pipesf4dad392012-06-05 16:03:58 -040017
Sean Dague1937d092013-05-17 16:36:38 -040018from tempest.api.network import base
Rohan Kanade35589aa2014-08-19 14:56:12 +020019from tempest.common import custom_matchers
Andrea Frittolicd368412017-08-14 21:37:56 +010020from tempest.common import utils
Matthew Treinish03b48df2014-01-29 16:59:49 +000021from tempest import config
Ken'ichi Ohmichif50e4df2017-03-10 10:52:53 -080022from tempest.lib.common.utils import data_utils
Jordan Pittier9e227c52016-02-09 14:35:18 +010023from tempest.lib.common.utils import test_utils
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -080024from tempest.lib import decorators
Andrea Frittoli (andreaf)db9672e2016-02-23 14:07:24 -050025from tempest.lib import exceptions as lib_exc
Unmesh Gurjar44986832012-05-08 19:57:10 +053026
Matthew Treinish03b48df2014-01-29 16:59:49 +000027CONF = config.CONF
28
Unmesh Gurjar44986832012-05-08 19:57:10 +053029
Jonte Watford871547c2016-10-10 20:11:04 +000030class BaseNetworkTestResources(base.BaseNetworkTest):
zhufl0abb76f2020-04-26 14:37:47 +080031 """Test networks"""
Miguel Lavallecc939612013-02-22 17:27:20 -060032
Unmesh Gurjar44986832012-05-08 19:57:10 +053033 @classmethod
Andrea Frittolida4a2452014-09-15 13:12:08 +010034 def resource_setup(cls):
Jonte Watford871547c2016-10-10 20:11:04 +000035 super(BaseNetworkTestResources, cls).resource_setup()
Jay Pipesf4dad392012-06-05 16:03:58 -040036 cls.network = cls.create_network()
zhuflec61bac2017-09-01 15:59:50 +080037 cls.subnet = cls._create_subnet_with_last_subnet_block(cls.network)
Rohan Kanade35589aa2014-08-19 14:56:12 +020038 cls._subnet_data = {6: {'gateway':
39 str(cls._get_gateway_from_tempest_conf(6)),
40 'allocation_pools':
41 cls._get_allocation_pools_from_gateway(6),
42 'dns_nameservers': ['2001:4860:4860::8844',
43 '2001:4860:4860::8888'],
44 'host_routes': [{'destination': '2001::/64',
45 'nexthop': '2003::1'}],
46 'new_host_routes': [{'destination':
47 '2001::/64',
48 'nexthop': '2005::1'}],
49 'new_dns_nameservers':
50 ['2001:4860:4860::7744',
51 '2001:4860:4860::7888']},
52 4: {'gateway':
53 str(cls._get_gateway_from_tempest_conf(4)),
54 'allocation_pools':
55 cls._get_allocation_pools_from_gateway(4),
56 'dns_nameservers': ['8.8.4.4', '8.8.8.8'],
57 'host_routes': [{'destination': '10.20.0.0/32',
58 'nexthop': '10.100.1.1'}],
59 'new_host_routes': [{'destination':
60 '10.20.0.0/32',
61 'nexthop':
62 '10.100.1.2'}],
63 'new_dns_nameservers': ['7.8.8.8', '7.8.4.4']}}
64
65 @classmethod
zhuflec61bac2017-09-01 15:59:50 +080066 def _create_subnet_with_last_subnet_block(cls, network):
Sean Dagueed6e5862016-04-04 10:49:13 -040067 # Derive last subnet CIDR block from project CIDR and
Ken'ichi Ohmichie03bea92015-11-19 07:45:58 +000068 # create the subnet with that derived CIDR
zhuflec61bac2017-09-01 15:59:50 +080069 subnet_cidr = list(cls.cidr.subnet(cls.mask_bits))[-1]
venakata anil1a2a64a2014-12-02 07:25:59 +000070 gateway_ip = str(netaddr.IPAddress(subnet_cidr) + 1)
71 return cls.create_subnet(network, gateway=gateway_ip,
zhuflec61bac2017-09-01 15:59:50 +080072 cidr=subnet_cidr, mask_bits=cls.mask_bits)
venakata anil1a2a64a2014-12-02 07:25:59 +000073
74 @classmethod
Rohan Kanade35589aa2014-08-19 14:56:12 +020075 def _get_gateway_from_tempest_conf(cls, ip_version):
76 """Return first subnet gateway for configured CIDR """
77 if ip_version == 4:
Sean Dagueed6e5862016-04-04 10:49:13 -040078 cidr = netaddr.IPNetwork(CONF.network.project_network_cidr)
79 mask_bits = CONF.network.project_network_mask_bits
Rohan Kanade35589aa2014-08-19 14:56:12 +020080 elif ip_version == 6:
Sean Dagueed6e5862016-04-04 10:49:13 -040081 cidr = netaddr.IPNetwork(CONF.network.project_network_v6_cidr)
82 mask_bits = CONF.network.project_network_v6_mask_bits
Rohan Kanade35589aa2014-08-19 14:56:12 +020083
84 if mask_bits >= cidr.prefixlen:
85 return netaddr.IPAddress(cidr) + 1
86 else:
87 for subnet in cidr.subnet(mask_bits):
88 return netaddr.IPAddress(subnet) + 1
89
90 @classmethod
91 def _get_allocation_pools_from_gateway(cls, ip_version):
92 """Return allocation range for subnet of given gateway"""
93 gateway = cls._get_gateway_from_tempest_conf(ip_version)
Hynek Mlnarikbe634fc2016-06-27 09:34:15 +020094 return [{'start': str(gateway + 2), 'end': str(gateway + 6)}]
Rohan Kanade35589aa2014-08-19 14:56:12 +020095
96 def subnet_dict(self, include_keys):
Ken'ichi Ohmichie03bea92015-11-19 07:45:58 +000097 # Return a subnet dict which has include_keys and their corresponding
98 # value from self._subnet_data
Rohan Kanade35589aa2014-08-19 14:56:12 +020099 return dict((key, self._subnet_data[self._ip_version][key])
100 for key in include_keys)
101
102 def _compare_resource_attrs(self, actual, expected):
103 exclude_keys = set(actual).symmetric_difference(expected)
104 self.assertThat(actual, custom_matchers.MatchesDictExceptForKeys(
105 expected, exclude_keys))
106
107 def _create_verify_delete_subnet(self, cidr=None, mask_bits=None,
108 **kwargs):
109 network = self.create_network()
110 net_id = network['id']
111 gateway = kwargs.pop('gateway', None)
112 subnet = self.create_subnet(network, gateway, cidr, mask_bits,
113 **kwargs)
114 compare_args_full = dict(gateway_ip=gateway, cidr=cidr,
115 mask_bits=mask_bits, **kwargs)
guo yunxian7bbbec12016-08-21 20:03:10 +0800116 compare_args = dict((k, v) for k, v in compare_args_full.items()
Rohan Kanade35589aa2014-08-19 14:56:12 +0200117 if v is not None)
118
119 if 'dns_nameservers' in set(subnet).intersection(compare_args):
120 self.assertEqual(sorted(compare_args['dns_nameservers']),
121 sorted(subnet['dns_nameservers']))
122 del subnet['dns_nameservers'], compare_args['dns_nameservers']
123
124 self._compare_resource_attrs(subnet, compare_args)
John Warren94d8faf2015-09-15 12:22:24 -0400125 self.networks_client.delete_network(net_id)
Unmesh Gurjar44986832012-05-08 19:57:10 +0530126
Jonte Watford871547c2016-10-10 20:11:04 +0000127
128class NetworksTest(BaseNetworkTestResources):
129 """Tests the following operations in the Neutron API:
130
131 create a network for a project
132 list project's networks
133 show a project network details
134 create a subnet for a project
135 list project's subnets
136 show a project subnet details
137 network update
138 subnet update
139 delete a network also deletes its subnets
140 list external networks
141
142 All subnet tests are run once with ipv4 and once with ipv6.
143
144 v2.0 of the Neutron API is assumed. It is also assumed that the following
145 options are defined in the [network] section of etc/tempest.conf:
146
147 project_network_cidr with a block of cidr's from which smaller blocks
148 can be allocated for project ipv4 subnets
149
150 project_network_v6_cidr is the equivalent for ipv6 subnets
151
152 project_network_mask_bits with the mask bits to be used to partition
153 the block defined by project_network_cidr
154
155 project_network_v6_mask_bits is the equivalent for ipv6 subnets
156 """
157
Jordan Pittier3b46d272017-04-12 16:17:28 +0200158 @decorators.attr(type='smoke')
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800159 @decorators.idempotent_id('0e269138-0da6-4efc-a46d-578161e7b221')
raiesmh08e1aad982013-08-05 14:19:36 +0530160 def test_create_update_delete_network_subnet(self):
zhufl0abb76f2020-04-26 14:37:47 +0800161 """Verify creating, updating and deleting network subnet"""
Mark Maglana5885eb32014-02-28 10:57:34 -0800162 # Create a network
zhufld2c40ca2016-10-18 17:03:07 +0800163 network = self.create_network()
Slawek Kaplonski748dd8d2019-04-16 23:38:35 +0200164 self.addCleanup(test_utils.call_and_ignore_notfound_exc,
165 self.networks_client.delete_network, network['id'])
raiesmh08e1aad982013-08-05 14:19:36 +0530166 net_id = network['id']
Santosh Kumar42c94802014-08-08 04:31:42 -0700167 self.assertEqual('ACTIVE', network['status'])
Mark Maglana5885eb32014-02-28 10:57:34 -0800168 # Verify network update
raiesmh08e1aad982013-08-05 14:19:36 +0530169 new_name = "New_network"
John Warren94d8faf2015-09-15 12:22:24 -0400170 body = self.networks_client.update_network(net_id, name=new_name)
raiesmh08e1aad982013-08-05 14:19:36 +0530171 updated_net = body['network']
172 self.assertEqual(updated_net['name'], new_name)
Miguel Lavallecc939612013-02-22 17:27:20 -0600173 # Find a cidr that is not in use yet and create a subnet with it
Matthew Treinish6b8cd2a2014-03-03 20:45:56 +0000174 subnet = self.create_subnet(network)
raiesmh08e1aad982013-08-05 14:19:36 +0530175 subnet_id = subnet['id']
Mark Maglana5885eb32014-02-28 10:57:34 -0800176 # Verify subnet update
177 new_name = "New_subnet"
John Warren3961acd2015-10-02 14:38:53 -0400178 body = self.subnets_client.update_subnet(subnet_id, name=new_name)
raiesmh08e1aad982013-08-05 14:19:36 +0530179 updated_subnet = body['subnet']
Mark Maglana5885eb32014-02-28 10:57:34 -0800180 self.assertEqual(updated_subnet['name'], new_name)
Slawek Kaplonski748dd8d2019-04-16 23:38:35 +0200181 # Verify network delete
182 self.networks_client.delete_network(network['id'])
Unmesh Gurjar44986832012-05-08 19:57:10 +0530183
Jordan Pittier3b46d272017-04-12 16:17:28 +0200184 @decorators.attr(type='smoke')
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800185 @decorators.idempotent_id('2bf13842-c93f-4a69-83ed-717d2ec3b44e')
Unmesh Gurjar44986832012-05-08 19:57:10 +0530186 def test_show_network(self):
zhufl0abb76f2020-04-26 14:37:47 +0800187 """Verify the details of a network"""
John Warren94d8faf2015-09-15 12:22:24 -0400188 body = self.networks_client.show_network(self.network['id'])
Unmesh Gurjar44986832012-05-08 19:57:10 +0530189 network = body['network']
Mark Maglana5885eb32014-02-28 10:57:34 -0800190 for key in ['id', 'name']:
191 self.assertEqual(network[key], self.network[key])
Unmesh Gurjar44986832012-05-08 19:57:10 +0530192
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800193 @decorators.idempotent_id('867819bb-c4b6-45f7-acf9-90edcf70aa5e')
jun xied557d9b2014-01-09 14:00:36 +0800194 def test_show_network_fields(self):
zhufl0abb76f2020-04-26 14:37:47 +0800195 """Verify specific fields of a network"""
Zhi Kun Liu903596c2014-04-11 08:55:53 -0500196 fields = ['id', 'name']
Andrea Frittolicd368412017-08-14 21:37:56 +0100197 if utils.is_extension_enabled('net-mtu', 'network'):
Bruce Tand3e9b4a2016-09-22 09:17:06 +0000198 fields.append('mtu')
John Warren94d8faf2015-09-15 12:22:24 -0400199 body = self.networks_client.show_network(self.network['id'],
200 fields=fields)
jun xied557d9b2014-01-09 14:00:36 +0800201 network = body['network']
Zhi Kun Liu903596c2014-04-11 08:55:53 -0500202 self.assertEqual(sorted(network.keys()), sorted(fields))
203 for field_name in fields:
Mark Maglana5885eb32014-02-28 10:57:34 -0800204 self.assertEqual(network[field_name], self.network[field_name])
Bruce Tand3e9b4a2016-09-22 09:17:06 +0000205 self.assertNotIn('tenant_id', network)
206 self.assertNotIn('project_id', network)
jun xied557d9b2014-01-09 14:00:36 +0800207
Jordan Pittier3b46d272017-04-12 16:17:28 +0200208 @decorators.attr(type='smoke')
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800209 @decorators.idempotent_id('f7ffdeda-e200-4a7a-bcbe-05716e86bf43')
Unmesh Gurjar44986832012-05-08 19:57:10 +0530210 def test_list_networks(self):
zhufl0abb76f2020-04-26 14:37:47 +0800211 """Verify the network exists in the list of all networks"""
John Warren94d8faf2015-09-15 12:22:24 -0400212 body = self.networks_client.list_networks()
Mark Maglana5885eb32014-02-28 10:57:34 -0800213 networks = [network['id'] for network in body['networks']
214 if network['id'] == self.network['id']]
215 self.assertNotEmpty(networks, "Created network not found in the list")
Unmesh Gurjar44986832012-05-08 19:57:10 +0530216
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800217 @decorators.idempotent_id('6ae6d24f-9194-4869-9c85-c313cb20e080')
jun xie0b4735d2014-01-07 15:42:58 +0800218 def test_list_networks_fields(self):
zhufl0abb76f2020-04-26 14:37:47 +0800219 """Verify specific fields of the networks"""
Zhi Kun Liu903596c2014-04-11 08:55:53 -0500220 fields = ['id', 'name']
Andrea Frittolicd368412017-08-14 21:37:56 +0100221 if utils.is_extension_enabled('net-mtu', 'network'):
Bruce Tand3e9b4a2016-09-22 09:17:06 +0000222 fields.append('mtu')
John Warren94d8faf2015-09-15 12:22:24 -0400223 body = self.networks_client.list_networks(fields=fields)
jun xie0b4735d2014-01-07 15:42:58 +0800224 networks = body['networks']
Mark Maglana5885eb32014-02-28 10:57:34 -0800225 self.assertNotEmpty(networks, "Network list returned is empty")
226 for network in networks:
Zhi Kun Liu903596c2014-04-11 08:55:53 -0500227 self.assertEqual(sorted(network.keys()), sorted(fields))
jun xie0b4735d2014-01-07 15:42:58 +0800228
Jordan Pittier3b46d272017-04-12 16:17:28 +0200229 @decorators.attr(type='smoke')
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800230 @decorators.idempotent_id('bd635d81-6030-4dd1-b3b9-31ba0cfdf6cc')
Miguel Lavallecc939612013-02-22 17:27:20 -0600231 def test_show_subnet(self):
zhufl0abb76f2020-04-26 14:37:47 +0800232 """Verify the details of a subnet"""
John Warren3961acd2015-10-02 14:38:53 -0400233 body = self.subnets_client.show_subnet(self.subnet['id'])
Miguel Lavallecc939612013-02-22 17:27:20 -0600234 subnet = body['subnet']
Mark Maglana5885eb32014-02-28 10:57:34 -0800235 self.assertNotEmpty(subnet, "Subnet returned has no fields")
236 for key in ['id', 'cidr']:
237 self.assertIn(key, subnet)
238 self.assertEqual(subnet[key], self.subnet[key])
Miguel Lavallecc939612013-02-22 17:27:20 -0600239
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800240 @decorators.idempotent_id('270fff0b-8bfc-411f-a184-1e8fd35286f0')
jun xied557d9b2014-01-09 14:00:36 +0800241 def test_show_subnet_fields(self):
zhufl0abb76f2020-04-26 14:37:47 +0800242 """Verify specific fields of a subnet"""
Zhi Kun Liu903596c2014-04-11 08:55:53 -0500243 fields = ['id', 'network_id']
John Warren3961acd2015-10-02 14:38:53 -0400244 body = self.subnets_client.show_subnet(self.subnet['id'],
245 fields=fields)
jun xied557d9b2014-01-09 14:00:36 +0800246 subnet = body['subnet']
Zhi Kun Liu903596c2014-04-11 08:55:53 -0500247 self.assertEqual(sorted(subnet.keys()), sorted(fields))
248 for field_name in fields:
Mark Maglana5885eb32014-02-28 10:57:34 -0800249 self.assertEqual(subnet[field_name], self.subnet[field_name])
jun xied557d9b2014-01-09 14:00:36 +0800250
Jordan Pittier3b46d272017-04-12 16:17:28 +0200251 @decorators.attr(type='smoke')
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800252 @decorators.idempotent_id('db68ba48-f4ea-49e9-81d1-e367f6d0b20a')
Miguel Lavallecc939612013-02-22 17:27:20 -0600253 def test_list_subnets(self):
zhufl0abb76f2020-04-26 14:37:47 +0800254 """Verify the subnet exists in the list of all subnets"""
John Warren3961acd2015-10-02 14:38:53 -0400255 body = self.subnets_client.list_subnets()
Mark Maglana5885eb32014-02-28 10:57:34 -0800256 subnets = [subnet['id'] for subnet in body['subnets']
257 if subnet['id'] == self.subnet['id']]
258 self.assertNotEmpty(subnets, "Created subnet not found in the list")
raiesmh08e1aad982013-08-05 14:19:36 +0530259
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800260 @decorators.idempotent_id('842589e3-9663-46b0-85e4-7f01273b0412')
jun xie0b4735d2014-01-07 15:42:58 +0800261 def test_list_subnets_fields(self):
zhufl0abb76f2020-04-26 14:37:47 +0800262 """Verify specific fields of subnets"""
Zhi Kun Liu903596c2014-04-11 08:55:53 -0500263 fields = ['id', 'network_id']
John Warren3961acd2015-10-02 14:38:53 -0400264 body = self.subnets_client.list_subnets(fields=fields)
jun xie0b4735d2014-01-07 15:42:58 +0800265 subnets = body['subnets']
Mark Maglana5885eb32014-02-28 10:57:34 -0800266 self.assertNotEmpty(subnets, "Subnet list returned is empty")
267 for subnet in subnets:
Zhi Kun Liu903596c2014-04-11 08:55:53 -0500268 self.assertEqual(sorted(subnet.keys()), sorted(fields))
jun xie0b4735d2014-01-07 15:42:58 +0800269
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800270 @decorators.idempotent_id('f04f61a9-b7f3-4194-90b2-9bcf660d1bfe')
sukhdevc704a702014-01-15 11:50:56 -0800271 def test_delete_network_with_subnet(self):
zhufl0abb76f2020-04-26 14:37:47 +0800272 """Verify deleting network with subnet"""
sukhdevc704a702014-01-15 11:50:56 -0800273 # Creates a network
Tianbiao Qi309ac412016-10-31 19:42:37 +0800274 network = self.create_network()
sukhdevc704a702014-01-15 11:50:56 -0800275 net_id = network['id']
Jordan Pittier9e227c52016-02-09 14:35:18 +0100276 self.addCleanup(test_utils.call_and_ignore_notfound_exc,
zhufl587efc02017-11-28 09:52:50 +0800277 self.networks_client.delete_network, network['id'])
sukhdevc704a702014-01-15 11:50:56 -0800278
279 # Find a cidr that is not in use yet and create a subnet with it
280 subnet = self.create_subnet(network)
281 subnet_id = subnet['id']
282
283 # Delete network while the subnet still exists
Tianbiao Qi309ac412016-10-31 19:42:37 +0800284 self.networks_client.delete_network(net_id)
sukhdevc704a702014-01-15 11:50:56 -0800285
286 # Verify that the subnet got automatically deleted.
John Warren3961acd2015-10-02 14:38:53 -0400287 self.assertRaises(lib_exc.NotFound, self.subnets_client.show_subnet,
sukhdevc704a702014-01-15 11:50:56 -0800288 subnet_id)
289
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800290 @decorators.idempotent_id('d2d596e2-8e76-47a9-ac51-d4648009f4d3')
Sergey Shnaidman18cf5972014-09-02 22:05:00 +0400291 def test_create_delete_subnet_without_gateway(self):
zhufl0abb76f2020-04-26 14:37:47 +0800292 """Verify creating and deleting subnet without gateway"""
Sergey Shnaidman18cf5972014-09-02 22:05:00 +0400293 self._create_verify_delete_subnet()
294
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800295 @decorators.idempotent_id('9393b468-186d-496d-aa36-732348cd76e7')
Edgar Magana6a9ac342014-01-16 13:52:49 -0800296 def test_create_delete_subnet_with_gw(self):
zhufl0abb76f2020-04-26 14:37:47 +0800297 """Verify creating and deleting subnet with gateway"""
Rohan Kanade35589aa2014-08-19 14:56:12 +0200298 self._create_verify_delete_subnet(
299 **self.subnet_dict(['gateway']))
Edgar Magana6a9ac342014-01-16 13:52:49 -0800300
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800301 @decorators.idempotent_id('bec949c4-3147-4ba6-af5f-cd2306118404')
Rohan Kanade35589aa2014-08-19 14:56:12 +0200302 def test_create_delete_subnet_with_allocation_pools(self):
zhufl0abb76f2020-04-26 14:37:47 +0800303 """Verify creating and deleting subnet with allocation pools"""
Rohan Kanade35589aa2014-08-19 14:56:12 +0200304 self._create_verify_delete_subnet(
305 **self.subnet_dict(['allocation_pools']))
306
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800307 @decorators.idempotent_id('8217a149-0c6c-4cfb-93db-0486f707d13f')
Rohan Kanade35589aa2014-08-19 14:56:12 +0200308 def test_create_delete_subnet_with_gw_and_allocation_pools(self):
zhufl0abb76f2020-04-26 14:37:47 +0800309 """Verify create/delete subnet with gateway and allocation pools"""
Rohan Kanade35589aa2014-08-19 14:56:12 +0200310 self._create_verify_delete_subnet(**self.subnet_dict(
311 ['gateway', 'allocation_pools']))
312
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800313 @decorators.idempotent_id('d830de0a-be47-468f-8f02-1fd996118289')
Rohan Kanade35589aa2014-08-19 14:56:12 +0200314 def test_create_delete_subnet_with_host_routes_and_dns_nameservers(self):
zhufl0abb76f2020-04-26 14:37:47 +0800315 """Verify create/delete subnet with host routes and name servers"""
Rohan Kanade35589aa2014-08-19 14:56:12 +0200316 self._create_verify_delete_subnet(
317 **self.subnet_dict(['host_routes', 'dns_nameservers']))
318
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800319 @decorators.idempotent_id('94ce038d-ff0a-4a4c-a56b-09da3ca0b55d')
Rohan Kanade35589aa2014-08-19 14:56:12 +0200320 def test_create_delete_subnet_with_dhcp_enabled(self):
zhufl0abb76f2020-04-26 14:37:47 +0800321 """Verify create/delete subnet with dhcp enabled"""
Rohan Kanade35589aa2014-08-19 14:56:12 +0200322 self._create_verify_delete_subnet(enable_dhcp=True)
323
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800324 @decorators.idempotent_id('3d3852eb-3009-49ec-97ac-5ce83b73010a')
Rohan Kanade35589aa2014-08-19 14:56:12 +0200325 def test_update_subnet_gw_dns_host_routes_dhcp(self):
zhufl0abb76f2020-04-26 14:37:47 +0800326 """Verify updating subnet's gateway/nameserver/routes/dhcp"""
Rohan Kanade35589aa2014-08-19 14:56:12 +0200327 network = self.create_network()
Slawek Kaplonski748dd8d2019-04-16 23:38:35 +0200328 self.addCleanup(test_utils.call_and_ignore_notfound_exc,
329 self.networks_client.delete_network, network['id'])
Rohan Kanade35589aa2014-08-19 14:56:12 +0200330
331 subnet = self.create_subnet(
332 network, **self.subnet_dict(['gateway', 'host_routes',
afazekas40fcb9b2019-03-08 11:25:11 +0100333 'dns_nameservers',
Rohan Kanade35589aa2014-08-19 14:56:12 +0200334 'allocation_pools']))
335 subnet_id = subnet['id']
336 new_gateway = str(netaddr.IPAddress(
337 self._subnet_data[self._ip_version]['gateway']) + 1)
338 # Verify subnet update
339 new_host_routes = self._subnet_data[self._ip_version][
340 'new_host_routes']
341
342 new_dns_nameservers = self._subnet_data[self._ip_version][
343 'new_dns_nameservers']
344 kwargs = {'host_routes': new_host_routes,
345 'dns_nameservers': new_dns_nameservers,
346 'gateway_ip': new_gateway, 'enable_dhcp': True}
347
348 new_name = "New_subnet"
John Warren3961acd2015-10-02 14:38:53 -0400349 body = self.subnets_client.update_subnet(subnet_id, name=new_name,
350 **kwargs)
Rohan Kanade35589aa2014-08-19 14:56:12 +0200351 updated_subnet = body['subnet']
352 kwargs['name'] = new_name
353 self.assertEqual(sorted(updated_subnet['dns_nameservers']),
354 sorted(kwargs['dns_nameservers']))
355 del subnet['dns_nameservers'], kwargs['dns_nameservers']
356
357 self._compare_resource_attrs(updated_subnet, kwargs)
358
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800359 @decorators.idempotent_id('a4d9ec4c-0306-4111-a75c-db01a709030b')
Rohan Kanade35589aa2014-08-19 14:56:12 +0200360 def test_create_delete_subnet_all_attributes(self):
zhufl0abb76f2020-04-26 14:37:47 +0800361 """Verify create/delete subnet's all attributes"""
Rohan Kanade35589aa2014-08-19 14:56:12 +0200362 self._create_verify_delete_subnet(
363 enable_dhcp=True,
364 **self.subnet_dict(['gateway', 'host_routes', 'dns_nameservers']))
Edgar Magana6a9ac342014-01-16 13:52:49 -0800365
Jordan Pittier3b46d272017-04-12 16:17:28 +0200366 @decorators.attr(type='smoke')
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800367 @decorators.idempotent_id('af774677-42a9-4e4b-bb58-16fe6a5bc1ec')
Andrea Frittolicd368412017-08-14 21:37:56 +0100368 @utils.requires_ext(extension='external-net', service='network')
Kevin Benton6919da42016-03-05 18:00:03 -0800369 @testtools.skipUnless(CONF.network.public_network_id,
370 'The public_network_id option must be specified.')
Yair Friedbfdfc752014-09-28 13:56:45 +0300371 def test_external_network_visibility(self):
zhufl0abb76f2020-04-26 14:37:47 +0800372 """Verify external network's visibility"""
Duc Truongded59722017-07-18 14:33:24 -0700373 public_network_id = CONF.network.public_network_id
374
375 # find external network matching public_network_id
John Warren94d8faf2015-09-15 12:22:24 -0400376 body = self.networks_client.list_networks(**{'router:external': True})
Duc Truongded59722017-07-18 14:33:24 -0700377 external_network = next((network for network in body['networks']
378 if network['id'] == public_network_id), None)
379 self.assertIsNotNone(external_network, "Public network %s not found "
380 "in external network list"
381 % public_network_id)
Yair Friedbfdfc752014-09-28 13:56:45 +0300382
383 nonexternal = [net for net in body['networks'] if
384 not net['router:external']]
385 self.assertEmpty(nonexternal, "Found non-external networks"
386 " in filtered list (%s)." % nonexternal)
Duc Truongded59722017-07-18 14:33:24 -0700387
Kevin Benton6919da42016-03-05 18:00:03 -0800388 # only check the public network ID because the other networks may
389 # belong to other tests and their state may have changed during this
390 # test
Duc Truongded59722017-07-18 14:33:24 -0700391 body = self.subnets_client.list_subnets(network_id=public_network_id)
Rodolfo Alonso Hernandez27797122024-06-27 13:40:36 +0000392 extensions = [
393 ext['alias'] for ext in
394 self.network_extensions_client.list_extensions()['extensions']]
395 is_sen_ext = 'subnet-external-network' in extensions
Duc Truongded59722017-07-18 14:33:24 -0700396
397 # check subnet visibility of external_network
Rodolfo Alonso Hernandez27797122024-06-27 13:40:36 +0000398 if external_network['shared'] or is_sen_ext:
399 self.assertNotEmpty(body['subnets'],
400 'Subnets should be visible for shared or '
401 'external networks %s' % public_network_id)
Duc Truongded59722017-07-18 14:33:24 -0700402 else:
Rodolfo Alonso Hernandez27797122024-06-27 13:40:36 +0000403 self.assertEmpty(body['subnets'],
404 'Subnets should not be visible for non-shared or'
405 'non-external networks %s' % public_network_id)
Yair Friedbfdfc752014-09-28 13:56:45 +0300406
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800407 @decorators.idempotent_id('c72c1c0c-2193-4aca-ccc4-b1442640bbbb')
Andrea Frittolicd368412017-08-14 21:37:56 +0100408 @utils.requires_ext(extension="standard-attr-description",
409 service="network")
Bruce Tand3e9b4a2016-09-22 09:17:06 +0000410 def test_create_update_network_description(self):
zhufl0abb76f2020-04-26 14:37:47 +0800411 """Verify creating and updating network's description"""
Bruce Tand3e9b4a2016-09-22 09:17:06 +0000412 body = self.create_network(description='d1')
413 self.assertEqual('d1', body['description'])
414 net_id = body['id']
415 body = self.networks_client.list_networks(id=net_id)['networks'][0]
416 self.assertEqual('d1', body['description'])
417 body = self.networks_client.update_network(body['id'],
418 description='d2')
419 self.assertEqual('d2', body['network']['description'])
420 body = self.networks_client.list_networks(id=net_id)['networks'][0]
421 self.assertEqual('d2', body['description'])
422
raiesmh086b055e22013-09-16 12:59:57 +0530423
Tong Liu7012c862016-04-11 22:32:05 +0000424class BulkNetworkOpsTest(base.BaseNetworkTest):
Ken'ichi Ohmichie03bea92015-11-19 07:45:58 +0000425 """Tests the following operations in the Neutron API:
raiesmh086b055e22013-09-16 12:59:57 +0530426
427 bulk network creation
428 bulk subnet creation
Eugene Nikanorove9d255a2013-12-18 16:31:42 +0400429 bulk port creation
Sean Dagueed6e5862016-04-04 10:49:13 -0400430 list project's networks
raiesmh086b055e22013-09-16 12:59:57 +0530431
432 v2.0 of the Neutron API is assumed. It is also assumed that the following
433 options are defined in the [network] section of etc/tempest.conf:
434
Sean Dagueed6e5862016-04-04 10:49:13 -0400435 project_network_cidr with a block of cidr's from which smaller blocks
436 can be allocated for project networks
raiesmh086b055e22013-09-16 12:59:57 +0530437
Sean Dagueed6e5862016-04-04 10:49:13 -0400438 project_network_mask_bits with the mask bits to be used to partition
439 the block defined by project-network_cidr
raiesmh086b055e22013-09-16 12:59:57 +0530440 """
441
raiesmh086b055e22013-09-16 12:59:57 +0530442 def _delete_networks(self, created_networks):
443 for n in created_networks:
John Warren94d8faf2015-09-15 12:22:24 -0400444 self.networks_client.delete_network(n['id'])
raiesmh086b055e22013-09-16 12:59:57 +0530445 # Asserting that the networks are not found in the list after deletion
John Warren94d8faf2015-09-15 12:22:24 -0400446 body = self.networks_client.list_networks()
Mark Maglana5885eb32014-02-28 10:57:34 -0800447 networks_list = [network['id'] for network in body['networks']]
raiesmh086b055e22013-09-16 12:59:57 +0530448 for n in created_networks:
449 self.assertNotIn(n['id'], networks_list)
450
451 def _delete_subnets(self, created_subnets):
452 for n in created_subnets:
John Warren3961acd2015-10-02 14:38:53 -0400453 self.subnets_client.delete_subnet(n['id'])
raiesmh086b055e22013-09-16 12:59:57 +0530454 # Asserting that the subnets are not found in the list after deletion
John Warren3961acd2015-10-02 14:38:53 -0400455 body = self.subnets_client.list_subnets()
Mark Maglana5885eb32014-02-28 10:57:34 -0800456 subnets_list = [subnet['id'] for subnet in body['subnets']]
raiesmh086b055e22013-09-16 12:59:57 +0530457 for n in created_subnets:
458 self.assertNotIn(n['id'], subnets_list)
459
460 def _delete_ports(self, created_ports):
461 for n in created_ports:
John Warren49c0fe52015-10-22 12:35:54 -0400462 self.ports_client.delete_port(n['id'])
raiesmh086b055e22013-09-16 12:59:57 +0530463 # Asserting that the ports are not found in the list after deletion
John Warren49c0fe52015-10-22 12:35:54 -0400464 body = self.ports_client.list_ports()
Mark Maglana5885eb32014-02-28 10:57:34 -0800465 ports_list = [port['id'] for port in body['ports']]
raiesmh086b055e22013-09-16 12:59:57 +0530466 for n in created_ports:
467 self.assertNotIn(n['id'], ports_list)
468
Jordan Pittier3b46d272017-04-12 16:17:28 +0200469 @decorators.attr(type='smoke')
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800470 @decorators.idempotent_id('d4f9024d-1e28-4fc1-a6b1-25dbc6fa11e2')
Nayna Patelb03eab42013-08-08 08:58:48 +0000471 def test_bulk_create_delete_network(self):
zhufl0abb76f2020-04-26 14:37:47 +0800472 """Verify creating and deleting multiple networks in one request"""
Nayna Patelb03eab42013-08-08 08:58:48 +0000473 # Creates 2 networks in one request
Martin Kopec213d0a42023-11-30 10:28:14 +0100474 network_list = [
475 {'name': data_utils.rand_name(
476 'network-', prefix=CONF.resource_name_prefix)},
477 {'name': data_utils.rand_name(
478 'network-', prefix=CONF.resource_name_prefix)}]
Ken'ichi Ohmichi1f52fd92016-03-03 12:24:12 -0800479 body = self.networks_client.create_bulk_networks(networks=network_list)
Nayna Patelb03eab42013-08-08 08:58:48 +0000480 created_networks = body['networks']
Nayna Patelb03eab42013-08-08 08:58:48 +0000481 self.addCleanup(self._delete_networks, created_networks)
482 # Asserting that the networks are found in the list after creation
John Warren94d8faf2015-09-15 12:22:24 -0400483 body = self.networks_client.list_networks()
Mark Maglana5885eb32014-02-28 10:57:34 -0800484 networks_list = [network['id'] for network in body['networks']]
Nayna Patelb03eab42013-08-08 08:58:48 +0000485 for n in created_networks:
486 self.assertIsNotNone(n['id'])
487 self.assertIn(n['id'], networks_list)
raiesmh0867698322013-08-20 13:09:01 +0530488
Jordan Pittier3b46d272017-04-12 16:17:28 +0200489 @decorators.attr(type='smoke')
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800490 @decorators.idempotent_id('8936533b-c0aa-4f29-8e53-6cc873aec489')
raiesmh082d5c6512013-09-06 15:35:05 +0530491 def test_bulk_create_delete_subnet(self):
zhufl0abb76f2020-04-26 14:37:47 +0800492 """Verify creating and deleting multiple subnets in one request"""
Assaf Mullere4f78992014-06-19 17:32:14 +0300493 networks = [self.create_network(), self.create_network()]
raiesmh082d5c6512013-09-06 15:35:05 +0530494 # Creates 2 subnets in one request
zhuflec61bac2017-09-01 15:59:50 +0800495 cidrs = [subnet_cidr
496 for subnet_cidr in self.cidr.subnet(self.mask_bits)]
Rohan Kanade0efb0232015-02-19 13:33:31 +0530497
Martin Kopec213d0a42023-11-30 10:28:14 +0100498 names = [data_utils.rand_name(
499 name='subnet-', prefix=CONF.resource_name_prefix)
500 for i in range(len(networks))]
Mark Maglana5885eb32014-02-28 10:57:34 -0800501 subnets_list = []
raiesmh082d5c6512013-09-06 15:35:05 +0530502 for i in range(len(names)):
503 p1 = {
Assaf Mullere4f78992014-06-19 17:32:14 +0300504 'network_id': networks[i]['id'],
raiesmh082d5c6512013-09-06 15:35:05 +0530505 'cidr': str(cidrs[(i)]),
506 'name': names[i],
Rohan Kanade0efb0232015-02-19 13:33:31 +0530507 'ip_version': self._ip_version
raiesmh082d5c6512013-09-06 15:35:05 +0530508 }
Mark Maglana5885eb32014-02-28 10:57:34 -0800509 subnets_list.append(p1)
510 del subnets_list[1]['name']
Ken'ichi Ohmichi1f52fd92016-03-03 12:24:12 -0800511 body = self.subnets_client.create_bulk_subnets(subnets=subnets_list)
raiesmh082d5c6512013-09-06 15:35:05 +0530512 created_subnets = body['subnets']
513 self.addCleanup(self._delete_subnets, created_subnets)
raiesmh082d5c6512013-09-06 15:35:05 +0530514 # Asserting that the subnets are found in the list after creation
John Warren3961acd2015-10-02 14:38:53 -0400515 body = self.subnets_client.list_subnets()
Mark Maglana5885eb32014-02-28 10:57:34 -0800516 subnets_list = [subnet['id'] for subnet in body['subnets']]
raiesmh082d5c6512013-09-06 15:35:05 +0530517 for n in created_subnets:
518 self.assertIsNotNone(n['id'])
519 self.assertIn(n['id'], subnets_list)
520
Jordan Pittier3b46d272017-04-12 16:17:28 +0200521 @decorators.attr(type='smoke')
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800522 @decorators.idempotent_id('48037ff2-e889-4c3b-b86a-8e3f34d2d060')
raiesmh082d5c6512013-09-06 15:35:05 +0530523 def test_bulk_create_delete_port(self):
zhufl0abb76f2020-04-26 14:37:47 +0800524 """Verify creating and deleting multiple ports in one request"""
Assaf Mullere4f78992014-06-19 17:32:14 +0300525 networks = [self.create_network(), self.create_network()]
raiesmh082d5c6512013-09-06 15:35:05 +0530526 # Creates 2 ports in one request
Martin Kopec213d0a42023-11-30 10:28:14 +0100527 names = [data_utils.rand_name(
528 name='port-', prefix=CONF.resource_name_prefix)
529 for i in range(len(networks))]
raiesmh082d5c6512013-09-06 15:35:05 +0530530 port_list = []
531 state = [True, False]
532 for i in range(len(names)):
533 p1 = {
Assaf Mullere4f78992014-06-19 17:32:14 +0300534 'network_id': networks[i]['id'],
raiesmh082d5c6512013-09-06 15:35:05 +0530535 'name': names[i],
536 'admin_state_up': state[i],
537 }
538 port_list.append(p1)
539 del port_list[1]['name']
Ken'ichi Ohmichi1f52fd92016-03-03 12:24:12 -0800540 body = self.ports_client.create_bulk_ports(ports=port_list)
raiesmh082d5c6512013-09-06 15:35:05 +0530541 created_ports = body['ports']
542 self.addCleanup(self._delete_ports, created_ports)
raiesmh082d5c6512013-09-06 15:35:05 +0530543 # Asserting that the ports are found in the list after creation
John Warren49c0fe52015-10-22 12:35:54 -0400544 body = self.ports_client.list_ports()
Mark Maglana5885eb32014-02-28 10:57:34 -0800545 ports_list = [port['id'] for port in body['ports']]
raiesmh082d5c6512013-09-06 15:35:05 +0530546 for n in created_ports:
547 self.assertIsNotNone(n['id'])
548 self.assertIn(n['id'], ports_list)
549
raiesmh0867698322013-08-20 13:09:01 +0530550
Tong Liu7012c862016-04-11 22:32:05 +0000551class BulkNetworkOpsIpV6Test(BulkNetworkOpsTest):
Rohan Kanade0efb0232015-02-19 13:33:31 +0530552 _ip_version = 6
553
554
Tong Liu7012c862016-04-11 22:32:05 +0000555class NetworksIpV6Test(NetworksTest):
Henry Gessauffda37a2014-01-16 11:17:55 -0500556 _ip_version = 6
Henry Gessauffda37a2014-01-16 11:17:55 -0500557
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800558 @decorators.idempotent_id('e41a4888-65a6-418c-a095-f7c2ef4ad59a')
Edgar Magana6a9ac342014-01-16 13:52:49 -0800559 def test_create_delete_subnet_with_gw(self):
zhufl0abb76f2020-04-26 14:37:47 +0800560 """Verify creating and deleting subnet with gateway"""
Sean Dagueed6e5862016-04-04 10:49:13 -0400561 net = netaddr.IPNetwork(CONF.network.project_network_v6_cidr)
sridhargaddamea73d532014-05-13 14:48:30 +0530562 gateway = str(netaddr.IPAddress(net.first + 2))
zhufld2c40ca2016-10-18 17:03:07 +0800563 network = self.create_network()
Edgar Magana6a9ac342014-01-16 13:52:49 -0800564 subnet = self.create_subnet(network, gateway)
565 # Verifies Subnet GW in IPv6
566 self.assertEqual(subnet['gateway_ip'], gateway)
Edgar Magana6a9ac342014-01-16 13:52:49 -0800567
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800568 @decorators.idempotent_id('ebb4fd95-524f-46af-83c1-0305b239338f')
Sergey Shnaidman18cf5972014-09-02 22:05:00 +0400569 def test_create_delete_subnet_with_default_gw(self):
zhufl0abb76f2020-04-26 14:37:47 +0800570 """Verify creating and deleting subnet without specified gateway"""
Sean Dagueed6e5862016-04-04 10:49:13 -0400571 net = netaddr.IPNetwork(CONF.network.project_network_v6_cidr)
sridhargaddamea73d532014-05-13 14:48:30 +0530572 gateway_ip = str(netaddr.IPAddress(net.first + 1))
zhufld2c40ca2016-10-18 17:03:07 +0800573 network = self.create_network()
Edgar Magana6a9ac342014-01-16 13:52:49 -0800574 subnet = self.create_subnet(network)
575 # Verifies Subnet GW in IPv6
sridhargaddamea73d532014-05-13 14:48:30 +0530576 self.assertEqual(subnet['gateway_ip'], gateway_ip)
Edgar Magana6a9ac342014-01-16 13:52:49 -0800577
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800578 @decorators.idempotent_id('a9653883-b2a4-469b-8c3c-4518430a7e55')
Sergey Shnaidman18cf5972014-09-02 22:05:00 +0400579 def test_create_list_subnet_with_no_gw64_one_network(self):
zhufl0abb76f2020-04-26 14:37:47 +0800580 """Verify subnets with and without gateway are in one network
581
582 First we create a network, then we create one ipv6 subnet with
583 gateway and one ipv4 subnet without gateway, the two subnets
584 should be in the same network
585 """
zhufld2c40ca2016-10-18 17:03:07 +0800586 network = self.create_network()
Sergey Shnaidman18cf5972014-09-02 22:05:00 +0400587 ipv6_gateway = self.subnet_dict(['gateway'])['gateway']
588 subnet1 = self.create_subnet(network,
589 ip_version=6,
590 gateway=ipv6_gateway)
591 self.assertEqual(netaddr.IPNetwork(subnet1['cidr']).version, 6,
592 'The created subnet is not IPv6')
593 subnet2 = self.create_subnet(network,
594 gateway=None,
595 ip_version=4)
596 self.assertEqual(netaddr.IPNetwork(subnet2['cidr']).version, 4,
597 'The created subnet is not IPv4')
598 # Verifies Subnet GW is set in IPv6
599 self.assertEqual(subnet1['gateway_ip'], ipv6_gateway)
600 # Verifies Subnet GW is None in IPv4
guo yunxian0306a4a2016-07-29 16:32:28 +0800601 self.assertIsNone(subnet2['gateway_ip'])
Sergey Shnaidman18cf5972014-09-02 22:05:00 +0400602 # Verifies all 2 subnets in the same network
John Warren3961acd2015-10-02 14:38:53 -0400603 body = self.subnets_client.list_subnets()
Sergey Shnaidman18cf5972014-09-02 22:05:00 +0400604 subnets = [sub['id'] for sub in body['subnets']
605 if sub['network_id'] == network['id']]
606 test_subnet_ids = [sub['id'] for sub in (subnet1, subnet2)]
songwenpinge6623072021-02-22 14:47:34 +0800607 self.assertCountEqual(subnets,
608 test_subnet_ids,
609 'Subnet are not in the same network')
Sergey Shnaidman18cf5972014-09-02 22:05:00 +0400610
Sergey She757c332014-11-25 01:16:32 +0300611
Jonte Watford871547c2016-10-10 20:11:04 +0000612class NetworksIpV6TestAttrs(BaseNetworkTestResources):
613
614 _ip_version = 6
Sergey She757c332014-11-25 01:16:32 +0300615
616 @classmethod
Rohan Kanadea565e452015-01-27 14:00:13 +0530617 def skip_checks(cls):
618 super(NetworksIpV6TestAttrs, cls).skip_checks()
Sergey She757c332014-11-25 01:16:32 +0300619 if not CONF.network_feature_enabled.ipv6_subnet_attributes:
620 raise cls.skipException("IPv6 extended attributes for "
621 "subnets not available")
Sergey She757c332014-11-25 01:16:32 +0300622
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800623 @decorators.idempotent_id('da40cd1b-a833-4354-9a85-cd9b8a3b74ca')
Sergey Shnaidman18cf5972014-09-02 22:05:00 +0400624 def test_create_delete_subnet_with_v6_attributes_stateful(self):
zhufl0abb76f2020-04-26 14:37:47 +0800625 """Test create/delete subnet with ipv6 attributes stateful"""
Rohan Kanade35589aa2014-08-19 14:56:12 +0200626 self._create_verify_delete_subnet(
627 gateway=self._subnet_data[self._ip_version]['gateway'],
Sergey Shnaidman18cf5972014-09-02 22:05:00 +0400628 ipv6_ra_mode='dhcpv6-stateful',
629 ipv6_address_mode='dhcpv6-stateful')
630
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800631 @decorators.idempotent_id('176b030f-a923-4040-a755-9dc94329e60c')
Sergey Shnaidman18cf5972014-09-02 22:05:00 +0400632 def test_create_delete_subnet_with_v6_attributes_slaac(self):
zhufl0abb76f2020-04-26 14:37:47 +0800633 """Test create/delete subnet with ipv6 attributes slaac"""
Sergey Shnaidman18cf5972014-09-02 22:05:00 +0400634 self._create_verify_delete_subnet(
Rohan Kanade35589aa2014-08-19 14:56:12 +0200635 ipv6_ra_mode='slaac',
636 ipv6_address_mode='slaac')
Sean M. Collinsdd27a4d2014-05-13 10:33:15 -0400637
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800638 @decorators.idempotent_id('7d410310-8c86-4902-adf9-865d08e31adb')
Sergey Shnaidman18cf5972014-09-02 22:05:00 +0400639 def test_create_delete_subnet_with_v6_attributes_stateless(self):
zhufl0abb76f2020-04-26 14:37:47 +0800640 """Test create/delete subnet with ipv6 attributes stateless"""
Sergey Shnaidman18cf5972014-09-02 22:05:00 +0400641 self._create_verify_delete_subnet(
642 ipv6_ra_mode='dhcpv6-stateless',
643 ipv6_address_mode='dhcpv6-stateless')
Sergey She757c332014-11-25 01:16:32 +0300644
645 def _test_delete_subnet_with_ports(self, mode):
646 """Create subnet and delete it with existing ports"""
647 slaac_network = self.create_network()
648 subnet_slaac = self.create_subnet(slaac_network,
649 **{'ipv6_ra_mode': mode,
650 'ipv6_address_mode': mode})
651 port = self.create_port(slaac_network)
652 self.assertIsNotNone(port['fixed_ips'][0]['ip_address'])
John Warren3961acd2015-10-02 14:38:53 -0400653 self.subnets_client.delete_subnet(subnet_slaac['id'])
John Warren3961acd2015-10-02 14:38:53 -0400654 subnets = self.subnets_client.list_subnets()
Sergey She757c332014-11-25 01:16:32 +0300655 subnet_ids = [subnet['id'] for subnet in subnets['subnets']]
656 self.assertNotIn(subnet_slaac['id'], subnet_ids,
657 "Subnet wasn't deleted")
reedip6fb7e1a2016-03-10 13:32:01 +0900658 self.assertRaisesRegex(
Masayuki Igawad9388762015-01-20 14:56:42 +0900659 lib_exc.Conflict,
Sergey She757c332014-11-25 01:16:32 +0300660 "There are one or more ports still in use on the network",
John Warren94d8faf2015-09-15 12:22:24 -0400661 self.networks_client.delete_network,
Sergey She757c332014-11-25 01:16:32 +0300662 slaac_network['id'])
663
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800664 @decorators.idempotent_id('88554555-ebf8-41ef-9300-4926d45e06e9')
Sergey She757c332014-11-25 01:16:32 +0300665 def test_create_delete_slaac_subnet_with_ports(self):
666 """Test deleting subnet with SLAAC ports
667
668 Create subnet with SLAAC, create ports in network
669 and then you shall be able to delete subnet without port
670 deletion. But you still can not delete the network.
671 """
672 self._test_delete_subnet_with_ports("slaac")
673
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800674 @decorators.idempotent_id('2de6ab5a-fcf0-4144-9813-f91a940291f1')
Sergey She757c332014-11-25 01:16:32 +0300675 def test_create_delete_stateless_subnet_with_ports(self):
676 """Test deleting subnet with DHCPv6 stateless ports
677
678 Create subnet with DHCPv6 stateless, create ports in network
679 and then you shall be able to delete subnet without port
680 deletion. But you still can not delete the network.
681 """
682 self._test_delete_subnet_with_ports("dhcpv6-stateless")