summaryrefslogtreecommitdiffstats
path: root/nova
diff options
context:
space:
mode:
authorDan Smith <danms@us.ibm.com>2013-04-29 16:33:49 -0700
committerDan Smith <danms@us.ibm.com>2013-04-30 09:17:43 -0700
commit08c7cf5c67a75dea9b453bd915a0cd55e67c4adc (patch)
tree2cb6dda6327df99e3ef954e1ff942ac77c4d0af5 /nova
parenta9c1480df7cd7bd192afffc8674db193f1a8aed4 (diff)
Fix building quantumapi network model with network list
Bug 1171636 occurs when _build_network_info_model() receives a list of networks that does not fully map all of an instance's ports. It crashes in _ensure_requested_network_ordering() when the list of all ports is sorted by the subset of networks provided. This change simplifies the early part of that function to only consider ports within the networks provided, and to always sort those ports in network order. This allows us to remove some error path code from the loop below that iterates over the ports (which contained a fatal typo, by the way) which is now dead code. The affected code is really untested at the moment, due to the structure of the method, making it hard to add a unit test to cover this fix. In order to make the change clear from the existing code, this fix is provided here first, and the following patch restructures the method and add tests for this change and the rest of the surrounding code. Fixes bug 1171636 Change-Id: Idf519a88415844451b18959b38cc48ce92c090d1
Diffstat (limited to 'nova')
-rw-r--r--nova/network/quantumv2/api.py22
1 files changed, 9 insertions, 13 deletions
diff --git a/nova/network/quantumv2/api.py b/nova/network/quantumv2/api.py
index 83441cad1..39c3d47d0 100644
--- a/nova/network/quantumv2/api.py
+++ b/nova/network/quantumv2/api.py
@@ -816,27 +816,23 @@ class API(base.Base):
if networks is None:
networks = self._get_available_networks(context,
instance['project_id'])
- else:
- # ensure ports are in preferred network order
- _ensure_requested_network_ordering(
- lambda x: x['network_id'],
- ports,
- [n['id'] for n in networks])
+
+ # ensure ports are in preferred network order, and filter out
+ # those not attached to one of the provided list of networks
+ net_ids = [n['id'] for n in networks]
+ ports = [port for port in ports if port['network_id'] in net_ids]
+ _ensure_requested_network_ordering(lambda x: x['network_id'],
+ ports, net_ids)
nw_info = network_model.NetworkInfo()
for port in ports:
- network_name = None
+ # NOTE(danms): This loop can't fail to find a network since we
+ # filtered ports to only the ones matching networks above.
for net in networks:
if port['network_id'] == net['id']:
network_name = net['name']
break
- if network_name is None:
- raise exception.NotFound(_('Network %(net)s for '
- 'port %(port_id)s not found!') %
- {'net': port['network_id'],
- 'port': port['id']})
-
network_IPs = []
for fixed_ip in port['fixed_ips']:
fixed = network_model.FixedIP(address=fixed_ip['ip_address'])