Fix memory leak in the haproxy provider driver

The haproxy provider driver uses a dict for caching load balancer
resources (including children resources). That alone already increases
memory consumption. A neutron-server restart solves this.

But the real issue is that the driver leaves some data behind when a LB
is deleted without freeing it up (unless neutron-server is restart)
hence the memory leak.

Story: 2003802
Task: 26534

Change-Id: I7c79271998d839c6afbeb6d92f888f6acd67704e
(cherry picked from commit 111d0b2852)
This commit is contained in:
Carlos Goncalves 2018-09-18 19:49:58 +02:00
parent 74dddcb23b
commit f243150233
2 changed files with 4 additions and 0 deletions

View File

@ -178,6 +178,9 @@ class HaproxyNSDriver(agent_device_driver.AgentDeviceDriver):
ns = ip_lib.IPWrapper(namespace=namespace)
ns.garbage_collect_namespace()
if loadbalancer_id in self.deployed_loadbalancers:
del self.deployed_loadbalancers[loadbalancer_id]
def remove_orphans(self, known_loadbalancer_ids):
if not os.path.exists(self.state_path):
return

View File

@ -108,6 +108,7 @@ class TestHaproxyNSDriver(base.BaseTestCase):
namespace=ns)
mock_shutil.assert_called_once_with('/path/' + self.lb.id)
mock_ns.garbage_collect_namespace.assert_called_once_with()
self.assertDictEqual(self.driver.deployed_loadbalancers, {})
@mock.patch('os.makedirs')
@mock.patch('os.path.dirname')