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 | |
| 16 | from tempest.api.network import base |
Andrea Frittoli | cd36841 | 2017-08-14 21:37:56 +0100 | [diff] [blame] | 17 | from tempest.common import utils |
Ryan Tidwell | 1964a26 | 2016-05-04 15:13:23 -0700 | [diff] [blame] | 18 | from tempest.common.utils import net_utils |
Matthew Treinish | 03b48df | 2014-01-29 16:59:49 +0000 | [diff] [blame] | 19 | from tempest import config |
Ghanshyam Mann | ef0e291 | 2020-12-29 15:22:33 -0600 | [diff] [blame] | 20 | from tempest.lib.common.utils import data_utils |
Slawek Kaplonski | 748dd8d | 2019-04-16 23:38:35 +0200 | [diff] [blame] | 21 | from tempest.lib.common.utils import test_utils |
Ken'ichi Ohmichi | 53b9a63 | 2017-01-27 18:04:39 -0800 | [diff] [blame] | 22 | from tempest.lib import decorators |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 23 | |
Matthew Treinish | 03b48df | 2014-01-29 16:59:49 +0000 | [diff] [blame] | 24 | CONF = config.CONF |
| 25 | |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 26 | |
Attila Fazekas | c74aede | 2013-09-11 13:04:02 +0200 | [diff] [blame] | 27 | class FloatingIPTestJSON(base.BaseNetworkTest): |
Ken'ichi Ohmichi | e03bea9 | 2015-11-19 07:45:58 +0000 | [diff] [blame] | 28 | """Tests the following operations in the Neutron API: |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 29 | |
| 30 | Create a Floating IP |
| 31 | Update a Floating IP |
| 32 | Delete a Floating IP |
| 33 | List all Floating IPs |
| 34 | Show Floating IP details |
rossella | b24ec38 | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 35 | Associate a Floating IP with a port and then delete that port |
| 36 | Associate a Floating IP with a port and then with a port on another |
| 37 | router |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 38 | |
rossella | bc9b4bd | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 39 | 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] | 40 | options are defined in the [network] section of etc/tempest.conf: |
| 41 | |
| 42 | public_network_id which is the id for the external network present |
| 43 | """ |
| 44 | |
| 45 | @classmethod |
Rohan Kanade | a565e45 | 2015-01-27 14:00:13 +0530 | [diff] [blame] | 46 | def skip_checks(cls): |
| 47 | super(FloatingIPTestJSON, cls).skip_checks() |
Andrea Frittoli | cd36841 | 2017-08-14 21:37:56 +0100 | [diff] [blame] | 48 | if not utils.is_extension_enabled('router', 'network'): |
Yoshihiro Kaneko | 0567026 | 2014-01-18 19:22:44 +0900 | [diff] [blame] | 49 | msg = "router extension not enabled." |
| 50 | raise cls.skipException(msg) |
zhufl | 6b7040a | 2017-01-18 16:38:34 +0800 | [diff] [blame] | 51 | if not CONF.network.public_network_id: |
| 52 | msg = "The public_network_id option must be specified." |
| 53 | raise cls.skipException(msg) |
Matthew Treinish | 3312de3 | 2017-05-19 12:08:17 -0400 | [diff] [blame] | 54 | if not CONF.network_feature_enabled.floating_ips: |
| 55 | raise cls.skipException("Floating ips are not available") |
Rohan Kanade | a565e45 | 2015-01-27 14:00:13 +0530 | [diff] [blame] | 56 | |
| 57 | @classmethod |
| 58 | def resource_setup(cls): |
| 59 | super(FloatingIPTestJSON, cls).resource_setup() |
Matthew Treinish | 03b48df | 2014-01-29 16:59:49 +0000 | [diff] [blame] | 60 | cls.ext_net_id = CONF.network.public_network_id |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 61 | |
| 62 | # Create network, subnet, router and add interface |
| 63 | cls.network = cls.create_network() |
Kevin Benton | a70710b | 2016-07-08 15:24:38 -0700 | [diff] [blame] | 64 | cls.subnet = cls.create_subnet(cls.network, enable_dhcp=False) |
zhufl | d2c40ca | 2016-10-18 17:03:07 +0800 | [diff] [blame] | 65 | cls.router = cls.create_router(external_network_id=cls.ext_net_id) |
rossella | bc9b4bd | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 66 | cls.create_router_interface(cls.router['id'], cls.subnet['id']) |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 67 | # Create two ports one each for Creation and Updating of floatingIP |
ghanshyam | 906e284 | 2018-08-03 08:58:50 +0000 | [diff] [blame] | 68 | cls.ports = [] |
zhufl | bf5ed0b | 2020-11-18 15:34:25 +0800 | [diff] [blame] | 69 | for _ in range(2): |
ghanshyam | 906e284 | 2018-08-03 08:58:50 +0000 | [diff] [blame] | 70 | port = cls.create_port(cls.network) |
| 71 | cls.ports.append(port) |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 72 | |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 73 | @decorators.attr(type='smoke') |
Ken'ichi Ohmichi | 53b9a63 | 2017-01-27 18:04:39 -0800 | [diff] [blame] | 74 | @decorators.idempotent_id('62595970-ab1c-4b7f-8fcc-fddfe55e8718') |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 75 | def test_create_list_show_update_delete_floating_ip(self): |
zhufl | 4810d88 | 2020-04-22 16:14:19 +0800 | [diff] [blame] | 76 | """Test create/list/show/update/delete floating ip""" |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 77 | # Creates a floating IP |
John Warren | fbf2a89 | 2015-11-17 12:36:14 -0500 | [diff] [blame] | 78 | body = self.floating_ips_client.create_floatingip( |
Rohan Kanade | eeb2164 | 2014-08-14 12:00:26 +0200 | [diff] [blame] | 79 | floating_network_id=self.ext_net_id, |
| 80 | port_id=self.ports[0]['id']) |
Ann Kamyshnikova | 47a4ff8 | 2014-03-17 12:48:57 +0400 | [diff] [blame] | 81 | created_floating_ip = body['floatingip'] |
Slawek Kaplonski | 748dd8d | 2019-04-16 23:38:35 +0200 | [diff] [blame] | 82 | self.addCleanup( |
| 83 | test_utils.call_and_ignore_notfound_exc, |
| 84 | self.floating_ips_client.delete_floatingip, |
| 85 | created_floating_ip['id']) |
rossella | bc9b4bd | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 86 | self.assertIsNotNone(created_floating_ip['id']) |
Rodolfo Alonso Hernandez | c1449d4 | 2020-02-15 13:24:28 +0000 | [diff] [blame] | 87 | self.assertIsNotNone(created_floating_ip['project_id']) |
rossella | bc9b4bd | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 88 | self.assertIsNotNone(created_floating_ip['floating_ip_address']) |
| 89 | self.assertEqual(created_floating_ip['port_id'], self.ports[0]['id']) |
| 90 | self.assertEqual(created_floating_ip['floating_network_id'], |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 91 | self.ext_net_id) |
Ann Kamyshnikova | 7d2275b | 2013-12-19 16:38:42 +0400 | [diff] [blame] | 92 | self.assertIn(created_floating_ip['fixed_ip_address'], |
| 93 | [ip['ip_address'] for ip in self.ports[0]['fixed_ips']]) |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 94 | # Verifies the details of a floating_ip |
John Warren | fbf2a89 | 2015-11-17 12:36:14 -0500 | [diff] [blame] | 95 | floating_ip = self.floating_ips_client.show_floatingip( |
| 96 | created_floating_ip['id']) |
rossella | bc9b4bd | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 97 | shown_floating_ip = floating_ip['floatingip'] |
| 98 | self.assertEqual(shown_floating_ip['id'], created_floating_ip['id']) |
| 99 | self.assertEqual(shown_floating_ip['floating_network_id'], |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 100 | self.ext_net_id) |
Rodolfo Alonso Hernandez | c1449d4 | 2020-02-15 13:24:28 +0000 | [diff] [blame] | 101 | self.assertEqual(shown_floating_ip['project_id'], |
| 102 | created_floating_ip['project_id']) |
rossella | bc9b4bd | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 103 | self.assertEqual(shown_floating_ip['floating_ip_address'], |
| 104 | created_floating_ip['floating_ip_address']) |
| 105 | self.assertEqual(shown_floating_ip['port_id'], self.ports[0]['id']) |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 106 | |
| 107 | # Verify the floating ip exists in the list of all floating_ips |
John Warren | fbf2a89 | 2015-11-17 12:36:14 -0500 | [diff] [blame] | 108 | floating_ips = self.floating_ips_client.list_floatingips() |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 109 | floatingip_id_list = list() |
| 110 | for f in floating_ips['floatingips']: |
| 111 | floatingip_id_list.append(f['id']) |
rossella | bc9b4bd | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 112 | self.assertIn(created_floating_ip['id'], floatingip_id_list) |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 113 | # Associate floating IP to the other port |
John Warren | fbf2a89 | 2015-11-17 12:36:14 -0500 | [diff] [blame] | 114 | floating_ip = self.floating_ips_client.update_floatingip( |
Rohan Kanade | eeb2164 | 2014-08-14 12:00:26 +0200 | [diff] [blame] | 115 | created_floating_ip['id'], |
| 116 | port_id=self.ports[1]['id']) |
rossella | bc9b4bd | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 117 | updated_floating_ip = floating_ip['floatingip'] |
| 118 | self.assertEqual(updated_floating_ip['port_id'], self.ports[1]['id']) |
| 119 | self.assertEqual(updated_floating_ip['fixed_ip_address'], |
| 120 | self.ports[1]['fixed_ips'][0]['ip_address']) |
| 121 | self.assertEqual(updated_floating_ip['router_id'], self.router['id']) |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 122 | |
| 123 | # Disassociate floating IP from the port |
John Warren | fbf2a89 | 2015-11-17 12:36:14 -0500 | [diff] [blame] | 124 | floating_ip = self.floating_ips_client.update_floatingip( |
Rohan Kanade | eeb2164 | 2014-08-14 12:00:26 +0200 | [diff] [blame] | 125 | created_floating_ip['id'], |
| 126 | port_id=None) |
rossella | bc9b4bd | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 127 | updated_floating_ip = floating_ip['floatingip'] |
| 128 | self.assertIsNone(updated_floating_ip['port_id']) |
| 129 | self.assertIsNone(updated_floating_ip['fixed_ip_address']) |
| 130 | self.assertIsNone(updated_floating_ip['router_id']) |
Attila Fazekas | c74aede | 2013-09-11 13:04:02 +0200 | [diff] [blame] | 131 | |
Rajesh Tailor | a85bdb4 | 2024-04-02 12:01:53 +0530 | [diff] [blame^] | 132 | # Explicitly test deletion of floating IP |
Slawek Kaplonski | 748dd8d | 2019-04-16 23:38:35 +0200 | [diff] [blame] | 133 | self.floating_ips_client.delete_floatingip(created_floating_ip['id']) |
| 134 | |
Ken'ichi Ohmichi | 53b9a63 | 2017-01-27 18:04:39 -0800 | [diff] [blame] | 135 | @decorators.idempotent_id('e1f6bffd-442f-4668-b30e-df13f2705e77') |
rossella | b24ec38 | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 136 | def test_floating_ip_delete_port(self): |
zhufl | 4810d88 | 2020-04-22 16:14:19 +0800 | [diff] [blame] | 137 | """Test deleting floating ip's port |
| 138 | |
| 139 | 1. Create a floating ip |
| 140 | 2. Create a port |
| 141 | 3. Update the floating ip's port_id to the created port |
| 142 | 4. Delete the port |
| 143 | 5. Verify that the port details are cleared from the floating ip |
| 144 | """ |
rossella | b24ec38 | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 145 | # Create a floating IP |
John Warren | fbf2a89 | 2015-11-17 12:36:14 -0500 | [diff] [blame] | 146 | body = self.floating_ips_client.create_floatingip( |
Ann Kamyshnikova | 47a4ff8 | 2014-03-17 12:48:57 +0400 | [diff] [blame] | 147 | floating_network_id=self.ext_net_id) |
Ann Kamyshnikova | 47a4ff8 | 2014-03-17 12:48:57 +0400 | [diff] [blame] | 148 | created_floating_ip = body['floatingip'] |
Slawek Kaplonski | 748dd8d | 2019-04-16 23:38:35 +0200 | [diff] [blame] | 149 | self.addCleanup( |
| 150 | test_utils.call_and_ignore_notfound_exc, |
| 151 | self.floating_ips_client.delete_floatingip, |
| 152 | created_floating_ip['id']) |
rossella | b24ec38 | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 153 | # Create a port |
Doug Schveninger | 24675aa | 2019-08-16 22:28:39 -0500 | [diff] [blame] | 154 | port = self.ports_client.create_port( |
| 155 | network_id=self.network['id'], |
Martin Kopec | 213d0a4 | 2023-11-30 10:28:14 +0100 | [diff] [blame] | 156 | name=data_utils.rand_name( |
| 157 | self.__class__.__name__, prefix=CONF.resource_name_prefix)) |
rossella | b24ec38 | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 158 | created_port = port['port'] |
John Warren | fbf2a89 | 2015-11-17 12:36:14 -0500 | [diff] [blame] | 159 | floating_ip = self.floating_ips_client.update_floatingip( |
Rohan Kanade | eeb2164 | 2014-08-14 12:00:26 +0200 | [diff] [blame] | 160 | created_floating_ip['id'], |
| 161 | port_id=created_port['id']) |
rossella | b24ec38 | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 162 | # Delete port |
John Warren | 49c0fe5 | 2015-10-22 12:35:54 -0400 | [diff] [blame] | 163 | self.ports_client.delete_port(created_port['id']) |
rossella | b24ec38 | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 164 | # Verifies the details of the floating_ip |
John Warren | fbf2a89 | 2015-11-17 12:36:14 -0500 | [diff] [blame] | 165 | floating_ip = self.floating_ips_client.show_floatingip( |
| 166 | created_floating_ip['id']) |
rossella | b24ec38 | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 167 | shown_floating_ip = floating_ip['floatingip'] |
| 168 | # Confirm the fields are back to None |
| 169 | self.assertEqual(shown_floating_ip['id'], created_floating_ip['id']) |
| 170 | self.assertIsNone(shown_floating_ip['port_id']) |
| 171 | self.assertIsNone(shown_floating_ip['fixed_ip_address']) |
| 172 | self.assertIsNone(shown_floating_ip['router_id']) |
| 173 | |
Ken'ichi Ohmichi | 53b9a63 | 2017-01-27 18:04:39 -0800 | [diff] [blame] | 174 | @decorators.idempotent_id('1bb2f731-fe5a-4b8c-8409-799ade1bed4d') |
rossella | b24ec38 | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 175 | def test_floating_ip_update_different_router(self): |
zhufl | 4810d88 | 2020-04-22 16:14:19 +0800 | [diff] [blame] | 176 | """Test associating a floating ip to a port on different router""" |
rossella | b24ec38 | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 177 | # Associate a floating IP to a port on a router |
John Warren | fbf2a89 | 2015-11-17 12:36:14 -0500 | [diff] [blame] | 178 | body = self.floating_ips_client.create_floatingip( |
Rohan Kanade | eeb2164 | 2014-08-14 12:00:26 +0200 | [diff] [blame] | 179 | floating_network_id=self.ext_net_id, |
| 180 | port_id=self.ports[1]['id']) |
Ann Kamyshnikova | 47a4ff8 | 2014-03-17 12:48:57 +0400 | [diff] [blame] | 181 | created_floating_ip = body['floatingip'] |
Slawek Kaplonski | 748dd8d | 2019-04-16 23:38:35 +0200 | [diff] [blame] | 182 | self.addCleanup( |
| 183 | test_utils.call_and_ignore_notfound_exc, |
| 184 | self.floating_ips_client.delete_floatingip, |
| 185 | created_floating_ip['id']) |
rossella | b24ec38 | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 186 | self.assertEqual(created_floating_ip['router_id'], self.router['id']) |
Martin Kopec | 213d0a4 | 2023-11-30 10:28:14 +0100 | [diff] [blame] | 187 | network_name = data_utils.rand_name( |
| 188 | self.__class__.__name__, prefix=CONF.resource_name_prefix) |
deepak_mourya | b4fb438 | 2018-06-04 10:11:32 +0530 | [diff] [blame] | 189 | network2 = self.networks_client.create_network( |
| 190 | name=network_name)['network'] |
Slawek Kaplonski | 748dd8d | 2019-04-16 23:38:35 +0200 | [diff] [blame] | 191 | self.addCleanup( |
| 192 | test_utils.call_and_ignore_notfound_exc, |
| 193 | self.networks_client.delete_network, |
| 194 | network2['id']) |
rossella | b24ec38 | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 195 | subnet2 = self.create_subnet(network2) |
Slawek Kaplonski | 748dd8d | 2019-04-16 23:38:35 +0200 | [diff] [blame] | 196 | self.addCleanup( |
| 197 | test_utils.call_and_ignore_notfound_exc, |
| 198 | self.subnets_client.delete_subnet, subnet2['id']) |
zhufl | d2c40ca | 2016-10-18 17:03:07 +0800 | [diff] [blame] | 199 | router2 = self.create_router(external_network_id=self.ext_net_id) |
Slawek Kaplonski | 748dd8d | 2019-04-16 23:38:35 +0200 | [diff] [blame] | 200 | self.addCleanup( |
| 201 | test_utils.call_and_ignore_notfound_exc, |
| 202 | self.routers_client.delete_router, router2['id']) |
rossella | b24ec38 | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 203 | self.create_router_interface(router2['id'], subnet2['id']) |
Slawek Kaplonski | 748dd8d | 2019-04-16 23:38:35 +0200 | [diff] [blame] | 204 | self.addCleanup( |
| 205 | test_utils.call_and_ignore_notfound_exc, |
| 206 | self.routers_client.remove_router_interface, |
| 207 | router2['id'], subnet_id=subnet2['id']) |
rossella | b24ec38 | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 208 | port_other_router = self.create_port(network2) |
Slawek Kaplonski | 748dd8d | 2019-04-16 23:38:35 +0200 | [diff] [blame] | 209 | self.addCleanup( |
| 210 | test_utils.call_and_ignore_notfound_exc, |
| 211 | self.ports_client.delete_port, |
| 212 | port_other_router['id']) |
rossella | b24ec38 | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 213 | # Associate floating IP to the other port on another router |
John Warren | fbf2a89 | 2015-11-17 12:36:14 -0500 | [diff] [blame] | 214 | floating_ip = self.floating_ips_client.update_floatingip( |
Rohan Kanade | eeb2164 | 2014-08-14 12:00:26 +0200 | [diff] [blame] | 215 | created_floating_ip['id'], |
| 216 | port_id=port_other_router['id']) |
rossella | b24ec38 | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 217 | updated_floating_ip = floating_ip['floatingip'] |
| 218 | self.assertEqual(updated_floating_ip['router_id'], router2['id']) |
| 219 | self.assertEqual(updated_floating_ip['port_id'], |
| 220 | port_other_router['id']) |
| 221 | self.assertIsNotNone(updated_floating_ip['fixed_ip_address']) |
| 222 | |
Jordan Pittier | 3b46d27 | 2017-04-12 16:17:28 +0200 | [diff] [blame] | 223 | @decorators.attr(type='smoke') |
Ken'ichi Ohmichi | 53b9a63 | 2017-01-27 18:04:39 -0800 | [diff] [blame] | 224 | @decorators.idempotent_id('36de4bd0-f09c-43e3-a8e1-1decc1ffd3a5') |
Ann Kamyshnikova | 7d2275b | 2013-12-19 16:38:42 +0400 | [diff] [blame] | 225 | def test_create_floating_ip_specifying_a_fixed_ip_address(self): |
zhufl | 4810d88 | 2020-04-22 16:14:19 +0800 | [diff] [blame] | 226 | """Test creating floating ip with specified fixed ip""" |
John Warren | fbf2a89 | 2015-11-17 12:36:14 -0500 | [diff] [blame] | 227 | body = self.floating_ips_client.create_floatingip( |
Ann Kamyshnikova | 7d2275b | 2013-12-19 16:38:42 +0400 | [diff] [blame] | 228 | floating_network_id=self.ext_net_id, |
| 229 | port_id=self.ports[1]['id'], |
| 230 | fixed_ip_address=self.ports[1]['fixed_ips'][0]['ip_address']) |
Ann Kamyshnikova | 7d2275b | 2013-12-19 16:38:42 +0400 | [diff] [blame] | 231 | created_floating_ip = body['floatingip'] |
Slawek Kaplonski | 748dd8d | 2019-04-16 23:38:35 +0200 | [diff] [blame] | 232 | self.addCleanup( |
| 233 | test_utils.call_and_ignore_notfound_exc, |
| 234 | self.floating_ips_client.delete_floatingip, |
| 235 | created_floating_ip['id']) |
Ann Kamyshnikova | 7d2275b | 2013-12-19 16:38:42 +0400 | [diff] [blame] | 236 | self.assertIsNotNone(created_floating_ip['id']) |
| 237 | self.assertEqual(created_floating_ip['fixed_ip_address'], |
| 238 | self.ports[1]['fixed_ips'][0]['ip_address']) |
John Warren | fbf2a89 | 2015-11-17 12:36:14 -0500 | [diff] [blame] | 239 | floating_ip = self.floating_ips_client.update_floatingip( |
Rohan Kanade | eeb2164 | 2014-08-14 12:00:26 +0200 | [diff] [blame] | 240 | created_floating_ip['id'], |
| 241 | port_id=None) |
Ann Kamyshnikova | 7d2275b | 2013-12-19 16:38:42 +0400 | [diff] [blame] | 242 | self.assertIsNone(floating_ip['floatingip']['port_id']) |
| 243 | |
Ken'ichi Ohmichi | 53b9a63 | 2017-01-27 18:04:39 -0800 | [diff] [blame] | 244 | @decorators.idempotent_id('45c4c683-ea97-41ef-9c51-5e9802f2f3d7') |
Ann Kamyshnikova | df10284 | 2014-02-05 13:52:57 +0400 | [diff] [blame] | 245 | def test_create_update_floatingip_with_port_multiple_ip_address(self): |
zhufl | 4810d88 | 2020-04-22 16:14:19 +0800 | [diff] [blame] | 246 | """Test updating floating ip's fixed_ips to another ip of same port |
| 247 | |
| 248 | First we create a port with 2 fixed ips, then we create a floating ip |
| 249 | with one of the fixed ips, and then we update the floating ip to |
| 250 | another fixed ip of that port. |
| 251 | """ |
Ann Kamyshnikova | df10284 | 2014-02-05 13:52:57 +0400 | [diff] [blame] | 252 | # Find out ips that can be used for tests |
Ryan Tidwell | 1964a26 | 2016-05-04 15:13:23 -0700 | [diff] [blame] | 253 | list_ips = net_utils.get_unused_ip_addresses( |
| 254 | self.ports_client, |
| 255 | self.subnets_client, |
| 256 | self.subnet['network_id'], |
| 257 | self.subnet['id'], |
| 258 | 2) |
Ann Kamyshnikova | df10284 | 2014-02-05 13:52:57 +0400 | [diff] [blame] | 259 | fixed_ips = [{'ip_address': list_ips[0]}, {'ip_address': list_ips[1]}] |
| 260 | # Create port |
Doug Schveninger | 24675aa | 2019-08-16 22:28:39 -0500 | [diff] [blame] | 261 | body = self.ports_client.create_port( |
| 262 | network_id=self.network['id'], |
Martin Kopec | 213d0a4 | 2023-11-30 10:28:14 +0100 | [diff] [blame] | 263 | name=data_utils.rand_name( |
| 264 | self.__class__.__name__, prefix=CONF.resource_name_prefix), |
Doug Schveninger | 24675aa | 2019-08-16 22:28:39 -0500 | [diff] [blame] | 265 | fixed_ips=fixed_ips) |
Ann Kamyshnikova | df10284 | 2014-02-05 13:52:57 +0400 | [diff] [blame] | 266 | port = body['port'] |
Slawek Kaplonski | 748dd8d | 2019-04-16 23:38:35 +0200 | [diff] [blame] | 267 | self.addCleanup(test_utils.call_and_ignore_notfound_exc, |
| 268 | self.ports_client.delete_port, port['id']) |
Ann Kamyshnikova | df10284 | 2014-02-05 13:52:57 +0400 | [diff] [blame] | 269 | # Create floating ip |
John Warren | fbf2a89 | 2015-11-17 12:36:14 -0500 | [diff] [blame] | 270 | body = self.floating_ips_client.create_floatingip( |
Rohan Kanade | eeb2164 | 2014-08-14 12:00:26 +0200 | [diff] [blame] | 271 | floating_network_id=self.ext_net_id, |
| 272 | port_id=port['id'], |
Ann Kamyshnikova | df10284 | 2014-02-05 13:52:57 +0400 | [diff] [blame] | 273 | fixed_ip_address=list_ips[0]) |
Ann Kamyshnikova | df10284 | 2014-02-05 13:52:57 +0400 | [diff] [blame] | 274 | floating_ip = body['floatingip'] |
Slawek Kaplonski | 748dd8d | 2019-04-16 23:38:35 +0200 | [diff] [blame] | 275 | self.addCleanup(test_utils.call_and_ignore_notfound_exc, |
| 276 | self.floating_ips_client.delete_floatingip, |
John Warren | fbf2a89 | 2015-11-17 12:36:14 -0500 | [diff] [blame] | 277 | floating_ip['id']) |
Ann Kamyshnikova | df10284 | 2014-02-05 13:52:57 +0400 | [diff] [blame] | 278 | self.assertIsNotNone(floating_ip['id']) |
| 279 | self.assertEqual(floating_ip['fixed_ip_address'], list_ips[0]) |
| 280 | # Update floating ip |
John Warren | fbf2a89 | 2015-11-17 12:36:14 -0500 | [diff] [blame] | 281 | body = self.floating_ips_client.update_floatingip( |
| 282 | floating_ip['id'], port_id=port['id'], |
| 283 | fixed_ip_address=list_ips[1]) |
Ann Kamyshnikova | df10284 | 2014-02-05 13:52:57 +0400 | [diff] [blame] | 284 | update_floating_ip = body['floatingip'] |
| 285 | self.assertEqual(update_floating_ip['fixed_ip_address'], |
| 286 | list_ips[1]) |