blob: e39ad08f92f69f35e77ca0bb0fb484a180c47f60 [file] [log] [blame]
Nayna Patelf1a29152013-08-09 07:18:13 +00001# Copyright 2013 OpenStack Foundation
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
16from tempest.api.network import base
Andrea Frittolicd368412017-08-14 21:37:56 +010017from tempest.common import utils
Ryan Tidwell1964a262016-05-04 15:13:23 -070018from tempest.common.utils import net_utils
Matthew Treinish03b48df2014-01-29 16:59:49 +000019from tempest import config
Ghanshyam Mannef0e2912020-12-29 15:22:33 -060020from tempest.lib.common.utils import data_utils
Slawek Kaplonski748dd8d2019-04-16 23:38:35 +020021from tempest.lib.common.utils import test_utils
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -080022from tempest.lib import decorators
Nayna Patelf1a29152013-08-09 07:18:13 +000023
Matthew Treinish03b48df2014-01-29 16:59:49 +000024CONF = config.CONF
25
Nayna Patelf1a29152013-08-09 07:18:13 +000026
Attila Fazekasc74aede2013-09-11 13:04:02 +020027class FloatingIPTestJSON(base.BaseNetworkTest):
Ken'ichi Ohmichie03bea92015-11-19 07:45:58 +000028 """Tests the following operations in the Neutron API:
Nayna Patelf1a29152013-08-09 07:18:13 +000029
30 Create a Floating IP
31 Update a Floating IP
32 Delete a Floating IP
33 List all Floating IPs
34 Show Floating IP details
rossellab24ec382013-11-13 10:21:59 +010035 Associate a Floating IP with a port and then delete that port
36 Associate a Floating IP with a port and then with a port on another
37 router
Nayna Patelf1a29152013-08-09 07:18:13 +000038
rossellabc9b4bd2013-11-13 10:21:59 +010039 v2.0 of the Neutron API is assumed. It is also assumed that the following
Nayna Patelf1a29152013-08-09 07:18:13 +000040 options are defined in the [network] section of etc/tempest.conf:
41
42 public_network_id which is the id for the external network present
43 """
44
45 @classmethod
Rohan Kanadea565e452015-01-27 14:00:13 +053046 def skip_checks(cls):
47 super(FloatingIPTestJSON, cls).skip_checks()
Andrea Frittolicd368412017-08-14 21:37:56 +010048 if not utils.is_extension_enabled('router', 'network'):
Yoshihiro Kaneko05670262014-01-18 19:22:44 +090049 msg = "router extension not enabled."
50 raise cls.skipException(msg)
zhufl6b7040a2017-01-18 16:38:34 +080051 if not CONF.network.public_network_id:
52 msg = "The public_network_id option must be specified."
53 raise cls.skipException(msg)
Matthew Treinish3312de32017-05-19 12:08:17 -040054 if not CONF.network_feature_enabled.floating_ips:
55 raise cls.skipException("Floating ips are not available")
Rohan Kanadea565e452015-01-27 14:00:13 +053056
57 @classmethod
58 def resource_setup(cls):
59 super(FloatingIPTestJSON, cls).resource_setup()
Matthew Treinish03b48df2014-01-29 16:59:49 +000060 cls.ext_net_id = CONF.network.public_network_id
Nayna Patelf1a29152013-08-09 07:18:13 +000061
62 # Create network, subnet, router and add interface
63 cls.network = cls.create_network()
Kevin Bentona70710b2016-07-08 15:24:38 -070064 cls.subnet = cls.create_subnet(cls.network, enable_dhcp=False)
zhufld2c40ca2016-10-18 17:03:07 +080065 cls.router = cls.create_router(external_network_id=cls.ext_net_id)
rossellabc9b4bd2013-11-13 10:21:59 +010066 cls.create_router_interface(cls.router['id'], cls.subnet['id'])
Nayna Patelf1a29152013-08-09 07:18:13 +000067 # Create two ports one each for Creation and Updating of floatingIP
ghanshyam906e2842018-08-03 08:58:50 +000068 cls.ports = []
zhuflbf5ed0b2020-11-18 15:34:25 +080069 for _ in range(2):
ghanshyam906e2842018-08-03 08:58:50 +000070 port = cls.create_port(cls.network)
71 cls.ports.append(port)
Nayna Patelf1a29152013-08-09 07:18:13 +000072
Jordan Pittier3b46d272017-04-12 16:17:28 +020073 @decorators.attr(type='smoke')
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -080074 @decorators.idempotent_id('62595970-ab1c-4b7f-8fcc-fddfe55e8718')
Nayna Patelf1a29152013-08-09 07:18:13 +000075 def test_create_list_show_update_delete_floating_ip(self):
zhufl4810d882020-04-22 16:14:19 +080076 """Test create/list/show/update/delete floating ip"""
Nayna Patelf1a29152013-08-09 07:18:13 +000077 # Creates a floating IP
John Warrenfbf2a892015-11-17 12:36:14 -050078 body = self.floating_ips_client.create_floatingip(
Rohan Kanadeeeb21642014-08-14 12:00:26 +020079 floating_network_id=self.ext_net_id,
80 port_id=self.ports[0]['id'])
Ann Kamyshnikova47a4ff82014-03-17 12:48:57 +040081 created_floating_ip = body['floatingip']
Slawek Kaplonski748dd8d2019-04-16 23:38:35 +020082 self.addCleanup(
83 test_utils.call_and_ignore_notfound_exc,
84 self.floating_ips_client.delete_floatingip,
85 created_floating_ip['id'])
rossellabc9b4bd2013-11-13 10:21:59 +010086 self.assertIsNotNone(created_floating_ip['id'])
Rodolfo Alonso Hernandezc1449d42020-02-15 13:24:28 +000087 self.assertIsNotNone(created_floating_ip['project_id'])
rossellabc9b4bd2013-11-13 10:21:59 +010088 self.assertIsNotNone(created_floating_ip['floating_ip_address'])
89 self.assertEqual(created_floating_ip['port_id'], self.ports[0]['id'])
90 self.assertEqual(created_floating_ip['floating_network_id'],
Nayna Patelf1a29152013-08-09 07:18:13 +000091 self.ext_net_id)
Ann Kamyshnikova7d2275b2013-12-19 16:38:42 +040092 self.assertIn(created_floating_ip['fixed_ip_address'],
93 [ip['ip_address'] for ip in self.ports[0]['fixed_ips']])
Nayna Patelf1a29152013-08-09 07:18:13 +000094 # Verifies the details of a floating_ip
John Warrenfbf2a892015-11-17 12:36:14 -050095 floating_ip = self.floating_ips_client.show_floatingip(
96 created_floating_ip['id'])
rossellabc9b4bd2013-11-13 10:21:59 +010097 shown_floating_ip = floating_ip['floatingip']
98 self.assertEqual(shown_floating_ip['id'], created_floating_ip['id'])
99 self.assertEqual(shown_floating_ip['floating_network_id'],
Nayna Patelf1a29152013-08-09 07:18:13 +0000100 self.ext_net_id)
Rodolfo Alonso Hernandezc1449d42020-02-15 13:24:28 +0000101 self.assertEqual(shown_floating_ip['project_id'],
102 created_floating_ip['project_id'])
rossellabc9b4bd2013-11-13 10:21:59 +0100103 self.assertEqual(shown_floating_ip['floating_ip_address'],
104 created_floating_ip['floating_ip_address'])
105 self.assertEqual(shown_floating_ip['port_id'], self.ports[0]['id'])
Nayna Patelf1a29152013-08-09 07:18:13 +0000106
107 # Verify the floating ip exists in the list of all floating_ips
John Warrenfbf2a892015-11-17 12:36:14 -0500108 floating_ips = self.floating_ips_client.list_floatingips()
Nayna Patelf1a29152013-08-09 07:18:13 +0000109 floatingip_id_list = list()
110 for f in floating_ips['floatingips']:
111 floatingip_id_list.append(f['id'])
rossellabc9b4bd2013-11-13 10:21:59 +0100112 self.assertIn(created_floating_ip['id'], floatingip_id_list)
Nayna Patelf1a29152013-08-09 07:18:13 +0000113 # Associate floating IP to the other port
John Warrenfbf2a892015-11-17 12:36:14 -0500114 floating_ip = self.floating_ips_client.update_floatingip(
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200115 created_floating_ip['id'],
116 port_id=self.ports[1]['id'])
rossellabc9b4bd2013-11-13 10:21:59 +0100117 updated_floating_ip = floating_ip['floatingip']
118 self.assertEqual(updated_floating_ip['port_id'], self.ports[1]['id'])
119 self.assertEqual(updated_floating_ip['fixed_ip_address'],
120 self.ports[1]['fixed_ips'][0]['ip_address'])
121 self.assertEqual(updated_floating_ip['router_id'], self.router['id'])
Nayna Patelf1a29152013-08-09 07:18:13 +0000122
123 # Disassociate floating IP from the port
John Warrenfbf2a892015-11-17 12:36:14 -0500124 floating_ip = self.floating_ips_client.update_floatingip(
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200125 created_floating_ip['id'],
126 port_id=None)
rossellabc9b4bd2013-11-13 10:21:59 +0100127 updated_floating_ip = floating_ip['floatingip']
128 self.assertIsNone(updated_floating_ip['port_id'])
129 self.assertIsNone(updated_floating_ip['fixed_ip_address'])
130 self.assertIsNone(updated_floating_ip['router_id'])
Attila Fazekasc74aede2013-09-11 13:04:02 +0200131
Slawek Kaplonski748dd8d2019-04-16 23:38:35 +0200132 # Explicity test deletion of floating IP
133 self.floating_ips_client.delete_floatingip(created_floating_ip['id'])
134
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800135 @decorators.idempotent_id('e1f6bffd-442f-4668-b30e-df13f2705e77')
rossellab24ec382013-11-13 10:21:59 +0100136 def test_floating_ip_delete_port(self):
zhufl4810d882020-04-22 16:14:19 +0800137 """Test deleting floating ip's port
138
139 1. Create a floating ip
140 2. Create a port
141 3. Update the floating ip's port_id to the created port
142 4. Delete the port
143 5. Verify that the port details are cleared from the floating ip
144 """
rossellab24ec382013-11-13 10:21:59 +0100145 # Create a floating IP
John Warrenfbf2a892015-11-17 12:36:14 -0500146 body = self.floating_ips_client.create_floatingip(
Ann Kamyshnikova47a4ff82014-03-17 12:48:57 +0400147 floating_network_id=self.ext_net_id)
Ann Kamyshnikova47a4ff82014-03-17 12:48:57 +0400148 created_floating_ip = body['floatingip']
Slawek Kaplonski748dd8d2019-04-16 23:38:35 +0200149 self.addCleanup(
150 test_utils.call_and_ignore_notfound_exc,
151 self.floating_ips_client.delete_floatingip,
152 created_floating_ip['id'])
rossellab24ec382013-11-13 10:21:59 +0100153 # Create a port
Doug Schveninger24675aa2019-08-16 22:28:39 -0500154 port = self.ports_client.create_port(
155 network_id=self.network['id'],
Martin Kopec213d0a42023-11-30 10:28:14 +0100156 name=data_utils.rand_name(
157 self.__class__.__name__, prefix=CONF.resource_name_prefix))
rossellab24ec382013-11-13 10:21:59 +0100158 created_port = port['port']
John Warrenfbf2a892015-11-17 12:36:14 -0500159 floating_ip = self.floating_ips_client.update_floatingip(
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200160 created_floating_ip['id'],
161 port_id=created_port['id'])
rossellab24ec382013-11-13 10:21:59 +0100162 # Delete port
John Warren49c0fe52015-10-22 12:35:54 -0400163 self.ports_client.delete_port(created_port['id'])
rossellab24ec382013-11-13 10:21:59 +0100164 # Verifies the details of the floating_ip
John Warrenfbf2a892015-11-17 12:36:14 -0500165 floating_ip = self.floating_ips_client.show_floatingip(
166 created_floating_ip['id'])
rossellab24ec382013-11-13 10:21:59 +0100167 shown_floating_ip = floating_ip['floatingip']
168 # Confirm the fields are back to None
169 self.assertEqual(shown_floating_ip['id'], created_floating_ip['id'])
170 self.assertIsNone(shown_floating_ip['port_id'])
171 self.assertIsNone(shown_floating_ip['fixed_ip_address'])
172 self.assertIsNone(shown_floating_ip['router_id'])
173
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800174 @decorators.idempotent_id('1bb2f731-fe5a-4b8c-8409-799ade1bed4d')
rossellab24ec382013-11-13 10:21:59 +0100175 def test_floating_ip_update_different_router(self):
zhufl4810d882020-04-22 16:14:19 +0800176 """Test associating a floating ip to a port on different router"""
rossellab24ec382013-11-13 10:21:59 +0100177 # Associate a floating IP to a port on a router
John Warrenfbf2a892015-11-17 12:36:14 -0500178 body = self.floating_ips_client.create_floatingip(
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200179 floating_network_id=self.ext_net_id,
180 port_id=self.ports[1]['id'])
Ann Kamyshnikova47a4ff82014-03-17 12:48:57 +0400181 created_floating_ip = body['floatingip']
Slawek Kaplonski748dd8d2019-04-16 23:38:35 +0200182 self.addCleanup(
183 test_utils.call_and_ignore_notfound_exc,
184 self.floating_ips_client.delete_floatingip,
185 created_floating_ip['id'])
rossellab24ec382013-11-13 10:21:59 +0100186 self.assertEqual(created_floating_ip['router_id'], self.router['id'])
Martin Kopec213d0a42023-11-30 10:28:14 +0100187 network_name = data_utils.rand_name(
188 self.__class__.__name__, prefix=CONF.resource_name_prefix)
deepak_mouryab4fb4382018-06-04 10:11:32 +0530189 network2 = self.networks_client.create_network(
190 name=network_name)['network']
Slawek Kaplonski748dd8d2019-04-16 23:38:35 +0200191 self.addCleanup(
192 test_utils.call_and_ignore_notfound_exc,
193 self.networks_client.delete_network,
194 network2['id'])
rossellab24ec382013-11-13 10:21:59 +0100195 subnet2 = self.create_subnet(network2)
Slawek Kaplonski748dd8d2019-04-16 23:38:35 +0200196 self.addCleanup(
197 test_utils.call_and_ignore_notfound_exc,
198 self.subnets_client.delete_subnet, subnet2['id'])
zhufld2c40ca2016-10-18 17:03:07 +0800199 router2 = self.create_router(external_network_id=self.ext_net_id)
Slawek Kaplonski748dd8d2019-04-16 23:38:35 +0200200 self.addCleanup(
201 test_utils.call_and_ignore_notfound_exc,
202 self.routers_client.delete_router, router2['id'])
rossellab24ec382013-11-13 10:21:59 +0100203 self.create_router_interface(router2['id'], subnet2['id'])
Slawek Kaplonski748dd8d2019-04-16 23:38:35 +0200204 self.addCleanup(
205 test_utils.call_and_ignore_notfound_exc,
206 self.routers_client.remove_router_interface,
207 router2['id'], subnet_id=subnet2['id'])
rossellab24ec382013-11-13 10:21:59 +0100208 port_other_router = self.create_port(network2)
Slawek Kaplonski748dd8d2019-04-16 23:38:35 +0200209 self.addCleanup(
210 test_utils.call_and_ignore_notfound_exc,
211 self.ports_client.delete_port,
212 port_other_router['id'])
rossellab24ec382013-11-13 10:21:59 +0100213 # Associate floating IP to the other port on another router
John Warrenfbf2a892015-11-17 12:36:14 -0500214 floating_ip = self.floating_ips_client.update_floatingip(
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200215 created_floating_ip['id'],
216 port_id=port_other_router['id'])
rossellab24ec382013-11-13 10:21:59 +0100217 updated_floating_ip = floating_ip['floatingip']
218 self.assertEqual(updated_floating_ip['router_id'], router2['id'])
219 self.assertEqual(updated_floating_ip['port_id'],
220 port_other_router['id'])
221 self.assertIsNotNone(updated_floating_ip['fixed_ip_address'])
222
Jordan Pittier3b46d272017-04-12 16:17:28 +0200223 @decorators.attr(type='smoke')
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800224 @decorators.idempotent_id('36de4bd0-f09c-43e3-a8e1-1decc1ffd3a5')
Ann Kamyshnikova7d2275b2013-12-19 16:38:42 +0400225 def test_create_floating_ip_specifying_a_fixed_ip_address(self):
zhufl4810d882020-04-22 16:14:19 +0800226 """Test creating floating ip with specified fixed ip"""
John Warrenfbf2a892015-11-17 12:36:14 -0500227 body = self.floating_ips_client.create_floatingip(
Ann Kamyshnikova7d2275b2013-12-19 16:38:42 +0400228 floating_network_id=self.ext_net_id,
229 port_id=self.ports[1]['id'],
230 fixed_ip_address=self.ports[1]['fixed_ips'][0]['ip_address'])
Ann Kamyshnikova7d2275b2013-12-19 16:38:42 +0400231 created_floating_ip = body['floatingip']
Slawek Kaplonski748dd8d2019-04-16 23:38:35 +0200232 self.addCleanup(
233 test_utils.call_and_ignore_notfound_exc,
234 self.floating_ips_client.delete_floatingip,
235 created_floating_ip['id'])
Ann Kamyshnikova7d2275b2013-12-19 16:38:42 +0400236 self.assertIsNotNone(created_floating_ip['id'])
237 self.assertEqual(created_floating_ip['fixed_ip_address'],
238 self.ports[1]['fixed_ips'][0]['ip_address'])
John Warrenfbf2a892015-11-17 12:36:14 -0500239 floating_ip = self.floating_ips_client.update_floatingip(
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200240 created_floating_ip['id'],
241 port_id=None)
Ann Kamyshnikova7d2275b2013-12-19 16:38:42 +0400242 self.assertIsNone(floating_ip['floatingip']['port_id'])
243
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800244 @decorators.idempotent_id('45c4c683-ea97-41ef-9c51-5e9802f2f3d7')
Ann Kamyshnikovadf102842014-02-05 13:52:57 +0400245 def test_create_update_floatingip_with_port_multiple_ip_address(self):
zhufl4810d882020-04-22 16:14:19 +0800246 """Test updating floating ip's fixed_ips to another ip of same port
247
248 First we create a port with 2 fixed ips, then we create a floating ip
249 with one of the fixed ips, and then we update the floating ip to
250 another fixed ip of that port.
251 """
Ann Kamyshnikovadf102842014-02-05 13:52:57 +0400252 # Find out ips that can be used for tests
Ryan Tidwell1964a262016-05-04 15:13:23 -0700253 list_ips = net_utils.get_unused_ip_addresses(
254 self.ports_client,
255 self.subnets_client,
256 self.subnet['network_id'],
257 self.subnet['id'],
258 2)
Ann Kamyshnikovadf102842014-02-05 13:52:57 +0400259 fixed_ips = [{'ip_address': list_ips[0]}, {'ip_address': list_ips[1]}]
260 # Create port
Doug Schveninger24675aa2019-08-16 22:28:39 -0500261 body = self.ports_client.create_port(
262 network_id=self.network['id'],
Martin Kopec213d0a42023-11-30 10:28:14 +0100263 name=data_utils.rand_name(
264 self.__class__.__name__, prefix=CONF.resource_name_prefix),
Doug Schveninger24675aa2019-08-16 22:28:39 -0500265 fixed_ips=fixed_ips)
Ann Kamyshnikovadf102842014-02-05 13:52:57 +0400266 port = body['port']
Slawek Kaplonski748dd8d2019-04-16 23:38:35 +0200267 self.addCleanup(test_utils.call_and_ignore_notfound_exc,
268 self.ports_client.delete_port, port['id'])
Ann Kamyshnikovadf102842014-02-05 13:52:57 +0400269 # Create floating ip
John Warrenfbf2a892015-11-17 12:36:14 -0500270 body = self.floating_ips_client.create_floatingip(
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200271 floating_network_id=self.ext_net_id,
272 port_id=port['id'],
Ann Kamyshnikovadf102842014-02-05 13:52:57 +0400273 fixed_ip_address=list_ips[0])
Ann Kamyshnikovadf102842014-02-05 13:52:57 +0400274 floating_ip = body['floatingip']
Slawek Kaplonski748dd8d2019-04-16 23:38:35 +0200275 self.addCleanup(test_utils.call_and_ignore_notfound_exc,
276 self.floating_ips_client.delete_floatingip,
John Warrenfbf2a892015-11-17 12:36:14 -0500277 floating_ip['id'])
Ann Kamyshnikovadf102842014-02-05 13:52:57 +0400278 self.assertIsNotNone(floating_ip['id'])
279 self.assertEqual(floating_ip['fixed_ip_address'], list_ips[0])
280 # Update floating ip
John Warrenfbf2a892015-11-17 12:36:14 -0500281 body = self.floating_ips_client.update_floatingip(
282 floating_ip['id'], port_id=port['id'],
283 fixed_ip_address=list_ips[1])
Ann Kamyshnikovadf102842014-02-05 13:52:57 +0400284 update_floating_ip = body['floatingip']
285 self.assertEqual(update_floating_ip['fixed_ip_address'],
286 list_ips[1])