From bba498d2cf6d897789641ca093c2d3b9daff8472 Mon Sep 17 00:00:00 2001 From: Oleksandr Kuchmystyi Date: Tue, 21 Oct 2025 15:51:31 +0300 Subject: haproxy: T7906: Probing of a port other than the one to which normal traffic is sent Add support for specifying a custom health check port for HAProxy backend servers. This allows health probes to target a dedicated endpoint - such as port 8080 - separate from normal traffic ports (e.g., 80 or 443). --- .../scripts/cli/test_load-balancing_haproxy.py | 60 ++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'smoketest/scripts/cli/test_load-balancing_haproxy.py') diff --git a/smoketest/scripts/cli/test_load-balancing_haproxy.py b/smoketest/scripts/cli/test_load-balancing_haproxy.py index 2b8672e1f..84e9f21fe 100755 --- a/smoketest/scripts/cli/test_load-balancing_haproxy.py +++ b/smoketest/scripts/cli/test_load-balancing_haproxy.py @@ -485,6 +485,66 @@ class TestLoadBalancingReverseProxy(VyOSUnitTestSHIM.TestCase): config = read_file(HAPROXY_CONF) self.assertIn(f'option smtpchk', config) + def test_reverse_proxy_tcp_health_checks_custom_port(self): + # Define variables + service = 'my-tcp-api' + mode = 'tcp' + front_port = '9000' + backend = 'bk-01' + balance = 'round-robin' + servers = [ + ('srv01', '192.0.2.11', '9001', '9011'), + ('srv02', '192.0.2.12', '9002', None), + ('srv03', '192.0.2.13', '9003', '9013'), + ] + + # Configure frontend + self.cli_set(base_path + ['service', service, 'backend', backend]) + self.cli_set(base_path + ['service', service, 'mode', mode]) + self.cli_set(base_path + ['service', service, 'port', front_port]) + + # Configure backend + self.cli_set(base_path + ['backend', backend, 'balance', balance]) + self.cli_set(base_path + ['backend', backend, 'mode', mode]) + + # Configure backend servers + for name, addr, port, check_port in servers: + base_server_path = base_path + ['backend', backend, 'server', name] + self.cli_set(base_server_path + ['address', addr]) + self.cli_set(base_server_path + ['port', port]) + + if check_port: + self.cli_set(base_server_path + ['check', 'port', check_port]) + else: + self.cli_set(base_server_path + ['check']) + + # Commit and read config + self.cli_commit() + config = read_file(HAPROXY_CONF) + config_lines = [line.strip() for line in config.splitlines()] + + # Validate Frontend + self.assertIn(f'frontend {service}', config) + self.assertIn(f'bind [::]:{front_port} v4v6', config) + self.assertIn(f'mode {mode}', config) + self.assertIn(f'default_backend {backend}', config) + + # Validate Backend + self.assertIn(f'backend {backend}', config) + self.assertIn('balance roundrobin', config) + self.assertIn(f'mode {mode}', config) + + # Validate backend servers + for name, addr, port, check_port in servers: + with self.subTest(name=name): + expected_line = f'server {name} {addr}:{port}' + if check_port: + expected_line += f' check port {check_port}' + else: + expected_line += f' check' + + self.assertIn(expected_line, config_lines) + def test_reverse_proxy_logging(self): # Setup base self.base_config() -- cgit v1.2.3