From 6dc61b74d1c28596c24496ba85c660e106cb6b04 Mon Sep 17 00:00:00 2001 From: weikeyou Date: Mon, 8 Jan 2018 15:14:50 +0800 Subject: [PATCH] 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 --- zun/network/kuryr_network.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/zun/network/kuryr_network.py b/zun/network/kuryr_network.py index 0691c6340..99af32268 100644 --- a/zun/network/kuryr_network.py +++ b/zun/network/kuryr_network.py @@ -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/'