diff options
author | Brent Eagles <beagles@redhat.com> | 2013-06-14 13:21:54 -0230 |
---|---|---|
committer | Brent Eagles <beagles@redhat.com> | 2013-06-25 11:33:27 -0230 |
commit | 8f3b3db9b04bb5ff7b9486dc6fc211745b983855 (patch) | |
tree | d25492d53a2f6b99daaa08f12e05d8f1c88dcbbd /nova | |
parent | 328b347cd058f1c87d7e32a18d9decc0ba517266 (diff) | |
download | nova-8f3b3db9b04bb5ff7b9486dc6fc211745b983855.tar.gz nova-8f3b3db9b04bb5ff7b9486dc6fc211745b983855.tar.xz nova-8f3b3db9b04bb5ff7b9486dc6fc211745b983855.zip |
Skip security group code when there is no network.
This patch adds a simple check to the nova/quantum API that immediately
returns an empty list if there are no configured networks available.
Fixes bug 1191044
Change-Id: I34ac4dd56c71f99c7ed9ff632d6dc7036d91008d
Diffstat (limited to 'nova')
-rw-r--r-- | nova/network/quantumv2/api.py | 5 | ||||
-rw-r--r-- | nova/tests/network/test_quantumv2.py | 13 |
2 files changed, 18 insertions, 0 deletions
diff --git a/nova/network/quantumv2/api.py b/nova/network/quantumv2/api.py index 054611cd3..e28d86b0e 100644 --- a/nova/network/quantumv2/api.py +++ b/nova/network/quantumv2/api.py @@ -184,6 +184,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 0b6f184ae..b8cadc8d6 100644 --- a/nova/tests/network/test_quantumv2.py +++ b/nova/tests/network/test_quantumv2.py @@ -607,6 +607,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. |