Elena Ezhova | 1ec6e18 | 2013-12-24 17:45:59 +0400 | [diff] [blame] | 1 | # Copyright 2014 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 | import socket |
| 17 | |
| 18 | from tempest.api.network import base |
Neeti Dahiya | de29177 | 2014-09-22 10:43:12 +0530 | [diff] [blame^] | 19 | from tempest.api.network import base_security_groups as sec_base |
Santosh Kumar | f0cbf9a | 2014-08-25 07:31:15 -0700 | [diff] [blame] | 20 | from tempest.common import custom_matchers |
Elena Ezhova | 1ec6e18 | 2013-12-24 17:45:59 +0400 | [diff] [blame] | 21 | from tempest.common.utils import data_utils |
| 22 | from tempest import config |
| 23 | from tempest import test |
| 24 | |
| 25 | CONF = config.CONF |
| 26 | |
| 27 | |
Neeti Dahiya | de29177 | 2014-09-22 10:43:12 +0530 | [diff] [blame^] | 28 | class PortsTestJSON(sec_base.BaseSecGroupTest): |
Elena Ezhova | 1ec6e18 | 2013-12-24 17:45:59 +0400 | [diff] [blame] | 29 | _interface = 'json' |
| 30 | |
Elena Ezhova | 5c95715 | 2014-03-26 12:01:10 +0400 | [diff] [blame] | 31 | """ |
| 32 | Test the following operations for ports: |
| 33 | |
| 34 | port create |
| 35 | port delete |
| 36 | port list |
| 37 | port show |
| 38 | port update |
| 39 | """ |
| 40 | |
Elena Ezhova | 1ec6e18 | 2013-12-24 17:45:59 +0400 | [diff] [blame] | 41 | @classmethod |
Andrea Frittoli | da4a245 | 2014-09-15 13:12:08 +0100 | [diff] [blame] | 42 | def resource_setup(cls): |
| 43 | super(PortsTestJSON, cls).resource_setup() |
Elena Ezhova | 1ec6e18 | 2013-12-24 17:45:59 +0400 | [diff] [blame] | 44 | cls.network = cls.create_network() |
| 45 | cls.port = cls.create_port(cls.network) |
| 46 | |
| 47 | def _delete_port(self, port_id): |
Rohan Kanade | eeb2164 | 2014-08-14 12:00:26 +0200 | [diff] [blame] | 48 | self.client.delete_port(port_id) |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 49 | body = self.client.list_ports() |
Elena Ezhova | 1ec6e18 | 2013-12-24 17:45:59 +0400 | [diff] [blame] | 50 | ports_list = body['ports'] |
| 51 | self.assertFalse(port_id in [n['id'] for n in ports_list]) |
| 52 | |
| 53 | @test.attr(type='smoke') |
| 54 | def test_create_update_delete_port(self): |
| 55 | # Verify port creation |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 56 | body = self.client.create_port(network_id=self.network['id']) |
Elena Ezhova | 1ec6e18 | 2013-12-24 17:45:59 +0400 | [diff] [blame] | 57 | port = body['port'] |
Dane LeBlanc | cbc4bc5 | 2014-03-19 16:03:23 -0400 | [diff] [blame] | 58 | # Schedule port deletion with verification upon test completion |
| 59 | self.addCleanup(self._delete_port, port['id']) |
Elena Ezhova | 1ec6e18 | 2013-12-24 17:45:59 +0400 | [diff] [blame] | 60 | self.assertTrue(port['admin_state_up']) |
| 61 | # Verify port update |
| 62 | new_name = "New_Port" |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 63 | body = self.client.update_port(port['id'], |
| 64 | name=new_name, |
| 65 | admin_state_up=False) |
Elena Ezhova | 1ec6e18 | 2013-12-24 17:45:59 +0400 | [diff] [blame] | 66 | updated_port = body['port'] |
| 67 | self.assertEqual(updated_port['name'], new_name) |
| 68 | self.assertFalse(updated_port['admin_state_up']) |
Elena Ezhova | 1ec6e18 | 2013-12-24 17:45:59 +0400 | [diff] [blame] | 69 | |
abhishek60014726 | 0737310 | 2014-11-25 04:39:20 -0800 | [diff] [blame] | 70 | def test_create_bulk_port(self): |
| 71 | network1 = self.network |
| 72 | name = data_utils.rand_name('network-') |
| 73 | network2 = self.create_network(network_name=name) |
| 74 | network_list = [network1['id'], network2['id']] |
| 75 | port_list = [{'network_id': net_id} for net_id in network_list] |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 76 | body = self.client.create_bulk_port(port_list) |
abhishek60014726 | 0737310 | 2014-11-25 04:39:20 -0800 | [diff] [blame] | 77 | created_ports = body['ports'] |
| 78 | port1 = created_ports[0] |
| 79 | port2 = created_ports[1] |
| 80 | self.addCleanup(self._delete_port, port1['id']) |
| 81 | self.addCleanup(self._delete_port, port2['id']) |
| 82 | self.assertEqual(port1['network_id'], network1['id']) |
| 83 | self.assertEqual(port2['network_id'], network2['id']) |
| 84 | self.assertTrue(port1['admin_state_up']) |
| 85 | self.assertTrue(port2['admin_state_up']) |
| 86 | |
Elena Ezhova | 1ec6e18 | 2013-12-24 17:45:59 +0400 | [diff] [blame] | 87 | @test.attr(type='smoke') |
| 88 | def test_show_port(self): |
| 89 | # Verify the details of port |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 90 | body = self.client.show_port(self.port['id']) |
Elena Ezhova | 1ec6e18 | 2013-12-24 17:45:59 +0400 | [diff] [blame] | 91 | port = body['port'] |
| 92 | self.assertIn('id', port) |
Santosh Kumar | f0cbf9a | 2014-08-25 07:31:15 -0700 | [diff] [blame] | 93 | # TODO(Santosh)- This is a temporary workaround to compare create_port |
| 94 | # and show_port dict elements.Remove this once extra_dhcp_opts issue |
| 95 | # gets fixed in neutron.( bug - 1365341.) |
| 96 | self.assertThat(self.port, |
| 97 | custom_matchers.MatchesDictExceptForKeys |
| 98 | (port, excluded_keys=['extra_dhcp_opts'])) |
Elena Ezhova | 1ec6e18 | 2013-12-24 17:45:59 +0400 | [diff] [blame] | 99 | |
| 100 | @test.attr(type='smoke') |
| 101 | def test_show_port_fields(self): |
| 102 | # Verify specific fields of a port |
Zhi Kun Liu | 903596c | 2014-04-11 08:55:53 -0500 | [diff] [blame] | 103 | fields = ['id', 'mac_address'] |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 104 | body = self.client.show_port(self.port['id'], |
| 105 | fields=fields) |
Elena Ezhova | 1ec6e18 | 2013-12-24 17:45:59 +0400 | [diff] [blame] | 106 | port = body['port'] |
Zhi Kun Liu | 903596c | 2014-04-11 08:55:53 -0500 | [diff] [blame] | 107 | self.assertEqual(sorted(port.keys()), sorted(fields)) |
| 108 | for field_name in fields: |
Elena Ezhova | 1ec6e18 | 2013-12-24 17:45:59 +0400 | [diff] [blame] | 109 | self.assertEqual(port[field_name], self.port[field_name]) |
| 110 | |
| 111 | @test.attr(type='smoke') |
| 112 | def test_list_ports(self): |
| 113 | # Verify the port exists in the list of all ports |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 114 | body = self.client.list_ports() |
Elena Ezhova | 1ec6e18 | 2013-12-24 17:45:59 +0400 | [diff] [blame] | 115 | ports = [port['id'] for port in body['ports'] |
| 116 | if port['id'] == self.port['id']] |
| 117 | self.assertNotEmpty(ports, "Created port not found in the list") |
| 118 | |
| 119 | @test.attr(type='smoke') |
| 120 | def test_port_list_filter_by_router_id(self): |
| 121 | # Create a router |
| 122 | network = self.create_network() |
| 123 | self.create_subnet(network) |
| 124 | router = self.create_router(data_utils.rand_name('router-')) |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 125 | port = self.client.create_port(network_id=network['id']) |
Elena Ezhova | 1ec6e18 | 2013-12-24 17:45:59 +0400 | [diff] [blame] | 126 | # Add router interface to port created above |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 127 | self.client.add_router_interface_with_port_id( |
Elena Ezhova | 1ec6e18 | 2013-12-24 17:45:59 +0400 | [diff] [blame] | 128 | router['id'], port['port']['id']) |
| 129 | self.addCleanup(self.client.remove_router_interface_with_port_id, |
| 130 | router['id'], port['port']['id']) |
| 131 | # List ports filtered by router_id |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 132 | port_list = self.client.list_ports(device_id=router['id']) |
Elena Ezhova | 1ec6e18 | 2013-12-24 17:45:59 +0400 | [diff] [blame] | 133 | ports = port_list['ports'] |
| 134 | self.assertEqual(len(ports), 1) |
| 135 | self.assertEqual(ports[0]['id'], port['port']['id']) |
| 136 | self.assertEqual(ports[0]['device_id'], router['id']) |
| 137 | |
| 138 | @test.attr(type='smoke') |
| 139 | def test_list_ports_fields(self): |
| 140 | # Verify specific fields of ports |
Zhi Kun Liu | 903596c | 2014-04-11 08:55:53 -0500 | [diff] [blame] | 141 | fields = ['id', 'mac_address'] |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 142 | body = self.client.list_ports(fields=fields) |
Elena Ezhova | 1ec6e18 | 2013-12-24 17:45:59 +0400 | [diff] [blame] | 143 | ports = body['ports'] |
| 144 | self.assertNotEmpty(ports, "Port list returned is empty") |
| 145 | # Asserting the fields returned are correct |
| 146 | for port in ports: |
Zhi Kun Liu | 903596c | 2014-04-11 08:55:53 -0500 | [diff] [blame] | 147 | self.assertEqual(sorted(fields), sorted(port.keys())) |
Elena Ezhova | 1ec6e18 | 2013-12-24 17:45:59 +0400 | [diff] [blame] | 148 | |
Dane LeBlanc | cbc4bc5 | 2014-03-19 16:03:23 -0400 | [diff] [blame] | 149 | @test.attr(type='smoke') |
Neeti Dahiya | de29177 | 2014-09-22 10:43:12 +0530 | [diff] [blame^] | 150 | def test_create_update_port_with_second_ip(self): |
Dane LeBlanc | cbc4bc5 | 2014-03-19 16:03:23 -0400 | [diff] [blame] | 151 | # Create a network with two subnets |
| 152 | network = self.create_network() |
| 153 | subnet_1 = self.create_subnet(network) |
| 154 | subnet_2 = self.create_subnet(network) |
| 155 | fixed_ip_1 = [{'subnet_id': subnet_1['id']}] |
| 156 | fixed_ip_2 = [{'subnet_id': subnet_2['id']}] |
| 157 | |
Dane LeBlanc | cbc4bc5 | 2014-03-19 16:03:23 -0400 | [diff] [blame] | 158 | fixed_ips = fixed_ip_1 + fixed_ip_2 |
Neeti Dahiya | de29177 | 2014-09-22 10:43:12 +0530 | [diff] [blame^] | 159 | |
| 160 | # Create a port with multiple IP addresses |
| 161 | port = self.create_port(network, |
| 162 | fixed_ips=fixed_ips) |
Dane LeBlanc | cbc4bc5 | 2014-03-19 16:03:23 -0400 | [diff] [blame] | 163 | self.assertEqual(2, len(port['fixed_ips'])) |
Neeti Dahiya | de29177 | 2014-09-22 10:43:12 +0530 | [diff] [blame^] | 164 | check_fixed_ips = [subnet_1['id'], subnet_2['id']] |
| 165 | for item in port['fixed_ips']: |
| 166 | self.assertIn(item['subnet_id'], check_fixed_ips) |
Dane LeBlanc | cbc4bc5 | 2014-03-19 16:03:23 -0400 | [diff] [blame] | 167 | |
| 168 | # Update the port to return to a single IP address |
| 169 | port = self.update_port(port, fixed_ips=fixed_ip_1) |
| 170 | self.assertEqual(1, len(port['fixed_ips'])) |
| 171 | |
Neeti Dahiya | de29177 | 2014-09-22 10:43:12 +0530 | [diff] [blame^] | 172 | # Update the port with a second IP address from second subnet |
| 173 | port = self.update_port(port, fixed_ips=fixed_ips) |
| 174 | self.assertEqual(2, len(port['fixed_ips'])) |
| 175 | |
Ashish Gupta | dba59f9 | 2014-07-16 02:24:45 -0700 | [diff] [blame] | 176 | def _update_port_with_security_groups(self, security_groups_names): |
Neeti Dahiya | de29177 | 2014-09-22 10:43:12 +0530 | [diff] [blame^] | 177 | subnet_1 = self.create_subnet(self.network) |
| 178 | fixed_ip_1 = [{'subnet_id': subnet_1['id']}] |
| 179 | |
Ashish Gupta | dba59f9 | 2014-07-16 02:24:45 -0700 | [diff] [blame] | 180 | security_groups_list = list() |
| 181 | for name in security_groups_names: |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 182 | group_create_body = self.client.create_security_group( |
Ashish Gupta | dba59f9 | 2014-07-16 02:24:45 -0700 | [diff] [blame] | 183 | name=name) |
| 184 | self.addCleanup(self.client.delete_security_group, |
| 185 | group_create_body['security_group']['id']) |
| 186 | security_groups_list.append(group_create_body['security_group'] |
| 187 | ['id']) |
| 188 | # Create a port |
Neeti Dahiya | de29177 | 2014-09-22 10:43:12 +0530 | [diff] [blame^] | 189 | sec_grp_name = data_utils.rand_name('secgroup') |
| 190 | security_group = self.client.create_security_group(name=sec_grp_name) |
| 191 | self.addCleanup(self.client.delete_security_group, |
| 192 | security_group['security_group']['id']) |
| 193 | post_body = { |
| 194 | "name": data_utils.rand_name('port-'), |
| 195 | "security_groups": [security_group['security_group']['id']], |
| 196 | "network_id": self.network['id'], |
| 197 | "admin_state_up": True, |
| 198 | "fixed_ips": fixed_ip_1} |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 199 | body = self.client.create_port(**post_body) |
Ashish Gupta | dba59f9 | 2014-07-16 02:24:45 -0700 | [diff] [blame] | 200 | self.addCleanup(self.client.delete_port, body['port']['id']) |
| 201 | port = body['port'] |
Neeti Dahiya | de29177 | 2014-09-22 10:43:12 +0530 | [diff] [blame^] | 202 | |
Ashish Gupta | dba59f9 | 2014-07-16 02:24:45 -0700 | [diff] [blame] | 203 | # Update the port with security groups |
Neeti Dahiya | de29177 | 2014-09-22 10:43:12 +0530 | [diff] [blame^] | 204 | subnet_2 = self.create_subnet(self.network) |
| 205 | fixed_ip_2 = [{'subnet_id': subnet_2['id']}] |
| 206 | update_body = {"name": data_utils.rand_name('port-'), |
| 207 | "admin_state_up": False, |
| 208 | "fixed_ips": fixed_ip_2, |
| 209 | "security_groups": security_groups_list} |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 210 | body = self.client.update_port(port['id'], **update_body) |
Ashish Gupta | dba59f9 | 2014-07-16 02:24:45 -0700 | [diff] [blame] | 211 | port_show = body['port'] |
Neeti Dahiya | de29177 | 2014-09-22 10:43:12 +0530 | [diff] [blame^] | 212 | # Verify the security groups and other attributes updated to port |
| 213 | exclude_keys = set(port_show).symmetric_difference(update_body) |
| 214 | exclude_keys.add('fixed_ips') |
| 215 | exclude_keys.add('security_groups') |
| 216 | self.assertThat(port_show, custom_matchers.MatchesDictExceptForKeys( |
| 217 | update_body, exclude_keys)) |
| 218 | self.assertEqual(fixed_ip_2[0]['subnet_id'], |
| 219 | port_show['fixed_ips'][0]['subnet_id']) |
| 220 | |
Ashish Gupta | dba59f9 | 2014-07-16 02:24:45 -0700 | [diff] [blame] | 221 | for security_group in security_groups_list: |
| 222 | self.assertIn(security_group, port_show['security_groups']) |
| 223 | |
| 224 | @test.attr(type='smoke') |
Neeti Dahiya | de29177 | 2014-09-22 10:43:12 +0530 | [diff] [blame^] | 225 | def test_update_port_with_security_group_and_extra_attributes(self): |
Ashish Gupta | dba59f9 | 2014-07-16 02:24:45 -0700 | [diff] [blame] | 226 | self._update_port_with_security_groups( |
| 227 | [data_utils.rand_name('secgroup')]) |
| 228 | |
| 229 | @test.attr(type='smoke') |
Neeti Dahiya | de29177 | 2014-09-22 10:43:12 +0530 | [diff] [blame^] | 230 | def test_update_port_with_two_security_groups_and_extra_attributes(self): |
Ashish Gupta | dba59f9 | 2014-07-16 02:24:45 -0700 | [diff] [blame] | 231 | self._update_port_with_security_groups( |
| 232 | [data_utils.rand_name('secgroup'), |
| 233 | data_utils.rand_name('secgroup')]) |
| 234 | |
Ashish Gupta | d42b6e1 | 2014-11-20 02:06:03 -0800 | [diff] [blame] | 235 | @test.attr(type='smoke') |
| 236 | def test_create_show_delete_port_user_defined_mac(self): |
| 237 | # Create a port for a legal mac |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 238 | body = self.client.create_port(network_id=self.network['id']) |
Ashish Gupta | d42b6e1 | 2014-11-20 02:06:03 -0800 | [diff] [blame] | 239 | old_port = body['port'] |
| 240 | free_mac_address = old_port['mac_address'] |
| 241 | self.client.delete_port(old_port['id']) |
| 242 | # Create a new port with user defined mac |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 243 | body = self.client.create_port(network_id=self.network['id'], |
| 244 | mac_address=free_mac_address) |
Ashish Gupta | d42b6e1 | 2014-11-20 02:06:03 -0800 | [diff] [blame] | 245 | self.addCleanup(self.client.delete_port, body['port']['id']) |
| 246 | port = body['port'] |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 247 | body = self.client.show_port(port['id']) |
Ashish Gupta | d42b6e1 | 2014-11-20 02:06:03 -0800 | [diff] [blame] | 248 | show_port = body['port'] |
| 249 | self.assertEqual(free_mac_address, |
| 250 | show_port['mac_address']) |
| 251 | |
Rajkumar Thiyagarajan | 0f562a8 | 2014-08-21 01:59:19 -0700 | [diff] [blame] | 252 | @test.attr(type='smoke') |
| 253 | def test_create_port_with_no_securitygroups(self): |
Salvatore | 18dd66e | 2014-12-31 00:13:57 +0100 | [diff] [blame] | 254 | network = self.create_network() |
| 255 | self.create_subnet(network) |
| 256 | port = self.create_port(network, security_groups=[]) |
Rajkumar Thiyagarajan | 0f562a8 | 2014-08-21 01:59:19 -0700 | [diff] [blame] | 257 | self.assertIsNotNone(port['security_groups']) |
| 258 | self.assertEmpty(port['security_groups']) |
| 259 | |
| 260 | @test.attr(type='smoke') |
| 261 | def test_update_port_with_no_securitygroups(self): |
Salvatore | 18dd66e | 2014-12-31 00:13:57 +0100 | [diff] [blame] | 262 | network = self.create_network() |
| 263 | self.create_subnet(network) |
| 264 | port = self.create_port(network) |
Rajkumar Thiyagarajan | 0f562a8 | 2014-08-21 01:59:19 -0700 | [diff] [blame] | 265 | # Verify that port is created with default security group |
| 266 | self.assertIsNotNone(port['security_groups']) |
| 267 | self.assertNotEmpty(port['security_groups']) |
| 268 | updated_port = self.update_port(port, security_groups=[]) |
| 269 | self.assertIsNotNone(updated_port['security_groups']) |
| 270 | self.assertEmpty(updated_port['security_groups']) |
| 271 | |
Elena Ezhova | 1ec6e18 | 2013-12-24 17:45:59 +0400 | [diff] [blame] | 272 | |
Elena Ezhova | 1ec6e18 | 2013-12-24 17:45:59 +0400 | [diff] [blame] | 273 | class PortsAdminExtendedAttrsTestJSON(base.BaseAdminNetworkTest): |
| 274 | _interface = 'json' |
| 275 | |
| 276 | @classmethod |
Andrea Frittoli | da4a245 | 2014-09-15 13:12:08 +0100 | [diff] [blame] | 277 | def resource_setup(cls): |
| 278 | super(PortsAdminExtendedAttrsTestJSON, cls).resource_setup() |
Elena Ezhova | 1ec6e18 | 2013-12-24 17:45:59 +0400 | [diff] [blame] | 279 | cls.identity_client = cls._get_identity_admin_client() |
| 280 | cls.tenant = cls.identity_client.get_tenant_by_name( |
| 281 | CONF.identity.tenant_name) |
| 282 | cls.network = cls.create_network() |
| 283 | cls.host_id = socket.gethostname() |
| 284 | |
| 285 | @test.attr(type='smoke') |
| 286 | def test_create_port_binding_ext_attr(self): |
| 287 | post_body = {"network_id": self.network['id'], |
| 288 | "binding:host_id": self.host_id} |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 289 | body = self.admin_client.create_port(**post_body) |
Elena Ezhova | 1ec6e18 | 2013-12-24 17:45:59 +0400 | [diff] [blame] | 290 | port = body['port'] |
| 291 | self.addCleanup(self.admin_client.delete_port, port['id']) |
| 292 | host_id = port['binding:host_id'] |
| 293 | self.assertIsNotNone(host_id) |
| 294 | self.assertEqual(self.host_id, host_id) |
| 295 | |
| 296 | @test.attr(type='smoke') |
| 297 | def test_update_port_binding_ext_attr(self): |
| 298 | post_body = {"network_id": self.network['id']} |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 299 | body = self.admin_client.create_port(**post_body) |
Elena Ezhova | 1ec6e18 | 2013-12-24 17:45:59 +0400 | [diff] [blame] | 300 | port = body['port'] |
| 301 | self.addCleanup(self.admin_client.delete_port, port['id']) |
| 302 | update_body = {"binding:host_id": self.host_id} |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 303 | body = self.admin_client.update_port(port['id'], **update_body) |
Elena Ezhova | 1ec6e18 | 2013-12-24 17:45:59 +0400 | [diff] [blame] | 304 | updated_port = body['port'] |
| 305 | host_id = updated_port['binding:host_id'] |
| 306 | self.assertIsNotNone(host_id) |
| 307 | self.assertEqual(self.host_id, host_id) |
| 308 | |
| 309 | @test.attr(type='smoke') |
| 310 | def test_list_ports_binding_ext_attr(self): |
Adam Gandelman | 7e80e4e | 2014-04-03 00:38:26 -0700 | [diff] [blame] | 311 | # Create a new port |
| 312 | post_body = {"network_id": self.network['id']} |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 313 | body = self.admin_client.create_port(**post_body) |
Adam Gandelman | 7e80e4e | 2014-04-03 00:38:26 -0700 | [diff] [blame] | 314 | port = body['port'] |
| 315 | self.addCleanup(self.admin_client.delete_port, port['id']) |
| 316 | |
| 317 | # Update the port's binding attributes so that is now 'bound' |
| 318 | # to a host |
| 319 | update_body = {"binding:host_id": self.host_id} |
Rohan Kanade | eeb2164 | 2014-08-14 12:00:26 +0200 | [diff] [blame] | 320 | self.admin_client.update_port(port['id'], **update_body) |
Adam Gandelman | 7e80e4e | 2014-04-03 00:38:26 -0700 | [diff] [blame] | 321 | |
| 322 | # List all ports, ensure new port is part of list and its binding |
| 323 | # attributes are set and accurate |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 324 | body = self.admin_client.list_ports() |
Elena Ezhova | 1ec6e18 | 2013-12-24 17:45:59 +0400 | [diff] [blame] | 325 | ports_list = body['ports'] |
Adam Gandelman | 7e80e4e | 2014-04-03 00:38:26 -0700 | [diff] [blame] | 326 | pids_list = [p['id'] for p in ports_list] |
| 327 | self.assertIn(port['id'], pids_list) |
| 328 | listed_port = [p for p in ports_list if p['id'] == port['id']] |
| 329 | self.assertEqual(1, len(listed_port), |
| 330 | 'Multiple ports listed with id %s in ports listing: ' |
| 331 | '%s' % (port['id'], ports_list)) |
| 332 | self.assertEqual(self.host_id, listed_port[0]['binding:host_id']) |
Elena Ezhova | 1ec6e18 | 2013-12-24 17:45:59 +0400 | [diff] [blame] | 333 | |
| 334 | @test.attr(type='smoke') |
| 335 | def test_show_port_binding_ext_attr(self): |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 336 | body = self.admin_client.create_port(network_id=self.network['id']) |
Elena Ezhova | 1ec6e18 | 2013-12-24 17:45:59 +0400 | [diff] [blame] | 337 | port = body['port'] |
| 338 | self.addCleanup(self.admin_client.delete_port, port['id']) |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 339 | body = self.admin_client.show_port(port['id']) |
Elena Ezhova | 1ec6e18 | 2013-12-24 17:45:59 +0400 | [diff] [blame] | 340 | show_port = body['port'] |
| 341 | self.assertEqual(port['binding:host_id'], |
| 342 | show_port['binding:host_id']) |
| 343 | self.assertEqual(port['binding:vif_type'], |
| 344 | show_port['binding:vif_type']) |
| 345 | self.assertEqual(port['binding:vif_details'], |
| 346 | show_port['binding:vif_details']) |
| 347 | |
| 348 | |
Elena Ezhova | 1ec6e18 | 2013-12-24 17:45:59 +0400 | [diff] [blame] | 349 | class PortsIpV6TestJSON(PortsTestJSON): |
| 350 | _ip_version = 6 |
| 351 | _tenant_network_cidr = CONF.network.tenant_network_v6_cidr |
| 352 | _tenant_network_mask_bits = CONF.network.tenant_network_v6_mask_bits |
| 353 | |
Elena Ezhova | 1ec6e18 | 2013-12-24 17:45:59 +0400 | [diff] [blame] | 354 | |
Elena Ezhova | 1ec6e18 | 2013-12-24 17:45:59 +0400 | [diff] [blame] | 355 | class PortsAdminExtendedAttrsIpV6TestJSON(PortsAdminExtendedAttrsTestJSON): |
| 356 | _ip_version = 6 |
| 357 | _tenant_network_cidr = CONF.network.tenant_network_v6_cidr |
| 358 | _tenant_network_mask_bits = CONF.network.tenant_network_v6_mask_bits |