diff options
author | Jenkins <jenkins@review.openstack.org> | 2013-04-22 17:51:35 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2013-04-22 17:51:35 +0000 |
commit | bd6deacd6a4dc0f30405dce47ccb6e91f0a93194 (patch) | |
tree | b563a6430e88f6115078f7b746272c26fe915a1f /nova | |
parent | 3eac61132268575e30f187eefc5b314c3a3e52db (diff) | |
parent | 8eadd2aee9086815f9fe600d1e2d26145d7b5c16 (diff) | |
download | nova-bd6deacd6a4dc0f30405dce47ccb6e91f0a93194.tar.gz nova-bd6deacd6a4dc0f30405dce47ccb6e91f0a93194.tar.xz nova-bd6deacd6a4dc0f30405dce47ccb6e91f0a93194.zip |
Merge "Raise correct exception for duplicate networks"
Diffstat (limited to 'nova')
-rw-r--r-- | nova/network/quantumv2/api.py | 18 | ||||
-rw-r--r-- | nova/tests/network/test_quantumv2.py | 14 |
2 files changed, 23 insertions, 9 deletions
diff --git a/nova/network/quantumv2/api.py b/nova/network/quantumv2/api.py index 7e34ec30c..83441cad1 100644 --- a/nova/network/quantumv2/api.py +++ b/nova/network/quantumv2/api.py @@ -457,15 +457,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 ab8752dec..6a00b4723 100644 --- a/nova/tests/network/test_quantumv2.py +++ b/nova/tests/network/test_quantumv2.py @@ -822,6 +822,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 |