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 |
Fei Long Wang | d39431f | 2015-05-14 11:30:48 +1200 | [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): |
Ken'ichi Ohmichi | e03bea9 | 2015-11-19 07:45:58 +0000 | [diff] [blame^] | 27 | """Tests the following operations in the Neutron API: |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 28 | |
| 29 | Create a Floating IP |
| 30 | Update a Floating IP |
| 31 | Delete a Floating IP |
| 32 | List all Floating IPs |
| 33 | Show Floating IP details |
rossella | b24ec38 | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 34 | Associate a Floating IP with a port and then delete that port |
| 35 | Associate a Floating IP with a port and then with a port on another |
| 36 | router |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 37 | |
rossella | bc9b4bd | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 38 | 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] | 39 | options are defined in the [network] section of etc/tempest.conf: |
| 40 | |
| 41 | public_network_id which is the id for the external network present |
| 42 | """ |
| 43 | |
| 44 | @classmethod |
Rohan Kanade | a565e45 | 2015-01-27 14:00:13 +0530 | [diff] [blame] | 45 | def skip_checks(cls): |
| 46 | super(FloatingIPTestJSON, cls).skip_checks() |
Yoshihiro Kaneko | 0567026 | 2014-01-18 19:22:44 +0900 | [diff] [blame] | 47 | if not test.is_extension_enabled('router', 'network'): |
| 48 | msg = "router extension not enabled." |
| 49 | raise cls.skipException(msg) |
Rohan Kanade | a565e45 | 2015-01-27 14:00:13 +0530 | [diff] [blame] | 50 | |
| 51 | @classmethod |
| 52 | def resource_setup(cls): |
| 53 | super(FloatingIPTestJSON, cls).resource_setup() |
Matthew Treinish | 03b48df | 2014-01-29 16:59:49 +0000 | [diff] [blame] | 54 | cls.ext_net_id = CONF.network.public_network_id |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 55 | |
| 56 | # Create network, subnet, router and add interface |
| 57 | cls.network = cls.create_network() |
| 58 | cls.subnet = cls.create_subnet(cls.network) |
rossella | bc9b4bd | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 59 | cls.router = cls.create_router(data_utils.rand_name('router-'), |
| 60 | external_network_id=cls.ext_net_id) |
| 61 | cls.create_router_interface(cls.router['id'], cls.subnet['id']) |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 62 | cls.port = list() |
| 63 | # Create two ports one each for Creation and Updating of floatingIP |
| 64 | for i in range(2): |
rossella | bc9b4bd | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 65 | cls.create_port(cls.network) |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 66 | |
Yoshihiro Kaneko | 0567026 | 2014-01-18 19:22:44 +0900 | [diff] [blame] | 67 | @test.attr(type='smoke') |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 68 | @test.idempotent_id('62595970-ab1c-4b7f-8fcc-fddfe55e8718') |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 69 | def test_create_list_show_update_delete_floating_ip(self): |
| 70 | # Creates a floating IP |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 71 | body = self.client.create_floatingip( |
Rohan Kanade | eeb2164 | 2014-08-14 12:00:26 +0200 | [diff] [blame] | 72 | floating_network_id=self.ext_net_id, |
| 73 | port_id=self.ports[0]['id']) |
Ann Kamyshnikova | 47a4ff8 | 2014-03-17 12:48:57 +0400 | [diff] [blame] | 74 | created_floating_ip = body['floatingip'] |
| 75 | self.addCleanup(self.client.delete_floatingip, |
| 76 | created_floating_ip['id']) |
rossella | bc9b4bd | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 77 | 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 Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 82 | self.ext_net_id) |
Ann Kamyshnikova | 7d2275b | 2013-12-19 16:38:42 +0400 | [diff] [blame] | 83 | self.assertIn(created_floating_ip['fixed_ip_address'], |
| 84 | [ip['ip_address'] for ip in self.ports[0]['fixed_ips']]) |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 85 | # Verifies the details of a floating_ip |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 86 | floating_ip = self.client.show_floatingip(created_floating_ip['id']) |
rossella | bc9b4bd | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 87 | 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 Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 90 | self.ext_net_id) |
rossella | bc9b4bd | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 91 | 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 Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 96 | |
| 97 | # Verify the floating ip exists in the list of all floating_ips |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 98 | floating_ips = self.client.list_floatingips() |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 99 | floatingip_id_list = list() |
| 100 | for f in floating_ips['floatingips']: |
| 101 | floatingip_id_list.append(f['id']) |
rossella | bc9b4bd | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 102 | self.assertIn(created_floating_ip['id'], floatingip_id_list) |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 103 | # Associate floating IP to the other port |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 104 | floating_ip = self.client.update_floatingip( |
Rohan Kanade | eeb2164 | 2014-08-14 12:00:26 +0200 | [diff] [blame] | 105 | created_floating_ip['id'], |
| 106 | port_id=self.ports[1]['id']) |
rossella | bc9b4bd | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 107 | 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 Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 112 | |
| 113 | # Disassociate floating IP from the port |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 114 | floating_ip = self.client.update_floatingip( |
Rohan Kanade | eeb2164 | 2014-08-14 12:00:26 +0200 | [diff] [blame] | 115 | created_floating_ip['id'], |
| 116 | port_id=None) |
rossella | bc9b4bd | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 117 | 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 Fazekas | c74aede | 2013-09-11 13:04:02 +0200 | [diff] [blame] | 121 | |
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 |
John Warren | 49c0fe5 | 2015-10-22 12:35:54 -0400 | [diff] [blame] | 131 | port = self.ports_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 |
John Warren | 49c0fe5 | 2015-10-22 12:35:54 -0400 | [diff] [blame] | 137 | self.ports_client.delete_port(created_port['id']) |
rossella | b24ec38 | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 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 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 147 | @test.idempotent_id('1bb2f731-fe5a-4b8c-8409-799ade1bed4d') |
rossella | b24ec38 | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 148 | def test_floating_ip_update_different_router(self): |
| 149 | # Associate a floating IP to a port on a router |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 150 | body = self.client.create_floatingip( |
Rohan Kanade | eeb2164 | 2014-08-14 12:00:26 +0200 | [diff] [blame] | 151 | floating_network_id=self.ext_net_id, |
| 152 | port_id=self.ports[1]['id']) |
Ann Kamyshnikova | 47a4ff8 | 2014-03-17 12:48:57 +0400 | [diff] [blame] | 153 | created_floating_ip = body['floatingip'] |
| 154 | self.addCleanup(self.client.delete_floatingip, |
| 155 | created_floating_ip['id']) |
rossella | b24ec38 | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 156 | 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 |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 164 | floating_ip = self.client.update_floatingip( |
Rohan Kanade | eeb2164 | 2014-08-14 12:00:26 +0200 | [diff] [blame] | 165 | created_floating_ip['id'], |
| 166 | port_id=port_other_router['id']) |
rossella | b24ec38 | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 167 | 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 Kamyshnikova | 7d2275b | 2013-12-19 16:38:42 +0400 | [diff] [blame] | 173 | @test.attr(type='smoke') |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 174 | @test.idempotent_id('36de4bd0-f09c-43e3-a8e1-1decc1ffd3a5') |
Ann Kamyshnikova | 7d2275b | 2013-12-19 16:38:42 +0400 | [diff] [blame] | 175 | def test_create_floating_ip_specifying_a_fixed_ip_address(self): |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 176 | body = self.client.create_floatingip( |
Ann Kamyshnikova | 7d2275b | 2013-12-19 16:38:42 +0400 | [diff] [blame] | 177 | floating_network_id=self.ext_net_id, |
| 178 | port_id=self.ports[1]['id'], |
| 179 | fixed_ip_address=self.ports[1]['fixed_ips'][0]['ip_address']) |
Ann Kamyshnikova | 7d2275b | 2013-12-19 16:38:42 +0400 | [diff] [blame] | 180 | created_floating_ip = body['floatingip'] |
| 181 | self.addCleanup(self.client.delete_floatingip, |
| 182 | created_floating_ip['id']) |
| 183 | self.assertIsNotNone(created_floating_ip['id']) |
| 184 | self.assertEqual(created_floating_ip['fixed_ip_address'], |
| 185 | self.ports[1]['fixed_ips'][0]['ip_address']) |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 186 | floating_ip = self.client.update_floatingip( |
Rohan Kanade | eeb2164 | 2014-08-14 12:00:26 +0200 | [diff] [blame] | 187 | created_floating_ip['id'], |
| 188 | port_id=None) |
Ann Kamyshnikova | 7d2275b | 2013-12-19 16:38:42 +0400 | [diff] [blame] | 189 | self.assertIsNone(floating_ip['floatingip']['port_id']) |
| 190 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 191 | @test.idempotent_id('45c4c683-ea97-41ef-9c51-5e9802f2f3d7') |
Ann Kamyshnikova | df10284 | 2014-02-05 13:52:57 +0400 | [diff] [blame] | 192 | def test_create_update_floatingip_with_port_multiple_ip_address(self): |
| 193 | # Find out ips that can be used for tests |
| 194 | ips = list(netaddr.IPNetwork(self.subnet['cidr'])) |
| 195 | list_ips = [str(ip) for ip in ips[-3:-1]] |
| 196 | fixed_ips = [{'ip_address': list_ips[0]}, {'ip_address': list_ips[1]}] |
| 197 | # Create port |
John Warren | 49c0fe5 | 2015-10-22 12:35:54 -0400 | [diff] [blame] | 198 | body = self.ports_client.create_port(network_id=self.network['id'], |
| 199 | fixed_ips=fixed_ips) |
Ann Kamyshnikova | df10284 | 2014-02-05 13:52:57 +0400 | [diff] [blame] | 200 | port = body['port'] |
John Warren | 49c0fe5 | 2015-10-22 12:35:54 -0400 | [diff] [blame] | 201 | self.addCleanup(self.ports_client.delete_port, port['id']) |
Ann Kamyshnikova | df10284 | 2014-02-05 13:52:57 +0400 | [diff] [blame] | 202 | # Create floating ip |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 203 | body = self.client.create_floatingip( |
Rohan Kanade | eeb2164 | 2014-08-14 12:00:26 +0200 | [diff] [blame] | 204 | floating_network_id=self.ext_net_id, |
| 205 | port_id=port['id'], |
Ann Kamyshnikova | df10284 | 2014-02-05 13:52:57 +0400 | [diff] [blame] | 206 | fixed_ip_address=list_ips[0]) |
Ann Kamyshnikova | df10284 | 2014-02-05 13:52:57 +0400 | [diff] [blame] | 207 | floating_ip = body['floatingip'] |
| 208 | self.addCleanup(self.client.delete_floatingip, floating_ip['id']) |
| 209 | self.assertIsNotNone(floating_ip['id']) |
| 210 | self.assertEqual(floating_ip['fixed_ip_address'], list_ips[0]) |
| 211 | # Update floating ip |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 212 | body = self.client.update_floatingip(floating_ip['id'], |
| 213 | port_id=port['id'], |
| 214 | fixed_ip_address=list_ips[1]) |
Ann Kamyshnikova | df10284 | 2014-02-05 13:52:57 +0400 | [diff] [blame] | 215 | update_floating_ip = body['floatingip'] |
| 216 | self.assertEqual(update_floating_ip['fixed_ip_address'], |
| 217 | list_ips[1]) |