diff options
| author | Haw Loeung <[email protected]> | 2024-03-17 23:32:44 +0000 |
|---|---|---|
| committer | Canonical IS Mergebot <[email protected]> | 2024-03-17 23:32:44 +0000 |
| commit | 779931cc1a753a42196348823e752200c98f5923 (patch) | |
| tree | 23e3c8232f2e7f78316dbc2bd46be57a2515e3c5 | |
| parent | bad538f03a268d584d4e23b880ac5ab762cc1845 (diff) | |
| parent | 75daee99f6627bb7ac466ad07b19760d9a6e23b5 (diff) | |
Newer versions of HAProxy (such as 2.9) fails to start unless headers are sent via http-check send
Reviewed-on: https://code.launchpad.net/~hloeung/content-cache-charm/+git/content-cache-charm/+merge/462551
Reviewed-by: James Simpson <[email protected]>
4 files changed, 67 insertions, 33 deletions
diff --git a/lib/haproxy.py b/lib/haproxy.py index 845854d..d37b560 100644 --- a/lib/haproxy.py +++ b/lib/haproxy.py @@ -373,17 +373,22 @@ backend backend-{name} if opts: options = '\n'.join(opts + ['']) - httpchk = ( - r"option httpchk {method} {path} HTTP/1.1\r\n" - r"Host:\ {site_name}\r\n" - r"User-Agent:\ haproxy/httpchk" - ).format(method=method, path=path, site_name=site_name) + httpchk = "option httpchk {method} {path} HTTP/1.1".format(method=method, path=path) + httpchk_extras = "\n{indent}http-check send hdr Host {site_name} hdr User-Agent haproxy/httpchk".format( + site_name=site_name, indent=INDENT + ) + # Older versions of HAProxy such as 1.8 shiped with Bionic + # doesn't support 'http-check send'. + if LooseVersion(utils.package_version('haproxy')) <= LooseVersion('2.1'): + httpchk_extras = r"\r\nHost:\ {site_name}\r\nUser-Agent:\ haproxy/httpchk".format( + site_name=site_name + ) output = backend_stanza.format( name=backend_name, site=site, site_name=site_name, - httpchk=httpchk, + httpchk=httpchk + httpchk_extras, load_balancing_algorithm=self.load_balancing_algorithm, backends='\n'.join(backend_confs), options=options, diff --git a/tests/unit/files/content_cache_rendered_haproxy_test_output_processes_and_threads_haproxy2.txt b/tests/unit/files/content_cache_rendered_haproxy_test_output_processes_and_threads_haproxy2.txt index e288539..5b54864 100644 --- a/tests/unit/files/content_cache_rendered_haproxy_test_output_processes_and_threads_haproxy2.txt +++ b/tests/unit/files/content_cache_rendered_haproxy_test_output_processes_and_threads_haproxy2.txt @@ -185,14 +185,16 @@ listen site12-local default_backend backend-site12-local backend backend-cached-site1-local - option httpchk HEAD /?token=1861920000_f3e404e205ed44749e942d481f7a7bec57c5e78a HTTP/1.1\r\nHost:\ site1.local\r\nUser-Agent:\ haproxy/httpchk + option httpchk HEAD /?token=1861920000_f3e404e205ed44749e942d481f7a7bec57c5e78a HTTP/1.1 + http-check send hdr Host site1.local hdr User-Agent haproxy/httpchk http-request set-header Host site1.local http-request set-header X-Forwarded-For %[src] balance leastconn server server_1 127.0.0.1:6080 check inter 2s rise 2 fall 60 maxconn 600 backend backend-site1-local - option httpchk HEAD / HTTP/1.1\r\nHost:\ site1.local\r\nUser-Agent:\ haproxy/httpchk + option httpchk HEAD / HTTP/1.1 + http-check send hdr Host site1.local hdr User-Agent haproxy/httpchk http-request set-header Host site1.local retry-on all-retryable-errors option redispatch 1 @@ -202,14 +204,16 @@ backend backend-site1-local server server_3 127.0.1.12:80 check inter 5s rise 2 fall 5 maxconn 200 backend backend-cached-site2-local - option httpchk GET /_status/content-cache-check HTTP/1.1\r\nHost:\ site2.local\r\nUser-Agent:\ haproxy/httpchk + option httpchk GET /_status/content-cache-check HTTP/1.1 + http-check send hdr Host site2.local hdr User-Agent haproxy/httpchk http-request set-header Host site2.local http-request set-header X-Forwarded-For %[src] balance leastconn server server_1 127.0.0.1:6081 check inter 2s rise 2 fall 60 maxconn 3072 backend backend-site2-local - option httpchk GET /check/ HTTP/1.1\r\nHost:\ site2.local\r\nUser-Agent:\ haproxy/httpchk + option httpchk GET /check/ HTTP/1.1 + http-check send hdr Host site2.local hdr User-Agent haproxy/httpchk http-request set-header Host site2.local retry-on all-retryable-errors option redispatch 1 @@ -219,14 +223,16 @@ backend backend-site2-local server server_3 127.0.1.12:443 check inter 5s rise 2 fall 5 maxconn 1024 ssl sni str(site2.local) check-sni site2.local verify required ca-file ca-certificates.crt alpn h2,http/1.1 check-alpn http/1.1 backend backend-cached-site3-local - option httpchk GET /_status/content-cache-check HTTP/1.1\r\nHost:\ site3.local\r\nUser-Agent:\ haproxy/httpchk + option httpchk GET /_status/content-cache-check HTTP/1.1 + http-check send hdr Host site3.local hdr User-Agent haproxy/httpchk http-request set-header Host site3.local http-request set-header X-Forwarded-For %[src] balance leastconn server server_1 127.0.0.1:6082 check inter 2s rise 2 fall 60 maxconn 4096 backend backend-site3-local - option httpchk HEAD / HTTP/1.1\r\nHost:\ site3.local\r\nUser-Agent:\ haproxy/httpchk + option httpchk HEAD / HTTP/1.1 + http-check send hdr Host site3.local hdr User-Agent haproxy/httpchk http-request set-header Host site3.local option forwardfor except 127.0.0.1 192.168.1.1 option forceclose @@ -238,21 +244,24 @@ backend backend-site3-local server server_3 127.0.1.12:80 check inter 5s rise 2 fall 5 maxconn 200 backend backend-cached-site4-local - option httpchk GET /_status/content-cache-check HTTP/1.1\r\nHost:\ site4.local\r\nUser-Agent:\ haproxy/httpchk + option httpchk GET /_status/content-cache-check HTTP/1.1 + http-check send hdr Host site4.local hdr User-Agent haproxy/httpchk http-request set-header Host site4.local http-request set-header X-Forwarded-For %[src] balance leastconn server server_1 127.0.0.1:6083 check inter 2s rise 2 fall 60 maxconn 200 backend backend-cached-site5 - option httpchk GET /_status/content-cache-check HTTP/1.1\r\nHost:\ site5.local\r\nUser-Agent:\ haproxy/httpchk + option httpchk GET /_status/content-cache-check HTTP/1.1 + http-check send hdr Host site5.local hdr User-Agent haproxy/httpchk http-request set-header Host site5.local http-request set-header X-Forwarded-For %[src] balance leastconn server server_1 127.0.0.1:6084 check inter 2s rise 2 fall 60 maxconn 200 backend backend-site5 - option httpchk HEAD / HTTP/1.1\r\nHost:\ site5.local\r\nUser-Agent:\ haproxy/httpchk + option httpchk HEAD / HTTP/1.1 + http-check send hdr Host site5.local hdr User-Agent haproxy/httpchk http-request set-header Host site5.local retry-on all-retryable-errors option redispatch 1 @@ -260,7 +269,8 @@ backend backend-site5 server server_1 127.0.1.10:80 check inter 5s rise 2 fall 5 maxconn 200 backend backend-site5-2 - option httpchk HEAD /status HTTP/1.1\r\nHost:\ site5.local\r\nUser-Agent:\ haproxy/httpchk + option httpchk HEAD /status HTTP/1.1 + http-check send hdr Host site5.local hdr User-Agent haproxy/httpchk http-request set-header Host site5.local retry-on all-retryable-errors option redispatch 1 @@ -268,14 +278,16 @@ backend backend-site5-2 server server_1 127.0.1.11:80 check inter 5s rise 2 fall 5 maxconn 200 backend backend-cached-site6-local - option httpchk GET /_status/content-cache-check HTTP/1.1\r\nHost:\ site6.local\r\nUser-Agent:\ haproxy/httpchk + option httpchk GET /_status/content-cache-check HTTP/1.1 + http-check send hdr Host site6.local hdr User-Agent haproxy/httpchk http-request set-header Host site6.local http-request set-header X-Forwarded-For %[src] balance leastconn server server_1 127.0.0.1:6085 check inter 2s rise 2 fall 60 maxconn 200 backend backend-site6-local - option httpchk HEAD / HTTP/1.1\r\nHost:\ site6.local\r\nUser-Agent:\ haproxy/httpchk + option httpchk HEAD / HTTP/1.1 + http-check send hdr Host site6.local hdr User-Agent haproxy/httpchk http-request set-header Host site6.local retry-on all-retryable-errors option redispatch 1 @@ -283,14 +295,16 @@ backend backend-site6-local server server_1 127.0.1.10:443 check inter 5s rise 2 fall 5 maxconn 200 ssl sni str(site6.local) check-sni site6.local verify required ca-file ca-certificates.crt alpn h2,http/1.1 check-alpn http/1.1 backend backend-cached-site7-local - option httpchk GET /_status/content-cache-check HTTP/1.1\r\nHost:\ site7.local\r\nUser-Agent:\ haproxy/httpchk + option httpchk GET /_status/content-cache-check HTTP/1.1 + http-check send hdr Host site7.local hdr User-Agent haproxy/httpchk http-request set-header Host site7.local http-request set-header X-Forwarded-For %[src] balance leastconn server server_1 127.0.0.1:6086 check inter 2s rise 2 fall 60 maxconn 200 backend backend-site7-local - option httpchk HEAD / HTTP/1.1\r\nHost:\ site7.local\r\nUser-Agent:\ haproxy/httpchk + option httpchk HEAD / HTTP/1.1 + http-check send hdr Host site7.local hdr User-Agent haproxy/httpchk http-request set-header Host site7.local retry-on all-retryable-errors option redispatch 1 @@ -298,14 +312,16 @@ backend backend-site7-local server server_1 127.0.1.10:80 check inter 5s rise 2 fall 5 maxconn 200 backend backend-cached-site8-local - option httpchk GET /_status/content-cache-check HTTP/1.1\r\nHost:\ site8.local\r\nUser-Agent:\ haproxy/httpchk + option httpchk GET /_status/content-cache-check HTTP/1.1 + http-check send hdr Host site8.local hdr User-Agent haproxy/httpchk http-request set-header Host site8.local http-request set-header X-Forwarded-For %[src] balance leastconn server server_1 127.0.0.1:6087 check inter 2s rise 2 fall 60 maxconn 200 backend backend-site8-local - option httpchk HEAD / HTTP/1.1\r\nHost:\ site8.local\r\nUser-Agent:\ haproxy/httpchk + option httpchk HEAD / HTTP/1.1 + http-check send hdr Host site8.local hdr User-Agent haproxy/httpchk http-request set-header Host site8.local retry-on all-retryable-errors option redispatch 1 @@ -313,7 +329,8 @@ backend backend-site8-local server server_1 127.0.1.10:80 check inter 5s rise 2 fall 5 maxconn 200 backend backend-site8-local-2 - option httpchk HEAD / HTTP/1.1\r\nHost:\ auth.site8.local\r\nUser-Agent:\ haproxy/httpchk + option httpchk HEAD / HTTP/1.1 + http-check send hdr Host auth.site8.local hdr User-Agent haproxy/httpchk http-request set-header Host auth.site8.local retry-on all-retryable-errors option redispatch 1 @@ -321,7 +338,8 @@ backend backend-site8-local-2 server server_1 127.0.1.10:443 check inter 5s rise 2 fall 5 maxconn 200 ssl sni str(auth.site8.local) check-sni auth.site8.local verify required ca-file ca-certificates.crt alpn h2,http/1.1 check-alpn http/1.1 backend backend-cached-site9-local - option httpchk GET /_status/content-cache-check HTTP/1.1\r\nHost:\ site9.local\r\nUser-Agent:\ haproxy/httpchk + option httpchk GET /_status/content-cache-check HTTP/1.1 + http-check send hdr Host site9.local hdr User-Agent haproxy/httpchk stick-table type ip size 1m expire 30s store http_req_rate(10s) http-request track-sc0 src http-request deny deny_status 429 if { sc_http_req_rate(0) gt 20 } @@ -331,7 +349,8 @@ backend backend-cached-site9-local server server_1 127.0.0.1:6088 check inter 2s rise 2 fall 60 maxconn 200 backend backend-site9-local - option httpchk HEAD / HTTP/1.1\r\nHost:\ site9.local\r\nUser-Agent:\ haproxy/httpchk + option httpchk HEAD / HTTP/1.1 + http-check send hdr Host site9.local hdr User-Agent haproxy/httpchk http-request set-header Host site9.local retry-on all-retryable-errors option redispatch 1 @@ -339,14 +358,16 @@ backend backend-site9-local server server_1 127.0.1.15:80 check inter 1m rise 2 fall 5 maxconn 200 backend backend-cached-site10-local - option httpchk GET /_status/content-cache-check HTTP/1.1\r\nHost:\ site10.local\r\nUser-Agent:\ haproxy/httpchk + option httpchk GET /_status/content-cache-check HTTP/1.1 + http-check send hdr Host site10.local hdr User-Agent haproxy/httpchk http-request set-header Host site10.local http-request set-header X-Forwarded-For %[src] balance leastconn server server_1 127.0.0.1:6089 check inter 2s rise 2 fall 60 maxconn 200 backend backend-cached-site11-local - option httpchk GET /_status/content-cache-check HTTP/1.1\r\nHost:\ site11.local\r\nUser-Agent:\ haproxy/httpchk + option httpchk GET /_status/content-cache-check HTTP/1.1 + http-check send hdr Host site11.local hdr User-Agent haproxy/httpchk http-request set-header Host site11.local http-request set-header X-Forwarded-For %[src] acl restricted_page query -m reg ^q=............$ @@ -355,7 +376,8 @@ backend backend-cached-site11-local server server_1 127.0.0.1:6090 check inter 2s rise 2 fall 60 maxconn 600 backend backend-site11-local - option httpchk HEAD / HTTP/1.1\r\nHost:\ site11.local\r\nUser-Agent:\ haproxy/httpchk + option httpchk HEAD / HTTP/1.1 + http-check send hdr Host site11.local hdr User-Agent haproxy/httpchk http-request set-header Host site11.local option forwardfor except 127.0.0.1 192.168.1.1 option forceclose @@ -367,14 +389,16 @@ backend backend-site11-local server server_3 127.0.1.12:80 check inter 5s rise 2 fall 5 maxconn 200 backend backend-cached-site12-local - option httpchk GET /_status/content-cache-check HTTP/1.1\r\nHost:\ site12.local\r\nUser-Agent:\ haproxy/httpchk + option httpchk GET /_status/content-cache-check HTTP/1.1 + http-check send hdr Host site12.local hdr User-Agent haproxy/httpchk http-request set-header Host site12.local http-request set-header X-Forwarded-For %[src] balance leastconn server server_1 127.0.0.1:6091 check inter 2s rise 2 fall 60 maxconn 600 backend backend-site12-local - option httpchk HEAD / HTTP/1.1\r\nHost:\ site12.local\r\nUser-Agent:\ haproxy/httpchk + option httpchk HEAD / HTTP/1.1 + http-check send hdr Host site12.local hdr User-Agent haproxy/httpchk http-request set-header Host site12.local retry-on all-retryable-errors option redispatch 1 diff --git a/tests/unit/files/haproxy_config_rendered_backends_stanzas_test_output3.txt b/tests/unit/files/haproxy_config_rendered_backends_stanzas_test_output3.txt index fa5df40..d557a23 100644 --- a/tests/unit/files/haproxy_config_rendered_backends_stanzas_test_output3.txt +++ b/tests/unit/files/haproxy_config_rendered_backends_stanzas_test_output3.txt @@ -1,12 +1,14 @@ backend backend-site1-local - option httpchk HEAD /swift/v1/AUTH_aabbccdd001122/mybucket/index.html HTTP/1.1\r\nHost:\ objectstorage.ps5.internal\r\nUser-Agent:\ haproxy/httpchk + option httpchk HEAD /swift/v1/AUTH_aabbccdd001122/mybucket/index.html HTTP/1.1 + http-check send hdr Host objectstorage.ps5.internal hdr User-Agent haproxy/httpchk http-request set-header Host objectstorage.ps5.internal balance leastconn server server_1 10.0.1.10:443 check inter 5s rise 2 fall 5 maxconn 200 ssl sni str(objectstorage.ps5.internal) check-sni objectstorage.ps5.internal verify required ca-file ca-certificates.crt alpn h2,http/1.1 check-alpn http/1.1 backend backend-site2-local - option httpchk HEAD /swift/v1/AUTH_aabbccdd001122/mybucket/index.html HTTP/1.1\r\nHost:\ objectstorage.ps5.internal\r\nUser-Agent:\ haproxy/httpchk + option httpchk HEAD /swift/v1/AUTH_aabbccdd001122/mybucket/index.html HTTP/1.1 + http-check send hdr Host objectstorage.ps5.internal hdr User-Agent haproxy/httpchk http-request set-header Host objectstorage.ps5.internal balance leastconn server server_1 10.0.1.10:443 check inter 5s rise 2 fall 5 maxconn 200 ssl sni str(objectstorage.ps5.internal) check-sni objectstorage.ps5.internal verify required ca-file ca-certificates.crt alpn h2,http/1.1 check-alpn http/1.1 diff --git a/tests/unit/test_haproxy.py b/tests/unit/test_haproxy.py index 2a2f86b..67f52ec 100644 --- a/tests/unit/test_haproxy.py +++ b/tests/unit/test_haproxy.py @@ -152,7 +152,10 @@ class TestLibHAProxy(unittest.TestCase): want = f.read() self.assertEqual(''.join(haproxy.render_stanza_backend(config)), want) - def test_haproxy_config_rendered_backend_stanzas_use_dns(self): + @freezegun.freeze_time("2019-10-10", tz_offset=0) + @mock.patch('lib.utils.package_version') + def test_haproxy_config_rendered_backend_stanzas_use_dns(self, package_version): + package_version.return_value = '1.8.8-1ubuntu0.10' haproxy = HAProxy.HAProxyConf(self.tmpdir) config = {'site1.local': {'locations': {'/': {'backends': ['archive.ubuntu.com:80']}}}} output = 'tests/unit/files/haproxy_config_rendered_backends_stanzas_test_output2.txt' |
