summaryrefslogtreecommitdiffstats
path: root/nova
diff options
context:
space:
mode:
authorBen Nemec <bnemec@us.ibm.com>2013-04-05 16:48:01 +0000
committerBen Nemec <bnemec@us.ibm.com>2013-04-08 21:48:03 +0000
commit8eadd2aee9086815f9fe600d1e2d26145d7b5c16 (patch)
tree8471ab220364c13cb4f0bae9ffe4882892cc3c48 /nova
parent88cd09445ea46bba0f62ef58894fd92243021a88 (diff)
Raise correct exception for duplicate networks
When using Quantum, if duplicate network ids are passed in on a nova boot, nova-api raises a NetworkNotFound exception, which is not correct. This change causes it to raise a NetworkDuplicated exception instead. Fixes bug 1165088 Change-Id: I4f1f9aa5e1fa0e740b78e67760d924e2dd1d4d98
Diffstat (limited to 'nova')
-rw-r--r--nova/network/quantumv2/api.py18
-rw-r--r--nova/tests/network/test_quantumv2.py14
2 files changed, 23 insertions, 9 deletions
diff --git a/nova/network/quantumv2/api.py b/nova/network/quantumv2/api.py
index 3a6870d6e..5fe1ada51 100644
--- a/nova/network/quantumv2/api.py
+++ b/nova/network/quantumv2/api.py
@@ -441,15 +441,15 @@ class API(base.Base):
net_ids = []
for (net_id, _i, port_id) in requested_networks:
- if not port_id:
- net_ids.append(net_id)
- continue
- port = quantumv2.get_client(context).show_port(port_id).get('port')
- if not port:
- raise exception.PortNotFound(port_id=port_id)
- if port.get('device_id', None):
- raise exception.PortInUse(port_id=port_id)
- net_id = port['network_id']
+ if port_id:
+ port = (quantumv2.get_client(context)
+ .show_port(port_id)
+ .get('port'))
+ if not port:
+ raise exception.PortNotFound(port_id=port_id)
+ if port.get('device_id', None):
+ raise exception.PortInUse(port_id=port_id)
+ net_id = port['network_id']
if net_id in net_ids:
raise exception.NetworkDuplicated(network_id=net_id)
net_ids.append(net_id)
diff --git a/nova/tests/network/test_quantumv2.py b/nova/tests/network/test_quantumv2.py
index 6a3b31412..95352425e 100644
--- a/nova/tests/network/test_quantumv2.py
+++ b/nova/tests/network/test_quantumv2.py
@@ -825,6 +825,20 @@ class TestQuantumv2(test.TestCase):
except exception.NetworkNotFound as ex:
self.assertTrue("my_netid2, my_netid3" in str(ex))
+ def test_validate_networks_duplicate(self):
+ """Verify that the correct exception is thrown when duplicate
+ network ids are passed to validate_networks.
+ """
+ requested_networks = [('my_netid1', None, None),
+ ('my_netid1', None, None)]
+ self.mox.ReplayAll()
+ # Expected call from setUp.
+ quantumv2.get_client(None)
+ api = quantumapi.API()
+ self.assertRaises(exception.NetworkDuplicated,
+ api.validate_networks,
+ self.context, requested_networks)
+
def _mock_list_ports(self, port_data=None):
if port_data is None:
port_data = self.port_data2