blob: abcbbf766892c878ed3ee771bb938e182d574d9a [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
deepak_mouryab4fb4382018-06-04 10:11:32 +053018from tempest.common.utils import data_utils
Ryan Tidwell1964a262016-05-04 15:13:23 -070019from tempest.common.utils import net_utils
Matthew Treinish03b48df2014-01-29 16:59:49 +000020from tempest import config
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 = []
Nayna Patelf1a29152013-08-09 07:18:13 +000069 for i 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):
76 # Creates a floating IP
John Warrenfbf2a892015-11-17 12:36:14 -050077 body = self.floating_ips_client.create_floatingip(
Rohan Kanadeeeb21642014-08-14 12:00:26 +020078 floating_network_id=self.ext_net_id,
79 port_id=self.ports[0]['id'])
Ann Kamyshnikova47a4ff82014-03-17 12:48:57 +040080 created_floating_ip = body['floatingip']
Slawek Kaplonski748dd8d2019-04-16 23:38:35 +020081 self.addCleanup(
82 test_utils.call_and_ignore_notfound_exc,
83 self.floating_ips_client.delete_floatingip,
84 created_floating_ip['id'])
rossellabc9b4bd2013-11-13 10:21:59 +010085 self.assertIsNotNone(created_floating_ip['id'])
Rodolfo Alonso Hernandezc1449d42020-02-15 13:24:28 +000086 self.assertIsNotNone(created_floating_ip['project_id'])
rossellabc9b4bd2013-11-13 10:21:59 +010087 self.assertIsNotNone(created_floating_ip['floating_ip_address'])
88 self.assertEqual(created_floating_ip['port_id'], self.ports[0]['id'])
89 self.assertEqual(created_floating_ip['floating_network_id'],
Nayna Patelf1a29152013-08-09 07:18:13 +000090 self.ext_net_id)
Ann Kamyshnikova7d2275b2013-12-19 16:38:42 +040091 self.assertIn(created_floating_ip['fixed_ip_address'],
92 [ip['ip_address'] for ip in self.ports[0]['fixed_ips']])
Nayna Patelf1a29152013-08-09 07:18:13 +000093 # Verifies the details of a floating_ip
John Warrenfbf2a892015-11-17 12:36:14 -050094 floating_ip = self.floating_ips_client.show_floatingip(
95 created_floating_ip['id'])
rossellabc9b4bd2013-11-13 10:21:59 +010096 shown_floating_ip = floating_ip['floatingip']
97 self.assertEqual(shown_floating_ip['id'], created_floating_ip['id'])
98 self.assertEqual(shown_floating_ip['floating_network_id'],
Nayna Patelf1a29152013-08-09 07:18:13 +000099 self.ext_net_id)
Rodolfo Alonso Hernandezc1449d42020-02-15 13:24:28 +0000100 self.assertEqual(shown_floating_ip['project_id'],
101 created_floating_ip['project_id'])
rossellabc9b4bd2013-11-13 10:21:59 +0100102 self.assertEqual(shown_floating_ip['floating_ip_address'],
103 created_floating_ip['floating_ip_address'])
104 self.assertEqual(shown_floating_ip['port_id'], self.ports[0]['id'])
Nayna Patelf1a29152013-08-09 07:18:13 +0000105
106 # Verify the floating ip exists in the list of all floating_ips
John Warrenfbf2a892015-11-17 12:36:14 -0500107 floating_ips = self.floating_ips_client.list_floatingips()
Nayna Patelf1a29152013-08-09 07:18:13 +0000108 floatingip_id_list = list()
109 for f in floating_ips['floatingips']:
110 floatingip_id_list.append(f['id'])
rossellabc9b4bd2013-11-13 10:21:59 +0100111 self.assertIn(created_floating_ip['id'], floatingip_id_list)
Nayna Patelf1a29152013-08-09 07:18:13 +0000112 # Associate floating IP to the other port
John Warrenfbf2a892015-11-17 12:36:14 -0500113 floating_ip = self.floating_ips_client.update_floatingip(
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200114 created_floating_ip['id'],
115 port_id=self.ports[1]['id'])
rossellabc9b4bd2013-11-13 10:21:59 +0100116 updated_floating_ip = floating_ip['floatingip']
117 self.assertEqual(updated_floating_ip['port_id'], self.ports[1]['id'])
118 self.assertEqual(updated_floating_ip['fixed_ip_address'],
119 self.ports[1]['fixed_ips'][0]['ip_address'])
120 self.assertEqual(updated_floating_ip['router_id'], self.router['id'])
Nayna Patelf1a29152013-08-09 07:18:13 +0000121
122 # Disassociate floating IP from the port
John Warrenfbf2a892015-11-17 12:36:14 -0500123 floating_ip = self.floating_ips_client.update_floatingip(
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200124 created_floating_ip['id'],
125 port_id=None)
rossellabc9b4bd2013-11-13 10:21:59 +0100126 updated_floating_ip = floating_ip['floatingip']
127 self.assertIsNone(updated_floating_ip['port_id'])
128 self.assertIsNone(updated_floating_ip['fixed_ip_address'])
129 self.assertIsNone(updated_floating_ip['router_id'])
Attila Fazekasc74aede2013-09-11 13:04:02 +0200130
Slawek Kaplonski748dd8d2019-04-16 23:38:35 +0200131 # Explicity test deletion of floating IP
132 self.floating_ips_client.delete_floatingip(created_floating_ip['id'])
133
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800134 @decorators.idempotent_id('e1f6bffd-442f-4668-b30e-df13f2705e77')
rossellab24ec382013-11-13 10:21:59 +0100135 def test_floating_ip_delete_port(self):
136 # Create a floating IP
John Warrenfbf2a892015-11-17 12:36:14 -0500137 body = self.floating_ips_client.create_floatingip(
Ann Kamyshnikova47a4ff82014-03-17 12:48:57 +0400138 floating_network_id=self.ext_net_id)
Ann Kamyshnikova47a4ff82014-03-17 12:48:57 +0400139 created_floating_ip = body['floatingip']
Slawek Kaplonski748dd8d2019-04-16 23:38:35 +0200140 self.addCleanup(
141 test_utils.call_and_ignore_notfound_exc,
142 self.floating_ips_client.delete_floatingip,
143 created_floating_ip['id'])
rossellab24ec382013-11-13 10:21:59 +0100144 # Create a port
Doug Schveninger24675aa2019-08-16 22:28:39 -0500145 port = self.ports_client.create_port(
146 network_id=self.network['id'],
147 name=data_utils.rand_name(self.__class__.__name__))
rossellab24ec382013-11-13 10:21:59 +0100148 created_port = port['port']
John Warrenfbf2a892015-11-17 12:36:14 -0500149 floating_ip = self.floating_ips_client.update_floatingip(
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200150 created_floating_ip['id'],
151 port_id=created_port['id'])
rossellab24ec382013-11-13 10:21:59 +0100152 # Delete port
John Warren49c0fe52015-10-22 12:35:54 -0400153 self.ports_client.delete_port(created_port['id'])
rossellab24ec382013-11-13 10:21:59 +0100154 # Verifies the details of the floating_ip
John Warrenfbf2a892015-11-17 12:36:14 -0500155 floating_ip = self.floating_ips_client.show_floatingip(
156 created_floating_ip['id'])
rossellab24ec382013-11-13 10:21:59 +0100157 shown_floating_ip = floating_ip['floatingip']
158 # Confirm the fields are back to None
159 self.assertEqual(shown_floating_ip['id'], created_floating_ip['id'])
160 self.assertIsNone(shown_floating_ip['port_id'])
161 self.assertIsNone(shown_floating_ip['fixed_ip_address'])
162 self.assertIsNone(shown_floating_ip['router_id'])
163
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800164 @decorators.idempotent_id('1bb2f731-fe5a-4b8c-8409-799ade1bed4d')
rossellab24ec382013-11-13 10:21:59 +0100165 def test_floating_ip_update_different_router(self):
166 # Associate a floating IP to a port on a router
John Warrenfbf2a892015-11-17 12:36:14 -0500167 body = self.floating_ips_client.create_floatingip(
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200168 floating_network_id=self.ext_net_id,
169 port_id=self.ports[1]['id'])
Ann Kamyshnikova47a4ff82014-03-17 12:48:57 +0400170 created_floating_ip = body['floatingip']
Slawek Kaplonski748dd8d2019-04-16 23:38:35 +0200171 self.addCleanup(
172 test_utils.call_and_ignore_notfound_exc,
173 self.floating_ips_client.delete_floatingip,
174 created_floating_ip['id'])
rossellab24ec382013-11-13 10:21:59 +0100175 self.assertEqual(created_floating_ip['router_id'], self.router['id'])
deepak_mouryab4fb4382018-06-04 10:11:32 +0530176 network_name = data_utils.rand_name(self.__class__.__name__)
177 network2 = self.networks_client.create_network(
178 name=network_name)['network']
Slawek Kaplonski748dd8d2019-04-16 23:38:35 +0200179 self.addCleanup(
180 test_utils.call_and_ignore_notfound_exc,
181 self.networks_client.delete_network,
182 network2['id'])
rossellab24ec382013-11-13 10:21:59 +0100183 subnet2 = self.create_subnet(network2)
Slawek Kaplonski748dd8d2019-04-16 23:38:35 +0200184 self.addCleanup(
185 test_utils.call_and_ignore_notfound_exc,
186 self.subnets_client.delete_subnet, subnet2['id'])
zhufld2c40ca2016-10-18 17:03:07 +0800187 router2 = self.create_router(external_network_id=self.ext_net_id)
Slawek Kaplonski748dd8d2019-04-16 23:38:35 +0200188 self.addCleanup(
189 test_utils.call_and_ignore_notfound_exc,
190 self.routers_client.delete_router, router2['id'])
rossellab24ec382013-11-13 10:21:59 +0100191 self.create_router_interface(router2['id'], subnet2['id'])
Slawek Kaplonski748dd8d2019-04-16 23:38:35 +0200192 self.addCleanup(
193 test_utils.call_and_ignore_notfound_exc,
194 self.routers_client.remove_router_interface,
195 router2['id'], subnet_id=subnet2['id'])
rossellab24ec382013-11-13 10:21:59 +0100196 port_other_router = self.create_port(network2)
Slawek Kaplonski748dd8d2019-04-16 23:38:35 +0200197 self.addCleanup(
198 test_utils.call_and_ignore_notfound_exc,
199 self.ports_client.delete_port,
200 port_other_router['id'])
rossellab24ec382013-11-13 10:21:59 +0100201 # Associate floating IP to the other port on another router
John Warrenfbf2a892015-11-17 12:36:14 -0500202 floating_ip = self.floating_ips_client.update_floatingip(
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200203 created_floating_ip['id'],
204 port_id=port_other_router['id'])
rossellab24ec382013-11-13 10:21:59 +0100205 updated_floating_ip = floating_ip['floatingip']
206 self.assertEqual(updated_floating_ip['router_id'], router2['id'])
207 self.assertEqual(updated_floating_ip['port_id'],
208 port_other_router['id'])
209 self.assertIsNotNone(updated_floating_ip['fixed_ip_address'])
210
Jordan Pittier3b46d272017-04-12 16:17:28 +0200211 @decorators.attr(type='smoke')
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800212 @decorators.idempotent_id('36de4bd0-f09c-43e3-a8e1-1decc1ffd3a5')
Ann Kamyshnikova7d2275b2013-12-19 16:38:42 +0400213 def test_create_floating_ip_specifying_a_fixed_ip_address(self):
John Warrenfbf2a892015-11-17 12:36:14 -0500214 body = self.floating_ips_client.create_floatingip(
Ann Kamyshnikova7d2275b2013-12-19 16:38:42 +0400215 floating_network_id=self.ext_net_id,
216 port_id=self.ports[1]['id'],
217 fixed_ip_address=self.ports[1]['fixed_ips'][0]['ip_address'])
Ann Kamyshnikova7d2275b2013-12-19 16:38:42 +0400218 created_floating_ip = body['floatingip']
Slawek Kaplonski748dd8d2019-04-16 23:38:35 +0200219 self.addCleanup(
220 test_utils.call_and_ignore_notfound_exc,
221 self.floating_ips_client.delete_floatingip,
222 created_floating_ip['id'])
Ann Kamyshnikova7d2275b2013-12-19 16:38:42 +0400223 self.assertIsNotNone(created_floating_ip['id'])
224 self.assertEqual(created_floating_ip['fixed_ip_address'],
225 self.ports[1]['fixed_ips'][0]['ip_address'])
John Warrenfbf2a892015-11-17 12:36:14 -0500226 floating_ip = self.floating_ips_client.update_floatingip(
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200227 created_floating_ip['id'],
228 port_id=None)
Ann Kamyshnikova7d2275b2013-12-19 16:38:42 +0400229 self.assertIsNone(floating_ip['floatingip']['port_id'])
230
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800231 @decorators.idempotent_id('45c4c683-ea97-41ef-9c51-5e9802f2f3d7')
Ann Kamyshnikovadf102842014-02-05 13:52:57 +0400232 def test_create_update_floatingip_with_port_multiple_ip_address(self):
233 # Find out ips that can be used for tests
Ryan Tidwell1964a262016-05-04 15:13:23 -0700234 list_ips = net_utils.get_unused_ip_addresses(
235 self.ports_client,
236 self.subnets_client,
237 self.subnet['network_id'],
238 self.subnet['id'],
239 2)
Ann Kamyshnikovadf102842014-02-05 13:52:57 +0400240 fixed_ips = [{'ip_address': list_ips[0]}, {'ip_address': list_ips[1]}]
241 # Create port
Doug Schveninger24675aa2019-08-16 22:28:39 -0500242 body = self.ports_client.create_port(
243 network_id=self.network['id'],
244 name=data_utils.rand_name(self.__class__.__name__),
245 fixed_ips=fixed_ips)
Ann Kamyshnikovadf102842014-02-05 13:52:57 +0400246 port = body['port']
Slawek Kaplonski748dd8d2019-04-16 23:38:35 +0200247 self.addCleanup(test_utils.call_and_ignore_notfound_exc,
248 self.ports_client.delete_port, port['id'])
Ann Kamyshnikovadf102842014-02-05 13:52:57 +0400249 # Create floating ip
John Warrenfbf2a892015-11-17 12:36:14 -0500250 body = self.floating_ips_client.create_floatingip(
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200251 floating_network_id=self.ext_net_id,
252 port_id=port['id'],
Ann Kamyshnikovadf102842014-02-05 13:52:57 +0400253 fixed_ip_address=list_ips[0])
Ann Kamyshnikovadf102842014-02-05 13:52:57 +0400254 floating_ip = body['floatingip']
Slawek Kaplonski748dd8d2019-04-16 23:38:35 +0200255 self.addCleanup(test_utils.call_and_ignore_notfound_exc,
256 self.floating_ips_client.delete_floatingip,
John Warrenfbf2a892015-11-17 12:36:14 -0500257 floating_ip['id'])
Ann Kamyshnikovadf102842014-02-05 13:52:57 +0400258 self.assertIsNotNone(floating_ip['id'])
259 self.assertEqual(floating_ip['fixed_ip_address'], list_ips[0])
260 # Update floating ip
John Warrenfbf2a892015-11-17 12:36:14 -0500261 body = self.floating_ips_client.update_floatingip(
262 floating_ip['id'], port_id=port['id'],
263 fixed_ip_address=list_ips[1])
Ann Kamyshnikovadf102842014-02-05 13:52:57 +0400264 update_floating_ip = body['floatingip']
265 self.assertEqual(update_floating_ip['fixed_ip_address'],
266 list_ips[1])