summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--nova/network/quantumv2/api.py5
-rw-r--r--nova/tests/network/test_quantumv2.py13
2 files changed, 18 insertions, 0 deletions
diff --git a/nova/network/quantumv2/api.py b/nova/network/quantumv2/api.py
index c7f4ffd58..814b66ee0 100644
--- a/nova/network/quantumv2/api.py
+++ b/nova/network/quantumv2/api.py
@@ -182,6 +182,11 @@ class API(base.Base):
nets = self._get_available_networks(context, instance['project_id'],
net_ids)
+
+ if not nets:
+ LOG.warn(_("No network configured!"), instance=instance)
+ return []
+
security_groups = kwargs.get('security_groups', [])
security_group_ids = []
diff --git a/nova/tests/network/test_quantumv2.py b/nova/tests/network/test_quantumv2.py
index 2ddeb72bf..a2e7efcc0 100644
--- a/nova/tests/network/test_quantumv2.py
+++ b/nova/tests/network/test_quantumv2.py
@@ -594,6 +594,19 @@ class TestQuantumv2(test.TestCase):
self._allocate_for_instance(net_idx=1,
requested_networks=requested_networks)
+ def test_allocate_for_instance_no_networks(self):
+ """verify the exception thrown when there are no networks defined."""
+ api = quantumapi.API()
+ self.moxed_client.list_networks(
+ tenant_id=self.instance['project_id'],
+ shared=False).AndReturn(
+ {'networks': []})
+ self.moxed_client.list_networks(shared=True).AndReturn(
+ {'networks': []})
+ self.mox.ReplayAll()
+ nwinfo = api.allocate_for_instance(self.context, self.instance)
+ self.assertEqual(len(nwinfo), 0)
+
def test_allocate_for_instance_ex1(self):
"""verify we will delete created ports
if we fail to allocate all net resources.