diff options
| author | Dan Smith <danms@us.ibm.com> | 2013-02-21 13:15:23 -0500 |
|---|---|---|
| committer | Dan Smith <danms@us.ibm.com> | 2013-02-26 09:57:17 -0500 |
| commit | cdf5e432de2cf1c0c5466470a6a0bccf999fcdd4 (patch) | |
| tree | 6df68bb406cfb9d1791b711b0beae5c65fc67081 | |
| parent | a8fef8e5103973d8b9747bca3784c98e4075e454 (diff) | |
Fix crash in quantumapi if no network or port id is specified
The existing code assumes that if no port id or fixed ip was specified,
that the network id passed in is valid. This is not necessarily the case,
and results in adding None to the list of network ids, which later
causes a check to see if the network id list is empty to fail.
This only adds the network id to the list if it was specified, and
adds a more explicit check to the region that previously fell through
without finding a matching network so that a similar case would be
easier to debug in the future.
Addresses bug #1131264
Change-Id: I7a8aaea5772707b8bd6313249e74b1302eedefe8
| -rw-r--r-- | nova/network/quantumv2/api.py | 11 | ||||
| -rw-r--r-- | nova/tests/network/test_quantumv2.py | 15 |
2 files changed, 24 insertions, 2 deletions
diff --git a/nova/network/quantumv2/api.py b/nova/network/quantumv2/api.py index 851a544dc..50e38eebd 100644 --- a/nova/network/quantumv2/api.py +++ b/nova/network/quantumv2/api.py @@ -172,9 +172,10 @@ class API(base.Base): available_macs.discard(port['mac_address']) network_id = port['network_id'] ports[network_id] = port - elif fixed_ip: + elif fixed_ip and network_id: fixed_ips[network_id] = fixed_ip - net_ids.append(network_id) + if network_id: + net_ids.append(network_id) nets = self._get_available_networks(context, instance['project_id'], net_ids) @@ -774,6 +775,12 @@ class API(base.Base): 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 = [network_model.FixedIP(address=ip_address) for ip_address in [ip['ip_address'] for ip in port['fixed_ips']]] diff --git a/nova/tests/network/test_quantumv2.py b/nova/tests/network/test_quantumv2.py index e9e19ef45..a168e451f 100644 --- a/nova/tests/network/test_quantumv2.py +++ b/nova/tests/network/test_quantumv2.py @@ -631,6 +631,21 @@ class TestQuantumv2(test.TestCase): self.assertRaises(QUANTUM_CLIENT_EXCEPTION, api.allocate_for_instance, self.context, self.instance) + def test_allocate_for_instance_no_port_or_network(self): + class BailOutEarly(Exception): + pass + api = quantumapi.API() + self.mox.StubOutWithMock(api, '_get_available_networks') + # Make sure we get an empty list and then bail out of the rest + # of the function + api._get_available_networks(self.context, self.instance['project_id'], + []).AndRaise(BailOutEarly) + self.mox.ReplayAll() + self.assertRaises(BailOutEarly, + api.allocate_for_instance, + self.context, self.instance, + requested_networks=[(None, None, None)]) + def _deallocate_for_instance(self, number): port_data = number == 1 and self.port_data1 or self.port_data2 self.moxed_client.list_ports( |
