Add device_id when creating ports
Currently, when nova is creating ports, we don't update the device_id until we bind the port much later in the process. It's better to set the device_id when we create the port for a variety of reasons, such as it stops other instances trying to use the port we just created. The real reason it is changed here is because in a few edge cases Nova still fails to correctly clean up ports we created. By adding the device_id we should be able to more easily track down the cause of the leaking ports, and it may help fix the issue too. Change-Id: Ie697ad6520622d6f01f06b19b143d5f8ac21e053 Related-Bug: 1603909
This commit is contained in:
parent
8b34afcfa1
commit
15280bde1d
|
@ -369,7 +369,9 @@ class API(base_api.NetworkAPI):
|
|||
IpAddressGenerationFailure error.
|
||||
:raises: PortBindingFailed: If port binding failed.
|
||||
"""
|
||||
port_req_body = {'port': {}}
|
||||
# Set the device_id so it's clear who this port was created for,
|
||||
# and to stop other instances trying to use it
|
||||
port_req_body = {'port': {'device_id': instance.uuid}}
|
||||
try:
|
||||
if fixed_ip:
|
||||
port_req_body['port']['fixed_ips'] = [
|
||||
|
|
|
@ -711,7 +711,8 @@ class TestNeutronv2Base(test.TestCase):
|
|||
if network is None:
|
||||
continue
|
||||
|
||||
port_req_body_create = {'port': {}}
|
||||
port_req_body_create = {'port': {'device_id':
|
||||
self.instance.uuid}}
|
||||
request.address = fixed_ips.get(request.network_id)
|
||||
if request.address:
|
||||
port_req_body_create['port']['fixed_ips'] = [
|
||||
|
@ -5269,7 +5270,7 @@ class TestAllocateForInstance(test.NoDBTestCase):
|
|||
mock_client.create_port.assert_called_once_with(
|
||||
{'port': {
|
||||
'network_id': uuids.net, 'tenant_id': uuids.tenant_id,
|
||||
'admin_state_up': True}})
|
||||
'admin_state_up': True, 'device_id': self.instance.uuid}})
|
||||
|
||||
def test_create_ports_for_instance_with_security_groups(self):
|
||||
api = neutronapi.API()
|
||||
|
@ -5286,7 +5287,8 @@ class TestAllocateForInstance(test.NoDBTestCase):
|
|||
mock_client.create_port.assert_called_once_with(
|
||||
{'port': {
|
||||
'network_id': uuids.net, 'tenant_id': uuids.tenant_id,
|
||||
'admin_state_up': True, 'security_groups': security_groups}})
|
||||
'admin_state_up': True, 'security_groups': security_groups,
|
||||
'device_id': self.instance.uuid}})
|
||||
|
||||
def test_create_ports_for_instance_with_cleanup_after_pc_failure(self):
|
||||
api = neutronapi.API()
|
||||
|
|
Loading…
Reference in New Issue