blob: 4f5456266d37efc4972b7779dde13609650fc67b [file] [log] [blame]
Elena Ezhova1ec6e182013-12-24 17:45:59 +04001# 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
16import socket
17
Matthew Treinish01472ff2015-02-20 17:26:52 -050018import netaddr
Matthew Treinish01472ff2015-02-20 17:26:52 -050019
Elena Ezhova1ec6e182013-12-24 17:45:59 +040020from tempest.api.network import base
Neeti Dahiyade291772014-09-22 10:43:12 +053021from tempest.api.network import base_security_groups as sec_base
Santosh Kumarf0cbf9a2014-08-25 07:31:15 -070022from tempest.common import custom_matchers
Fei Long Wangd39431f2015-05-14 11:30:48 +120023from tempest.common.utils import data_utils
Elena Ezhova1ec6e182013-12-24 17:45:59 +040024from tempest import config
25from tempest import test
26
27CONF = config.CONF
28
29
Neeti Dahiyade291772014-09-22 10:43:12 +053030class PortsTestJSON(sec_base.BaseSecGroupTest):
Elena Ezhova5c957152014-03-26 12:01:10 +040031 """
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 Ezhova1ec6e182013-12-24 17:45:59 +040041 @classmethod
Andrea Frittolida4a2452014-09-15 13:12:08 +010042 def resource_setup(cls):
43 super(PortsTestJSON, cls).resource_setup()
Elena Ezhova1ec6e182013-12-24 17:45:59 +040044 cls.network = cls.create_network()
45 cls.port = cls.create_port(cls.network)
46
47 def _delete_port(self, port_id):
Rohan Kanadeeeb21642014-08-14 12:00:26 +020048 self.client.delete_port(port_id)
David Kranz34e88122014-12-11 15:24:05 -050049 body = self.client.list_ports()
Elena Ezhova1ec6e182013-12-24 17:45:59 +040050 ports_list = body['ports']
51 self.assertFalse(port_id in [n['id'] for n in ports_list])
52
53 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -080054 @test.idempotent_id('c72c1c0c-2193-4aca-aaa4-b1442640f51c')
Elena Ezhova1ec6e182013-12-24 17:45:59 +040055 def test_create_update_delete_port(self):
56 # Verify port creation
David Kranz34e88122014-12-11 15:24:05 -050057 body = self.client.create_port(network_id=self.network['id'])
Elena Ezhova1ec6e182013-12-24 17:45:59 +040058 port = body['port']
Dane LeBlanccbc4bc52014-03-19 16:03:23 -040059 # Schedule port deletion with verification upon test completion
60 self.addCleanup(self._delete_port, port['id'])
Elena Ezhova1ec6e182013-12-24 17:45:59 +040061 self.assertTrue(port['admin_state_up'])
62 # Verify port update
63 new_name = "New_Port"
David Kranz34e88122014-12-11 15:24:05 -050064 body = self.client.update_port(port['id'],
65 name=new_name,
66 admin_state_up=False)
Elena Ezhova1ec6e182013-12-24 17:45:59 +040067 updated_port = body['port']
68 self.assertEqual(updated_port['name'], new_name)
69 self.assertFalse(updated_port['admin_state_up'])
Elena Ezhova1ec6e182013-12-24 17:45:59 +040070
Chris Hoge7579c1a2015-02-26 14:12:15 -080071 @test.idempotent_id('67f1b811-f8db-43e2-86bd-72c074d4a42c')
abhishek6001472607373102014-11-25 04:39:20 -080072 def test_create_bulk_port(self):
73 network1 = self.network
74 name = data_utils.rand_name('network-')
75 network2 = self.create_network(network_name=name)
76 network_list = [network1['id'], network2['id']]
77 port_list = [{'network_id': net_id} for net_id in network_list]
David Kranz34e88122014-12-11 15:24:05 -050078 body = self.client.create_bulk_port(port_list)
abhishek6001472607373102014-11-25 04:39:20 -080079 created_ports = body['ports']
80 port1 = created_ports[0]
81 port2 = created_ports[1]
82 self.addCleanup(self._delete_port, port1['id'])
83 self.addCleanup(self._delete_port, port2['id'])
84 self.assertEqual(port1['network_id'], network1['id'])
85 self.assertEqual(port2['network_id'], network2['id'])
86 self.assertTrue(port1['admin_state_up'])
87 self.assertTrue(port2['admin_state_up'])
88
abhishek60014726de45a5e2014-12-16 03:01:35 -080089 @classmethod
90 def _get_ipaddress_from_tempest_conf(cls):
91 """Return first subnet gateway for configured CIDR """
92 if cls._ip_version == 4:
93 cidr = netaddr.IPNetwork(CONF.network.tenant_network_cidr)
94
95 elif cls._ip_version == 6:
96 cidr = netaddr.IPNetwork(CONF.network.tenant_network_v6_cidr)
97
98 return netaddr.IPAddress(cidr)
99
100 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800101 @test.idempotent_id('0435f278-40ae-48cb-a404-b8a087bc09b1')
abhishek60014726de45a5e2014-12-16 03:01:35 -0800102 def test_create_port_in_allowed_allocation_pools(self):
103 network = self.create_network()
104 net_id = network['id']
105 address = self._get_ipaddress_from_tempest_conf()
106 allocation_pools = {'allocation_pools': [{'start': str(address + 4),
107 'end': str(address + 6)}]}
Adam Gandelmane8650042015-01-16 11:36:37 -0800108 subnet = self.create_subnet(network, **allocation_pools)
109 self.addCleanup(self.client.delete_subnet, subnet['id'])
abhishek60014726de45a5e2014-12-16 03:01:35 -0800110 body = self.client.create_port(network_id=net_id)
111 self.addCleanup(self.client.delete_port, body['port']['id'])
112 port = body['port']
113 ip_address = port['fixed_ips'][0]['ip_address']
114 start_ip_address = allocation_pools['allocation_pools'][0]['start']
115 end_ip_address = allocation_pools['allocation_pools'][0]['end']
116 ip_range = netaddr.IPRange(start_ip_address, end_ip_address)
117 self.assertIn(ip_address, ip_range)
118
Elena Ezhova1ec6e182013-12-24 17:45:59 +0400119 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800120 @test.idempotent_id('c9a685bd-e83f-499c-939f-9f7863ca259f')
Elena Ezhova1ec6e182013-12-24 17:45:59 +0400121 def test_show_port(self):
122 # Verify the details of port
David Kranz34e88122014-12-11 15:24:05 -0500123 body = self.client.show_port(self.port['id'])
Elena Ezhova1ec6e182013-12-24 17:45:59 +0400124 port = body['port']
125 self.assertIn('id', port)
Santosh Kumarf0cbf9a2014-08-25 07:31:15 -0700126 # TODO(Santosh)- This is a temporary workaround to compare create_port
127 # and show_port dict elements.Remove this once extra_dhcp_opts issue
128 # gets fixed in neutron.( bug - 1365341.)
129 self.assertThat(self.port,
130 custom_matchers.MatchesDictExceptForKeys
131 (port, excluded_keys=['extra_dhcp_opts']))
Elena Ezhova1ec6e182013-12-24 17:45:59 +0400132
Chris Hoge7579c1a2015-02-26 14:12:15 -0800133 @test.idempotent_id('45fcdaf2-dab0-4c13-ac6c-fcddfb579dbd')
Elena Ezhova1ec6e182013-12-24 17:45:59 +0400134 def test_show_port_fields(self):
135 # Verify specific fields of a port
Zhi Kun Liu903596c2014-04-11 08:55:53 -0500136 fields = ['id', 'mac_address']
David Kranz34e88122014-12-11 15:24:05 -0500137 body = self.client.show_port(self.port['id'],
138 fields=fields)
Elena Ezhova1ec6e182013-12-24 17:45:59 +0400139 port = body['port']
Zhi Kun Liu903596c2014-04-11 08:55:53 -0500140 self.assertEqual(sorted(port.keys()), sorted(fields))
141 for field_name in fields:
Elena Ezhova1ec6e182013-12-24 17:45:59 +0400142 self.assertEqual(port[field_name], self.port[field_name])
143
144 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800145 @test.idempotent_id('cf95b358-3e92-4a29-a148-52445e1ac50e')
Elena Ezhova1ec6e182013-12-24 17:45:59 +0400146 def test_list_ports(self):
147 # Verify the port exists in the list of all ports
David Kranz34e88122014-12-11 15:24:05 -0500148 body = self.client.list_ports()
Elena Ezhova1ec6e182013-12-24 17:45:59 +0400149 ports = [port['id'] for port in body['ports']
150 if port['id'] == self.port['id']]
151 self.assertNotEmpty(ports, "Created port not found in the list")
152
Arx Cruze8dfad92015-05-29 09:57:14 +0200153 @test.idempotent_id('e7fe260b-1e79-4dd3-86d9-bec6a7959fc5')
154 def test_port_list_filter_by_ip(self):
155 # Create network and subnet
156 network = self.create_network()
157 subnet = self.create_subnet(network)
158 self.addCleanup(self.client.delete_subnet, subnet['id'])
159 # Create two ports specifying a fixed_ips
160 address = self._get_ipaddress_from_tempest_conf()
161 _fixed_ip_1 = str(address + 3)
162 _fixed_ip_2 = str(address + 4)
163 fixed_ips_1 = [{'ip_address': _fixed_ip_1}]
164 port_1 = self.client.create_port(network_id=network['id'],
165 fixed_ips=fixed_ips_1)
166 self.addCleanup(self.client.delete_port, port_1['port']['id'])
167 fixed_ips_2 = [{'ip_address': _fixed_ip_2}]
168 port_2 = self.client.create_port(network_id=network['id'],
169 fixed_ips=fixed_ips_2)
170 self.addCleanup(self.client.delete_port, port_2['port']['id'])
171 # List ports filtered by fixed_ips
172 fixed_ips = 'ip_address=' + _fixed_ip_1
173 port_list = self.client.list_ports(fixed_ips=fixed_ips)
174 ports = port_list['ports']
175 self.assertEqual(len(ports), 1)
176 self.assertEqual(ports[0]['id'], port_1['port']['id'])
177 self.assertEqual(ports[0]['fixed_ips'][0]['ip_address'],
178 _fixed_ip_1)
179 self.assertEqual(ports[0]['network_id'], network['id'])
180
Chris Hoge7579c1a2015-02-26 14:12:15 -0800181 @test.idempotent_id('5ad01ed0-0e6e-4c5d-8194-232801b15c72')
Elena Ezhova1ec6e182013-12-24 17:45:59 +0400182 def test_port_list_filter_by_router_id(self):
183 # Create a router
184 network = self.create_network()
Adam Gandelmane8650042015-01-16 11:36:37 -0800185 self.addCleanup(self.client.delete_network, network['id'])
186 subnet = self.create_subnet(network)
187 self.addCleanup(self.client.delete_subnet, subnet['id'])
Elena Ezhova1ec6e182013-12-24 17:45:59 +0400188 router = self.create_router(data_utils.rand_name('router-'))
Adam Gandelmane8650042015-01-16 11:36:37 -0800189 self.addCleanup(self.client.delete_router, router['id'])
David Kranz34e88122014-12-11 15:24:05 -0500190 port = self.client.create_port(network_id=network['id'])
Elena Ezhova1ec6e182013-12-24 17:45:59 +0400191 # Add router interface to port created above
David Kranz34e88122014-12-11 15:24:05 -0500192 self.client.add_router_interface_with_port_id(
Elena Ezhova1ec6e182013-12-24 17:45:59 +0400193 router['id'], port['port']['id'])
194 self.addCleanup(self.client.remove_router_interface_with_port_id,
195 router['id'], port['port']['id'])
196 # List ports filtered by router_id
David Kranz34e88122014-12-11 15:24:05 -0500197 port_list = self.client.list_ports(device_id=router['id'])
Elena Ezhova1ec6e182013-12-24 17:45:59 +0400198 ports = port_list['ports']
199 self.assertEqual(len(ports), 1)
200 self.assertEqual(ports[0]['id'], port['port']['id'])
201 self.assertEqual(ports[0]['device_id'], router['id'])
202
Chris Hoge7579c1a2015-02-26 14:12:15 -0800203 @test.idempotent_id('ff7f117f-f034-4e0e-abff-ccef05c454b4')
Elena Ezhova1ec6e182013-12-24 17:45:59 +0400204 def test_list_ports_fields(self):
205 # Verify specific fields of ports
Zhi Kun Liu903596c2014-04-11 08:55:53 -0500206 fields = ['id', 'mac_address']
David Kranz34e88122014-12-11 15:24:05 -0500207 body = self.client.list_ports(fields=fields)
Elena Ezhova1ec6e182013-12-24 17:45:59 +0400208 ports = body['ports']
209 self.assertNotEmpty(ports, "Port list returned is empty")
210 # Asserting the fields returned are correct
211 for port in ports:
Zhi Kun Liu903596c2014-04-11 08:55:53 -0500212 self.assertEqual(sorted(fields), sorted(port.keys()))
Elena Ezhova1ec6e182013-12-24 17:45:59 +0400213
Chris Hoge7579c1a2015-02-26 14:12:15 -0800214 @test.idempotent_id('63aeadd4-3b49-427f-a3b1-19ca81f06270')
Neeti Dahiyade291772014-09-22 10:43:12 +0530215 def test_create_update_port_with_second_ip(self):
Dane LeBlanccbc4bc52014-03-19 16:03:23 -0400216 # Create a network with two subnets
217 network = self.create_network()
Adam Gandelmane8650042015-01-16 11:36:37 -0800218 self.addCleanup(self.client.delete_network, network['id'])
Dane LeBlanccbc4bc52014-03-19 16:03:23 -0400219 subnet_1 = self.create_subnet(network)
Adam Gandelmane8650042015-01-16 11:36:37 -0800220 self.addCleanup(self.client.delete_subnet, subnet_1['id'])
Dane LeBlanccbc4bc52014-03-19 16:03:23 -0400221 subnet_2 = self.create_subnet(network)
Adam Gandelmane8650042015-01-16 11:36:37 -0800222 self.addCleanup(self.client.delete_subnet, subnet_2['id'])
Dane LeBlanccbc4bc52014-03-19 16:03:23 -0400223 fixed_ip_1 = [{'subnet_id': subnet_1['id']}]
224 fixed_ip_2 = [{'subnet_id': subnet_2['id']}]
225
Dane LeBlanccbc4bc52014-03-19 16:03:23 -0400226 fixed_ips = fixed_ip_1 + fixed_ip_2
Neeti Dahiyade291772014-09-22 10:43:12 +0530227
228 # Create a port with multiple IP addresses
229 port = self.create_port(network,
230 fixed_ips=fixed_ips)
Adam Gandelmane8650042015-01-16 11:36:37 -0800231 self.addCleanup(self.client.delete_port, port['id'])
Dane LeBlanccbc4bc52014-03-19 16:03:23 -0400232 self.assertEqual(2, len(port['fixed_ips']))
Neeti Dahiyade291772014-09-22 10:43:12 +0530233 check_fixed_ips = [subnet_1['id'], subnet_2['id']]
234 for item in port['fixed_ips']:
235 self.assertIn(item['subnet_id'], check_fixed_ips)
Dane LeBlanccbc4bc52014-03-19 16:03:23 -0400236
237 # Update the port to return to a single IP address
238 port = self.update_port(port, fixed_ips=fixed_ip_1)
239 self.assertEqual(1, len(port['fixed_ips']))
240
Neeti Dahiyade291772014-09-22 10:43:12 +0530241 # Update the port with a second IP address from second subnet
242 port = self.update_port(port, fixed_ips=fixed_ips)
243 self.assertEqual(2, len(port['fixed_ips']))
244
Ashish Guptadba59f92014-07-16 02:24:45 -0700245 def _update_port_with_security_groups(self, security_groups_names):
Neeti Dahiyade291772014-09-22 10:43:12 +0530246 subnet_1 = self.create_subnet(self.network)
Adam Gandelmane8650042015-01-16 11:36:37 -0800247 self.addCleanup(self.client.delete_subnet, subnet_1['id'])
Neeti Dahiyade291772014-09-22 10:43:12 +0530248 fixed_ip_1 = [{'subnet_id': subnet_1['id']}]
249
Ashish Guptadba59f92014-07-16 02:24:45 -0700250 security_groups_list = list()
251 for name in security_groups_names:
David Kranz34e88122014-12-11 15:24:05 -0500252 group_create_body = self.client.create_security_group(
Ashish Guptadba59f92014-07-16 02:24:45 -0700253 name=name)
254 self.addCleanup(self.client.delete_security_group,
255 group_create_body['security_group']['id'])
256 security_groups_list.append(group_create_body['security_group']
257 ['id'])
258 # Create a port
Neeti Dahiyade291772014-09-22 10:43:12 +0530259 sec_grp_name = data_utils.rand_name('secgroup')
260 security_group = self.client.create_security_group(name=sec_grp_name)
261 self.addCleanup(self.client.delete_security_group,
262 security_group['security_group']['id'])
263 post_body = {
264 "name": data_utils.rand_name('port-'),
265 "security_groups": [security_group['security_group']['id']],
266 "network_id": self.network['id'],
267 "admin_state_up": True,
268 "fixed_ips": fixed_ip_1}
David Kranz34e88122014-12-11 15:24:05 -0500269 body = self.client.create_port(**post_body)
Ashish Guptadba59f92014-07-16 02:24:45 -0700270 self.addCleanup(self.client.delete_port, body['port']['id'])
271 port = body['port']
Neeti Dahiyade291772014-09-22 10:43:12 +0530272
Ashish Guptadba59f92014-07-16 02:24:45 -0700273 # Update the port with security groups
Neeti Dahiyade291772014-09-22 10:43:12 +0530274 subnet_2 = self.create_subnet(self.network)
275 fixed_ip_2 = [{'subnet_id': subnet_2['id']}]
276 update_body = {"name": data_utils.rand_name('port-'),
277 "admin_state_up": False,
278 "fixed_ips": fixed_ip_2,
279 "security_groups": security_groups_list}
David Kranz34e88122014-12-11 15:24:05 -0500280 body = self.client.update_port(port['id'], **update_body)
Ashish Guptadba59f92014-07-16 02:24:45 -0700281 port_show = body['port']
Neeti Dahiyade291772014-09-22 10:43:12 +0530282 # Verify the security groups and other attributes updated to port
283 exclude_keys = set(port_show).symmetric_difference(update_body)
284 exclude_keys.add('fixed_ips')
285 exclude_keys.add('security_groups')
286 self.assertThat(port_show, custom_matchers.MatchesDictExceptForKeys(
287 update_body, exclude_keys))
288 self.assertEqual(fixed_ip_2[0]['subnet_id'],
289 port_show['fixed_ips'][0]['subnet_id'])
290
Ashish Guptadba59f92014-07-16 02:24:45 -0700291 for security_group in security_groups_list:
292 self.assertIn(security_group, port_show['security_groups'])
293
Chris Hoge7579c1a2015-02-26 14:12:15 -0800294 @test.idempotent_id('58091b66-4ff4-4cc1-a549-05d60c7acd1a')
Neeti Dahiyade291772014-09-22 10:43:12 +0530295 def test_update_port_with_security_group_and_extra_attributes(self):
Ashish Guptadba59f92014-07-16 02:24:45 -0700296 self._update_port_with_security_groups(
297 [data_utils.rand_name('secgroup')])
298
Chris Hoge7579c1a2015-02-26 14:12:15 -0800299 @test.idempotent_id('edf6766d-3d40-4621-bc6e-2521a44c257d')
Neeti Dahiyade291772014-09-22 10:43:12 +0530300 def test_update_port_with_two_security_groups_and_extra_attributes(self):
Ashish Guptadba59f92014-07-16 02:24:45 -0700301 self._update_port_with_security_groups(
302 [data_utils.rand_name('secgroup'),
303 data_utils.rand_name('secgroup')])
304
Chris Hoge7579c1a2015-02-26 14:12:15 -0800305 @test.idempotent_id('13e95171-6cbd-489c-9d7c-3f9c58215c18')
Ashish Guptad42b6e12014-11-20 02:06:03 -0800306 def test_create_show_delete_port_user_defined_mac(self):
307 # Create a port for a legal mac
David Kranz34e88122014-12-11 15:24:05 -0500308 body = self.client.create_port(network_id=self.network['id'])
Ashish Guptad42b6e12014-11-20 02:06:03 -0800309 old_port = body['port']
310 free_mac_address = old_port['mac_address']
311 self.client.delete_port(old_port['id'])
312 # Create a new port with user defined mac
David Kranz34e88122014-12-11 15:24:05 -0500313 body = self.client.create_port(network_id=self.network['id'],
314 mac_address=free_mac_address)
Ashish Guptad42b6e12014-11-20 02:06:03 -0800315 self.addCleanup(self.client.delete_port, body['port']['id'])
316 port = body['port']
David Kranz34e88122014-12-11 15:24:05 -0500317 body = self.client.show_port(port['id'])
Ashish Guptad42b6e12014-11-20 02:06:03 -0800318 show_port = body['port']
319 self.assertEqual(free_mac_address,
320 show_port['mac_address'])
321
Rajkumar Thiyagarajan0f562a82014-08-21 01:59:19 -0700322 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800323 @test.idempotent_id('4179dcb9-1382-4ced-84fe-1b91c54f5735')
Rajkumar Thiyagarajan0f562a82014-08-21 01:59:19 -0700324 def test_create_port_with_no_securitygroups(self):
Salvatore18dd66e2014-12-31 00:13:57 +0100325 network = self.create_network()
Adam Gandelmane8650042015-01-16 11:36:37 -0800326 self.addCleanup(self.client.delete_network, network['id'])
327 subnet = self.create_subnet(network)
328 self.addCleanup(self.client.delete_subnet, subnet['id'])
Salvatore18dd66e2014-12-31 00:13:57 +0100329 port = self.create_port(network, security_groups=[])
Adam Gandelmane8650042015-01-16 11:36:37 -0800330 self.addCleanup(self.client.delete_port, port['id'])
Rajkumar Thiyagarajan0f562a82014-08-21 01:59:19 -0700331 self.assertIsNotNone(port['security_groups'])
332 self.assertEmpty(port['security_groups'])
333
Elena Ezhova1ec6e182013-12-24 17:45:59 +0400334
Elena Ezhova1ec6e182013-12-24 17:45:59 +0400335class PortsAdminExtendedAttrsTestJSON(base.BaseAdminNetworkTest):
Elena Ezhova1ec6e182013-12-24 17:45:59 +0400336
337 @classmethod
Rohan Kanadea565e452015-01-27 14:00:13 +0530338 def setup_clients(cls):
339 super(PortsAdminExtendedAttrsTestJSON, cls).setup_clients()
340 cls.identity_client = cls.os_adm.identity_client
341
342 @classmethod
Andrea Frittolida4a2452014-09-15 13:12:08 +0100343 def resource_setup(cls):
344 super(PortsAdminExtendedAttrsTestJSON, cls).resource_setup()
Elena Ezhova1ec6e182013-12-24 17:45:59 +0400345 cls.network = cls.create_network()
346 cls.host_id = socket.gethostname()
347
Chris Hoge7579c1a2015-02-26 14:12:15 -0800348 @test.idempotent_id('8e8569c1-9ac7-44db-8bc1-f5fb2814f29b')
Elena Ezhova1ec6e182013-12-24 17:45:59 +0400349 def test_create_port_binding_ext_attr(self):
350 post_body = {"network_id": self.network['id'],
351 "binding:host_id": self.host_id}
David Kranz34e88122014-12-11 15:24:05 -0500352 body = self.admin_client.create_port(**post_body)
Elena Ezhova1ec6e182013-12-24 17:45:59 +0400353 port = body['port']
354 self.addCleanup(self.admin_client.delete_port, port['id'])
355 host_id = port['binding:host_id']
356 self.assertIsNotNone(host_id)
357 self.assertEqual(self.host_id, host_id)
358
Chris Hoge7579c1a2015-02-26 14:12:15 -0800359 @test.idempotent_id('6f6c412c-711f-444d-8502-0ac30fbf5dd5')
Elena Ezhova1ec6e182013-12-24 17:45:59 +0400360 def test_update_port_binding_ext_attr(self):
361 post_body = {"network_id": self.network['id']}
David Kranz34e88122014-12-11 15:24:05 -0500362 body = self.admin_client.create_port(**post_body)
Elena Ezhova1ec6e182013-12-24 17:45:59 +0400363 port = body['port']
364 self.addCleanup(self.admin_client.delete_port, port['id'])
365 update_body = {"binding:host_id": self.host_id}
David Kranz34e88122014-12-11 15:24:05 -0500366 body = self.admin_client.update_port(port['id'], **update_body)
Elena Ezhova1ec6e182013-12-24 17:45:59 +0400367 updated_port = body['port']
368 host_id = updated_port['binding:host_id']
369 self.assertIsNotNone(host_id)
370 self.assertEqual(self.host_id, host_id)
371
Chris Hoge7579c1a2015-02-26 14:12:15 -0800372 @test.idempotent_id('1c82a44a-6c6e-48ff-89e1-abe7eaf8f9f8')
Elena Ezhova1ec6e182013-12-24 17:45:59 +0400373 def test_list_ports_binding_ext_attr(self):
Adam Gandelman7e80e4e2014-04-03 00:38:26 -0700374 # Create a new port
375 post_body = {"network_id": self.network['id']}
David Kranz34e88122014-12-11 15:24:05 -0500376 body = self.admin_client.create_port(**post_body)
Adam Gandelman7e80e4e2014-04-03 00:38:26 -0700377 port = body['port']
378 self.addCleanup(self.admin_client.delete_port, port['id'])
379
380 # Update the port's binding attributes so that is now 'bound'
381 # to a host
382 update_body = {"binding:host_id": self.host_id}
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200383 self.admin_client.update_port(port['id'], **update_body)
Adam Gandelman7e80e4e2014-04-03 00:38:26 -0700384
385 # List all ports, ensure new port is part of list and its binding
386 # attributes are set and accurate
David Kranz34e88122014-12-11 15:24:05 -0500387 body = self.admin_client.list_ports()
Elena Ezhova1ec6e182013-12-24 17:45:59 +0400388 ports_list = body['ports']
Adam Gandelman7e80e4e2014-04-03 00:38:26 -0700389 pids_list = [p['id'] for p in ports_list]
390 self.assertIn(port['id'], pids_list)
391 listed_port = [p for p in ports_list if p['id'] == port['id']]
392 self.assertEqual(1, len(listed_port),
393 'Multiple ports listed with id %s in ports listing: '
394 '%s' % (port['id'], ports_list))
395 self.assertEqual(self.host_id, listed_port[0]['binding:host_id'])
Elena Ezhova1ec6e182013-12-24 17:45:59 +0400396
Chris Hoge7579c1a2015-02-26 14:12:15 -0800397 @test.idempotent_id('b54ac0ff-35fc-4c79-9ca3-c7dbd4ea4f13')
Elena Ezhova1ec6e182013-12-24 17:45:59 +0400398 def test_show_port_binding_ext_attr(self):
David Kranz34e88122014-12-11 15:24:05 -0500399 body = self.admin_client.create_port(network_id=self.network['id'])
Elena Ezhova1ec6e182013-12-24 17:45:59 +0400400 port = body['port']
401 self.addCleanup(self.admin_client.delete_port, port['id'])
David Kranz34e88122014-12-11 15:24:05 -0500402 body = self.admin_client.show_port(port['id'])
Elena Ezhova1ec6e182013-12-24 17:45:59 +0400403 show_port = body['port']
404 self.assertEqual(port['binding:host_id'],
405 show_port['binding:host_id'])
406 self.assertEqual(port['binding:vif_type'],
407 show_port['binding:vif_type'])
408 self.assertEqual(port['binding:vif_details'],
409 show_port['binding:vif_details'])
410
411
Elena Ezhova1ec6e182013-12-24 17:45:59 +0400412class PortsIpV6TestJSON(PortsTestJSON):
413 _ip_version = 6
414 _tenant_network_cidr = CONF.network.tenant_network_v6_cidr
415 _tenant_network_mask_bits = CONF.network.tenant_network_v6_mask_bits
416
Elena Ezhova1ec6e182013-12-24 17:45:59 +0400417
Elena Ezhova1ec6e182013-12-24 17:45:59 +0400418class PortsAdminExtendedAttrsIpV6TestJSON(PortsAdminExtendedAttrsTestJSON):
419 _ip_version = 6
420 _tenant_network_cidr = CONF.network.tenant_network_v6_cidr
421 _tenant_network_mask_bits = CONF.network.tenant_network_v6_mask_bits