update port device_id when device_id is docker endpointID

if port with device_id has been created by user,
kuryr should not release it.

Change-Id: Ia6c8d673b29fea653c034684e846d8104d570d2d
Closes-bug: #1753357
This commit is contained in:
WangChangyu 2018-03-05 11:49:35 +08:00
parent 4701079d79
commit 01e89e8ced
2 changed files with 8 additions and 4 deletions

View File

@ -118,8 +118,7 @@ def get_driver(port):
if driver is None:
raise exceptions.KuryrException(
"No port driver available for VNIC type %s" % vnic_type)
else:
return driver
return driver
def _cache_default_subnetpool_ids(app):
@ -1879,7 +1878,9 @@ def ipam_release_address():
app.neutron.delete_port(port['id'])
elif tags and const.KURYR_EXISTING_NEUTRON_PORT in tags:
updated_port = {'name': '', 'device_owner': '',
'device_id': '', 'binding:host_id': ''}
'binding:host_id': ''}
if port['name'].startswith(port['device_id']):
updated_port["device_id"] = ''
app.neutron.update_port(port['id'], {'port': updated_port})
_neutron_port_remove_tag(port['id'],
const.KURYR_EXISTING_NEUTRON_PORT)

View File

@ -1562,7 +1562,10 @@ class TestKuryrIpam(base.TestKuryrBase):
mock_list_subnets.assert_called_with(
subnetpool_id=fake_kuryr_subnetpool_id)
mock_list_ports.assert_called()
mock_update_port.assert_called()
expect_updated_port = {'name': '', 'device_owner': '',
'device_id': '', 'binding:host_id': ''}
mock_update_port.assert_called_with(fake_port['port']['id'],
{'port': expect_updated_port})
mock_delete_port.assert_not_called()
mock_remove_tag.assert_called_with('ports',
fake_port['port']['id'],