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 |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 18 | from tempest.test import attr |
| 19 | |
| 20 | |
Attila Fazekas | c74aede | 2013-09-11 13:04:02 +0200 | [diff] [blame] | 21 | class FloatingIPTestJSON(base.BaseNetworkTest): |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 22 | _interface = 'json' |
| 23 | |
| 24 | """ |
| 25 | Tests the following operations in the Quantum API using the REST client for |
rossella | bc9b4bd | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 26 | Neutron: |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 27 | |
| 28 | Create a Floating IP |
| 29 | Update a Floating IP |
| 30 | Delete a Floating IP |
| 31 | List all Floating IPs |
| 32 | Show Floating IP details |
rossella | b24ec38 | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 33 | Associate a Floating IP with a port and then delete that port |
| 34 | Associate a Floating IP with a port and then with a port on another |
| 35 | router |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 36 | |
rossella | bc9b4bd | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 37 | 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] | 38 | options are defined in the [network] section of etc/tempest.conf: |
| 39 | |
| 40 | public_network_id which is the id for the external network present |
| 41 | """ |
| 42 | |
| 43 | @classmethod |
| 44 | def setUpClass(cls): |
Attila Fazekas | c74aede | 2013-09-11 13:04:02 +0200 | [diff] [blame] | 45 | super(FloatingIPTestJSON, cls).setUpClass() |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 46 | cls.ext_net_id = cls.config.network.public_network_id |
| 47 | |
| 48 | # Create network, subnet, router and add interface |
| 49 | cls.network = cls.create_network() |
| 50 | cls.subnet = cls.create_subnet(cls.network) |
rossella | bc9b4bd | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 51 | cls.router = cls.create_router(data_utils.rand_name('router-'), |
| 52 | external_network_id=cls.ext_net_id) |
| 53 | cls.create_router_interface(cls.router['id'], cls.subnet['id']) |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 54 | cls.port = list() |
| 55 | # Create two ports one each for Creation and Updating of floatingIP |
| 56 | for i in range(2): |
rossella | bc9b4bd | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 57 | cls.create_port(cls.network) |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 58 | |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 59 | @attr(type='smoke') |
| 60 | def test_create_list_show_update_delete_floating_ip(self): |
| 61 | # Creates a floating IP |
rossella | dd68b23 | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 62 | created_floating_ip = self.create_floating_ip( |
rossella | bc9b4bd | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 63 | self.ext_net_id, port_id=self.ports[0]['id']) |
rossella | bc9b4bd | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 64 | self.assertIsNotNone(created_floating_ip['id']) |
| 65 | self.assertIsNotNone(created_floating_ip['tenant_id']) |
| 66 | self.assertIsNotNone(created_floating_ip['floating_ip_address']) |
| 67 | self.assertEqual(created_floating_ip['port_id'], self.ports[0]['id']) |
| 68 | self.assertEqual(created_floating_ip['floating_network_id'], |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 69 | self.ext_net_id) |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 70 | # Verifies the details of a floating_ip |
| 71 | resp, floating_ip = self.client.show_floating_ip( |
rossella | bc9b4bd | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 72 | created_floating_ip['id']) |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 73 | self.assertEqual('200', resp['status']) |
rossella | bc9b4bd | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 74 | shown_floating_ip = floating_ip['floatingip'] |
| 75 | self.assertEqual(shown_floating_ip['id'], created_floating_ip['id']) |
| 76 | self.assertEqual(shown_floating_ip['floating_network_id'], |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 77 | self.ext_net_id) |
rossella | bc9b4bd | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 78 | self.assertEqual(shown_floating_ip['tenant_id'], |
| 79 | created_floating_ip['tenant_id']) |
| 80 | self.assertEqual(shown_floating_ip['floating_ip_address'], |
| 81 | created_floating_ip['floating_ip_address']) |
| 82 | self.assertEqual(shown_floating_ip['port_id'], self.ports[0]['id']) |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 83 | |
| 84 | # Verify the floating ip exists in the list of all floating_ips |
Eugene Nikanorov | 909ded1 | 2013-12-15 17:45:37 +0400 | [diff] [blame] | 85 | resp, floating_ips = self.client.list_floatingips() |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 86 | self.assertEqual('200', resp['status']) |
| 87 | floatingip_id_list = list() |
| 88 | for f in floating_ips['floatingips']: |
| 89 | floatingip_id_list.append(f['id']) |
rossella | bc9b4bd | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 90 | self.assertIn(created_floating_ip['id'], floatingip_id_list) |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 91 | # Associate floating IP to the other port |
| 92 | resp, floating_ip = self.client.update_floating_ip( |
rossella | bc9b4bd | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 93 | created_floating_ip['id'], port_id=self.ports[1]['id']) |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 94 | self.assertEqual('200', resp['status']) |
rossella | bc9b4bd | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 95 | updated_floating_ip = floating_ip['floatingip'] |
| 96 | self.assertEqual(updated_floating_ip['port_id'], self.ports[1]['id']) |
| 97 | self.assertEqual(updated_floating_ip['fixed_ip_address'], |
| 98 | self.ports[1]['fixed_ips'][0]['ip_address']) |
| 99 | self.assertEqual(updated_floating_ip['router_id'], self.router['id']) |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 100 | |
| 101 | # Disassociate floating IP from the port |
| 102 | resp, floating_ip = self.client.update_floating_ip( |
rossella | bc9b4bd | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 103 | created_floating_ip['id'], port_id=None) |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 104 | self.assertEqual('200', resp['status']) |
rossella | bc9b4bd | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 105 | updated_floating_ip = floating_ip['floatingip'] |
| 106 | self.assertIsNone(updated_floating_ip['port_id']) |
| 107 | self.assertIsNone(updated_floating_ip['fixed_ip_address']) |
| 108 | self.assertIsNone(updated_floating_ip['router_id']) |
Attila Fazekas | c74aede | 2013-09-11 13:04:02 +0200 | [diff] [blame] | 109 | |
rossella | b24ec38 | 2013-11-13 10:21:59 +0100 | [diff] [blame] | 110 | @attr(type='smoke') |
| 111 | def test_floating_ip_delete_port(self): |
| 112 | # Create a floating IP |
| 113 | created_floating_ip = self.create_floating_ip(self.ext_net_id) |
| 114 | # Create a port |
| 115 | resp, port = self.client.create_port(self.network['id']) |
| 116 | created_port = port['port'] |
| 117 | resp, floating_ip = self.client.update_floating_ip( |
| 118 | created_floating_ip['id'], port_id=created_port['id']) |
| 119 | self.assertEqual('200', resp['status']) |
| 120 | # Delete port |
| 121 | self.client.delete_port(created_port['id']) |
| 122 | # Verifies the details of the floating_ip |
| 123 | resp, floating_ip = self.client.show_floating_ip( |
| 124 | created_floating_ip['id']) |
| 125 | self.assertEqual('200', resp['status']) |
| 126 | shown_floating_ip = floating_ip['floatingip'] |
| 127 | # Confirm the fields are back to None |
| 128 | self.assertEqual(shown_floating_ip['id'], created_floating_ip['id']) |
| 129 | self.assertIsNone(shown_floating_ip['port_id']) |
| 130 | self.assertIsNone(shown_floating_ip['fixed_ip_address']) |
| 131 | self.assertIsNone(shown_floating_ip['router_id']) |
| 132 | |
| 133 | @attr(type='smoke') |
| 134 | def test_floating_ip_update_different_router(self): |
| 135 | # Associate a floating IP to a port on a router |
| 136 | created_floating_ip = self.create_floating_ip( |
| 137 | self.ext_net_id, port_id=self.ports[1]['id']) |
| 138 | self.assertEqual(created_floating_ip['router_id'], self.router['id']) |
| 139 | network2 = self.create_network() |
| 140 | subnet2 = self.create_subnet(network2) |
| 141 | router2 = self.create_router(data_utils.rand_name('router-'), |
| 142 | external_network_id=self.ext_net_id) |
| 143 | self.create_router_interface(router2['id'], subnet2['id']) |
| 144 | port_other_router = self.create_port(network2) |
| 145 | # Associate floating IP to the other port on another router |
| 146 | resp, floating_ip = self.client.update_floating_ip( |
| 147 | created_floating_ip['id'], port_id=port_other_router['id']) |
| 148 | self.assertEqual('200', resp['status']) |
| 149 | updated_floating_ip = floating_ip['floatingip'] |
| 150 | self.assertEqual(updated_floating_ip['router_id'], router2['id']) |
| 151 | self.assertEqual(updated_floating_ip['port_id'], |
| 152 | port_other_router['id']) |
| 153 | self.assertIsNotNone(updated_floating_ip['fixed_ip_address']) |
| 154 | |
Attila Fazekas | c74aede | 2013-09-11 13:04:02 +0200 | [diff] [blame] | 155 | |
| 156 | class FloatingIPTestXML(FloatingIPTestJSON): |
| 157 | _interface = 'xml' |