blob: 06871ad0d20531ac1c1fa1ad020c875222f2eef1 [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
Masayuki Igawa259c1132013-10-31 17:48:44 +090017from tempest.common.utils import data_utils
Matthew Treinish03b48df2014-01-29 16:59:49 +000018from tempest import config
Yoshihiro Kaneko05670262014-01-18 19:22:44 +090019from tempest import test
Nayna Patelf1a29152013-08-09 07:18:13 +000020
Matthew Treinish03b48df2014-01-29 16:59:49 +000021CONF = config.CONF
22
Nayna Patelf1a29152013-08-09 07:18:13 +000023
Attila Fazekasc74aede2013-09-11 13:04:02 +020024class FloatingIPTestJSON(base.BaseNetworkTest):
Nayna Patelf1a29152013-08-09 07:18:13 +000025 _interface = 'json'
26
27 """
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
47 def setUpClass(cls):
Attila Fazekasc74aede2013-09-11 13:04:02 +020048 super(FloatingIPTestJSON, cls).setUpClass()
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)
Matthew Treinish03b48df2014-01-29 16:59:49 +000052 cls.ext_net_id = CONF.network.public_network_id
Nayna Patelf1a29152013-08-09 07:18:13 +000053
54 # Create network, subnet, router and add interface
55 cls.network = cls.create_network()
56 cls.subnet = cls.create_subnet(cls.network)
rossellabc9b4bd2013-11-13 10:21:59 +010057 cls.router = cls.create_router(data_utils.rand_name('router-'),
58 external_network_id=cls.ext_net_id)
59 cls.create_router_interface(cls.router['id'], cls.subnet['id'])
Nayna Patelf1a29152013-08-09 07:18:13 +000060 cls.port = list()
61 # Create two ports one each for Creation and Updating of floatingIP
62 for i in range(2):
rossellabc9b4bd2013-11-13 10:21:59 +010063 cls.create_port(cls.network)
Nayna Patelf1a29152013-08-09 07:18:13 +000064
Yoshihiro Kaneko05670262014-01-18 19:22:44 +090065 @test.attr(type='smoke')
Nayna Patelf1a29152013-08-09 07:18:13 +000066 def test_create_list_show_update_delete_floating_ip(self):
67 # Creates a floating IP
Ann Kamyshnikova47a4ff82014-03-17 12:48:57 +040068 resp, body = self.client.create_floatingip(
69 floating_network_id=self.ext_net_id, port_id=self.ports[0]['id'])
70 self.assertEqual('201', resp['status'])
71 created_floating_ip = body['floatingip']
72 self.addCleanup(self.client.delete_floatingip,
73 created_floating_ip['id'])
rossellabc9b4bd2013-11-13 10:21:59 +010074 self.assertIsNotNone(created_floating_ip['id'])
75 self.assertIsNotNone(created_floating_ip['tenant_id'])
76 self.assertIsNotNone(created_floating_ip['floating_ip_address'])
77 self.assertEqual(created_floating_ip['port_id'], self.ports[0]['id'])
78 self.assertEqual(created_floating_ip['floating_network_id'],
Nayna Patelf1a29152013-08-09 07:18:13 +000079 self.ext_net_id)
Nayna Patelf1a29152013-08-09 07:18:13 +000080 # Verifies the details of a floating_ip
Ann Kamyshnikova47a4ff82014-03-17 12:48:57 +040081 resp, floating_ip = self.client.show_floatingip(
rossellabc9b4bd2013-11-13 10:21:59 +010082 created_floating_ip['id'])
Nayna Patelf1a29152013-08-09 07:18:13 +000083 self.assertEqual('200', resp['status'])
rossellabc9b4bd2013-11-13 10:21:59 +010084 shown_floating_ip = floating_ip['floatingip']
85 self.assertEqual(shown_floating_ip['id'], created_floating_ip['id'])
86 self.assertEqual(shown_floating_ip['floating_network_id'],
Nayna Patelf1a29152013-08-09 07:18:13 +000087 self.ext_net_id)
rossellabc9b4bd2013-11-13 10:21:59 +010088 self.assertEqual(shown_floating_ip['tenant_id'],
89 created_floating_ip['tenant_id'])
90 self.assertEqual(shown_floating_ip['floating_ip_address'],
91 created_floating_ip['floating_ip_address'])
92 self.assertEqual(shown_floating_ip['port_id'], self.ports[0]['id'])
Nayna Patelf1a29152013-08-09 07:18:13 +000093
94 # Verify the floating ip exists in the list of all floating_ips
Eugene Nikanorov909ded12013-12-15 17:45:37 +040095 resp, floating_ips = self.client.list_floatingips()
Nayna Patelf1a29152013-08-09 07:18:13 +000096 self.assertEqual('200', resp['status'])
97 floatingip_id_list = list()
98 for f in floating_ips['floatingips']:
99 floatingip_id_list.append(f['id'])
rossellabc9b4bd2013-11-13 10:21:59 +0100100 self.assertIn(created_floating_ip['id'], floatingip_id_list)
Nayna Patelf1a29152013-08-09 07:18:13 +0000101 # Associate floating IP to the other port
Ann Kamyshnikova47a4ff82014-03-17 12:48:57 +0400102 resp, floating_ip = self.client.update_floatingip(
rossellabc9b4bd2013-11-13 10:21:59 +0100103 created_floating_ip['id'], port_id=self.ports[1]['id'])
Nayna Patelf1a29152013-08-09 07:18:13 +0000104 self.assertEqual('200', resp['status'])
rossellabc9b4bd2013-11-13 10:21:59 +0100105 updated_floating_ip = floating_ip['floatingip']
106 self.assertEqual(updated_floating_ip['port_id'], self.ports[1]['id'])
107 self.assertEqual(updated_floating_ip['fixed_ip_address'],
108 self.ports[1]['fixed_ips'][0]['ip_address'])
109 self.assertEqual(updated_floating_ip['router_id'], self.router['id'])
Nayna Patelf1a29152013-08-09 07:18:13 +0000110
111 # Disassociate floating IP from the port
Ann Kamyshnikova47a4ff82014-03-17 12:48:57 +0400112 resp, floating_ip = self.client.update_floatingip(
rossellabc9b4bd2013-11-13 10:21:59 +0100113 created_floating_ip['id'], port_id=None)
Nayna Patelf1a29152013-08-09 07:18:13 +0000114 self.assertEqual('200', resp['status'])
rossellabc9b4bd2013-11-13 10:21:59 +0100115 updated_floating_ip = floating_ip['floatingip']
116 self.assertIsNone(updated_floating_ip['port_id'])
117 self.assertIsNone(updated_floating_ip['fixed_ip_address'])
118 self.assertIsNone(updated_floating_ip['router_id'])
Attila Fazekasc74aede2013-09-11 13:04:02 +0200119
Yoshihiro Kaneko05670262014-01-18 19:22:44 +0900120 @test.attr(type='smoke')
rossellab24ec382013-11-13 10:21:59 +0100121 def test_floating_ip_delete_port(self):
122 # Create a floating IP
Ann Kamyshnikova47a4ff82014-03-17 12:48:57 +0400123 resp, body = self.client.create_floatingip(
124 floating_network_id=self.ext_net_id)
125 self.assertEqual('201', resp['status'])
126 created_floating_ip = body['floatingip']
127 self.addCleanup(self.client.delete_floatingip,
128 created_floating_ip['id'])
rossellab24ec382013-11-13 10:21:59 +0100129 # Create a port
Eugene Nikanorove9d255a2013-12-18 16:31:42 +0400130 resp, port = self.client.create_port(network_id=self.network['id'])
rossellab24ec382013-11-13 10:21:59 +0100131 created_port = port['port']
Ann Kamyshnikova47a4ff82014-03-17 12:48:57 +0400132 resp, floating_ip = self.client.update_floatingip(
rossellab24ec382013-11-13 10:21:59 +0100133 created_floating_ip['id'], port_id=created_port['id'])
134 self.assertEqual('200', resp['status'])
135 # Delete port
136 self.client.delete_port(created_port['id'])
137 # Verifies the details of the floating_ip
Ann Kamyshnikova47a4ff82014-03-17 12:48:57 +0400138 resp, floating_ip = self.client.show_floatingip(
rossellab24ec382013-11-13 10:21:59 +0100139 created_floating_ip['id'])
140 self.assertEqual('200', resp['status'])
141 shown_floating_ip = floating_ip['floatingip']
142 # Confirm the fields are back to None
143 self.assertEqual(shown_floating_ip['id'], created_floating_ip['id'])
144 self.assertIsNone(shown_floating_ip['port_id'])
145 self.assertIsNone(shown_floating_ip['fixed_ip_address'])
146 self.assertIsNone(shown_floating_ip['router_id'])
147
Yoshihiro Kaneko05670262014-01-18 19:22:44 +0900148 @test.attr(type='smoke')
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
Ann Kamyshnikova47a4ff82014-03-17 12:48:57 +0400151 resp, body = self.client.create_floatingip(
152 floating_network_id=self.ext_net_id, port_id=self.ports[1]['id'])
153 self.assertEqual('201', resp['status'])
154 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
Ann Kamyshnikova47a4ff82014-03-17 12:48:57 +0400165 resp, floating_ip = self.client.update_floatingip(
rossellab24ec382013-11-13 10:21:59 +0100166 created_floating_ip['id'], port_id=port_other_router['id'])
167 self.assertEqual('200', resp['status'])
168 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
Attila Fazekasc74aede2013-09-11 13:04:02 +0200174
175class FloatingIPTestXML(FloatingIPTestJSON):
176 _interface = 'xml'