blob: b31c09058bcfc3f8310ba3828287aadc3ca05300 [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
rosselladd68b232013-11-13 10:21:59 +010068 created_floating_ip = self.create_floating_ip(
rossellabc9b4bd2013-11-13 10:21:59 +010069 self.ext_net_id, port_id=self.ports[0]['id'])
rossellabc9b4bd2013-11-13 10:21:59 +010070 self.assertIsNotNone(created_floating_ip['id'])
71 self.assertIsNotNone(created_floating_ip['tenant_id'])
72 self.assertIsNotNone(created_floating_ip['floating_ip_address'])
73 self.assertEqual(created_floating_ip['port_id'], self.ports[0]['id'])
74 self.assertEqual(created_floating_ip['floating_network_id'],
Nayna Patelf1a29152013-08-09 07:18:13 +000075 self.ext_net_id)
Nayna Patelf1a29152013-08-09 07:18:13 +000076 # Verifies the details of a floating_ip
77 resp, floating_ip = self.client.show_floating_ip(
rossellabc9b4bd2013-11-13 10:21:59 +010078 created_floating_ip['id'])
Nayna Patelf1a29152013-08-09 07:18:13 +000079 self.assertEqual('200', resp['status'])
rossellabc9b4bd2013-11-13 10:21:59 +010080 shown_floating_ip = floating_ip['floatingip']
81 self.assertEqual(shown_floating_ip['id'], created_floating_ip['id'])
82 self.assertEqual(shown_floating_ip['floating_network_id'],
Nayna Patelf1a29152013-08-09 07:18:13 +000083 self.ext_net_id)
rossellabc9b4bd2013-11-13 10:21:59 +010084 self.assertEqual(shown_floating_ip['tenant_id'],
85 created_floating_ip['tenant_id'])
86 self.assertEqual(shown_floating_ip['floating_ip_address'],
87 created_floating_ip['floating_ip_address'])
88 self.assertEqual(shown_floating_ip['port_id'], self.ports[0]['id'])
Nayna Patelf1a29152013-08-09 07:18:13 +000089
90 # Verify the floating ip exists in the list of all floating_ips
Eugene Nikanorov909ded12013-12-15 17:45:37 +040091 resp, floating_ips = self.client.list_floatingips()
Nayna Patelf1a29152013-08-09 07:18:13 +000092 self.assertEqual('200', resp['status'])
93 floatingip_id_list = list()
94 for f in floating_ips['floatingips']:
95 floatingip_id_list.append(f['id'])
rossellabc9b4bd2013-11-13 10:21:59 +010096 self.assertIn(created_floating_ip['id'], floatingip_id_list)
Nayna Patelf1a29152013-08-09 07:18:13 +000097 # Associate floating IP to the other port
98 resp, floating_ip = self.client.update_floating_ip(
rossellabc9b4bd2013-11-13 10:21:59 +010099 created_floating_ip['id'], port_id=self.ports[1]['id'])
Nayna Patelf1a29152013-08-09 07:18:13 +0000100 self.assertEqual('200', resp['status'])
rossellabc9b4bd2013-11-13 10:21:59 +0100101 updated_floating_ip = floating_ip['floatingip']
102 self.assertEqual(updated_floating_ip['port_id'], self.ports[1]['id'])
103 self.assertEqual(updated_floating_ip['fixed_ip_address'],
104 self.ports[1]['fixed_ips'][0]['ip_address'])
105 self.assertEqual(updated_floating_ip['router_id'], self.router['id'])
Nayna Patelf1a29152013-08-09 07:18:13 +0000106
107 # Disassociate floating IP from the port
108 resp, floating_ip = self.client.update_floating_ip(
rossellabc9b4bd2013-11-13 10:21:59 +0100109 created_floating_ip['id'], port_id=None)
Nayna Patelf1a29152013-08-09 07:18:13 +0000110 self.assertEqual('200', resp['status'])
rossellabc9b4bd2013-11-13 10:21:59 +0100111 updated_floating_ip = floating_ip['floatingip']
112 self.assertIsNone(updated_floating_ip['port_id'])
113 self.assertIsNone(updated_floating_ip['fixed_ip_address'])
114 self.assertIsNone(updated_floating_ip['router_id'])
Attila Fazekasc74aede2013-09-11 13:04:02 +0200115
Yoshihiro Kaneko05670262014-01-18 19:22:44 +0900116 @test.attr(type='smoke')
rossellab24ec382013-11-13 10:21:59 +0100117 def test_floating_ip_delete_port(self):
118 # Create a floating IP
119 created_floating_ip = self.create_floating_ip(self.ext_net_id)
120 # Create a port
Eugene Nikanorove9d255a2013-12-18 16:31:42 +0400121 resp, port = self.client.create_port(network_id=self.network['id'])
rossellab24ec382013-11-13 10:21:59 +0100122 created_port = port['port']
123 resp, floating_ip = self.client.update_floating_ip(
124 created_floating_ip['id'], port_id=created_port['id'])
125 self.assertEqual('200', resp['status'])
126 # Delete port
127 self.client.delete_port(created_port['id'])
128 # Verifies the details of the floating_ip
129 resp, floating_ip = self.client.show_floating_ip(
130 created_floating_ip['id'])
131 self.assertEqual('200', resp['status'])
132 shown_floating_ip = floating_ip['floatingip']
133 # Confirm the fields are back to None
134 self.assertEqual(shown_floating_ip['id'], created_floating_ip['id'])
135 self.assertIsNone(shown_floating_ip['port_id'])
136 self.assertIsNone(shown_floating_ip['fixed_ip_address'])
137 self.assertIsNone(shown_floating_ip['router_id'])
138
Yoshihiro Kaneko05670262014-01-18 19:22:44 +0900139 @test.attr(type='smoke')
rossellab24ec382013-11-13 10:21:59 +0100140 def test_floating_ip_update_different_router(self):
141 # Associate a floating IP to a port on a router
142 created_floating_ip = self.create_floating_ip(
143 self.ext_net_id, port_id=self.ports[1]['id'])
144 self.assertEqual(created_floating_ip['router_id'], self.router['id'])
145 network2 = self.create_network()
146 subnet2 = self.create_subnet(network2)
147 router2 = self.create_router(data_utils.rand_name('router-'),
148 external_network_id=self.ext_net_id)
149 self.create_router_interface(router2['id'], subnet2['id'])
150 port_other_router = self.create_port(network2)
151 # Associate floating IP to the other port on another router
152 resp, floating_ip = self.client.update_floating_ip(
153 created_floating_ip['id'], port_id=port_other_router['id'])
154 self.assertEqual('200', resp['status'])
155 updated_floating_ip = floating_ip['floatingip']
156 self.assertEqual(updated_floating_ip['router_id'], router2['id'])
157 self.assertEqual(updated_floating_ip['port_id'],
158 port_other_router['id'])
159 self.assertIsNotNone(updated_floating_ip['fixed_ip_address'])
160
Attila Fazekasc74aede2013-09-11 13:04:02 +0200161
162class FloatingIPTestXML(FloatingIPTestJSON):
163 _interface = 'xml'