blob: df8da074636384255b42bb109b51237004415e16 [file] [log] [blame]
Dan Smith8ad1c472013-02-26 13:03:16 -05001# Copyright 2013 IBM Corp.
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
Rohan Kanade9ce97df2013-12-10 18:59:35 +053016import time
17
Slawek Kaplonskib3daeb42019-06-29 23:49:59 +020018from oslo_log import log
junbolibc2ae862017-07-29 15:46:48 +080019import six
20
Sean Dague1937d092013-05-17 16:36:38 -040021from tempest.api.compute import base
Matt Riedemanna8c641a2016-07-12 17:07:33 -040022from tempest.common import compute
Andrea Frittolicd368412017-08-14 21:37:56 +010023from tempest.common import utils
Ryan Tidwell1964a262016-05-04 15:13:23 -070024from tempest.common.utils import net_utils
Matt Riedemanna8c641a2016-07-12 17:07:33 -040025from tempest.common import waiters
Matthew Treinishb0a78fc2014-01-29 16:49:12 +000026from tempest import config
Doug Schveninger24675aa2019-08-16 22:28:39 -050027from tempest.lib.common.utils import data_utils
Lucas Alvares Gomes692422b2018-10-10 10:33:45 +010028from tempest.lib.common.utils.linux import remote_client
Matt Riedemannd4cb10f2018-09-26 13:03:08 -040029from tempest.lib.common.utils import test_utils
Matt Riedemann3570c1e2016-07-29 12:15:38 -040030from tempest.lib import decorators
Andrea Frittoli (andreaf)db9672e2016-02-23 14:07:24 -050031from tempest.lib import exceptions as lib_exc
Dan Smith8ad1c472013-02-26 13:03:16 -050032
Matthew Treinishb0a78fc2014-01-29 16:49:12 +000033CONF = config.CONF
34
Slawek Kaplonskib3daeb42019-06-29 23:49:59 +020035LOG = log.getLogger(__name__)
36
Dan Smith8ad1c472013-02-26 13:03:16 -050037
zhufl615e63b2018-08-01 17:23:38 +080038class AttachInterfacesTestBase(base.BaseV2ComputeTest):
Dan Smith8ad1c472013-02-26 13:03:16 -050039
40 @classmethod
Emily Hugenbruche7991d92014-12-12 16:53:36 +000041 def skip_checks(cls):
zhufl615e63b2018-08-01 17:23:38 +080042 super(AttachInterfacesTestBase, cls).skip_checks()
Matthew Treinishb0a78fc2014-01-29 16:49:12 +000043 if not CONF.service_available.neutron:
Mark McClainf2982e82013-07-06 17:48:03 -040044 raise cls.skipException("Neutron is required")
Adam Gandelman7186f7a2014-07-23 09:28:56 -040045 if not CONF.compute_feature_enabled.interface_attach:
46 raise cls.skipException("Interface attachment is not available.")
Artom Lifshitzb4775942018-09-05 16:24:01 +030047 if not CONF.validation.run_validation:
48 raise cls.skipException('Validation should be enabled to ensure '
49 'guest OS is running and capable of '
50 'processing ACPI events.')
Emily Hugenbruche7991d92014-12-12 16:53:36 +000051
52 @classmethod
53 def setup_credentials(cls):
Salvatore Orlando5a337242014-01-15 22:49:22 +000054 # This test class requires network and subnet
Artom Lifshitzb4775942018-09-05 16:24:01 +030055 cls.set_network_resources(network=True, subnet=True, router=True,
56 dhcp=True)
zhufl615e63b2018-08-01 17:23:38 +080057 super(AttachInterfacesTestBase, cls).setup_credentials()
Emily Hugenbruche7991d92014-12-12 16:53:36 +000058
59 @classmethod
60 def setup_clients(cls):
zhufl615e63b2018-08-01 17:23:38 +080061 super(AttachInterfacesTestBase, cls).setup_clients()
Jordan Pittier8160d312017-04-18 11:52:23 +020062 cls.subnets_client = cls.os_primary.subnets_client
63 cls.ports_client = cls.os_primary.ports_client
Dan Smith8ad1c472013-02-26 13:03:16 -050064
Artom Lifshitzb4775942018-09-05 16:24:01 +030065 def _wait_for_validation(self, server, validation_resources):
66 linux_client = remote_client.RemoteClient(
67 self.get_server_ip(server, validation_resources),
68 self.image_ssh_user,
69 self.image_ssh_password,
70 validation_resources['keypair']['private_key'],
71 server=server,
72 servers_client=self.servers_client)
73 linux_client.validate_authentication()
74
zhufl615e63b2018-08-01 17:23:38 +080075 def _create_server_get_interfaces(self):
Artom Lifshitzb4775942018-09-05 16:24:01 +030076 validation_resources = self.get_test_validation_resources(
77 self.os_primary)
78 server = self.create_test_server(
79 validatable=True,
80 validation_resources=validation_resources,
81 wait_until='ACTIVE')
Mark Goddardfa30d2f2019-09-02 14:41:02 +010082 # NOTE(mgoddard): Get detailed server to ensure addresses are present
83 # in fixed IP case.
84 server = self.servers_client.show_server(server['id'])['server']
Artom Lifshitzb4775942018-09-05 16:24:01 +030085 # NOTE(artom) self.create_test_server adds cleanups, but this is
86 # apparently not enough? Add cleanup here.
87 self.addCleanup(self.delete_server, server['id'])
88 self._wait_for_validation(server, validation_resources)
zhufl615e63b2018-08-01 17:23:38 +080089 ifs = (self.interfaces_client.list_interfaces(server['id'])
90 ['interfaceAttachments'])
91 body = waiters.wait_for_interface_status(
92 self.interfaces_client, server['id'], ifs[0]['port_id'], 'ACTIVE')
93 ifs[0]['port_state'] = body['port_state']
94 return server, ifs
95
96
97class AttachInterfacesTestJSON(AttachInterfacesTestBase):
98
Matt Riedemanna8c641a2016-07-12 17:07:33 -040099 def wait_for_port_detach(self, port_id):
100 """Waits for the port's device_id to be unset.
101
102 :param port_id: The id of the port being detached.
103 :returns: The final port dict from the show_port response.
104 """
105 port = self.ports_client.show_port(port_id)['port']
106 device_id = port['device_id']
107 start = int(time.time())
108
109 # NOTE(mriedem): Nova updates the port's device_id to '' rather than
110 # None, but it's not contractual so handle Falsey either way.
111 while device_id:
112 time.sleep(self.build_interval)
113 port = self.ports_client.show_port(port_id)['port']
114 device_id = port['device_id']
115
116 timed_out = int(time.time()) - start >= self.build_timeout
117
118 if device_id and timed_out:
119 message = ('Port %s failed to detach (device_id %s) within '
120 'the required time (%s s).' %
121 (port_id, device_id, self.build_timeout))
guo yunxianebb15f22016-11-01 21:03:35 +0800122 raise lib_exc.TimeoutException(message)
Matt Riedemanna8c641a2016-07-12 17:07:33 -0400123
124 return port
125
lianghao16353342017-11-28 21:08:12 +0800126 def _check_interface(self, iface, server_id=None, port_id=None,
127 network_id=None, fixed_ip=None, mac_addr=None):
128 if server_id:
129 iface = waiters.wait_for_interface_status(
130 self.interfaces_client, server_id, iface['port_id'], 'ACTIVE')
Dan Smith8ad1c472013-02-26 13:03:16 -0500131 if port_id:
132 self.assertEqual(iface['port_id'], port_id)
133 if network_id:
134 self.assertEqual(iface['net_id'], network_id)
135 if fixed_ip:
136 self.assertEqual(iface['fixed_ips'][0]['ip_address'], fixed_ip)
venkata anil45375302014-12-30 10:41:43 +0000137 if mac_addr:
138 self.assertEqual(iface['mac_addr'], mac_addr)
Dan Smith8ad1c472013-02-26 13:03:16 -0500139
Dan Smith8ad1c472013-02-26 13:03:16 -0500140 def _test_create_interface(self, server):
lkuchlan87b5a2d2016-09-27 15:46:16 +0300141 iface = (self.interfaces_client.create_interface(server['id'])
ghanshyama2364f12015-08-24 15:45:37 +0900142 ['interfaceAttachment'])
zhufl7b638332016-11-14 10:23:30 +0800143 iface = waiters.wait_for_interface_status(
144 self.interfaces_client, server['id'], iface['port_id'], 'ACTIVE')
Dan Smith8ad1c472013-02-26 13:03:16 -0500145 return iface
146
147 def _test_create_interface_by_network_id(self, server, ifs):
148 network_id = ifs[0]['net_id']
lkuchlan87b5a2d2016-09-27 15:46:16 +0300149 iface = self.interfaces_client.create_interface(
ghanshyama2364f12015-08-24 15:45:37 +0900150 server['id'], net_id=network_id)['interfaceAttachment']
lianghao16353342017-11-28 21:08:12 +0800151 self._check_interface(iface, server_id=server['id'],
152 network_id=network_id)
Dan Smith8ad1c472013-02-26 13:03:16 -0500153 return iface
154
Maho Koshiya3fc12462015-12-14 19:03:12 +0900155 def _test_create_interface_by_port_id(self, server, ifs):
156 network_id = ifs[0]['net_id']
Doug Schveninger24675aa2019-08-16 22:28:39 -0500157 port = self.ports_client.create_port(
158 network_id=network_id,
159 name=data_utils.rand_name(self.__class__.__name__))
Maho Koshiya3fc12462015-12-14 19:03:12 +0900160 port_id = port['port']['id']
161 self.addCleanup(self.ports_client.delete_port, port_id)
lkuchlan87b5a2d2016-09-27 15:46:16 +0300162 iface = self.interfaces_client.create_interface(
Maho Koshiya3fc12462015-12-14 19:03:12 +0900163 server['id'], port_id=port_id)['interfaceAttachment']
lianghao16353342017-11-28 21:08:12 +0800164 self._check_interface(iface, server_id=server['id'], port_id=port_id,
165 network_id=network_id)
Maho Koshiya3fc12462015-12-14 19:03:12 +0900166 return iface
167
Maho Koshiya7b629582016-02-22 10:59:01 +0900168 def _test_create_interface_by_fixed_ips(self, server, ifs):
169 network_id = ifs[0]['net_id']
Ryan Tidwell1964a262016-05-04 15:13:23 -0700170 subnet_id = ifs[0]['fixed_ips'][0]['subnet_id']
171 ip_list = net_utils.get_unused_ip_addresses(self.ports_client,
172 self.subnets_client,
173 network_id,
174 subnet_id,
175 1)
Maho Koshiya7b629582016-02-22 10:59:01 +0900176
Ryan Tidwell1964a262016-05-04 15:13:23 -0700177 fixed_ips = [{'ip_address': ip_list[0]}]
lkuchlan87b5a2d2016-09-27 15:46:16 +0300178 iface = self.interfaces_client.create_interface(
Maho Koshiya7b629582016-02-22 10:59:01 +0900179 server['id'], net_id=network_id,
180 fixed_ips=fixed_ips)['interfaceAttachment']
Attila Fazekas3588bb32018-11-04 12:40:27 +0100181 self.addCleanup(test_utils.call_and_ignore_notfound_exc,
182 self.ports_client.delete_port,
183 iface['port_id'])
lianghao16353342017-11-28 21:08:12 +0800184 self._check_interface(iface, server_id=server['id'],
185 fixed_ip=ip_list[0])
Maho Koshiya7b629582016-02-22 10:59:01 +0900186 return iface
187
Dan Smith8ad1c472013-02-26 13:03:16 -0500188 def _test_show_interface(self, server, ifs):
189 iface = ifs[0]
lkuchlan87b5a2d2016-09-27 15:46:16 +0300190 _iface = self.interfaces_client.show_interface(
ghanshyama2364f12015-08-24 15:45:37 +0900191 server['id'], iface['port_id'])['interfaceAttachment']
venkata anil45375302014-12-30 10:41:43 +0000192 self._check_interface(iface, port_id=_iface['port_id'],
193 network_id=_iface['net_id'],
194 fixed_ip=_iface['fixed_ips'][0]['ip_address'],
195 mac_addr=_iface['mac_addr'])
Dan Smith8ad1c472013-02-26 13:03:16 -0500196
197 def _test_delete_interface(self, server, ifs):
198 # NOTE(danms): delete not the first or last, but one in the middle
199 iface = ifs[1]
lkuchlan87b5a2d2016-09-27 15:46:16 +0300200 self.interfaces_client.delete_interface(server['id'], iface['port_id'])
201 _ifs = (self.interfaces_client.list_interfaces(server['id'])
ghanshyama2364f12015-08-24 15:45:37 +0900202 ['interfaceAttachments'])
Oleg Bondarevee50bb12014-01-16 00:01:34 +0400203 start = int(time.time())
Dan Smith8ad1c472013-02-26 13:03:16 -0500204
Oleg Bondarevee50bb12014-01-16 00:01:34 +0400205 while len(ifs) == len(_ifs):
206 time.sleep(self.build_interval)
lkuchlan87b5a2d2016-09-27 15:46:16 +0300207 _ifs = (self.interfaces_client.list_interfaces(server['id'])
ghanshyama2364f12015-08-24 15:45:37 +0900208 ['interfaceAttachments'])
Oleg Bondarevee50bb12014-01-16 00:01:34 +0400209 timed_out = int(time.time()) - start >= self.build_timeout
210 if len(ifs) == len(_ifs) and timed_out:
211 message = ('Failed to delete interface within '
212 'the required time: %s sec.' % self.build_timeout)
guo yunxianebb15f22016-11-01 21:03:35 +0800213 raise lib_exc.TimeoutException(message)
Oleg Bondarevee50bb12014-01-16 00:01:34 +0400214
215 self.assertNotIn(iface['port_id'], [i['port_id'] for i in _ifs])
Dan Smith8ad1c472013-02-26 13:03:16 -0500216 return _ifs
217
218 def _compare_iface_list(self, list1, list2):
219 # NOTE(danms): port_state will likely have changed, so just
220 # confirm the port_ids are the same at least
221 list1 = [x['port_id'] for x in list1]
222 list2 = [x['port_id'] for x in list2]
223
224 self.assertEqual(sorted(list1), sorted(list2))
225
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -0800226 @decorators.idempotent_id('73fe8f02-590d-4bf1-b184-e9ca81065051')
Andrea Frittolicd368412017-08-14 21:37:56 +0100227 @utils.services('network')
zhufl607cfbf2017-12-28 14:55:08 +0800228 def test_create_list_show_delete_interfaces_by_network_port(self):
Dan Smith8ad1c472013-02-26 13:03:16 -0500229 server, ifs = self._create_server_get_interfaces()
230 interface_count = len(ifs)
zhufl080dcfb2016-10-21 17:45:38 +0800231 self.assertGreater(interface_count, 0)
Dan Smith8ad1c472013-02-26 13:03:16 -0500232
Rohan Kanade9ce97df2013-12-10 18:59:35 +0530233 try:
234 iface = self._test_create_interface(server)
235 except lib_exc.BadRequest as e:
236 msg = ('Multiple possible networks found, use a Network ID to be '
237 'more specific.')
junbolibc2ae862017-07-29 15:46:48 +0800238 if not CONF.compute.fixed_network_name and six.text_type(e) == msg:
Rohan Kanade9ce97df2013-12-10 18:59:35 +0530239 raise
240 else:
241 ifs.append(iface)
Dan Smith8ad1c472013-02-26 13:03:16 -0500242
243 iface = self._test_create_interface_by_network_id(server, ifs)
244 ifs.append(iface)
245
Maho Koshiya3fc12462015-12-14 19:03:12 +0900246 iface = self._test_create_interface_by_port_id(server, ifs)
247 ifs.append(iface)
248
zhufl607cfbf2017-12-28 14:55:08 +0800249 _ifs = (self.interfaces_client.list_interfaces(server['id'])
250 ['interfaceAttachments'])
251 self._compare_iface_list(ifs, _ifs)
252
253 self._test_show_interface(server, ifs)
254
255 _ifs = self._test_delete_interface(server, ifs)
256 self.assertEqual(len(ifs) - 1, len(_ifs))
257
258 @decorators.idempotent_id('d290c06c-f5b3-11e7-8ec8-002293781009')
259 @utils.services('network')
260 def test_create_list_show_delete_interfaces_by_fixed_ip(self):
261 # NOTE(zhufl) By default only project that is admin or network owner
262 # or project with role advsvc is authorised to create interfaces with
263 # fixed-ip, so if we don't create network for each project, do not
264 # test _test_create_interface_by_fixed_ips.
265 if not (CONF.auth.use_dynamic_credentials and
266 CONF.auth.create_isolated_networks and
267 not CONF.network.shared_physical_network):
Matt Riedemann91d92422019-01-29 16:19:49 -0500268 raise self.skipException("Only owner network supports "
269 "creating interface by fixed ip.")
zhufl607cfbf2017-12-28 14:55:08 +0800270
271 server, ifs = self._create_server_get_interfaces()
272 interface_count = len(ifs)
273 self.assertGreater(interface_count, 0)
274
Maho Koshiya7b629582016-02-22 10:59:01 +0900275 iface = self._test_create_interface_by_fixed_ips(server, ifs)
276 ifs.append(iface)
277
lkuchlan87b5a2d2016-09-27 15:46:16 +0300278 _ifs = (self.interfaces_client.list_interfaces(server['id'])
ghanshyama2364f12015-08-24 15:45:37 +0900279 ['interfaceAttachments'])
Dan Smith8ad1c472013-02-26 13:03:16 -0500280 self._compare_iface_list(ifs, _ifs)
281
282 self._test_show_interface(server, ifs)
283
284 _ifs = self._test_delete_interface(server, ifs)
285 self.assertEqual(len(ifs) - 1, len(_ifs))
286
Ken'ichi Ohmichi14b0ae12017-01-27 17:18:52 -0800287 @decorators.idempotent_id('2f3a0127-95c7-4977-92d2-bc5aec602fb4')
Matt Riedemanna8c641a2016-07-12 17:07:33 -0400288 def test_reassign_port_between_servers(self):
289 """Tests the following:
290
291 1. Create a port in Neutron.
292 2. Create two servers in Nova.
293 3. Attach the port to the first server.
294 4. Detach the port from the first server.
295 5. Attach the port to the second server.
296 6. Detach the port from the second server.
297 """
298 network = self.get_tenant_network()
299 network_id = network['id']
Doug Schveninger24675aa2019-08-16 22:28:39 -0500300 port = self.ports_client.create_port(
301 network_id=network_id,
302 name=data_utils.rand_name(self.__class__.__name__))
Matt Riedemanna8c641a2016-07-12 17:07:33 -0400303 port_id = port['port']['id']
304 self.addCleanup(self.ports_client.delete_port, port_id)
305
Artom Lifshitzb4775942018-09-05 16:24:01 +0300306 # NOTE(artom) We create two servers one at a time because
307 # create_test_server doesn't support multiple validatable servers.
308 validation_resources = self.get_test_validation_resources(
309 self.os_primary)
310
311 def _create_validatable_server():
312 _, servers = compute.create_test_server(
313 self.os_primary, tenant_network=network,
314 wait_until='ACTIVE', validatable=True,
315 validation_resources=validation_resources)
316 return servers[0]
317
318 servers = [_create_validatable_server(), _create_validatable_server()]
319
Matt Riedemanna8c641a2016-07-12 17:07:33 -0400320 # add our cleanups for the servers since we bypassed the base class
321 for server in servers:
zhufl1355d982017-01-05 12:06:20 +0800322 self.addCleanup(self.delete_server, server['id'])
Matt Riedemanna8c641a2016-07-12 17:07:33 -0400323
324 for server in servers:
Mark Goddardfa30d2f2019-09-02 14:41:02 +0100325 # NOTE(mgoddard): Get detailed server to ensure addresses are
326 # present in fixed IP case.
327 server = self.servers_client.show_server(server['id'])['server']
Artom Lifshitzb4775942018-09-05 16:24:01 +0300328 self._wait_for_validation(server, validation_resources)
Matt Riedemanna8c641a2016-07-12 17:07:33 -0400329 # attach the port to the server
lkuchlan87b5a2d2016-09-27 15:46:16 +0300330 iface = self.interfaces_client.create_interface(
Matt Riedemanna8c641a2016-07-12 17:07:33 -0400331 server['id'], port_id=port_id)['interfaceAttachment']
lianghao16353342017-11-28 21:08:12 +0800332 self._check_interface(iface, server_id=server['id'],
333 port_id=port_id)
Matt Riedemanna8c641a2016-07-12 17:07:33 -0400334
335 # detach the port from the server; this is a cast in the compute
336 # API so we have to poll the port until the device_id is unset.
lkuchlan87b5a2d2016-09-27 15:46:16 +0300337 self.interfaces_client.delete_interface(server['id'], port_id)
Matt Riedemanna8c641a2016-07-12 17:07:33 -0400338 self.wait_for_port_detach(port_id)
zhufl615e63b2018-08-01 17:23:38 +0800339
340
341class AttachInterfacesUnderV243Test(AttachInterfacesTestBase):
342 max_microversion = '2.43'
343
344 @decorators.attr(type='smoke')
345 @decorators.idempotent_id('c7e0e60b-ee45-43d0-abeb-8596fd42a2f9')
346 @utils.services('network')
347 def test_add_remove_fixed_ip(self):
Matthew Treinishc68546f2018-10-12 10:53:45 -0400348 # NOTE(zhufl) By default only project that is admin or network owner
349 # or project with role advsvc is authorised to add interfaces with
350 # fixed-ip, so if we don't create network for each project, do not
351 # test
352 if not (CONF.auth.use_dynamic_credentials and
353 CONF.auth.create_isolated_networks and
354 not CONF.network.shared_physical_network):
355 raise self.skipException("Only owner network supports "
356 "creating interface by fixed ip.")
357
zhufl615e63b2018-08-01 17:23:38 +0800358 # Add and Remove the fixed IP to server.
359 server, ifs = self._create_server_get_interfaces()
Matt Riedemannd4cb10f2018-09-26 13:03:08 -0400360 original_interface_count = len(ifs) # This is the number of ports.
361 self.assertGreater(original_interface_count, 0)
362 # Get the starting list of IPs on the server.
363 addresses = self.os_primary.servers_client.list_addresses(
364 server['id'])['addresses']
365 # There should be one entry for the single network mapped to a list of
366 # addresses, which at this point should have at least one entry.
367 # Note that we could start with two addresses depending on how tempest
368 # is configured for using floating IPs.
369 self.assertEqual(1, len(addresses), addresses) # number of networks
370 # Keep track of the original addresses so we can know which IP is new.
371 original_ips = [addr['addr'] for addr in list(addresses.values())[0]]
372 original_ip_count = len(original_ips)
373 self.assertGreater(original_ip_count, 0, addresses) # at least 1
zhufl615e63b2018-08-01 17:23:38 +0800374 network_id = ifs[0]['net_id']
Matt Riedemannd4cb10f2018-09-26 13:03:08 -0400375 # Add another fixed IP to the server. This should result in another
376 # fixed IP on the same network (and same port since we only have one
377 # port).
zhufl615e63b2018-08-01 17:23:38 +0800378 self.servers_client.add_fixed_ip(server['id'], networkId=network_id)
Matt Riedemannd4cb10f2018-09-26 13:03:08 -0400379 # Wait for the ips count to increase by one.
380
Slawek Kaplonskib3daeb42019-06-29 23:49:59 +0200381 def _get_server_floating_ips():
382 _floating_ips = []
383 _server = self.os_primary.servers_client.show_server(
384 server['id'])['server']
385 for _ip_set in _server['addresses']:
386 for _ip in _server['addresses'][_ip_set]:
387 if _ip['OS-EXT-IPS:type'] == 'floating':
388 _floating_ips.append(_ip['addr'])
389 return _floating_ips
390
Matt Riedemannd4cb10f2018-09-26 13:03:08 -0400391 def _wait_for_ip_increase():
392 _addresses = self.os_primary.servers_client.list_addresses(
393 server['id'])['addresses']
Slawek Kaplonskib3daeb42019-06-29 23:49:59 +0200394 _ips = [addr['addr'] for addr in list(_addresses.values())[0]]
395 LOG.debug("Wait for IP increase. All IPs still associated to "
396 "the server %(id)s: %(ips)s",
397 {'id': server['id'], 'ips': _ips})
398 if len(_ips) == original_ip_count + 1:
399 return True
400 elif len(_ips) == original_ip_count:
401 return False
402 # If not, lets remove any floating IP from the list and check again
403 _fips = _get_server_floating_ips()
404 _ips = [_ip for _ip in _ips if _ip not in _fips]
405 LOG.debug("Wait for IP increase. Fixed IPs still associated to "
406 "the server %(id)s: %(ips)s",
407 {'id': server['id'], 'ips': _ips})
408 return len(_ips) == original_ip_count + 1
Matt Riedemannd4cb10f2018-09-26 13:03:08 -0400409
410 if not test_utils.call_until_true(
411 _wait_for_ip_increase, CONF.compute.build_timeout,
412 CONF.compute.build_interval):
413 raise lib_exc.TimeoutException(
414 'Timed out while waiting for IP count to increase.')
415
416 # Remove the fixed IP that we just added.
zhufl615e63b2018-08-01 17:23:38 +0800417 server_detail = self.os_primary.servers_client.show_server(
418 server['id'])['server']
419 # Get the Fixed IP from server.
420 fixed_ip = None
421 for ip_set in server_detail['addresses']:
422 for ip in server_detail['addresses'][ip_set]:
Matt Riedemannd4cb10f2018-09-26 13:03:08 -0400423 if (ip['OS-EXT-IPS:type'] == 'fixed' and
424 ip['addr'] not in original_ips):
zhufl615e63b2018-08-01 17:23:38 +0800425 fixed_ip = ip['addr']
426 break
427 if fixed_ip is not None:
428 break
429 self.servers_client.remove_fixed_ip(server['id'], address=fixed_ip)
Matt Riedemannd4cb10f2018-09-26 13:03:08 -0400430 # Wait for the interface count to decrease by one.
431
432 def _wait_for_ip_decrease():
433 _addresses = self.os_primary.servers_client.list_addresses(
434 server['id'])['addresses']
Slawek Kaplonskib3daeb42019-06-29 23:49:59 +0200435 _ips = [addr['addr'] for addr in list(_addresses.values())[0]]
436 LOG.debug("Wait for IP decrease. All IPs still associated to "
437 "the server %(id)s: %(ips)s",
438 {'id': server['id'], 'ips': _ips})
439 if len(_ips) == original_ip_count:
440 return True
441 # If not, lets remove any floating IP from the list and check again
442 _fips = _get_server_floating_ips()
443 _ips = [_ip for _ip in _ips if _ip not in _fips]
444 LOG.debug("Wait for IP decrease. Fixed IPs still associated to "
445 "the server %(id)s: %(ips)s",
446 {'id': server['id'], 'ips': _ips})
447 return len(_ips) == original_ip_count
Matt Riedemannd4cb10f2018-09-26 13:03:08 -0400448
449 if not test_utils.call_until_true(
450 _wait_for_ip_decrease, CONF.compute.build_timeout,
451 CONF.compute.build_interval):
452 raise lib_exc.TimeoutException(
453 'Timed out while waiting for IP count to decrease.')