Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 1 | # 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 Kamyshnikova | df10284 | 2014-02-05 13:52:57 +0400 | [diff] [blame] | 16 | import netaddr |
| 17 | |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 18 | from tempest.api.network import base |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 19 | from tempest.common.utils import data_utils |
Matthew Treinish | 03b48df | 2014-01-29 16:59:49 +0000 | [diff] [blame] | 20 | from tempest import config |
Yoshihiro Kaneko | 0567026 | 2014-01-18 19:22:44 +0900 | [diff] [blame] | 21 | from tempest import test |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 22 | |
Matthew Treinish | 03b48df | 2014-01-29 16:59:49 +0000 | [diff] [blame] | 23 | CONF = config.CONF |
| 24 | |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 25 | |
Attila Fazekas | c74aede | 2013-09-11 13:04:02 +0200 | [diff] [blame] | 26 | class FloatingIPTestJSON(base.BaseNetworkTest): |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 27 | |
| 28 | """ |
| 29 | Tests the following operations in the Quantum API using the REST client for |
rossella | bc9b4bd | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 30 | Neutron: |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 31 | |
| 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 |
rossella | b24ec38 | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 37 | 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 Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 40 | |
rossella | bc9b4bd | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 41 | v2.0 of the Neutron API is assumed. It is also assumed that the following |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 42 | 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 Frittoli | da4a245 | 2014-09-15 13:12:08 +0100 | [diff] [blame] | 48 | def resource_setup(cls): |
| 49 | super(FloatingIPTestJSON, cls).resource_setup() |
Yoshihiro Kaneko | 0567026 | 2014-01-18 19:22:44 +0900 | [diff] [blame] | 50 | if not test.is_extension_enabled('router', 'network'): |
| 51 | msg = "router extension not enabled." |
| 52 | raise cls.skipException(msg) |
Matthew Treinish | 03b48df | 2014-01-29 16:59:49 +0000 | [diff] [blame] | 53 | cls.ext_net_id = CONF.network.public_network_id |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 54 | |
| 55 | # Create network, subnet, router and add interface |
| 56 | cls.network = cls.create_network() |
| 57 | cls.subnet = cls.create_subnet(cls.network) |
rossella | bc9b4bd | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 58 | 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 Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 61 | cls.port = list() |
| 62 | # Create two ports one each for Creation and Updating of floatingIP |
| 63 | for i in range(2): |
rossella | bc9b4bd | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 64 | cls.create_port(cls.network) |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 65 | |
Yoshihiro Kaneko | 0567026 | 2014-01-18 19:22:44 +0900 | [diff] [blame] | 66 | @test.attr(type='smoke') |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 67 | @test.idempotent_id('62595970-ab1c-4b7f-8fcc-fddfe55e8718') |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 68 | def test_create_list_show_update_delete_floating_ip(self): |
| 69 | # Creates a floating IP |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 70 | body = self.client.create_floatingip( |
Rohan Kanade | eeb2164 | 2014-08-14 12:00:26 +0200 | [diff] [blame] | 71 | floating_network_id=self.ext_net_id, |
| 72 | port_id=self.ports[0]['id']) |
Ann Kamyshnikova | 47a4ff8 | 2014-03-17 12:48:57 +0400 | [diff] [blame] | 73 | created_floating_ip = body['floatingip'] |
| 74 | self.addCleanup(self.client.delete_floatingip, |
| 75 | created_floating_ip['id']) |
rossella | bc9b4bd | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 76 | 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 Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 81 | self.ext_net_id) |
Ann Kamyshnikova | 7d2275b | 2013-12-19 16:38:42 +0400 | [diff] [blame] | 82 | self.assertIn(created_floating_ip['fixed_ip_address'], |
| 83 | [ip['ip_address'] for ip in self.ports[0]['fixed_ips']]) |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 84 | # Verifies the details of a floating_ip |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 85 | floating_ip = self.client.show_floatingip(created_floating_ip['id']) |
rossella | bc9b4bd | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 86 | 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 Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 89 | self.ext_net_id) |
rossella | bc9b4bd | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 90 | 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 Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 95 | |
| 96 | # Verify the floating ip exists in the list of all floating_ips |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 97 | floating_ips = self.client.list_floatingips() |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 98 | floatingip_id_list = list() |
| 99 | for f in floating_ips['floatingips']: |
| 100 | floatingip_id_list.append(f['id']) |
rossella | bc9b4bd | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 101 | self.assertIn(created_floating_ip['id'], floatingip_id_list) |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 102 | # Associate floating IP to the other port |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 103 | floating_ip = self.client.update_floatingip( |
Rohan Kanade | eeb2164 | 2014-08-14 12:00:26 +0200 | [diff] [blame] | 104 | created_floating_ip['id'], |
| 105 | port_id=self.ports[1]['id']) |
rossella | bc9b4bd | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 106 | 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 Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 111 | |
| 112 | # Disassociate floating IP from the port |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 113 | floating_ip = self.client.update_floatingip( |
Rohan Kanade | eeb2164 | 2014-08-14 12:00:26 +0200 | [diff] [blame] | 114 | created_floating_ip['id'], |
| 115 | port_id=None) |
rossella | bc9b4bd | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 116 | 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 Fazekas | c74aede | 2013-09-11 13:04:02 +0200 | [diff] [blame] | 120 | |
Yoshihiro Kaneko | 0567026 | 2014-01-18 19:22:44 +0900 | [diff] [blame] | 121 | @test.attr(type='smoke') |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 122 | @test.idempotent_id('e1f6bffd-442f-4668-b30e-df13f2705e77') |
rossella | b24ec38 | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 123 | def test_floating_ip_delete_port(self): |
| 124 | # Create a floating IP |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 125 | body = self.client.create_floatingip( |
Ann Kamyshnikova | 47a4ff8 | 2014-03-17 12:48:57 +0400 | [diff] [blame] | 126 | floating_network_id=self.ext_net_id) |
Ann Kamyshnikova | 47a4ff8 | 2014-03-17 12:48:57 +0400 | [diff] [blame] | 127 | created_floating_ip = body['floatingip'] |
| 128 | self.addCleanup(self.client.delete_floatingip, |
| 129 | created_floating_ip['id']) |
rossella | b24ec38 | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 130 | # Create a port |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 131 | port = self.client.create_port(network_id=self.network['id']) |
rossella | b24ec38 | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 132 | created_port = port['port'] |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 133 | floating_ip = self.client.update_floatingip( |
Rohan Kanade | eeb2164 | 2014-08-14 12:00:26 +0200 | [diff] [blame] | 134 | created_floating_ip['id'], |
| 135 | port_id=created_port['id']) |
rossella | b24ec38 | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 136 | # Delete port |
| 137 | self.client.delete_port(created_port['id']) |
| 138 | # Verifies the details of the floating_ip |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 139 | floating_ip = self.client.show_floatingip(created_floating_ip['id']) |
rossella | b24ec38 | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 140 | 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 Kaneko | 0567026 | 2014-01-18 19:22:44 +0900 | [diff] [blame] | 147 | @test.attr(type='smoke') |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 148 | @test.idempotent_id('1bb2f731-fe5a-4b8c-8409-799ade1bed4d') |
rossella | b24ec38 | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 149 | def test_floating_ip_update_different_router(self): |
| 150 | # Associate a floating IP to a port on a router |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 151 | body = self.client.create_floatingip( |
Rohan Kanade | eeb2164 | 2014-08-14 12:00:26 +0200 | [diff] [blame] | 152 | floating_network_id=self.ext_net_id, |
| 153 | port_id=self.ports[1]['id']) |
Ann Kamyshnikova | 47a4ff8 | 2014-03-17 12:48:57 +0400 | [diff] [blame] | 154 | created_floating_ip = body['floatingip'] |
| 155 | self.addCleanup(self.client.delete_floatingip, |
| 156 | created_floating_ip['id']) |
rossella | b24ec38 | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 157 | 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 Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 165 | floating_ip = self.client.update_floatingip( |
Rohan Kanade | eeb2164 | 2014-08-14 12:00:26 +0200 | [diff] [blame] | 166 | created_floating_ip['id'], |
| 167 | port_id=port_other_router['id']) |
rossella | b24ec38 | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 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 | |
Ann Kamyshnikova | 7d2275b | 2013-12-19 16:38:42 +0400 | [diff] [blame] | 174 | @test.attr(type='smoke') |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 175 | @test.idempotent_id('36de4bd0-f09c-43e3-a8e1-1decc1ffd3a5') |
Ann Kamyshnikova | 7d2275b | 2013-12-19 16:38:42 +0400 | [diff] [blame] | 176 | def test_create_floating_ip_specifying_a_fixed_ip_address(self): |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 177 | body = self.client.create_floatingip( |
Ann Kamyshnikova | 7d2275b | 2013-12-19 16:38:42 +0400 | [diff] [blame] | 178 | 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 Kamyshnikova | 7d2275b | 2013-12-19 16:38:42 +0400 | [diff] [blame] | 181 | 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 Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 187 | floating_ip = self.client.update_floatingip( |
Rohan Kanade | eeb2164 | 2014-08-14 12:00:26 +0200 | [diff] [blame] | 188 | created_floating_ip['id'], |
| 189 | port_id=None) |
Ann Kamyshnikova | 7d2275b | 2013-12-19 16:38:42 +0400 | [diff] [blame] | 190 | self.assertIsNone(floating_ip['floatingip']['port_id']) |
| 191 | |
Ann Kamyshnikova | df10284 | 2014-02-05 13:52:57 +0400 | [diff] [blame] | 192 | @test.attr(type='smoke') |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 193 | @test.idempotent_id('45c4c683-ea97-41ef-9c51-5e9802f2f3d7') |
Ann Kamyshnikova | df10284 | 2014-02-05 13:52:57 +0400 | [diff] [blame] | 194 | 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 Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 200 | body = self.client.create_port(network_id=self.network['id'], |
| 201 | fixed_ips=fixed_ips) |
Ann Kamyshnikova | df10284 | 2014-02-05 13:52:57 +0400 | [diff] [blame] | 202 | port = body['port'] |
| 203 | self.addCleanup(self.client.delete_port, port['id']) |
| 204 | # Create floating ip |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 205 | body = self.client.create_floatingip( |
Rohan Kanade | eeb2164 | 2014-08-14 12:00:26 +0200 | [diff] [blame] | 206 | floating_network_id=self.ext_net_id, |
| 207 | port_id=port['id'], |
Ann Kamyshnikova | df10284 | 2014-02-05 13:52:57 +0400 | [diff] [blame] | 208 | fixed_ip_address=list_ips[0]) |
Ann Kamyshnikova | df10284 | 2014-02-05 13:52:57 +0400 | [diff] [blame] | 209 | 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 Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 214 | body = self.client.update_floatingip(floating_ip['id'], |
| 215 | port_id=port['id'], |
| 216 | fixed_ip_address=list_ips[1]) |
Ann Kamyshnikova | df10284 | 2014-02-05 13:52:57 +0400 | [diff] [blame] | 217 | update_floating_ip = body['floatingip'] |
| 218 | self.assertEqual(update_floating_ip['fixed_ip_address'], |
| 219 | list_ips[1]) |