Can't use exiting port If this port has been used once when create container

We use pre-exiting port 1 when create container A, then delete container A.
If we use port 1 to create container B, we'll get the error :"Port 1 is still in use."
    Update the port's device_id if it is a pre-existing prot when delete the container.

Change-Id: I6481a5737eef0256c426555d2a01918eb1d14ce7
Closes-bug: #1741433
This commit is contained in:
weikeyou
2018-01-08 15:14:50 +08:00
parent 0ee4b55013
commit 6dc61b74d1

View File

@@ -289,9 +289,11 @@ class KuryrNetwork(network.Network):
container_id = container.container_id
neutron_ports = set()
all_ports = set()
if container.addresses and neutron_network_id:
addrs_list = container.addresses.get(neutron_network_id, [])
for addr in addrs_list:
all_ports.add(addr['port'])
if not addr['preserve_on_delete']:
port_id = addr['port']
neutron_ports.add(port_id)
@@ -300,9 +302,13 @@ class KuryrNetwork(network.Network):
self.docker.disconnect_container_from_network(container_id,
network_name)
finally:
for port_id in neutron_ports:
for port_id in all_ports:
try:
self.neutron_api.delete_port(port_id)
if port_id in neutron_ports:
self.neutron_api.delete_port(port_id)
else:
port_req_body = {'port': {'device_id': ""}}
self.neutron_api.update_port(port_id, port_req_body)
except exceptions.PortNotFoundClient:
LOG.warning('Maybe your libnetwork distribution do not '
'have patch https://review.openstack.org/#/c/'