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 |
| 19 | from tempest.common.utils.data_utils import rand_name |
| 20 | from tempest.test import attr |
| 21 | |
| 22 | |
| 23 | class FloatingIPTest(base.BaseNetworkTest): |
| 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): |
| 44 | super(FloatingIPTest, cls).setUpClass() |
| 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) |
| 50 | resp, router = cls.client.create_router( |
| 51 | rand_name('router-'), |
| 52 | external_gateway_info={"network_id": |
| 53 | cls.network_cfg.public_network_id}) |
| 54 | cls.router = router['router'] |
| 55 | resp, _ = cls.client.add_router_interface_with_subnet_id( |
| 56 | cls.router['id'], cls.subnet['id']) |
| 57 | cls.port = list() |
| 58 | # Create two ports one each for Creation and Updating of floatingIP |
| 59 | for i in range(2): |
| 60 | resp, port = cls.client.create_port(cls.network['id']) |
| 61 | cls.port.append(port['port']) |
| 62 | |
| 63 | @classmethod |
| 64 | def tearDownClass(cls): |
| 65 | cls.client.remove_router_interface_with_subnet_id(cls.router['id'], |
| 66 | cls.subnet['id']) |
| 67 | for i in range(2): |
| 68 | cls.client.delete_port(cls.port[i]['id']) |
| 69 | cls.client.delete_router(cls.router['id']) |
| 70 | super(FloatingIPTest, cls).tearDownClass() |
| 71 | |
| 72 | def _delete_floating_ip(self, floating_ip_id): |
| 73 | # Deletes a floating IP and verifies if it is deleted or not |
| 74 | resp, _ = self.client.delete_floating_ip(floating_ip_id) |
| 75 | self.assertEqual(204, resp.status) |
| 76 | # Asserting that the floating_ip is not found in list after deletion |
| 77 | resp, floating_ips = self.client.list_floating_ips() |
| 78 | floatingip_id_list = list() |
| 79 | for f in floating_ips['floatingips']: |
| 80 | floatingip_id_list.append(f['id']) |
| 81 | self.assertNotIn(floating_ip_id, floatingip_id_list) |
| 82 | |
| 83 | @attr(type='smoke') |
| 84 | def test_create_list_show_update_delete_floating_ip(self): |
| 85 | # Creates a floating IP |
| 86 | resp, floating_ip = self.client.create_floating_ip( |
| 87 | self.ext_net_id, port_id=self.port[0]['id']) |
| 88 | self.assertEqual('201', resp['status']) |
| 89 | create_floating_ip = floating_ip['floatingip'] |
| 90 | self.assertIsNotNone(create_floating_ip['id']) |
| 91 | self.assertIsNotNone(create_floating_ip['tenant_id']) |
| 92 | self.assertIsNotNone(create_floating_ip['floating_ip_address']) |
| 93 | self.assertEqual(create_floating_ip['port_id'], self.port[0]['id']) |
| 94 | self.assertEqual(create_floating_ip['floating_network_id'], |
| 95 | self.ext_net_id) |
| 96 | self.addCleanup(self._delete_floating_ip, create_floating_ip['id']) |
| 97 | # Verifies the details of a floating_ip |
| 98 | resp, floating_ip = self.client.show_floating_ip( |
| 99 | create_floating_ip['id']) |
| 100 | self.assertEqual('200', resp['status']) |
| 101 | show_floating_ip = floating_ip['floatingip'] |
| 102 | self.assertEqual(show_floating_ip['id'], create_floating_ip['id']) |
| 103 | self.assertEqual(show_floating_ip['floating_network_id'], |
| 104 | self.ext_net_id) |
| 105 | self.assertEqual(show_floating_ip['tenant_id'], |
| 106 | create_floating_ip['tenant_id']) |
| 107 | self.assertEqual(show_floating_ip['floating_ip_address'], |
| 108 | create_floating_ip['floating_ip_address']) |
| 109 | self.assertEqual(show_floating_ip['port_id'], self.port[0]['id']) |
| 110 | |
| 111 | # Verify the floating ip exists in the list of all floating_ips |
| 112 | resp, floating_ips = self.client.list_floating_ips() |
| 113 | self.assertEqual('200', resp['status']) |
| 114 | floatingip_id_list = list() |
| 115 | for f in floating_ips['floatingips']: |
| 116 | floatingip_id_list.append(f['id']) |
| 117 | self.assertIn(create_floating_ip['id'], floatingip_id_list) |
| 118 | |
| 119 | # Associate floating IP to the other port |
| 120 | resp, floating_ip = self.client.update_floating_ip( |
| 121 | create_floating_ip['id'], port_id=self.port[1]['id']) |
| 122 | self.assertEqual('200', resp['status']) |
| 123 | update_floating_ip = floating_ip['floatingip'] |
| 124 | self.assertEqual(update_floating_ip['port_id'], self.port[1]['id']) |
| 125 | self.assertIsNotNone(update_floating_ip['fixed_ip_address']) |
| 126 | self.assertEqual(update_floating_ip['router_id'], self.router['id']) |
| 127 | |
| 128 | # Disassociate floating IP from the port |
| 129 | resp, floating_ip = self.client.update_floating_ip( |
| 130 | create_floating_ip['id'], port_id=None) |
| 131 | self.assertEqual('200', resp['status']) |
| 132 | update_floating_ip = floating_ip['floatingip'] |
| 133 | self.assertIsNone(update_floating_ip['port_id']) |
| 134 | self.assertIsNone(update_floating_ip['fixed_ip_address']) |
| 135 | self.assertIsNone(update_floating_ip['router_id']) |