Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

haproxy: T6179: fix rule generation #3382

Merged
merged 1 commit into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions data/templates/load-balancing/haproxy.cfg.j2
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ frontend {{ front }}
{% if front_config.rule is vyos_defined %}
{% for rule, rule_config in front_config.rule.items() %}
# rule {{ rule }}
{% if rule_config.domain_name is vyos_defined and rule_config.set.backend is vyos_defined %}
{% if rule_config.domain_name is vyos_defined %}
{% set rule_options = 'hdr(host)' %}
{% if rule_config.ssl is vyos_defined %}
{% set ssl_rule_translate = {'req-ssl-sni': 'req_ssl_sni', 'ssl-fc-sni': 'ssl_fc_sni', 'ssl-fc-sni-end': 'ssl_fc_sni_end'} %}
Expand All @@ -94,16 +94,20 @@ frontend {{ front }}
{% for domain in rule_config.domain_name %}
acl {{ rule }} {{ rule_options }} -i {{ domain }}
{% endfor %}
use_backend {{ rule_config.set.backend }} if {{ rule }}
{% endif %}
{# path url #}
{% if rule_config.url_path is vyos_defined and rule_config.set.redirect_location is vyos_defined %}
{% if rule_config.url_path is vyos_defined %}
{% set path_mod_translate = {'begin': '-i -m beg', 'end': '-i -m end', 'exact': ''} %}
{% for path, path_config in rule_config.url_path.items() %}
{% for url in path_config %}
acl {{ rule }} path {{ path_mod_translate[path] }} {{ url }}
{% endfor %}
{% endfor %}
{% endif %}
{% if rule_config.set.backend is vyos_defined %}
use_backend {{ rule_config.set.backend }} if {{ rule }}
{% endif %}
{% if rule_config.set.redirect_location is vyos_defined %}
http-request redirect location {{ rule_config.set.redirect_location }} code 301 if {{ rule }}
{% endif %}
{# endpath #}
Expand Down
5 changes: 5 additions & 0 deletions smoketest/scripts/cli/test_load-balancing_reverse-proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ def test_01_lb_reverse_proxy_domain(self):
mode = 'http'
rule_ten = '10'
rule_twenty = '20'
rule_thirty = '30'
send_proxy = 'send-proxy'
max_connections = '1000'

Expand All @@ -192,6 +193,8 @@ def test_01_lb_reverse_proxy_domain(self):
self.cli_set(base_path + ['service', frontend, 'rule', rule_ten, 'set', 'backend', bk_first_name])
self.cli_set(base_path + ['service', frontend, 'rule', rule_twenty, 'domain-name', domain_bk_second])
self.cli_set(base_path + ['service', frontend, 'rule', rule_twenty, 'set', 'backend', bk_second_name])
self.cli_set(base_path + ['service', frontend, 'rule', rule_thirty, 'url-path', 'end', '/test'])
self.cli_set(base_path + ['service', frontend, 'rule', rule_thirty, 'set', 'backend', bk_second_name])

self.cli_set(back_base + [bk_first_name, 'mode', mode])
self.cli_set(back_base + [bk_first_name, 'server', bk_first_name, 'address', bk_server_first])
Expand Down Expand Up @@ -222,6 +225,8 @@ def test_01_lb_reverse_proxy_domain(self):
self.assertIn(f'use_backend {bk_first_name} if {rule_ten}', config)
self.assertIn(f'acl {rule_twenty} hdr(host) -i {domain_bk_second}', config)
self.assertIn(f'use_backend {bk_second_name} if {rule_twenty}', config)
self.assertIn(f'acl {rule_thirty} path -i -m end /test', config)
self.assertIn(f'use_backend {bk_second_name} if {rule_thirty}', config)

# Backend
self.assertIn(f'backend {bk_first_name}', config)
Expand Down
Loading