From 394c693e359ed4f19cc2f7d975b1f9ee5500b7f6 Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Thu, 21 Feb 2013 15:09:29 -0500 Subject: Make allocate_for_instance() return only info about ports allocated Previously, the compute manager was filtering the results based on the port id that the user requested. However, if they do not pass one (which is valid) then we can not do the filter and we fail. This makes the allocation function do the filtering, which should not affect the normal use case where it is only called once, since all the ports returned were allocated at that time. The manager filter behavior is thus removed and a test is added to verify that the allocate method does the right thing the second time around. This fixes the fallout found after fixing the actual cause of bug 1131264 Change-Id: I8f3af96051268503596007491af365e8ce28f5b3 --- nova/compute/manager.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'nova/compute') diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 99b97e921..942cc7f5c 100755 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -2763,13 +2763,15 @@ class ComputeManager(manager.SchedulerDependentManager): network_info = self.network_api.allocate_port_for_instance( context, instance, port_id, network_id, requested_ip, self.conductor_api) + if len(network_info) != 1: + LOG.error(_('allocate_port_for_instance returned %(port)s ports') % + dict(ports=len(network_info))) + raise exception.InterfaceAttachFailed(instance=instance) image_meta = _get_image_meta(context, instance['image_ref']) legacy_net_info = self._legacy_nw_info(network_info) - for (network, mapping) in legacy_net_info: - if mapping['vif_uuid'] == port_id: - self.driver.attach_interface(instance, image_meta, - [(network, mapping)]) - return (network, mapping) + (network, mapping) = legacy_net_info[0] + self.driver.attach_interface(instance, image_meta, legacy_net_info) + return legacy_net_info[0] def detach_interface(self, context, instance, port_id): """Detach an network adapter from an instance.""" -- cgit