From bd9d474b12bfda89988bd60aabc371701d633c14 Mon Sep 17 00:00:00 2001 From: Gregory Thiemonge Date: Mon, 19 Jun 2023 16:53:54 -0400 Subject: [PATCH] Fix haproxy global maxconn with disabled listeners global maxconn value is based on the connection-limit of the listeners of a LB, but it includes the connection-limit of disabled listeners. Disabled listeners are now skipped. Closes-Bug: #2024371 Change-Id: I45500d618b307f740b8e692c49f5efdd27dc10a0 (cherry picked from commit 21682f7056d9c08a322bcfddac3f075be939805d) --- .../haproxy/combined_listeners/jinja_cfg.py | 2 ++ .../combined_listeners/test_jinja_cfg.py | 22 +++++++++++++++++++ ...h-disabled-listeners-fa89f762a94b8fe9.yaml | 6 +++++ 3 files changed, 30 insertions(+) create mode 100644 releasenotes/notes/fix-haproxy-maxconn-with-disabled-listeners-fa89f762a94b8fe9.yaml diff --git a/octavia/common/jinja/haproxy/combined_listeners/jinja_cfg.py b/octavia/common/jinja/haproxy/combined_listeners/jinja_cfg.py index 094ea900fb..60f6798864 100644 --- a/octavia/common/jinja/haproxy/combined_listeners/jinja_cfg.py +++ b/octavia/common/jinja/haproxy/combined_listeners/jinja_cfg.py @@ -265,6 +265,8 @@ class JinjaTemplater(object): # listeners' connection limits. connection_limit_sum = 0 for listener in listeners: + if not listener.enabled: + continue if listener.protocol in constants.LVS_PROTOCOLS: continue if listener.connection_limit and listener.connection_limit > -1: diff --git a/octavia/tests/unit/common/jinja/haproxy/combined_listeners/test_jinja_cfg.py b/octavia/tests/unit/common/jinja/haproxy/combined_listeners/test_jinja_cfg.py index 5ae68b2d83..f3be659774 100644 --- a/octavia/tests/unit/common/jinja/haproxy/combined_listeners/test_jinja_cfg.py +++ b/octavia/tests/unit/common/jinja/haproxy/combined_listeners/test_jinja_cfg.py @@ -1559,6 +1559,28 @@ class TestHaproxyCfg(base.TestCase): self.assertLess(ret['global_connection_limit'], connection_limit_sum) + def test_transform_with_disabled_listeners(self): + in_amphora = sample_configs_combined.sample_amphora_tuple() + + in_listeners = [] + + connection_limit_sum = 0 + + in_listener = ( + sample_configs_combined.sample_listener_tuple()) + connection_limit_sum += constants.HAPROXY_DEFAULT_MAXCONN + in_listeners.append(in_listener) + + disabled_listener = ( + sample_configs_combined.sample_listener_tuple(enabled=False)) + in_listeners.append(disabled_listener) + + ret = self.jinja_cfg._transform_loadbalancer( + in_amphora, in_listeners[0].load_balancer, + in_listeners, None, {}) + self.assertEqual(ret['global_connection_limit'], + connection_limit_sum) + def test_transform_amphora(self): in_amphora = sample_configs_combined.sample_amphora_tuple() ret = self.jinja_cfg._transform_amphora(in_amphora, {}) diff --git a/releasenotes/notes/fix-haproxy-maxconn-with-disabled-listeners-fa89f762a94b8fe9.yaml b/releasenotes/notes/fix-haproxy-maxconn-with-disabled-listeners-fa89f762a94b8fe9.yaml new file mode 100644 index 0000000000..1642a97aa2 --- /dev/null +++ b/releasenotes/notes/fix-haproxy-maxconn-with-disabled-listeners-fa89f762a94b8fe9.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + Fixed the global number of concurrent connections in haproxy when disabling + listeners. The connection-limit of disabled listeners was used to compute + this value, disabled listeners are now skipped.