blob: c799b15a3c9fc4e64d7d187b9bfb4fba1a7a5de1 [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
Ryan Tidwell1964a262016-05-04 15:13:23 -070017from tempest.common.utils import net_utils
Matthew Treinish03b48df2014-01-29 16:59:49 +000018from tempest import config
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -080019from tempest.lib import decorators
Yoshihiro Kaneko05670262014-01-18 19:22:44 +090020from tempest import test
Nayna Patelf1a29152013-08-09 07:18:13 +000021
Matthew Treinish03b48df2014-01-29 16:59:49 +000022CONF = config.CONF
23
Nayna Patelf1a29152013-08-09 07:18:13 +000024
Attila Fazekasc74aede2013-09-11 13:04:02 +020025class FloatingIPTestJSON(base.BaseNetworkTest):
Ken'ichi Ohmichie03bea92015-11-19 07:45:58 +000026 """Tests the following operations in the Neutron API:
Nayna Patelf1a29152013-08-09 07:18:13 +000027
28 Create a Floating IP
29 Update a Floating IP
30 Delete a Floating IP
31 List all Floating IPs
32 Show Floating IP details
rossellab24ec382013-11-13 10:21:59 +010033 Associate a Floating IP with a port and then delete that port
34 Associate a Floating IP with a port and then with a port on another
35 router
Nayna Patelf1a29152013-08-09 07:18:13 +000036
rossellabc9b4bd2013-11-13 10:21:59 +010037 v2.0 of the Neutron API is assumed. It is also assumed that the following
Nayna Patelf1a29152013-08-09 07:18:13 +000038 options are defined in the [network] section of etc/tempest.conf:
39
40 public_network_id which is the id for the external network present
41 """
42
43 @classmethod
Rohan Kanadea565e452015-01-27 14:00:13 +053044 def skip_checks(cls):
45 super(FloatingIPTestJSON, cls).skip_checks()
Yoshihiro Kaneko05670262014-01-18 19:22:44 +090046 if not test.is_extension_enabled('router', 'network'):
47 msg = "router extension not enabled."
48 raise cls.skipException(msg)
zhufl6b7040a2017-01-18 16:38:34 +080049 if not CONF.network.public_network_id:
50 msg = "The public_network_id option must be specified."
51 raise cls.skipException(msg)
Matthew Treinish3312de32017-05-19 12:08:17 -040052 if not CONF.network_feature_enabled.floating_ips:
53 raise cls.skipException("Floating ips are not available")
Rohan Kanadea565e452015-01-27 14:00:13 +053054
55 @classmethod
56 def resource_setup(cls):
57 super(FloatingIPTestJSON, cls).resource_setup()
Matthew Treinish03b48df2014-01-29 16:59:49 +000058 cls.ext_net_id = CONF.network.public_network_id
Nayna Patelf1a29152013-08-09 07:18:13 +000059
60 # Create network, subnet, router and add interface
61 cls.network = cls.create_network()
Kevin Bentona70710b2016-07-08 15:24:38 -070062 cls.subnet = cls.create_subnet(cls.network, enable_dhcp=False)
zhufld2c40ca2016-10-18 17:03:07 +080063 cls.router = cls.create_router(external_network_id=cls.ext_net_id)
rossellabc9b4bd2013-11-13 10:21:59 +010064 cls.create_router_interface(cls.router['id'], cls.subnet['id'])
Nayna Patelf1a29152013-08-09 07:18:13 +000065 # Create two ports one each for Creation and Updating of floatingIP
66 for i in range(2):
rossellabc9b4bd2013-11-13 10:21:59 +010067 cls.create_port(cls.network)
Nayna Patelf1a29152013-08-09 07:18:13 +000068
Jordan Pittier3b46d272017-04-12 16:17:28 +020069 @decorators.attr(type='smoke')
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -080070 @decorators.idempotent_id('62595970-ab1c-4b7f-8fcc-fddfe55e8718')
Nayna Patelf1a29152013-08-09 07:18:13 +000071 def test_create_list_show_update_delete_floating_ip(self):
72 # Creates a floating IP
John Warrenfbf2a892015-11-17 12:36:14 -050073 body = self.floating_ips_client.create_floatingip(
Rohan Kanadeeeb21642014-08-14 12:00:26 +020074 floating_network_id=self.ext_net_id,
75 port_id=self.ports[0]['id'])
Ann Kamyshnikova47a4ff82014-03-17 12:48:57 +040076 created_floating_ip = body['floatingip']
John Warrenfbf2a892015-11-17 12:36:14 -050077 self.addCleanup(self.floating_ips_client.delete_floatingip,
Ann Kamyshnikova47a4ff82014-03-17 12:48:57 +040078 created_floating_ip['id'])
rossellabc9b4bd2013-11-13 10:21:59 +010079 self.assertIsNotNone(created_floating_ip['id'])
80 self.assertIsNotNone(created_floating_ip['tenant_id'])
81 self.assertIsNotNone(created_floating_ip['floating_ip_address'])
82 self.assertEqual(created_floating_ip['port_id'], self.ports[0]['id'])
83 self.assertEqual(created_floating_ip['floating_network_id'],
Nayna Patelf1a29152013-08-09 07:18:13 +000084 self.ext_net_id)
Ann Kamyshnikova7d2275b2013-12-19 16:38:42 +040085 self.assertIn(created_floating_ip['fixed_ip_address'],
86 [ip['ip_address'] for ip in self.ports[0]['fixed_ips']])
Nayna Patelf1a29152013-08-09 07:18:13 +000087 # Verifies the details of a floating_ip
John Warrenfbf2a892015-11-17 12:36:14 -050088 floating_ip = self.floating_ips_client.show_floatingip(
89 created_floating_ip['id'])
rossellabc9b4bd2013-11-13 10:21:59 +010090 shown_floating_ip = floating_ip['floatingip']
91 self.assertEqual(shown_floating_ip['id'], created_floating_ip['id'])
92 self.assertEqual(shown_floating_ip['floating_network_id'],
Nayna Patelf1a29152013-08-09 07:18:13 +000093 self.ext_net_id)
rossellabc9b4bd2013-11-13 10:21:59 +010094 self.assertEqual(shown_floating_ip['tenant_id'],
95 created_floating_ip['tenant_id'])
96 self.assertEqual(shown_floating_ip['floating_ip_address'],
97 created_floating_ip['floating_ip_address'])
98 self.assertEqual(shown_floating_ip['port_id'], self.ports[0]['id'])
Nayna Patelf1a29152013-08-09 07:18:13 +000099
100 # Verify the floating ip exists in the list of all floating_ips
John Warrenfbf2a892015-11-17 12:36:14 -0500101 floating_ips = self.floating_ips_client.list_floatingips()
Nayna Patelf1a29152013-08-09 07:18:13 +0000102 floatingip_id_list = list()
103 for f in floating_ips['floatingips']:
104 floatingip_id_list.append(f['id'])
rossellabc9b4bd2013-11-13 10:21:59 +0100105 self.assertIn(created_floating_ip['id'], floatingip_id_list)
Nayna Patelf1a29152013-08-09 07:18:13 +0000106 # Associate floating IP to the other port
John Warrenfbf2a892015-11-17 12:36:14 -0500107 floating_ip = self.floating_ips_client.update_floatingip(
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200108 created_floating_ip['id'],
109 port_id=self.ports[1]['id'])
rossellabc9b4bd2013-11-13 10:21:59 +0100110 updated_floating_ip = floating_ip['floatingip']
111 self.assertEqual(updated_floating_ip['port_id'], self.ports[1]['id'])
112 self.assertEqual(updated_floating_ip['fixed_ip_address'],
113 self.ports[1]['fixed_ips'][0]['ip_address'])
114 self.assertEqual(updated_floating_ip['router_id'], self.router['id'])
Nayna Patelf1a29152013-08-09 07:18:13 +0000115
116 # Disassociate floating IP from the port
John Warrenfbf2a892015-11-17 12:36:14 -0500117 floating_ip = self.floating_ips_client.update_floatingip(
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200118 created_floating_ip['id'],
119 port_id=None)
rossellabc9b4bd2013-11-13 10:21:59 +0100120 updated_floating_ip = floating_ip['floatingip']
121 self.assertIsNone(updated_floating_ip['port_id'])
122 self.assertIsNone(updated_floating_ip['fixed_ip_address'])
123 self.assertIsNone(updated_floating_ip['router_id'])
Attila Fazekasc74aede2013-09-11 13:04:02 +0200124
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800125 @decorators.idempotent_id('e1f6bffd-442f-4668-b30e-df13f2705e77')
rossellab24ec382013-11-13 10:21:59 +0100126 def test_floating_ip_delete_port(self):
127 # Create a floating IP
John Warrenfbf2a892015-11-17 12:36:14 -0500128 body = self.floating_ips_client.create_floatingip(
Ann Kamyshnikova47a4ff82014-03-17 12:48:57 +0400129 floating_network_id=self.ext_net_id)
Ann Kamyshnikova47a4ff82014-03-17 12:48:57 +0400130 created_floating_ip = body['floatingip']
John Warrenfbf2a892015-11-17 12:36:14 -0500131 self.addCleanup(self.floating_ips_client.delete_floatingip,
Ann Kamyshnikova47a4ff82014-03-17 12:48:57 +0400132 created_floating_ip['id'])
rossellab24ec382013-11-13 10:21:59 +0100133 # Create a port
John Warren49c0fe52015-10-22 12:35:54 -0400134 port = self.ports_client.create_port(network_id=self.network['id'])
rossellab24ec382013-11-13 10:21:59 +0100135 created_port = port['port']
John Warrenfbf2a892015-11-17 12:36:14 -0500136 floating_ip = self.floating_ips_client.update_floatingip(
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200137 created_floating_ip['id'],
138 port_id=created_port['id'])
rossellab24ec382013-11-13 10:21:59 +0100139 # Delete port
John Warren49c0fe52015-10-22 12:35:54 -0400140 self.ports_client.delete_port(created_port['id'])
rossellab24ec382013-11-13 10:21:59 +0100141 # Verifies the details of the floating_ip
John Warrenfbf2a892015-11-17 12:36:14 -0500142 floating_ip = self.floating_ips_client.show_floatingip(
143 created_floating_ip['id'])
rossellab24ec382013-11-13 10:21:59 +0100144 shown_floating_ip = floating_ip['floatingip']
145 # Confirm the fields are back to None
146 self.assertEqual(shown_floating_ip['id'], created_floating_ip['id'])
147 self.assertIsNone(shown_floating_ip['port_id'])
148 self.assertIsNone(shown_floating_ip['fixed_ip_address'])
149 self.assertIsNone(shown_floating_ip['router_id'])
150
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800151 @decorators.idempotent_id('1bb2f731-fe5a-4b8c-8409-799ade1bed4d')
rossellab24ec382013-11-13 10:21:59 +0100152 def test_floating_ip_update_different_router(self):
153 # Associate a floating IP to a port on a router
John Warrenfbf2a892015-11-17 12:36:14 -0500154 body = self.floating_ips_client.create_floatingip(
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200155 floating_network_id=self.ext_net_id,
156 port_id=self.ports[1]['id'])
Ann Kamyshnikova47a4ff82014-03-17 12:48:57 +0400157 created_floating_ip = body['floatingip']
John Warrenfbf2a892015-11-17 12:36:14 -0500158 self.addCleanup(self.floating_ips_client.delete_floatingip,
Ann Kamyshnikova47a4ff82014-03-17 12:48:57 +0400159 created_floating_ip['id'])
rossellab24ec382013-11-13 10:21:59 +0100160 self.assertEqual(created_floating_ip['router_id'], self.router['id'])
161 network2 = self.create_network()
162 subnet2 = self.create_subnet(network2)
zhufld2c40ca2016-10-18 17:03:07 +0800163 router2 = self.create_router(external_network_id=self.ext_net_id)
rossellab24ec382013-11-13 10:21:59 +0100164 self.create_router_interface(router2['id'], subnet2['id'])
165 port_other_router = self.create_port(network2)
166 # Associate floating IP to the other port on another router
John Warrenfbf2a892015-11-17 12:36:14 -0500167 floating_ip = self.floating_ips_client.update_floatingip(
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200168 created_floating_ip['id'],
169 port_id=port_other_router['id'])
rossellab24ec382013-11-13 10:21:59 +0100170 updated_floating_ip = floating_ip['floatingip']
171 self.assertEqual(updated_floating_ip['router_id'], router2['id'])
172 self.assertEqual(updated_floating_ip['port_id'],
173 port_other_router['id'])
174 self.assertIsNotNone(updated_floating_ip['fixed_ip_address'])
175
Jordan Pittier3b46d272017-04-12 16:17:28 +0200176 @decorators.attr(type='smoke')
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800177 @decorators.idempotent_id('36de4bd0-f09c-43e3-a8e1-1decc1ffd3a5')
Ann Kamyshnikova7d2275b2013-12-19 16:38:42 +0400178 def test_create_floating_ip_specifying_a_fixed_ip_address(self):
John Warrenfbf2a892015-11-17 12:36:14 -0500179 body = self.floating_ips_client.create_floatingip(
Ann Kamyshnikova7d2275b2013-12-19 16:38:42 +0400180 floating_network_id=self.ext_net_id,
181 port_id=self.ports[1]['id'],
182 fixed_ip_address=self.ports[1]['fixed_ips'][0]['ip_address'])
Ann Kamyshnikova7d2275b2013-12-19 16:38:42 +0400183 created_floating_ip = body['floatingip']
John Warrenfbf2a892015-11-17 12:36:14 -0500184 self.addCleanup(self.floating_ips_client.delete_floatingip,
Ann Kamyshnikova7d2275b2013-12-19 16:38:42 +0400185 created_floating_ip['id'])
186 self.assertIsNotNone(created_floating_ip['id'])
187 self.assertEqual(created_floating_ip['fixed_ip_address'],
188 self.ports[1]['fixed_ips'][0]['ip_address'])
John Warrenfbf2a892015-11-17 12:36:14 -0500189 floating_ip = self.floating_ips_client.update_floatingip(
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200190 created_floating_ip['id'],
191 port_id=None)
Ann Kamyshnikova7d2275b2013-12-19 16:38:42 +0400192 self.assertIsNone(floating_ip['floatingip']['port_id'])
193
Ken'ichi Ohmichi53b9a632017-01-27 18:04:39 -0800194 @decorators.idempotent_id('45c4c683-ea97-41ef-9c51-5e9802f2f3d7')
Ann Kamyshnikovadf102842014-02-05 13:52:57 +0400195 def test_create_update_floatingip_with_port_multiple_ip_address(self):
196 # Find out ips that can be used for tests
Ryan Tidwell1964a262016-05-04 15:13:23 -0700197 list_ips = net_utils.get_unused_ip_addresses(
198 self.ports_client,
199 self.subnets_client,
200 self.subnet['network_id'],
201 self.subnet['id'],
202 2)
Ann Kamyshnikovadf102842014-02-05 13:52:57 +0400203 fixed_ips = [{'ip_address': list_ips[0]}, {'ip_address': list_ips[1]}]
204 # Create port
John Warren49c0fe52015-10-22 12:35:54 -0400205 body = self.ports_client.create_port(network_id=self.network['id'],
206 fixed_ips=fixed_ips)
Ann Kamyshnikovadf102842014-02-05 13:52:57 +0400207 port = body['port']
John Warren49c0fe52015-10-22 12:35:54 -0400208 self.addCleanup(self.ports_client.delete_port, port['id'])
Ann Kamyshnikovadf102842014-02-05 13:52:57 +0400209 # Create floating ip
John Warrenfbf2a892015-11-17 12:36:14 -0500210 body = self.floating_ips_client.create_floatingip(
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200211 floating_network_id=self.ext_net_id,
212 port_id=port['id'],
Ann Kamyshnikovadf102842014-02-05 13:52:57 +0400213 fixed_ip_address=list_ips[0])
Ann Kamyshnikovadf102842014-02-05 13:52:57 +0400214 floating_ip = body['floatingip']
John Warrenfbf2a892015-11-17 12:36:14 -0500215 self.addCleanup(self.floating_ips_client.delete_floatingip,
216 floating_ip['id'])
Ann Kamyshnikovadf102842014-02-05 13:52:57 +0400217 self.assertIsNotNone(floating_ip['id'])
218 self.assertEqual(floating_ip['fixed_ip_address'], list_ips[0])
219 # Update floating ip
John Warrenfbf2a892015-11-17 12:36:14 -0500220 body = self.floating_ips_client.update_floatingip(
221 floating_ip['id'], port_id=port['id'],
222 fixed_ip_address=list_ips[1])
Ann Kamyshnikovadf102842014-02-05 13:52:57 +0400223 update_floating_ip = body['floatingip']
224 self.assertEqual(update_floating_ip['fixed_ip_address'],
225 list_ips[1])