blob: e9a553a19bd03204711ec5c229623a605977d452 [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
Ann Kamyshnikovadf102842014-02-05 13:52:57 +040016import netaddr
17
Nayna Patelf1a29152013-08-09 07:18:13 +000018from tempest.api.network import base
Fei Long Wangd39431f2015-05-14 11:30:48 +120019from tempest.common.utils import data_utils
Matthew Treinish03b48df2014-01-29 16:59:49 +000020from tempest import config
Yoshihiro Kaneko05670262014-01-18 19:22:44 +090021from tempest import test
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()
Yoshihiro Kaneko05670262014-01-18 19:22:44 +090047 if not test.is_extension_enabled('router', 'network'):
48 msg = "router extension not enabled."
49 raise cls.skipException(msg)
Rohan Kanadea565e452015-01-27 14:00:13 +053050
51 @classmethod
52 def resource_setup(cls):
53 super(FloatingIPTestJSON, cls).resource_setup()
Matthew Treinish03b48df2014-01-29 16:59:49 +000054 cls.ext_net_id = CONF.network.public_network_id
Nayna Patelf1a29152013-08-09 07:18:13 +000055
56 # Create network, subnet, router and add interface
57 cls.network = cls.create_network()
58 cls.subnet = cls.create_subnet(cls.network)
rossellabc9b4bd2013-11-13 10:21:59 +010059 cls.router = cls.create_router(data_utils.rand_name('router-'),
60 external_network_id=cls.ext_net_id)
61 cls.create_router_interface(cls.router['id'], cls.subnet['id'])
Nayna Patelf1a29152013-08-09 07:18:13 +000062 cls.port = list()
63 # Create two ports one each for Creation and Updating of floatingIP
64 for i in range(2):
rossellabc9b4bd2013-11-13 10:21:59 +010065 cls.create_port(cls.network)
Nayna Patelf1a29152013-08-09 07:18:13 +000066
Yoshihiro Kaneko05670262014-01-18 19:22:44 +090067 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -080068 @test.idempotent_id('62595970-ab1c-4b7f-8fcc-fddfe55e8718')
Nayna Patelf1a29152013-08-09 07:18:13 +000069 def test_create_list_show_update_delete_floating_ip(self):
70 # Creates a floating IP
David Kranz34e88122014-12-11 15:24:05 -050071 body = self.client.create_floatingip(
Rohan Kanadeeeb21642014-08-14 12:00:26 +020072 floating_network_id=self.ext_net_id,
73 port_id=self.ports[0]['id'])
Ann Kamyshnikova47a4ff82014-03-17 12:48:57 +040074 created_floating_ip = body['floatingip']
75 self.addCleanup(self.client.delete_floatingip,
76 created_floating_ip['id'])
rossellabc9b4bd2013-11-13 10:21:59 +010077 self.assertIsNotNone(created_floating_ip['id'])
78 self.assertIsNotNone(created_floating_ip['tenant_id'])
79 self.assertIsNotNone(created_floating_ip['floating_ip_address'])
80 self.assertEqual(created_floating_ip['port_id'], self.ports[0]['id'])
81 self.assertEqual(created_floating_ip['floating_network_id'],
Nayna Patelf1a29152013-08-09 07:18:13 +000082 self.ext_net_id)
Ann Kamyshnikova7d2275b2013-12-19 16:38:42 +040083 self.assertIn(created_floating_ip['fixed_ip_address'],
84 [ip['ip_address'] for ip in self.ports[0]['fixed_ips']])
Nayna Patelf1a29152013-08-09 07:18:13 +000085 # Verifies the details of a floating_ip
David Kranz34e88122014-12-11 15:24:05 -050086 floating_ip = self.client.show_floatingip(created_floating_ip['id'])
rossellabc9b4bd2013-11-13 10:21:59 +010087 shown_floating_ip = floating_ip['floatingip']
88 self.assertEqual(shown_floating_ip['id'], created_floating_ip['id'])
89 self.assertEqual(shown_floating_ip['floating_network_id'],
Nayna Patelf1a29152013-08-09 07:18:13 +000090 self.ext_net_id)
rossellabc9b4bd2013-11-13 10:21:59 +010091 self.assertEqual(shown_floating_ip['tenant_id'],
92 created_floating_ip['tenant_id'])
93 self.assertEqual(shown_floating_ip['floating_ip_address'],
94 created_floating_ip['floating_ip_address'])
95 self.assertEqual(shown_floating_ip['port_id'], self.ports[0]['id'])
Nayna Patelf1a29152013-08-09 07:18:13 +000096
97 # Verify the floating ip exists in the list of all floating_ips
David Kranz34e88122014-12-11 15:24:05 -050098 floating_ips = self.client.list_floatingips()
Nayna Patelf1a29152013-08-09 07:18:13 +000099 floatingip_id_list = list()
100 for f in floating_ips['floatingips']:
101 floatingip_id_list.append(f['id'])
rossellabc9b4bd2013-11-13 10:21:59 +0100102 self.assertIn(created_floating_ip['id'], floatingip_id_list)
Nayna Patelf1a29152013-08-09 07:18:13 +0000103 # Associate floating IP to the other port
David Kranz34e88122014-12-11 15:24:05 -0500104 floating_ip = self.client.update_floatingip(
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200105 created_floating_ip['id'],
106 port_id=self.ports[1]['id'])
rossellabc9b4bd2013-11-13 10:21:59 +0100107 updated_floating_ip = floating_ip['floatingip']
108 self.assertEqual(updated_floating_ip['port_id'], self.ports[1]['id'])
109 self.assertEqual(updated_floating_ip['fixed_ip_address'],
110 self.ports[1]['fixed_ips'][0]['ip_address'])
111 self.assertEqual(updated_floating_ip['router_id'], self.router['id'])
Nayna Patelf1a29152013-08-09 07:18:13 +0000112
113 # Disassociate floating IP from the port
David Kranz34e88122014-12-11 15:24:05 -0500114 floating_ip = self.client.update_floatingip(
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200115 created_floating_ip['id'],
116 port_id=None)
rossellabc9b4bd2013-11-13 10:21:59 +0100117 updated_floating_ip = floating_ip['floatingip']
118 self.assertIsNone(updated_floating_ip['port_id'])
119 self.assertIsNone(updated_floating_ip['fixed_ip_address'])
120 self.assertIsNone(updated_floating_ip['router_id'])
Attila Fazekasc74aede2013-09-11 13:04:02 +0200121
Chris Hoge7579c1a2015-02-26 14:12:15 -0800122 @test.idempotent_id('e1f6bffd-442f-4668-b30e-df13f2705e77')
rossellab24ec382013-11-13 10:21:59 +0100123 def test_floating_ip_delete_port(self):
124 # Create a floating IP
David Kranz34e88122014-12-11 15:24:05 -0500125 body = self.client.create_floatingip(
Ann Kamyshnikova47a4ff82014-03-17 12:48:57 +0400126 floating_network_id=self.ext_net_id)
Ann Kamyshnikova47a4ff82014-03-17 12:48:57 +0400127 created_floating_ip = body['floatingip']
128 self.addCleanup(self.client.delete_floatingip,
129 created_floating_ip['id'])
rossellab24ec382013-11-13 10:21:59 +0100130 # Create a port
John Warren49c0fe52015-10-22 12:35:54 -0400131 port = self.ports_client.create_port(network_id=self.network['id'])
rossellab24ec382013-11-13 10:21:59 +0100132 created_port = port['port']
David Kranz34e88122014-12-11 15:24:05 -0500133 floating_ip = self.client.update_floatingip(
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200134 created_floating_ip['id'],
135 port_id=created_port['id'])
rossellab24ec382013-11-13 10:21:59 +0100136 # Delete port
John Warren49c0fe52015-10-22 12:35:54 -0400137 self.ports_client.delete_port(created_port['id'])
rossellab24ec382013-11-13 10:21:59 +0100138 # Verifies the details of the floating_ip
David Kranz34e88122014-12-11 15:24:05 -0500139 floating_ip = self.client.show_floatingip(created_floating_ip['id'])
rossellab24ec382013-11-13 10:21:59 +0100140 shown_floating_ip = floating_ip['floatingip']
141 # Confirm the fields are back to None
142 self.assertEqual(shown_floating_ip['id'], created_floating_ip['id'])
143 self.assertIsNone(shown_floating_ip['port_id'])
144 self.assertIsNone(shown_floating_ip['fixed_ip_address'])
145 self.assertIsNone(shown_floating_ip['router_id'])
146
Chris Hoge7579c1a2015-02-26 14:12:15 -0800147 @test.idempotent_id('1bb2f731-fe5a-4b8c-8409-799ade1bed4d')
rossellab24ec382013-11-13 10:21:59 +0100148 def test_floating_ip_update_different_router(self):
149 # Associate a floating IP to a port on a router
David Kranz34e88122014-12-11 15:24:05 -0500150 body = self.client.create_floatingip(
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200151 floating_network_id=self.ext_net_id,
152 port_id=self.ports[1]['id'])
Ann Kamyshnikova47a4ff82014-03-17 12:48:57 +0400153 created_floating_ip = body['floatingip']
154 self.addCleanup(self.client.delete_floatingip,
155 created_floating_ip['id'])
rossellab24ec382013-11-13 10:21:59 +0100156 self.assertEqual(created_floating_ip['router_id'], self.router['id'])
157 network2 = self.create_network()
158 subnet2 = self.create_subnet(network2)
159 router2 = self.create_router(data_utils.rand_name('router-'),
160 external_network_id=self.ext_net_id)
161 self.create_router_interface(router2['id'], subnet2['id'])
162 port_other_router = self.create_port(network2)
163 # Associate floating IP to the other port on another router
David Kranz34e88122014-12-11 15:24:05 -0500164 floating_ip = self.client.update_floatingip(
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200165 created_floating_ip['id'],
166 port_id=port_other_router['id'])
rossellab24ec382013-11-13 10:21:59 +0100167 updated_floating_ip = floating_ip['floatingip']
168 self.assertEqual(updated_floating_ip['router_id'], router2['id'])
169 self.assertEqual(updated_floating_ip['port_id'],
170 port_other_router['id'])
171 self.assertIsNotNone(updated_floating_ip['fixed_ip_address'])
172
Ann Kamyshnikova7d2275b2013-12-19 16:38:42 +0400173 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800174 @test.idempotent_id('36de4bd0-f09c-43e3-a8e1-1decc1ffd3a5')
Ann Kamyshnikova7d2275b2013-12-19 16:38:42 +0400175 def test_create_floating_ip_specifying_a_fixed_ip_address(self):
David Kranz34e88122014-12-11 15:24:05 -0500176 body = self.client.create_floatingip(
Ann Kamyshnikova7d2275b2013-12-19 16:38:42 +0400177 floating_network_id=self.ext_net_id,
178 port_id=self.ports[1]['id'],
179 fixed_ip_address=self.ports[1]['fixed_ips'][0]['ip_address'])
Ann Kamyshnikova7d2275b2013-12-19 16:38:42 +0400180 created_floating_ip = body['floatingip']
181 self.addCleanup(self.client.delete_floatingip,
182 created_floating_ip['id'])
183 self.assertIsNotNone(created_floating_ip['id'])
184 self.assertEqual(created_floating_ip['fixed_ip_address'],
185 self.ports[1]['fixed_ips'][0]['ip_address'])
David Kranz34e88122014-12-11 15:24:05 -0500186 floating_ip = self.client.update_floatingip(
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200187 created_floating_ip['id'],
188 port_id=None)
Ann Kamyshnikova7d2275b2013-12-19 16:38:42 +0400189 self.assertIsNone(floating_ip['floatingip']['port_id'])
190
Chris Hoge7579c1a2015-02-26 14:12:15 -0800191 @test.idempotent_id('45c4c683-ea97-41ef-9c51-5e9802f2f3d7')
Ann Kamyshnikovadf102842014-02-05 13:52:57 +0400192 def test_create_update_floatingip_with_port_multiple_ip_address(self):
193 # Find out ips that can be used for tests
194 ips = list(netaddr.IPNetwork(self.subnet['cidr']))
195 list_ips = [str(ip) for ip in ips[-3:-1]]
196 fixed_ips = [{'ip_address': list_ips[0]}, {'ip_address': list_ips[1]}]
197 # Create port
John Warren49c0fe52015-10-22 12:35:54 -0400198 body = self.ports_client.create_port(network_id=self.network['id'],
199 fixed_ips=fixed_ips)
Ann Kamyshnikovadf102842014-02-05 13:52:57 +0400200 port = body['port']
John Warren49c0fe52015-10-22 12:35:54 -0400201 self.addCleanup(self.ports_client.delete_port, port['id'])
Ann Kamyshnikovadf102842014-02-05 13:52:57 +0400202 # Create floating ip
David Kranz34e88122014-12-11 15:24:05 -0500203 body = self.client.create_floatingip(
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200204 floating_network_id=self.ext_net_id,
205 port_id=port['id'],
Ann Kamyshnikovadf102842014-02-05 13:52:57 +0400206 fixed_ip_address=list_ips[0])
Ann Kamyshnikovadf102842014-02-05 13:52:57 +0400207 floating_ip = body['floatingip']
208 self.addCleanup(self.client.delete_floatingip, floating_ip['id'])
209 self.assertIsNotNone(floating_ip['id'])
210 self.assertEqual(floating_ip['fixed_ip_address'], list_ips[0])
211 # Update floating ip
David Kranz34e88122014-12-11 15:24:05 -0500212 body = self.client.update_floatingip(floating_ip['id'],
213 port_id=port['id'],
214 fixed_ip_address=list_ips[1])
Ann Kamyshnikovadf102842014-02-05 13:52:57 +0400215 update_floating_ip = body['floatingip']
216 self.assertEqual(update_floating_ip['fixed_ip_address'],
217 list_ips[1])