blob: 8b42a9eb5b6a57f4607db361d7a6b5634d03ca16 [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 _interface = 'json'
28
29 """
30 Tests the following operations in the Quantum API using the REST client for
rossellabc9b4bd2013-11-13 10:21:59 +010031 Neutron:
Nayna Patelf1a29152013-08-09 07:18:13 +000032
33 Create a Floating IP
34 Update a Floating IP
35 Delete a Floating IP
36 List all Floating IPs
37 Show Floating IP details
rossellab24ec382013-11-13 10:21:59 +010038 Associate a Floating IP with a port and then delete that port
39 Associate a Floating IP with a port and then with a port on another
40 router
Nayna Patelf1a29152013-08-09 07:18:13 +000041
rossellabc9b4bd2013-11-13 10:21:59 +010042 v2.0 of the Neutron API is assumed. It is also assumed that the following
Nayna Patelf1a29152013-08-09 07:18:13 +000043 options are defined in the [network] section of etc/tempest.conf:
44
45 public_network_id which is the id for the external network present
46 """
47
48 @classmethod
Masayuki Igawa6d495d62014-03-19 16:38:57 +090049 @test.safe_setup
Nayna Patelf1a29152013-08-09 07:18:13 +000050 def setUpClass(cls):
Attila Fazekasc74aede2013-09-11 13:04:02 +020051 super(FloatingIPTestJSON, cls).setUpClass()
Yoshihiro Kaneko05670262014-01-18 19:22:44 +090052 if not test.is_extension_enabled('router', 'network'):
53 msg = "router extension not enabled."
54 raise cls.skipException(msg)
Matthew Treinish03b48df2014-01-29 16:59:49 +000055 cls.ext_net_id = CONF.network.public_network_id
Nayna Patelf1a29152013-08-09 07:18:13 +000056
57 # Create network, subnet, router and add interface
58 cls.network = cls.create_network()
59 cls.subnet = cls.create_subnet(cls.network)
rossellabc9b4bd2013-11-13 10:21:59 +010060 cls.router = cls.create_router(data_utils.rand_name('router-'),
61 external_network_id=cls.ext_net_id)
62 cls.create_router_interface(cls.router['id'], cls.subnet['id'])
Nayna Patelf1a29152013-08-09 07:18:13 +000063 cls.port = list()
64 # Create two ports one each for Creation and Updating of floatingIP
65 for i in range(2):
rossellabc9b4bd2013-11-13 10:21:59 +010066 cls.create_port(cls.network)
Nayna Patelf1a29152013-08-09 07:18:13 +000067
Yoshihiro Kaneko05670262014-01-18 19:22:44 +090068 @test.attr(type='smoke')
Nayna Patelf1a29152013-08-09 07:18:13 +000069 def test_create_list_show_update_delete_floating_ip(self):
70 # Creates a floating IP
Rohan Kanadeeeb21642014-08-14 12:00:26 +020071 _, body = self.client.create_floatingip(
72 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
Rohan Kanadeeeb21642014-08-14 12:00:26 +020086 _, 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
Rohan Kanadeeeb21642014-08-14 12:00:26 +020098 _, 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
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200104 _, floating_ip = self.client.update_floatingip(
105 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
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200114 _, floating_ip = self.client.update_floatingip(
115 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
Yoshihiro Kaneko05670262014-01-18 19:22:44 +0900122 @test.attr(type='smoke')
rossellab24ec382013-11-13 10:21:59 +0100123 def test_floating_ip_delete_port(self):
124 # Create a floating IP
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200125 _, 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
Eugene Nikanorove9d255a2013-12-18 16:31:42 +0400131 resp, port = self.client.create_port(network_id=self.network['id'])
rossellab24ec382013-11-13 10:21:59 +0100132 created_port = port['port']
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200133 _, floating_ip = self.client.update_floatingip(
134 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
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200139 _, 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')
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
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200150 _, body = self.client.create_floatingip(
151 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
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200164 _, floating_ip = self.client.update_floatingip(
165 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')
174 def test_create_floating_ip_specifying_a_fixed_ip_address(self):
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200175 _, body = self.client.create_floatingip(
Ann Kamyshnikova7d2275b2013-12-19 16:38:42 +0400176 floating_network_id=self.ext_net_id,
177 port_id=self.ports[1]['id'],
178 fixed_ip_address=self.ports[1]['fixed_ips'][0]['ip_address'])
Ann Kamyshnikova7d2275b2013-12-19 16:38:42 +0400179 created_floating_ip = body['floatingip']
180 self.addCleanup(self.client.delete_floatingip,
181 created_floating_ip['id'])
182 self.assertIsNotNone(created_floating_ip['id'])
183 self.assertEqual(created_floating_ip['fixed_ip_address'],
184 self.ports[1]['fixed_ips'][0]['ip_address'])
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200185 _, floating_ip = self.client.update_floatingip(
186 created_floating_ip['id'],
187 port_id=None)
Ann Kamyshnikova7d2275b2013-12-19 16:38:42 +0400188 self.assertIsNone(floating_ip['floatingip']['port_id'])
189
Ann Kamyshnikovadf102842014-02-05 13:52:57 +0400190 @test.attr(type='smoke')
191 def test_create_update_floatingip_with_port_multiple_ip_address(self):
192 # Find out ips that can be used for tests
193 ips = list(netaddr.IPNetwork(self.subnet['cidr']))
194 list_ips = [str(ip) for ip in ips[-3:-1]]
195 fixed_ips = [{'ip_address': list_ips[0]}, {'ip_address': list_ips[1]}]
196 # Create port
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200197 _, body = self.client.create_port(network_id=self.network['id'],
198 fixed_ips=fixed_ips)
Ann Kamyshnikovadf102842014-02-05 13:52:57 +0400199 port = body['port']
200 self.addCleanup(self.client.delete_port, port['id'])
201 # Create floating ip
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200202 _, body = self.client.create_floatingip(
203 floating_network_id=self.ext_net_id,
204 port_id=port['id'],
Ann Kamyshnikovadf102842014-02-05 13:52:57 +0400205 fixed_ip_address=list_ips[0])
Ann Kamyshnikovadf102842014-02-05 13:52:57 +0400206 floating_ip = body['floatingip']
207 self.addCleanup(self.client.delete_floatingip, floating_ip['id'])
208 self.assertIsNotNone(floating_ip['id'])
209 self.assertEqual(floating_ip['fixed_ip_address'], list_ips[0])
210 # Update floating ip
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200211 _, body = self.client.update_floatingip(floating_ip['id'],
212 port_id=port['id'],
213 fixed_ip_address=list_ips[1])
Ann Kamyshnikovadf102842014-02-05 13:52:57 +0400214 update_floating_ip = body['floatingip']
215 self.assertEqual(update_floating_ip['fixed_ip_address'],
216 list_ips[1])
217
Attila Fazekasc74aede2013-09-11 13:04:02 +0200218
219class FloatingIPTestXML(FloatingIPTestJSON):
220 _interface = 'xml'