blob: b4bb88ec3746dab195da1de7b4dc864264f63a23 [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
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -080021from tempest.lib import decorators
Nayna Patelf1a29152013-08-09 07:18:13 +000022
Matthew Treinish03b48df2014-01-29 16:59:49 +000023CONF = config.CONF
24
Nayna Patelf1a29152013-08-09 07:18:13 +000025
Attila Fazekasc74aede2013-09-11 13:04:02 +020026class FloatingIPTestJSON(base.BaseNetworkTest):
Ken'ichi Ohmichie03bea92015-11-19 07:45:58 +000027 """Tests the following operations in the Neutron API:
Nayna Patelf1a29152013-08-09 07:18:13 +000028
29 Create a Floating IP
30 Update a Floating IP
31 Delete a Floating IP
32 List all Floating IPs
33 Show Floating IP details
rossellab24ec382013-11-13 10:21:59 +010034 Associate a Floating IP with a port and then delete that port
35 Associate a Floating IP with a port and then with a port on another
36 router
Nayna Patelf1a29152013-08-09 07:18:13 +000037
rossellabc9b4bd2013-11-13 10:21:59 +010038 v2.0 of the Neutron API is assumed. It is also assumed that the following
Nayna Patelf1a29152013-08-09 07:18:13 +000039 options are defined in the [network] section of etc/tempest.conf:
40
41 public_network_id which is the id for the external network present
42 """
43
44 @classmethod
Rohan Kanadea565e452015-01-27 14:00:13 +053045 def skip_checks(cls):
46 super(FloatingIPTestJSON, cls).skip_checks()
Andrea Frittolicd368412017-08-14 21:37:56 +010047 if not utils.is_extension_enabled('router', 'network'):
Yoshihiro Kaneko05670262014-01-18 19:22:44 +090048 msg = "router extension not enabled."
49 raise cls.skipException(msg)
zhufl6b7040a2017-01-18 16:38:34 +080050 if not CONF.network.public_network_id:
51 msg = "The public_network_id option must be specified."
52 raise cls.skipException(msg)
Matthew Treinish3312de32017-05-19 12:08:17 -040053 if not CONF.network_feature_enabled.floating_ips:
54 raise cls.skipException("Floating ips are not available")
Rohan Kanadea565e452015-01-27 14:00:13 +053055
56 @classmethod
57 def resource_setup(cls):
58 super(FloatingIPTestJSON, cls).resource_setup()
Matthew Treinish03b48df2014-01-29 16:59:49 +000059 cls.ext_net_id = CONF.network.public_network_id
Nayna Patelf1a29152013-08-09 07:18:13 +000060
61 # Create network, subnet, router and add interface
62 cls.network = cls.create_network()
Kevin Bentona70710b2016-07-08 15:24:38 -070063 cls.subnet = cls.create_subnet(cls.network, enable_dhcp=False)
zhufld2c40ca2016-10-18 17:03:07 +080064 cls.router = cls.create_router(external_network_id=cls.ext_net_id)
rossellabc9b4bd2013-11-13 10:21:59 +010065 cls.create_router_interface(cls.router['id'], cls.subnet['id'])
Nayna Patelf1a29152013-08-09 07:18:13 +000066 # Create two ports one each for Creation and Updating of floatingIP
67 for i in range(2):
rossellabc9b4bd2013-11-13 10:21:59 +010068 cls.create_port(cls.network)
Nayna Patelf1a29152013-08-09 07:18:13 +000069
Jordan Pittier3b46d272017-04-12 16:17:28 +020070 @decorators.attr(type='smoke')
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -080071 @decorators.idempotent_id('62595970-ab1c-4b7f-8fcc-fddfe55e8718')
Nayna Patelf1a29152013-08-09 07:18:13 +000072 def test_create_list_show_update_delete_floating_ip(self):
73 # Creates a floating IP
John Warrenfbf2a892015-11-17 12:36:14 -050074 body = self.floating_ips_client.create_floatingip(
Rohan Kanadeeeb21642014-08-14 12:00:26 +020075 floating_network_id=self.ext_net_id,
76 port_id=self.ports[0]['id'])
Ann Kamyshnikova47a4ff82014-03-17 12:48:57 +040077 created_floating_ip = body['floatingip']
John Warrenfbf2a892015-11-17 12:36:14 -050078 self.addCleanup(self.floating_ips_client.delete_floatingip,
Ann Kamyshnikova47a4ff82014-03-17 12:48:57 +040079 created_floating_ip['id'])
rossellabc9b4bd2013-11-13 10:21:59 +010080 self.assertIsNotNone(created_floating_ip['id'])
81 self.assertIsNotNone(created_floating_ip['tenant_id'])
82 self.assertIsNotNone(created_floating_ip['floating_ip_address'])
83 self.assertEqual(created_floating_ip['port_id'], self.ports[0]['id'])
84 self.assertEqual(created_floating_ip['floating_network_id'],
Nayna Patelf1a29152013-08-09 07:18:13 +000085 self.ext_net_id)
Ann Kamyshnikova7d2275b2013-12-19 16:38:42 +040086 self.assertIn(created_floating_ip['fixed_ip_address'],
87 [ip['ip_address'] for ip in self.ports[0]['fixed_ips']])
Nayna Patelf1a29152013-08-09 07:18:13 +000088 # Verifies the details of a floating_ip
John Warrenfbf2a892015-11-17 12:36:14 -050089 floating_ip = self.floating_ips_client.show_floatingip(
90 created_floating_ip['id'])
rossellabc9b4bd2013-11-13 10:21:59 +010091 shown_floating_ip = floating_ip['floatingip']
92 self.assertEqual(shown_floating_ip['id'], created_floating_ip['id'])
93 self.assertEqual(shown_floating_ip['floating_network_id'],
Nayna Patelf1a29152013-08-09 07:18:13 +000094 self.ext_net_id)
rossellabc9b4bd2013-11-13 10:21:59 +010095 self.assertEqual(shown_floating_ip['tenant_id'],
96 created_floating_ip['tenant_id'])
97 self.assertEqual(shown_floating_ip['floating_ip_address'],
98 created_floating_ip['floating_ip_address'])
99 self.assertEqual(shown_floating_ip['port_id'], self.ports[0]['id'])
Nayna Patelf1a29152013-08-09 07:18:13 +0000100
101 # Verify the floating ip exists in the list of all floating_ips
John Warrenfbf2a892015-11-17 12:36:14 -0500102 floating_ips = self.floating_ips_client.list_floatingips()
Nayna Patelf1a29152013-08-09 07:18:13 +0000103 floatingip_id_list = list()
104 for f in floating_ips['floatingips']:
105 floatingip_id_list.append(f['id'])
rossellabc9b4bd2013-11-13 10:21:59 +0100106 self.assertIn(created_floating_ip['id'], floatingip_id_list)
Nayna Patelf1a29152013-08-09 07:18:13 +0000107 # Associate floating IP to the other port
John Warrenfbf2a892015-11-17 12:36:14 -0500108 floating_ip = self.floating_ips_client.update_floatingip(
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200109 created_floating_ip['id'],
110 port_id=self.ports[1]['id'])
rossellabc9b4bd2013-11-13 10:21:59 +0100111 updated_floating_ip = floating_ip['floatingip']
112 self.assertEqual(updated_floating_ip['port_id'], self.ports[1]['id'])
113 self.assertEqual(updated_floating_ip['fixed_ip_address'],
114 self.ports[1]['fixed_ips'][0]['ip_address'])
115 self.assertEqual(updated_floating_ip['router_id'], self.router['id'])
Nayna Patelf1a29152013-08-09 07:18:13 +0000116
117 # Disassociate floating IP from the port
John Warrenfbf2a892015-11-17 12:36:14 -0500118 floating_ip = self.floating_ips_client.update_floatingip(
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200119 created_floating_ip['id'],
120 port_id=None)
rossellabc9b4bd2013-11-13 10:21:59 +0100121 updated_floating_ip = floating_ip['floatingip']
122 self.assertIsNone(updated_floating_ip['port_id'])
123 self.assertIsNone(updated_floating_ip['fixed_ip_address'])
124 self.assertIsNone(updated_floating_ip['router_id'])
Attila Fazekasc74aede2013-09-11 13:04:02 +0200125
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800126 @decorators.idempotent_id('e1f6bffd-442f-4668-b30e-df13f2705e77')
rossellab24ec382013-11-13 10:21:59 +0100127 def test_floating_ip_delete_port(self):
128 # Create a floating IP
John Warrenfbf2a892015-11-17 12:36:14 -0500129 body = self.floating_ips_client.create_floatingip(
Ann Kamyshnikova47a4ff82014-03-17 12:48:57 +0400130 floating_network_id=self.ext_net_id)
Ann Kamyshnikova47a4ff82014-03-17 12:48:57 +0400131 created_floating_ip = body['floatingip']
John Warrenfbf2a892015-11-17 12:36:14 -0500132 self.addCleanup(self.floating_ips_client.delete_floatingip,
Ann Kamyshnikova47a4ff82014-03-17 12:48:57 +0400133 created_floating_ip['id'])
rossellab24ec382013-11-13 10:21:59 +0100134 # Create a port
John Warren49c0fe52015-10-22 12:35:54 -0400135 port = self.ports_client.create_port(network_id=self.network['id'])
rossellab24ec382013-11-13 10:21:59 +0100136 created_port = port['port']
John Warrenfbf2a892015-11-17 12:36:14 -0500137 floating_ip = self.floating_ips_client.update_floatingip(
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200138 created_floating_ip['id'],
139 port_id=created_port['id'])
rossellab24ec382013-11-13 10:21:59 +0100140 # Delete port
John Warren49c0fe52015-10-22 12:35:54 -0400141 self.ports_client.delete_port(created_port['id'])
rossellab24ec382013-11-13 10:21:59 +0100142 # Verifies the details of the floating_ip
John Warrenfbf2a892015-11-17 12:36:14 -0500143 floating_ip = self.floating_ips_client.show_floatingip(
144 created_floating_ip['id'])
rossellab24ec382013-11-13 10:21:59 +0100145 shown_floating_ip = floating_ip['floatingip']
146 # Confirm the fields are back to None
147 self.assertEqual(shown_floating_ip['id'], created_floating_ip['id'])
148 self.assertIsNone(shown_floating_ip['port_id'])
149 self.assertIsNone(shown_floating_ip['fixed_ip_address'])
150 self.assertIsNone(shown_floating_ip['router_id'])
151
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800152 @decorators.idempotent_id('1bb2f731-fe5a-4b8c-8409-799ade1bed4d')
rossellab24ec382013-11-13 10:21:59 +0100153 def test_floating_ip_update_different_router(self):
154 # Associate a floating IP to a port on a router
John Warrenfbf2a892015-11-17 12:36:14 -0500155 body = self.floating_ips_client.create_floatingip(
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200156 floating_network_id=self.ext_net_id,
157 port_id=self.ports[1]['id'])
Ann Kamyshnikova47a4ff82014-03-17 12:48:57 +0400158 created_floating_ip = body['floatingip']
John Warrenfbf2a892015-11-17 12:36:14 -0500159 self.addCleanup(self.floating_ips_client.delete_floatingip,
Ann Kamyshnikova47a4ff82014-03-17 12:48:57 +0400160 created_floating_ip['id'])
rossellab24ec382013-11-13 10:21:59 +0100161 self.assertEqual(created_floating_ip['router_id'], self.router['id'])
deepak_mouryab4fb4382018-06-04 10:11:32 +0530162 network_name = data_utils.rand_name(self.__class__.__name__)
163 network2 = self.networks_client.create_network(
164 name=network_name)['network']
165 self.addCleanup(self.networks_client.delete_network,
166 network2['id'])
rossellab24ec382013-11-13 10:21:59 +0100167 subnet2 = self.create_subnet(network2)
deepak_mouryab4fb4382018-06-04 10:11:32 +0530168 self.addCleanup(self.subnets_client.delete_subnet, subnet2['id'])
zhufld2c40ca2016-10-18 17:03:07 +0800169 router2 = self.create_router(external_network_id=self.ext_net_id)
deepak_mouryab4fb4382018-06-04 10:11:32 +0530170 self.addCleanup(self.routers_client.delete_router, router2['id'])
rossellab24ec382013-11-13 10:21:59 +0100171 self.create_router_interface(router2['id'], subnet2['id'])
deepak_mouryab4fb4382018-06-04 10:11:32 +0530172 self.addCleanup(self.routers_client.remove_router_interface,
173 router2['id'], subnet_id=subnet2['id'])
rossellab24ec382013-11-13 10:21:59 +0100174 port_other_router = self.create_port(network2)
deepak_mouryab4fb4382018-06-04 10:11:32 +0530175 self.addCleanup(self.ports_client.delete_port,
176 port_other_router['id'])
rossellab24ec382013-11-13 10:21:59 +0100177 # Associate floating IP to the other port on another router
John Warrenfbf2a892015-11-17 12:36:14 -0500178 floating_ip = self.floating_ips_client.update_floatingip(
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200179 created_floating_ip['id'],
180 port_id=port_other_router['id'])
rossellab24ec382013-11-13 10:21:59 +0100181 updated_floating_ip = floating_ip['floatingip']
182 self.assertEqual(updated_floating_ip['router_id'], router2['id'])
183 self.assertEqual(updated_floating_ip['port_id'],
184 port_other_router['id'])
185 self.assertIsNotNone(updated_floating_ip['fixed_ip_address'])
186
Jordan Pittier3b46d272017-04-12 16:17:28 +0200187 @decorators.attr(type='smoke')
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800188 @decorators.idempotent_id('36de4bd0-f09c-43e3-a8e1-1decc1ffd3a5')
Ann Kamyshnikova7d2275b2013-12-19 16:38:42 +0400189 def test_create_floating_ip_specifying_a_fixed_ip_address(self):
John Warrenfbf2a892015-11-17 12:36:14 -0500190 body = self.floating_ips_client.create_floatingip(
Ann Kamyshnikova7d2275b2013-12-19 16:38:42 +0400191 floating_network_id=self.ext_net_id,
192 port_id=self.ports[1]['id'],
193 fixed_ip_address=self.ports[1]['fixed_ips'][0]['ip_address'])
Ann Kamyshnikova7d2275b2013-12-19 16:38:42 +0400194 created_floating_ip = body['floatingip']
John Warrenfbf2a892015-11-17 12:36:14 -0500195 self.addCleanup(self.floating_ips_client.delete_floatingip,
Ann Kamyshnikova7d2275b2013-12-19 16:38:42 +0400196 created_floating_ip['id'])
197 self.assertIsNotNone(created_floating_ip['id'])
198 self.assertEqual(created_floating_ip['fixed_ip_address'],
199 self.ports[1]['fixed_ips'][0]['ip_address'])
John Warrenfbf2a892015-11-17 12:36:14 -0500200 floating_ip = self.floating_ips_client.update_floatingip(
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200201 created_floating_ip['id'],
202 port_id=None)
Ann Kamyshnikova7d2275b2013-12-19 16:38:42 +0400203 self.assertIsNone(floating_ip['floatingip']['port_id'])
204
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800205 @decorators.idempotent_id('45c4c683-ea97-41ef-9c51-5e9802f2f3d7')
Ann Kamyshnikovadf102842014-02-05 13:52:57 +0400206 def test_create_update_floatingip_with_port_multiple_ip_address(self):
207 # Find out ips that can be used for tests
Ryan Tidwell1964a262016-05-04 15:13:23 -0700208 list_ips = net_utils.get_unused_ip_addresses(
209 self.ports_client,
210 self.subnets_client,
211 self.subnet['network_id'],
212 self.subnet['id'],
213 2)
Ann Kamyshnikovadf102842014-02-05 13:52:57 +0400214 fixed_ips = [{'ip_address': list_ips[0]}, {'ip_address': list_ips[1]}]
215 # Create port
John Warren49c0fe52015-10-22 12:35:54 -0400216 body = self.ports_client.create_port(network_id=self.network['id'],
217 fixed_ips=fixed_ips)
Ann Kamyshnikovadf102842014-02-05 13:52:57 +0400218 port = body['port']
John Warren49c0fe52015-10-22 12:35:54 -0400219 self.addCleanup(self.ports_client.delete_port, port['id'])
Ann Kamyshnikovadf102842014-02-05 13:52:57 +0400220 # Create floating ip
John Warrenfbf2a892015-11-17 12:36:14 -0500221 body = self.floating_ips_client.create_floatingip(
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200222 floating_network_id=self.ext_net_id,
223 port_id=port['id'],
Ann Kamyshnikovadf102842014-02-05 13:52:57 +0400224 fixed_ip_address=list_ips[0])
Ann Kamyshnikovadf102842014-02-05 13:52:57 +0400225 floating_ip = body['floatingip']
John Warrenfbf2a892015-11-17 12:36:14 -0500226 self.addCleanup(self.floating_ips_client.delete_floatingip,
227 floating_ip['id'])
Ann Kamyshnikovadf102842014-02-05 13:52:57 +0400228 self.assertIsNotNone(floating_ip['id'])
229 self.assertEqual(floating_ip['fixed_ip_address'], list_ips[0])
230 # Update floating ip
John Warrenfbf2a892015-11-17 12:36:14 -0500231 body = self.floating_ips_client.update_floatingip(
232 floating_ip['id'], port_id=port['id'],
233 fixed_ip_address=list_ips[1])
Ann Kamyshnikovadf102842014-02-05 13:52:57 +0400234 update_floating_ip = body['floatingip']
235 self.assertEqual(update_floating_ip['fixed_ip_address'],
236 list_ips[1])