blob: cc88852703465d230449f8398da536f99c246a76 [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
Masayuki Igawa259c1132013-10-31 17:48:44 +090019from 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 """
29 Tests the following operations in the Quantum API using the REST client for
rossellabc9b4bd2013-11-13 10:21:59 +010030 Neutron:
Nayna Patelf1a29152013-08-09 07:18:13 +000031
32 Create a Floating IP
33 Update a Floating IP
34 Delete a Floating IP
35 List all Floating IPs
36 Show Floating IP details
rossellab24ec382013-11-13 10:21:59 +010037 Associate a Floating IP with a port and then delete that port
38 Associate a Floating IP with a port and then with a port on another
39 router
Nayna Patelf1a29152013-08-09 07:18:13 +000040
rossellabc9b4bd2013-11-13 10:21:59 +010041 v2.0 of the Neutron API is assumed. It is also assumed that the following
Nayna Patelf1a29152013-08-09 07:18:13 +000042 options are defined in the [network] section of etc/tempest.conf:
43
44 public_network_id which is the id for the external network present
45 """
46
47 @classmethod
Andrea Frittolida4a2452014-09-15 13:12:08 +010048 def resource_setup(cls):
49 super(FloatingIPTestJSON, cls).resource_setup()
Yoshihiro Kaneko05670262014-01-18 19:22:44 +090050 if not test.is_extension_enabled('router', 'network'):
51 msg = "router extension not enabled."
52 raise cls.skipException(msg)
Matthew Treinish03b48df2014-01-29 16:59:49 +000053 cls.ext_net_id = CONF.network.public_network_id
Nayna Patelf1a29152013-08-09 07:18:13 +000054
55 # Create network, subnet, router and add interface
56 cls.network = cls.create_network()
57 cls.subnet = cls.create_subnet(cls.network)
rossellabc9b4bd2013-11-13 10:21:59 +010058 cls.router = cls.create_router(data_utils.rand_name('router-'),
59 external_network_id=cls.ext_net_id)
60 cls.create_router_interface(cls.router['id'], cls.subnet['id'])
Nayna Patelf1a29152013-08-09 07:18:13 +000061 cls.port = list()
62 # Create two ports one each for Creation and Updating of floatingIP
63 for i in range(2):
rossellabc9b4bd2013-11-13 10:21:59 +010064 cls.create_port(cls.network)
Nayna Patelf1a29152013-08-09 07:18:13 +000065
Yoshihiro Kaneko05670262014-01-18 19:22:44 +090066 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -080067 @test.idempotent_id('62595970-ab1c-4b7f-8fcc-fddfe55e8718')
Nayna Patelf1a29152013-08-09 07:18:13 +000068 def test_create_list_show_update_delete_floating_ip(self):
69 # Creates a floating IP
David Kranz34e88122014-12-11 15:24:05 -050070 body = self.client.create_floatingip(
Rohan Kanadeeeb21642014-08-14 12:00:26 +020071 floating_network_id=self.ext_net_id,
72 port_id=self.ports[0]['id'])
Ann Kamyshnikova47a4ff82014-03-17 12:48:57 +040073 created_floating_ip = body['floatingip']
74 self.addCleanup(self.client.delete_floatingip,
75 created_floating_ip['id'])
rossellabc9b4bd2013-11-13 10:21:59 +010076 self.assertIsNotNone(created_floating_ip['id'])
77 self.assertIsNotNone(created_floating_ip['tenant_id'])
78 self.assertIsNotNone(created_floating_ip['floating_ip_address'])
79 self.assertEqual(created_floating_ip['port_id'], self.ports[0]['id'])
80 self.assertEqual(created_floating_ip['floating_network_id'],
Nayna Patelf1a29152013-08-09 07:18:13 +000081 self.ext_net_id)
Ann Kamyshnikova7d2275b2013-12-19 16:38:42 +040082 self.assertIn(created_floating_ip['fixed_ip_address'],
83 [ip['ip_address'] for ip in self.ports[0]['fixed_ips']])
Nayna Patelf1a29152013-08-09 07:18:13 +000084 # Verifies the details of a floating_ip
David Kranz34e88122014-12-11 15:24:05 -050085 floating_ip = self.client.show_floatingip(created_floating_ip['id'])
rossellabc9b4bd2013-11-13 10:21:59 +010086 shown_floating_ip = floating_ip['floatingip']
87 self.assertEqual(shown_floating_ip['id'], created_floating_ip['id'])
88 self.assertEqual(shown_floating_ip['floating_network_id'],
Nayna Patelf1a29152013-08-09 07:18:13 +000089 self.ext_net_id)
rossellabc9b4bd2013-11-13 10:21:59 +010090 self.assertEqual(shown_floating_ip['tenant_id'],
91 created_floating_ip['tenant_id'])
92 self.assertEqual(shown_floating_ip['floating_ip_address'],
93 created_floating_ip['floating_ip_address'])
94 self.assertEqual(shown_floating_ip['port_id'], self.ports[0]['id'])
Nayna Patelf1a29152013-08-09 07:18:13 +000095
96 # Verify the floating ip exists in the list of all floating_ips
David Kranz34e88122014-12-11 15:24:05 -050097 floating_ips = self.client.list_floatingips()
Nayna Patelf1a29152013-08-09 07:18:13 +000098 floatingip_id_list = list()
99 for f in floating_ips['floatingips']:
100 floatingip_id_list.append(f['id'])
rossellabc9b4bd2013-11-13 10:21:59 +0100101 self.assertIn(created_floating_ip['id'], floatingip_id_list)
Nayna Patelf1a29152013-08-09 07:18:13 +0000102 # Associate floating IP to the other port
David Kranz34e88122014-12-11 15:24:05 -0500103 floating_ip = self.client.update_floatingip(
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200104 created_floating_ip['id'],
105 port_id=self.ports[1]['id'])
rossellabc9b4bd2013-11-13 10:21:59 +0100106 updated_floating_ip = floating_ip['floatingip']
107 self.assertEqual(updated_floating_ip['port_id'], self.ports[1]['id'])
108 self.assertEqual(updated_floating_ip['fixed_ip_address'],
109 self.ports[1]['fixed_ips'][0]['ip_address'])
110 self.assertEqual(updated_floating_ip['router_id'], self.router['id'])
Nayna Patelf1a29152013-08-09 07:18:13 +0000111
112 # Disassociate floating IP from the port
David Kranz34e88122014-12-11 15:24:05 -0500113 floating_ip = self.client.update_floatingip(
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200114 created_floating_ip['id'],
115 port_id=None)
rossellabc9b4bd2013-11-13 10:21:59 +0100116 updated_floating_ip = floating_ip['floatingip']
117 self.assertIsNone(updated_floating_ip['port_id'])
118 self.assertIsNone(updated_floating_ip['fixed_ip_address'])
119 self.assertIsNone(updated_floating_ip['router_id'])
Attila Fazekasc74aede2013-09-11 13:04:02 +0200120
Yoshihiro Kaneko05670262014-01-18 19:22:44 +0900121 @test.attr(type='smoke')
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
David Kranz34e88122014-12-11 15:24:05 -0500131 port = self.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
137 self.client.delete_port(created_port['id'])
138 # 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
Yoshihiro Kaneko05670262014-01-18 19:22:44 +0900147 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800148 @test.idempotent_id('1bb2f731-fe5a-4b8c-8409-799ade1bed4d')
rossellab24ec382013-11-13 10:21:59 +0100149 def test_floating_ip_update_different_router(self):
150 # Associate a floating IP to a port on a router
David Kranz34e88122014-12-11 15:24:05 -0500151 body = self.client.create_floatingip(
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200152 floating_network_id=self.ext_net_id,
153 port_id=self.ports[1]['id'])
Ann Kamyshnikova47a4ff82014-03-17 12:48:57 +0400154 created_floating_ip = body['floatingip']
155 self.addCleanup(self.client.delete_floatingip,
156 created_floating_ip['id'])
rossellab24ec382013-11-13 10:21:59 +0100157 self.assertEqual(created_floating_ip['router_id'], self.router['id'])
158 network2 = self.create_network()
159 subnet2 = self.create_subnet(network2)
160 router2 = self.create_router(data_utils.rand_name('router-'),
161 external_network_id=self.ext_net_id)
162 self.create_router_interface(router2['id'], subnet2['id'])
163 port_other_router = self.create_port(network2)
164 # Associate floating IP to the other port on another router
David Kranz34e88122014-12-11 15:24:05 -0500165 floating_ip = self.client.update_floatingip(
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200166 created_floating_ip['id'],
167 port_id=port_other_router['id'])
rossellab24ec382013-11-13 10:21:59 +0100168 updated_floating_ip = floating_ip['floatingip']
169 self.assertEqual(updated_floating_ip['router_id'], router2['id'])
170 self.assertEqual(updated_floating_ip['port_id'],
171 port_other_router['id'])
172 self.assertIsNotNone(updated_floating_ip['fixed_ip_address'])
173
Ann Kamyshnikova7d2275b2013-12-19 16:38:42 +0400174 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800175 @test.idempotent_id('36de4bd0-f09c-43e3-a8e1-1decc1ffd3a5')
Ann Kamyshnikova7d2275b2013-12-19 16:38:42 +0400176 def test_create_floating_ip_specifying_a_fixed_ip_address(self):
David Kranz34e88122014-12-11 15:24:05 -0500177 body = self.client.create_floatingip(
Ann Kamyshnikova7d2275b2013-12-19 16:38:42 +0400178 floating_network_id=self.ext_net_id,
179 port_id=self.ports[1]['id'],
180 fixed_ip_address=self.ports[1]['fixed_ips'][0]['ip_address'])
Ann Kamyshnikova7d2275b2013-12-19 16:38:42 +0400181 created_floating_ip = body['floatingip']
182 self.addCleanup(self.client.delete_floatingip,
183 created_floating_ip['id'])
184 self.assertIsNotNone(created_floating_ip['id'])
185 self.assertEqual(created_floating_ip['fixed_ip_address'],
186 self.ports[1]['fixed_ips'][0]['ip_address'])
David Kranz34e88122014-12-11 15:24:05 -0500187 floating_ip = self.client.update_floatingip(
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200188 created_floating_ip['id'],
189 port_id=None)
Ann Kamyshnikova7d2275b2013-12-19 16:38:42 +0400190 self.assertIsNone(floating_ip['floatingip']['port_id'])
191
Ann Kamyshnikovadf102842014-02-05 13:52:57 +0400192 @test.attr(type='smoke')
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])