blob: f0923d2b4d898dd70c74f50e37194fc33f3ee0fa [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):
Nayna Patelf1a29152013-08-09 07:18:13 +000027 """
28 Tests the following operations in the Quantum API using the REST client for
rossellabc9b4bd2013-11-13 10:21:59 +010029 Neutron:
Nayna Patelf1a29152013-08-09 07:18:13 +000030
31 Create a Floating IP
32 Update a Floating IP
33 Delete a Floating IP
34 List all Floating IPs
35 Show Floating IP details
rossellab24ec382013-11-13 10:21:59 +010036 Associate a Floating IP with a port and then delete that port
37 Associate a Floating IP with a port and then with a port on another
38 router
Nayna Patelf1a29152013-08-09 07:18:13 +000039
rossellabc9b4bd2013-11-13 10:21:59 +010040 v2.0 of the Neutron API is assumed. It is also assumed that the following
Nayna Patelf1a29152013-08-09 07:18:13 +000041 options are defined in the [network] section of etc/tempest.conf:
42
43 public_network_id which is the id for the external network present
44 """
45
46 @classmethod
Rohan Kanadea565e452015-01-27 14:00:13 +053047 def skip_checks(cls):
48 super(FloatingIPTestJSON, cls).skip_checks()
Yoshihiro Kaneko05670262014-01-18 19:22:44 +090049 if not test.is_extension_enabled('router', 'network'):
50 msg = "router extension not enabled."
51 raise cls.skipException(msg)
Rohan Kanadea565e452015-01-27 14:00:13 +053052
53 @classmethod
54 def resource_setup(cls):
55 super(FloatingIPTestJSON, cls).resource_setup()
Matthew Treinish03b48df2014-01-29 16:59:49 +000056 cls.ext_net_id = CONF.network.public_network_id
Nayna Patelf1a29152013-08-09 07:18:13 +000057
58 # Create network, subnet, router and add interface
59 cls.network = cls.create_network()
60 cls.subnet = cls.create_subnet(cls.network)
rossellabc9b4bd2013-11-13 10:21:59 +010061 cls.router = cls.create_router(data_utils.rand_name('router-'),
62 external_network_id=cls.ext_net_id)
63 cls.create_router_interface(cls.router['id'], cls.subnet['id'])
Nayna Patelf1a29152013-08-09 07:18:13 +000064 cls.port = list()
65 # 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
Yoshihiro Kaneko05670262014-01-18 19:22:44 +090069 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -080070 @test.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
David Kranz34e88122014-12-11 15:24:05 -050073 body = self.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']
77 self.addCleanup(self.client.delete_floatingip,
78 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
David Kranz34e88122014-12-11 15:24:05 -050088 floating_ip = self.client.show_floatingip(created_floating_ip['id'])
rossellabc9b4bd2013-11-13 10:21:59 +010089 shown_floating_ip = floating_ip['floatingip']
90 self.assertEqual(shown_floating_ip['id'], created_floating_ip['id'])
91 self.assertEqual(shown_floating_ip['floating_network_id'],
Nayna Patelf1a29152013-08-09 07:18:13 +000092 self.ext_net_id)
rossellabc9b4bd2013-11-13 10:21:59 +010093 self.assertEqual(shown_floating_ip['tenant_id'],
94 created_floating_ip['tenant_id'])
95 self.assertEqual(shown_floating_ip['floating_ip_address'],
96 created_floating_ip['floating_ip_address'])
97 self.assertEqual(shown_floating_ip['port_id'], self.ports[0]['id'])
Nayna Patelf1a29152013-08-09 07:18:13 +000098
99 # Verify the floating ip exists in the list of all floating_ips
David Kranz34e88122014-12-11 15:24:05 -0500100 floating_ips = self.client.list_floatingips()
Nayna Patelf1a29152013-08-09 07:18:13 +0000101 floatingip_id_list = list()
102 for f in floating_ips['floatingips']:
103 floatingip_id_list.append(f['id'])
rossellabc9b4bd2013-11-13 10:21:59 +0100104 self.assertIn(created_floating_ip['id'], floatingip_id_list)
Nayna Patelf1a29152013-08-09 07:18:13 +0000105 # Associate floating IP to the other port
David Kranz34e88122014-12-11 15:24:05 -0500106 floating_ip = self.client.update_floatingip(
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200107 created_floating_ip['id'],
108 port_id=self.ports[1]['id'])
rossellabc9b4bd2013-11-13 10:21:59 +0100109 updated_floating_ip = floating_ip['floatingip']
110 self.assertEqual(updated_floating_ip['port_id'], self.ports[1]['id'])
111 self.assertEqual(updated_floating_ip['fixed_ip_address'],
112 self.ports[1]['fixed_ips'][0]['ip_address'])
113 self.assertEqual(updated_floating_ip['router_id'], self.router['id'])
Nayna Patelf1a29152013-08-09 07:18:13 +0000114
115 # Disassociate floating IP from the port
David Kranz34e88122014-12-11 15:24:05 -0500116 floating_ip = self.client.update_floatingip(
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200117 created_floating_ip['id'],
118 port_id=None)
rossellabc9b4bd2013-11-13 10:21:59 +0100119 updated_floating_ip = floating_ip['floatingip']
120 self.assertIsNone(updated_floating_ip['port_id'])
121 self.assertIsNone(updated_floating_ip['fixed_ip_address'])
122 self.assertIsNone(updated_floating_ip['router_id'])
Attila Fazekasc74aede2013-09-11 13:04:02 +0200123
Chris Hoge7579c1a2015-02-26 14:12:15 -0800124 @test.idempotent_id('e1f6bffd-442f-4668-b30e-df13f2705e77')
rossellab24ec382013-11-13 10:21:59 +0100125 def test_floating_ip_delete_port(self):
126 # Create a floating IP
David Kranz34e88122014-12-11 15:24:05 -0500127 body = self.client.create_floatingip(
Ann Kamyshnikova47a4ff82014-03-17 12:48:57 +0400128 floating_network_id=self.ext_net_id)
Ann Kamyshnikova47a4ff82014-03-17 12:48:57 +0400129 created_floating_ip = body['floatingip']
130 self.addCleanup(self.client.delete_floatingip,
131 created_floating_ip['id'])
rossellab24ec382013-11-13 10:21:59 +0100132 # Create a port
David Kranz34e88122014-12-11 15:24:05 -0500133 port = self.client.create_port(network_id=self.network['id'])
rossellab24ec382013-11-13 10:21:59 +0100134 created_port = port['port']
David Kranz34e88122014-12-11 15:24:05 -0500135 floating_ip = self.client.update_floatingip(
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200136 created_floating_ip['id'],
137 port_id=created_port['id'])
rossellab24ec382013-11-13 10:21:59 +0100138 # Delete port
139 self.client.delete_port(created_port['id'])
140 # Verifies the details of the floating_ip
David Kranz34e88122014-12-11 15:24:05 -0500141 floating_ip = self.client.show_floatingip(created_floating_ip['id'])
rossellab24ec382013-11-13 10:21:59 +0100142 shown_floating_ip = floating_ip['floatingip']
143 # Confirm the fields are back to None
144 self.assertEqual(shown_floating_ip['id'], created_floating_ip['id'])
145 self.assertIsNone(shown_floating_ip['port_id'])
146 self.assertIsNone(shown_floating_ip['fixed_ip_address'])
147 self.assertIsNone(shown_floating_ip['router_id'])
148
Chris Hoge7579c1a2015-02-26 14:12:15 -0800149 @test.idempotent_id('1bb2f731-fe5a-4b8c-8409-799ade1bed4d')
rossellab24ec382013-11-13 10:21:59 +0100150 def test_floating_ip_update_different_router(self):
151 # Associate a floating IP to a port on a router
David Kranz34e88122014-12-11 15:24:05 -0500152 body = self.client.create_floatingip(
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200153 floating_network_id=self.ext_net_id,
154 port_id=self.ports[1]['id'])
Ann Kamyshnikova47a4ff82014-03-17 12:48:57 +0400155 created_floating_ip = body['floatingip']
156 self.addCleanup(self.client.delete_floatingip,
157 created_floating_ip['id'])
rossellab24ec382013-11-13 10:21:59 +0100158 self.assertEqual(created_floating_ip['router_id'], self.router['id'])
159 network2 = self.create_network()
160 subnet2 = self.create_subnet(network2)
161 router2 = self.create_router(data_utils.rand_name('router-'),
162 external_network_id=self.ext_net_id)
163 self.create_router_interface(router2['id'], subnet2['id'])
164 port_other_router = self.create_port(network2)
165 # Associate floating IP to the other port on another router
David Kranz34e88122014-12-11 15:24:05 -0500166 floating_ip = self.client.update_floatingip(
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200167 created_floating_ip['id'],
168 port_id=port_other_router['id'])
rossellab24ec382013-11-13 10:21:59 +0100169 updated_floating_ip = floating_ip['floatingip']
170 self.assertEqual(updated_floating_ip['router_id'], router2['id'])
171 self.assertEqual(updated_floating_ip['port_id'],
172 port_other_router['id'])
173 self.assertIsNotNone(updated_floating_ip['fixed_ip_address'])
174
Ann Kamyshnikova7d2275b2013-12-19 16:38:42 +0400175 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800176 @test.idempotent_id('36de4bd0-f09c-43e3-a8e1-1decc1ffd3a5')
Ann Kamyshnikova7d2275b2013-12-19 16:38:42 +0400177 def test_create_floating_ip_specifying_a_fixed_ip_address(self):
David Kranz34e88122014-12-11 15:24:05 -0500178 body = self.client.create_floatingip(
Ann Kamyshnikova7d2275b2013-12-19 16:38:42 +0400179 floating_network_id=self.ext_net_id,
180 port_id=self.ports[1]['id'],
181 fixed_ip_address=self.ports[1]['fixed_ips'][0]['ip_address'])
Ann Kamyshnikova7d2275b2013-12-19 16:38:42 +0400182 created_floating_ip = body['floatingip']
183 self.addCleanup(self.client.delete_floatingip,
184 created_floating_ip['id'])
185 self.assertIsNotNone(created_floating_ip['id'])
186 self.assertEqual(created_floating_ip['fixed_ip_address'],
187 self.ports[1]['fixed_ips'][0]['ip_address'])
David Kranz34e88122014-12-11 15:24:05 -0500188 floating_ip = self.client.update_floatingip(
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200189 created_floating_ip['id'],
190 port_id=None)
Ann Kamyshnikova7d2275b2013-12-19 16:38:42 +0400191 self.assertIsNone(floating_ip['floatingip']['port_id'])
192
Chris Hoge7579c1a2015-02-26 14:12:15 -0800193 @test.idempotent_id('45c4c683-ea97-41ef-9c51-5e9802f2f3d7')
Ann Kamyshnikovadf102842014-02-05 13:52:57 +0400194 def test_create_update_floatingip_with_port_multiple_ip_address(self):
195 # Find out ips that can be used for tests
196 ips = list(netaddr.IPNetwork(self.subnet['cidr']))
197 list_ips = [str(ip) for ip in ips[-3:-1]]
198 fixed_ips = [{'ip_address': list_ips[0]}, {'ip_address': list_ips[1]}]
199 # Create port
David Kranz34e88122014-12-11 15:24:05 -0500200 body = self.client.create_port(network_id=self.network['id'],
201 fixed_ips=fixed_ips)
Ann Kamyshnikovadf102842014-02-05 13:52:57 +0400202 port = body['port']
203 self.addCleanup(self.client.delete_port, port['id'])
204 # Create floating ip
David Kranz34e88122014-12-11 15:24:05 -0500205 body = self.client.create_floatingip(
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200206 floating_network_id=self.ext_net_id,
207 port_id=port['id'],
Ann Kamyshnikovadf102842014-02-05 13:52:57 +0400208 fixed_ip_address=list_ips[0])
Ann Kamyshnikovadf102842014-02-05 13:52:57 +0400209 floating_ip = body['floatingip']
210 self.addCleanup(self.client.delete_floatingip, floating_ip['id'])
211 self.assertIsNotNone(floating_ip['id'])
212 self.assertEqual(floating_ip['fixed_ip_address'], list_ips[0])
213 # Update floating ip
David Kranz34e88122014-12-11 15:24:05 -0500214 body = self.client.update_floatingip(floating_ip['id'],
215 port_id=port['id'],
216 fixed_ip_address=list_ips[1])
Ann Kamyshnikovadf102842014-02-05 13:52:57 +0400217 update_floating_ip = body['floatingip']
218 self.assertEqual(update_floating_ip['fixed_ip_address'],
219 list_ips[1])