diff options
author | Jenkins <jenkins@review.openstack.org> | 2013-10-11 03:11:07 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2013-10-11 03:11:07 +0000 |
commit | 516ec3e70ef06bd969d61d532c63534d2cd2466f (patch) | |
tree | 0af4611782c2cc4892dfcb79a7eb1a39031b1d03 | |
parent | a48f9df8520f6fb5235e074f4e53d4f577595ce3 (diff) | |
parent | fd5794c2d2a05267ce844b30ef508007dbe84173 (diff) | |
download | nova-516ec3e70ef06bd969d61d532c63534d2cd2466f.tar.gz |
Merge "Fix one port can be attached to more devices" into stable/grizzly
-rw-r--r-- | nova/network/quantumv2/api.py | 2 | ||||
-rw-r--r-- | nova/tests/network/test_quantumv2.py | 17 |
2 files changed, 17 insertions, 2 deletions
diff --git a/nova/network/quantumv2/api.py b/nova/network/quantumv2/api.py index 506c3b32bb..20713b9e72 100644 --- a/nova/network/quantumv2/api.py +++ b/nova/network/quantumv2/api.py @@ -164,6 +164,8 @@ class API(base.Base): for network_id, fixed_ip, port_id in requested_networks: if port_id: port = quantum.show_port(port_id)['port'] + if port.get('device_id'): + raise exception.PortInUse(port_id=port_id) if hypervisor_macs is not None: if port['mac_address'] not in hypervisor_macs: raise exception.PortNotUsable(port_id=port_id, diff --git a/nova/tests/network/test_quantumv2.py b/nova/tests/network/test_quantumv2.py index 57ccfd8094..78a4f4bf9a 100644 --- a/nova/tests/network/test_quantumv2.py +++ b/nova/tests/network/test_quantumv2.py @@ -440,8 +440,10 @@ class TestQuantumv2(test.TestCase): if port_id: self.moxed_client.show_port(port_id).AndReturn( {'port': {'id': 'my_portid1', - 'network_id': 'my_netid1', - 'mac_address': 'my_mac1'}}) + 'network_id': 'my_netid1', + 'mac_address': 'my_mac1', + 'device_id': kwargs.get('_device') and + 'device_id1' or ''}}) ports['my_netid1'] = self.port_data1[0] id = 'my_netid1' if macs is not None: @@ -727,6 +729,17 @@ class TestQuantumv2(test.TestCase): nw_info = self._allocate_for_instance() self.assertEqual(nw_info, [new_port]) + def test_allocate_for_instance_port_in_use(self): + # If a port is already in use, an exception should be raised. + requested_networks = [(None, None, 'my_portid1')] + api = self._stub_allocate_for_instance( + requested_networks=requested_networks, + _break='pre_list_networks', + _device=True) + self.assertRaises(exception.PortInUse, + api.allocate_for_instance, self.context, + self.instance, requested_networks=requested_networks) + def _deallocate_for_instance(self, number): port_data = number == 1 and self.port_data1 or self.port_data2 self.moxed_client.list_ports( |