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 |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 17 | from tempest.common.utils import data_utils |
Matthew Treinish | 03b48df | 2014-01-29 16:59:49 +0000 | [diff] [blame] | 18 | from tempest import config |
Yoshihiro Kaneko | 0567026 | 2014-01-18 19:22:44 +0900 | [diff] [blame] | 19 | from tempest import test |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 20 | |
Matthew Treinish | 03b48df | 2014-01-29 16:59:49 +0000 | [diff] [blame] | 21 | CONF = config.CONF |
| 22 | |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 23 | |
Attila Fazekas | c74aede | 2013-09-11 13:04:02 +0200 | [diff] [blame] | 24 | class FloatingIPTestJSON(base.BaseNetworkTest): |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 25 | _interface = 'json' |
| 26 | |
| 27 | """ |
| 28 | Tests the following operations in the Quantum API using the REST client for |
rossella | bc9b4bd | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 29 | Neutron: |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 30 | |
| 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 |
rossella | b24ec38 | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 36 | 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 Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 39 | |
rossella | bc9b4bd | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 40 | 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] | 41 | 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 |
Masayuki Igawa | 6d495d6 | 2014-03-19 16:38:57 +0900 | [diff] [blame] | 47 | @test.safe_setup |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 48 | def setUpClass(cls): |
Attila Fazekas | c74aede | 2013-09-11 13:04:02 +0200 | [diff] [blame] | 49 | super(FloatingIPTestJSON, cls).setUpClass() |
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') |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 67 | def test_create_list_show_update_delete_floating_ip(self): |
| 68 | # Creates a floating IP |
Ann Kamyshnikova | 47a4ff8 | 2014-03-17 12:48:57 +0400 | [diff] [blame] | 69 | resp, body = self.client.create_floatingip( |
| 70 | floating_network_id=self.ext_net_id, port_id=self.ports[0]['id']) |
| 71 | self.assertEqual('201', resp['status']) |
| 72 | created_floating_ip = body['floatingip'] |
| 73 | self.addCleanup(self.client.delete_floatingip, |
| 74 | created_floating_ip['id']) |
rossella | bc9b4bd | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 75 | self.assertIsNotNone(created_floating_ip['id']) |
| 76 | self.assertIsNotNone(created_floating_ip['tenant_id']) |
| 77 | self.assertIsNotNone(created_floating_ip['floating_ip_address']) |
| 78 | self.assertEqual(created_floating_ip['port_id'], self.ports[0]['id']) |
| 79 | self.assertEqual(created_floating_ip['floating_network_id'], |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 80 | self.ext_net_id) |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 81 | # Verifies the details of a floating_ip |
Ann Kamyshnikova | 47a4ff8 | 2014-03-17 12:48:57 +0400 | [diff] [blame] | 82 | resp, floating_ip = self.client.show_floatingip( |
rossella | bc9b4bd | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 83 | created_floating_ip['id']) |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 84 | self.assertEqual('200', resp['status']) |
rossella | bc9b4bd | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 85 | shown_floating_ip = floating_ip['floatingip'] |
| 86 | self.assertEqual(shown_floating_ip['id'], created_floating_ip['id']) |
| 87 | self.assertEqual(shown_floating_ip['floating_network_id'], |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 88 | self.ext_net_id) |
rossella | bc9b4bd | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 89 | self.assertEqual(shown_floating_ip['tenant_id'], |
| 90 | created_floating_ip['tenant_id']) |
| 91 | self.assertEqual(shown_floating_ip['floating_ip_address'], |
| 92 | created_floating_ip['floating_ip_address']) |
| 93 | self.assertEqual(shown_floating_ip['port_id'], self.ports[0]['id']) |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 94 | |
| 95 | # Verify the floating ip exists in the list of all floating_ips |
Eugene Nikanorov | 909ded1 | 2013-12-15 17:45:37 +0400 | [diff] [blame] | 96 | resp, floating_ips = self.client.list_floatingips() |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 97 | self.assertEqual('200', resp['status']) |
| 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 |
Ann Kamyshnikova | 47a4ff8 | 2014-03-17 12:48:57 +0400 | [diff] [blame] | 103 | resp, floating_ip = self.client.update_floatingip( |
rossella | bc9b4bd | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 104 | created_floating_ip['id'], port_id=self.ports[1]['id']) |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 105 | self.assertEqual('200', resp['status']) |
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 |
Ann Kamyshnikova | 47a4ff8 | 2014-03-17 12:48:57 +0400 | [diff] [blame] | 113 | resp, floating_ip = self.client.update_floatingip( |
rossella | bc9b4bd | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 114 | created_floating_ip['id'], port_id=None) |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 115 | self.assertEqual('200', resp['status']) |
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') |
rossella | b24ec38 | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 122 | def test_floating_ip_delete_port(self): |
| 123 | # Create a floating IP |
Ann Kamyshnikova | 47a4ff8 | 2014-03-17 12:48:57 +0400 | [diff] [blame] | 124 | resp, body = self.client.create_floatingip( |
| 125 | floating_network_id=self.ext_net_id) |
| 126 | self.assertEqual('201', resp['status']) |
| 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 |
Eugene Nikanorov | e9d255a | 2013-12-18 16:31:42 +0400 | [diff] [blame] | 131 | resp, 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'] |
Ann Kamyshnikova | 47a4ff8 | 2014-03-17 12:48:57 +0400 | [diff] [blame] | 133 | resp, floating_ip = self.client.update_floatingip( |
rossella | b24ec38 | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 134 | created_floating_ip['id'], port_id=created_port['id']) |
| 135 | self.assertEqual('200', resp['status']) |
| 136 | # Delete port |
| 137 | self.client.delete_port(created_port['id']) |
| 138 | # Verifies the details of the floating_ip |
Ann Kamyshnikova | 47a4ff8 | 2014-03-17 12:48:57 +0400 | [diff] [blame] | 139 | resp, floating_ip = self.client.show_floatingip( |
rossella | b24ec38 | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 140 | created_floating_ip['id']) |
| 141 | self.assertEqual('200', resp['status']) |
| 142 | shown_floating_ip = floating_ip['floatingip'] |
| 143 | # Confirm the fields are back to None |
| 144 | self.assertEqual(shown_floating_ip['id'], created_floating_ip['id']) |
| 145 | self.assertIsNone(shown_floating_ip['port_id']) |
| 146 | self.assertIsNone(shown_floating_ip['fixed_ip_address']) |
| 147 | self.assertIsNone(shown_floating_ip['router_id']) |
| 148 | |
Yoshihiro Kaneko | 0567026 | 2014-01-18 19:22:44 +0900 | [diff] [blame] | 149 | @test.attr(type='smoke') |
rossella | b24ec38 | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 150 | def test_floating_ip_update_different_router(self): |
| 151 | # Associate a floating IP to a port on a router |
Ann Kamyshnikova | 47a4ff8 | 2014-03-17 12:48:57 +0400 | [diff] [blame] | 152 | resp, body = self.client.create_floatingip( |
| 153 | floating_network_id=self.ext_net_id, port_id=self.ports[1]['id']) |
| 154 | self.assertEqual('201', resp['status']) |
| 155 | created_floating_ip = body['floatingip'] |
| 156 | self.addCleanup(self.client.delete_floatingip, |
| 157 | created_floating_ip['id']) |
rossella | b24ec38 | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 158 | self.assertEqual(created_floating_ip['router_id'], self.router['id']) |
| 159 | network2 = self.create_network() |
| 160 | subnet2 = self.create_subnet(network2) |
| 161 | router2 = self.create_router(data_utils.rand_name('router-'), |
| 162 | external_network_id=self.ext_net_id) |
| 163 | self.create_router_interface(router2['id'], subnet2['id']) |
| 164 | port_other_router = self.create_port(network2) |
| 165 | # Associate floating IP to the other port on another router |
Ann Kamyshnikova | 47a4ff8 | 2014-03-17 12:48:57 +0400 | [diff] [blame] | 166 | resp, floating_ip = self.client.update_floatingip( |
rossella | b24ec38 | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 167 | created_floating_ip['id'], port_id=port_other_router['id']) |
| 168 | self.assertEqual('200', resp['status']) |
| 169 | updated_floating_ip = floating_ip['floatingip'] |
| 170 | self.assertEqual(updated_floating_ip['router_id'], router2['id']) |
| 171 | self.assertEqual(updated_floating_ip['port_id'], |
| 172 | port_other_router['id']) |
| 173 | self.assertIsNotNone(updated_floating_ip['fixed_ip_address']) |
| 174 | |
Attila Fazekas | c74aede | 2013-09-11 13:04:02 +0200 | [diff] [blame] | 175 | |
| 176 | class FloatingIPTestXML(FloatingIPTestJSON): |
| 177 | _interface = 'xml' |