Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 |
| 2 | |
| 3 | # Copyright 2013 OpenStack Foundation |
| 4 | # All Rights Reserved. |
| 5 | # |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 7 | # not use this file except in compliance with the License. You may obtain |
| 8 | # a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 14 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 15 | # License for the specific language governing permissions and limitations |
| 16 | # under the License. |
| 17 | |
| 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 |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 20 | from tempest.test import attr |
| 21 | |
| 22 | |
Attila Fazekas | c74aede | 2013-09-11 13:04:02 +0200 | [diff] [blame] | 23 | class FloatingIPTestJSON(base.BaseNetworkTest): |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 24 | _interface = 'json' |
| 25 | |
| 26 | """ |
| 27 | Tests the following operations in the Quantum API using the REST client for |
| 28 | Quantum: |
| 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 |
| 35 | |
| 36 | v2.0 of the Quantum API is assumed. It is also assumed that the following |
| 37 | options are defined in the [network] section of etc/tempest.conf: |
| 38 | |
| 39 | public_network_id which is the id for the external network present |
| 40 | """ |
| 41 | |
| 42 | @classmethod |
| 43 | def setUpClass(cls): |
Attila Fazekas | c74aede | 2013-09-11 13:04:02 +0200 | [diff] [blame] | 44 | super(FloatingIPTestJSON, cls).setUpClass() |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 45 | cls.ext_net_id = cls.config.network.public_network_id |
| 46 | |
| 47 | # Create network, subnet, router and add interface |
| 48 | cls.network = cls.create_network() |
| 49 | cls.subnet = cls.create_subnet(cls.network) |
Salvatore Orlando | a85e8fe | 2013-09-20 03:48:02 -0700 | [diff] [blame] | 50 | cls.router = cls.create_router( |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 51 | data_utils.rand_name('router-'), |
Salvatore Orlando | a85e8fe | 2013-09-20 03:48:02 -0700 | [diff] [blame] | 52 | external_network_id=cls.network_cfg.public_network_id) |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 53 | resp, _ = cls.client.add_router_interface_with_subnet_id( |
| 54 | cls.router['id'], cls.subnet['id']) |
| 55 | cls.port = list() |
| 56 | # Create two ports one each for Creation and Updating of floatingIP |
| 57 | for i in range(2): |
| 58 | resp, port = cls.client.create_port(cls.network['id']) |
| 59 | cls.port.append(port['port']) |
| 60 | |
| 61 | @classmethod |
| 62 | def tearDownClass(cls): |
| 63 | cls.client.remove_router_interface_with_subnet_id(cls.router['id'], |
| 64 | cls.subnet['id']) |
| 65 | for i in range(2): |
| 66 | cls.client.delete_port(cls.port[i]['id']) |
Attila Fazekas | c74aede | 2013-09-11 13:04:02 +0200 | [diff] [blame] | 67 | super(FloatingIPTestJSON, cls).tearDownClass() |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 68 | |
| 69 | def _delete_floating_ip(self, floating_ip_id): |
| 70 | # Deletes a floating IP and verifies if it is deleted or not |
Eugene Nikanorov | 909ded1 | 2013-12-15 17:45:37 +0400 | [diff] [blame] | 71 | resp, _ = self.client.delete_floatingip(floating_ip_id) |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 72 | self.assertEqual(204, resp.status) |
| 73 | # Asserting that the floating_ip is not found in list after deletion |
Eugene Nikanorov | 909ded1 | 2013-12-15 17:45:37 +0400 | [diff] [blame] | 74 | resp, floating_ips = self.client.list_floatingips() |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 75 | floatingip_id_list = list() |
| 76 | for f in floating_ips['floatingips']: |
| 77 | floatingip_id_list.append(f['id']) |
| 78 | self.assertNotIn(floating_ip_id, floatingip_id_list) |
| 79 | |
| 80 | @attr(type='smoke') |
| 81 | def test_create_list_show_update_delete_floating_ip(self): |
| 82 | # Creates a floating IP |
| 83 | resp, floating_ip = self.client.create_floating_ip( |
| 84 | self.ext_net_id, port_id=self.port[0]['id']) |
| 85 | self.assertEqual('201', resp['status']) |
| 86 | create_floating_ip = floating_ip['floatingip'] |
| 87 | self.assertIsNotNone(create_floating_ip['id']) |
| 88 | self.assertIsNotNone(create_floating_ip['tenant_id']) |
| 89 | self.assertIsNotNone(create_floating_ip['floating_ip_address']) |
| 90 | self.assertEqual(create_floating_ip['port_id'], self.port[0]['id']) |
| 91 | self.assertEqual(create_floating_ip['floating_network_id'], |
| 92 | self.ext_net_id) |
| 93 | self.addCleanup(self._delete_floating_ip, create_floating_ip['id']) |
| 94 | # Verifies the details of a floating_ip |
| 95 | resp, floating_ip = self.client.show_floating_ip( |
| 96 | create_floating_ip['id']) |
| 97 | self.assertEqual('200', resp['status']) |
| 98 | show_floating_ip = floating_ip['floatingip'] |
| 99 | self.assertEqual(show_floating_ip['id'], create_floating_ip['id']) |
| 100 | self.assertEqual(show_floating_ip['floating_network_id'], |
| 101 | self.ext_net_id) |
| 102 | self.assertEqual(show_floating_ip['tenant_id'], |
| 103 | create_floating_ip['tenant_id']) |
| 104 | self.assertEqual(show_floating_ip['floating_ip_address'], |
| 105 | create_floating_ip['floating_ip_address']) |
| 106 | self.assertEqual(show_floating_ip['port_id'], self.port[0]['id']) |
| 107 | |
| 108 | # Verify the floating ip exists in the list of all floating_ips |
Eugene Nikanorov | 909ded1 | 2013-12-15 17:45:37 +0400 | [diff] [blame] | 109 | resp, floating_ips = self.client.list_floatingips() |
Nayna Patel | f1a2915 | 2013-08-09 07:18:13 +0000 | [diff] [blame] | 110 | self.assertEqual('200', resp['status']) |
| 111 | floatingip_id_list = list() |
| 112 | for f in floating_ips['floatingips']: |
| 113 | floatingip_id_list.append(f['id']) |
| 114 | self.assertIn(create_floating_ip['id'], floatingip_id_list) |
| 115 | |
| 116 | # Associate floating IP to the other port |
| 117 | resp, floating_ip = self.client.update_floating_ip( |
| 118 | create_floating_ip['id'], port_id=self.port[1]['id']) |
| 119 | self.assertEqual('200', resp['status']) |
| 120 | update_floating_ip = floating_ip['floatingip'] |
| 121 | self.assertEqual(update_floating_ip['port_id'], self.port[1]['id']) |
| 122 | self.assertIsNotNone(update_floating_ip['fixed_ip_address']) |
| 123 | self.assertEqual(update_floating_ip['router_id'], self.router['id']) |
| 124 | |
| 125 | # Disassociate floating IP from the port |
| 126 | resp, floating_ip = self.client.update_floating_ip( |
| 127 | create_floating_ip['id'], port_id=None) |
| 128 | self.assertEqual('200', resp['status']) |
| 129 | update_floating_ip = floating_ip['floatingip'] |
| 130 | self.assertIsNone(update_floating_ip['port_id']) |
| 131 | self.assertIsNone(update_floating_ip['fixed_ip_address']) |
| 132 | self.assertIsNone(update_floating_ip['router_id']) |
Attila Fazekas | c74aede | 2013-09-11 13:04:02 +0200 | [diff] [blame] | 133 | |
| 134 | |
| 135 | class FloatingIPTestXML(FloatingIPTestJSON): |
| 136 | _interface = 'xml' |