summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--nova/network/quantumv2/api.py11
-rw-r--r--nova/tests/network/test_quantumv2.py15
2 files changed, 24 insertions, 2 deletions
diff --git a/nova/network/quantumv2/api.py b/nova/network/quantumv2/api.py
index 1db1933a6..735adbe15 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 0928e748d..5d81c2b2a 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(