Merge ~hloeung/content-cache-charm:haproxy-config into content-cache-charm:master
- Git
- lp:~hloeung/content-cache-charm
- haproxy-config
- Merge into master
Proposed by
Haw Loeung
Status: | Merged |
---|---|
Approved by: | James Simpson |
Approved revision: | 75daee99f6627bb7ac466ad07b19760d9a6e23b5 |
Merged at revision: | 779931cc1a753a42196348823e752200c98f5923 |
Proposed branch: | ~hloeung/content-cache-charm:haproxy-config |
Merge into: | content-cache-charm:master |
Diff against target: |
304 lines (+67/-33) 4 files modified
lib/haproxy.py (+11/-6) tests/unit/files/content_cache_rendered_haproxy_test_output_processes_and_threads_haproxy2.txt (+48/-24) tests/unit/files/haproxy_config_rendered_backends_stanzas_test_output3.txt (+4/-2) tests/unit/test_haproxy.py (+4/-1) |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
James Simpson | Approve | ||
Canonical IS Reviewers | Pending | ||
Review via email: mp+462551@code.launchpad.net |
Commit message
Newer versions of HAProxy (such as 2.9) fails to start unless headers are sent via http-check send
Description of the change
To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote : | # |
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote : | # |
Change successfully merged at revision 779931cc1a753a4
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | diff --git a/lib/haproxy.py b/lib/haproxy.py |
2 | index 845854d..d37b560 100644 |
3 | --- a/lib/haproxy.py |
4 | +++ b/lib/haproxy.py |
5 | @@ -373,17 +373,22 @@ backend backend-{name} |
6 | if opts: |
7 | options = '\n'.join(opts + ['']) |
8 | |
9 | - httpchk = ( |
10 | - r"option httpchk {method} {path} HTTP/1.1\r\n" |
11 | - r"Host:\ {site_name}\r\n" |
12 | - r"User-Agent:\ haproxy/httpchk" |
13 | - ).format(method=method, path=path, site_name=site_name) |
14 | + httpchk = "option httpchk {method} {path} HTTP/1.1".format(method=method, path=path) |
15 | + httpchk_extras = "\n{indent}http-check send hdr Host {site_name} hdr User-Agent haproxy/httpchk".format( |
16 | + site_name=site_name, indent=INDENT |
17 | + ) |
18 | + # Older versions of HAProxy such as 1.8 shiped with Bionic |
19 | + # doesn't support 'http-check send'. |
20 | + if LooseVersion(utils.package_version('haproxy')) <= LooseVersion('2.1'): |
21 | + httpchk_extras = r"\r\nHost:\ {site_name}\r\nUser-Agent:\ haproxy/httpchk".format( |
22 | + site_name=site_name |
23 | + ) |
24 | |
25 | output = backend_stanza.format( |
26 | name=backend_name, |
27 | site=site, |
28 | site_name=site_name, |
29 | - httpchk=httpchk, |
30 | + httpchk=httpchk + httpchk_extras, |
31 | load_balancing_algorithm=self.load_balancing_algorithm, |
32 | backends='\n'.join(backend_confs), |
33 | options=options, |
34 | 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 |
35 | index e288539..5b54864 100644 |
36 | --- a/tests/unit/files/content_cache_rendered_haproxy_test_output_processes_and_threads_haproxy2.txt |
37 | +++ b/tests/unit/files/content_cache_rendered_haproxy_test_output_processes_and_threads_haproxy2.txt |
38 | @@ -185,14 +185,16 @@ listen site12-local |
39 | default_backend backend-site12-local |
40 | |
41 | backend backend-cached-site1-local |
42 | - option httpchk HEAD /?token=1861920000_f3e404e205ed44749e942d481f7a7bec57c5e78a HTTP/1.1\r\nHost:\ site1.local\r\nUser-Agent:\ haproxy/httpchk |
43 | + option httpchk HEAD /?token=1861920000_f3e404e205ed44749e942d481f7a7bec57c5e78a HTTP/1.1 |
44 | + http-check send hdr Host site1.local hdr User-Agent haproxy/httpchk |
45 | http-request set-header Host site1.local |
46 | http-request set-header X-Forwarded-For %[src] |
47 | balance leastconn |
48 | server server_1 127.0.0.1:6080 check inter 2s rise 2 fall 60 maxconn 600 |
49 | |
50 | backend backend-site1-local |
51 | - option httpchk HEAD / HTTP/1.1\r\nHost:\ site1.local\r\nUser-Agent:\ haproxy/httpchk |
52 | + option httpchk HEAD / HTTP/1.1 |
53 | + http-check send hdr Host site1.local hdr User-Agent haproxy/httpchk |
54 | http-request set-header Host site1.local |
55 | retry-on all-retryable-errors |
56 | option redispatch 1 |
57 | @@ -202,14 +204,16 @@ backend backend-site1-local |
58 | server server_3 127.0.1.12:80 check inter 5s rise 2 fall 5 maxconn 200 |
59 | |
60 | backend backend-cached-site2-local |
61 | - option httpchk GET /_status/content-cache-check HTTP/1.1\r\nHost:\ site2.local\r\nUser-Agent:\ haproxy/httpchk |
62 | + option httpchk GET /_status/content-cache-check HTTP/1.1 |
63 | + http-check send hdr Host site2.local hdr User-Agent haproxy/httpchk |
64 | http-request set-header Host site2.local |
65 | http-request set-header X-Forwarded-For %[src] |
66 | balance leastconn |
67 | server server_1 127.0.0.1:6081 check inter 2s rise 2 fall 60 maxconn 3072 |
68 | |
69 | backend backend-site2-local |
70 | - option httpchk GET /check/ HTTP/1.1\r\nHost:\ site2.local\r\nUser-Agent:\ haproxy/httpchk |
71 | + option httpchk GET /check/ HTTP/1.1 |
72 | + http-check send hdr Host site2.local hdr User-Agent haproxy/httpchk |
73 | http-request set-header Host site2.local |
74 | retry-on all-retryable-errors |
75 | option redispatch 1 |
76 | @@ -219,14 +223,16 @@ backend backend-site2-local |
77 | 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 |
78 | |
79 | backend backend-cached-site3-local |
80 | - option httpchk GET /_status/content-cache-check HTTP/1.1\r\nHost:\ site3.local\r\nUser-Agent:\ haproxy/httpchk |
81 | + option httpchk GET /_status/content-cache-check HTTP/1.1 |
82 | + http-check send hdr Host site3.local hdr User-Agent haproxy/httpchk |
83 | http-request set-header Host site3.local |
84 | http-request set-header X-Forwarded-For %[src] |
85 | balance leastconn |
86 | server server_1 127.0.0.1:6082 check inter 2s rise 2 fall 60 maxconn 4096 |
87 | |
88 | backend backend-site3-local |
89 | - option httpchk HEAD / HTTP/1.1\r\nHost:\ site3.local\r\nUser-Agent:\ haproxy/httpchk |
90 | + option httpchk HEAD / HTTP/1.1 |
91 | + http-check send hdr Host site3.local hdr User-Agent haproxy/httpchk |
92 | http-request set-header Host site3.local |
93 | option forwardfor except 127.0.0.1 192.168.1.1 |
94 | option forceclose |
95 | @@ -238,21 +244,24 @@ backend backend-site3-local |
96 | server server_3 127.0.1.12:80 check inter 5s rise 2 fall 5 maxconn 200 |
97 | |
98 | backend backend-cached-site4-local |
99 | - option httpchk GET /_status/content-cache-check HTTP/1.1\r\nHost:\ site4.local\r\nUser-Agent:\ haproxy/httpchk |
100 | + option httpchk GET /_status/content-cache-check HTTP/1.1 |
101 | + http-check send hdr Host site4.local hdr User-Agent haproxy/httpchk |
102 | http-request set-header Host site4.local |
103 | http-request set-header X-Forwarded-For %[src] |
104 | balance leastconn |
105 | server server_1 127.0.0.1:6083 check inter 2s rise 2 fall 60 maxconn 200 |
106 | |
107 | backend backend-cached-site5 |
108 | - option httpchk GET /_status/content-cache-check HTTP/1.1\r\nHost:\ site5.local\r\nUser-Agent:\ haproxy/httpchk |
109 | + option httpchk GET /_status/content-cache-check HTTP/1.1 |
110 | + http-check send hdr Host site5.local hdr User-Agent haproxy/httpchk |
111 | http-request set-header Host site5.local |
112 | http-request set-header X-Forwarded-For %[src] |
113 | balance leastconn |
114 | server server_1 127.0.0.1:6084 check inter 2s rise 2 fall 60 maxconn 200 |
115 | |
116 | backend backend-site5 |
117 | - option httpchk HEAD / HTTP/1.1\r\nHost:\ site5.local\r\nUser-Agent:\ haproxy/httpchk |
118 | + option httpchk HEAD / HTTP/1.1 |
119 | + http-check send hdr Host site5.local hdr User-Agent haproxy/httpchk |
120 | http-request set-header Host site5.local |
121 | retry-on all-retryable-errors |
122 | option redispatch 1 |
123 | @@ -260,7 +269,8 @@ backend backend-site5 |
124 | server server_1 127.0.1.10:80 check inter 5s rise 2 fall 5 maxconn 200 |
125 | |
126 | backend backend-site5-2 |
127 | - option httpchk HEAD /status HTTP/1.1\r\nHost:\ site5.local\r\nUser-Agent:\ haproxy/httpchk |
128 | + option httpchk HEAD /status HTTP/1.1 |
129 | + http-check send hdr Host site5.local hdr User-Agent haproxy/httpchk |
130 | http-request set-header Host site5.local |
131 | retry-on all-retryable-errors |
132 | option redispatch 1 |
133 | @@ -268,14 +278,16 @@ backend backend-site5-2 |
134 | server server_1 127.0.1.11:80 check inter 5s rise 2 fall 5 maxconn 200 |
135 | |
136 | backend backend-cached-site6-local |
137 | - option httpchk GET /_status/content-cache-check HTTP/1.1\r\nHost:\ site6.local\r\nUser-Agent:\ haproxy/httpchk |
138 | + option httpchk GET /_status/content-cache-check HTTP/1.1 |
139 | + http-check send hdr Host site6.local hdr User-Agent haproxy/httpchk |
140 | http-request set-header Host site6.local |
141 | http-request set-header X-Forwarded-For %[src] |
142 | balance leastconn |
143 | server server_1 127.0.0.1:6085 check inter 2s rise 2 fall 60 maxconn 200 |
144 | |
145 | backend backend-site6-local |
146 | - option httpchk HEAD / HTTP/1.1\r\nHost:\ site6.local\r\nUser-Agent:\ haproxy/httpchk |
147 | + option httpchk HEAD / HTTP/1.1 |
148 | + http-check send hdr Host site6.local hdr User-Agent haproxy/httpchk |
149 | http-request set-header Host site6.local |
150 | retry-on all-retryable-errors |
151 | option redispatch 1 |
152 | @@ -283,14 +295,16 @@ backend backend-site6-local |
153 | 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 |
154 | |
155 | backend backend-cached-site7-local |
156 | - option httpchk GET /_status/content-cache-check HTTP/1.1\r\nHost:\ site7.local\r\nUser-Agent:\ haproxy/httpchk |
157 | + option httpchk GET /_status/content-cache-check HTTP/1.1 |
158 | + http-check send hdr Host site7.local hdr User-Agent haproxy/httpchk |
159 | http-request set-header Host site7.local |
160 | http-request set-header X-Forwarded-For %[src] |
161 | balance leastconn |
162 | server server_1 127.0.0.1:6086 check inter 2s rise 2 fall 60 maxconn 200 |
163 | |
164 | backend backend-site7-local |
165 | - option httpchk HEAD / HTTP/1.1\r\nHost:\ site7.local\r\nUser-Agent:\ haproxy/httpchk |
166 | + option httpchk HEAD / HTTP/1.1 |
167 | + http-check send hdr Host site7.local hdr User-Agent haproxy/httpchk |
168 | http-request set-header Host site7.local |
169 | retry-on all-retryable-errors |
170 | option redispatch 1 |
171 | @@ -298,14 +312,16 @@ backend backend-site7-local |
172 | server server_1 127.0.1.10:80 check inter 5s rise 2 fall 5 maxconn 200 |
173 | |
174 | backend backend-cached-site8-local |
175 | - option httpchk GET /_status/content-cache-check HTTP/1.1\r\nHost:\ site8.local\r\nUser-Agent:\ haproxy/httpchk |
176 | + option httpchk GET /_status/content-cache-check HTTP/1.1 |
177 | + http-check send hdr Host site8.local hdr User-Agent haproxy/httpchk |
178 | http-request set-header Host site8.local |
179 | http-request set-header X-Forwarded-For %[src] |
180 | balance leastconn |
181 | server server_1 127.0.0.1:6087 check inter 2s rise 2 fall 60 maxconn 200 |
182 | |
183 | backend backend-site8-local |
184 | - option httpchk HEAD / HTTP/1.1\r\nHost:\ site8.local\r\nUser-Agent:\ haproxy/httpchk |
185 | + option httpchk HEAD / HTTP/1.1 |
186 | + http-check send hdr Host site8.local hdr User-Agent haproxy/httpchk |
187 | http-request set-header Host site8.local |
188 | retry-on all-retryable-errors |
189 | option redispatch 1 |
190 | @@ -313,7 +329,8 @@ backend backend-site8-local |
191 | server server_1 127.0.1.10:80 check inter 5s rise 2 fall 5 maxconn 200 |
192 | |
193 | backend backend-site8-local-2 |
194 | - option httpchk HEAD / HTTP/1.1\r\nHost:\ auth.site8.local\r\nUser-Agent:\ haproxy/httpchk |
195 | + option httpchk HEAD / HTTP/1.1 |
196 | + http-check send hdr Host auth.site8.local hdr User-Agent haproxy/httpchk |
197 | http-request set-header Host auth.site8.local |
198 | retry-on all-retryable-errors |
199 | option redispatch 1 |
200 | @@ -321,7 +338,8 @@ backend backend-site8-local-2 |
201 | 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 |
202 | |
203 | backend backend-cached-site9-local |
204 | - option httpchk GET /_status/content-cache-check HTTP/1.1\r\nHost:\ site9.local\r\nUser-Agent:\ haproxy/httpchk |
205 | + option httpchk GET /_status/content-cache-check HTTP/1.1 |
206 | + http-check send hdr Host site9.local hdr User-Agent haproxy/httpchk |
207 | stick-table type ip size 1m expire 30s store http_req_rate(10s) |
208 | http-request track-sc0 src |
209 | http-request deny deny_status 429 if { sc_http_req_rate(0) gt 20 } |
210 | @@ -331,7 +349,8 @@ backend backend-cached-site9-local |
211 | server server_1 127.0.0.1:6088 check inter 2s rise 2 fall 60 maxconn 200 |
212 | |
213 | backend backend-site9-local |
214 | - option httpchk HEAD / HTTP/1.1\r\nHost:\ site9.local\r\nUser-Agent:\ haproxy/httpchk |
215 | + option httpchk HEAD / HTTP/1.1 |
216 | + http-check send hdr Host site9.local hdr User-Agent haproxy/httpchk |
217 | http-request set-header Host site9.local |
218 | retry-on all-retryable-errors |
219 | option redispatch 1 |
220 | @@ -339,14 +358,16 @@ backend backend-site9-local |
221 | server server_1 127.0.1.15:80 check inter 1m rise 2 fall 5 maxconn 200 |
222 | |
223 | backend backend-cached-site10-local |
224 | - option httpchk GET /_status/content-cache-check HTTP/1.1\r\nHost:\ site10.local\r\nUser-Agent:\ haproxy/httpchk |
225 | + option httpchk GET /_status/content-cache-check HTTP/1.1 |
226 | + http-check send hdr Host site10.local hdr User-Agent haproxy/httpchk |
227 | http-request set-header Host site10.local |
228 | http-request set-header X-Forwarded-For %[src] |
229 | balance leastconn |
230 | server server_1 127.0.0.1:6089 check inter 2s rise 2 fall 60 maxconn 200 |
231 | |
232 | backend backend-cached-site11-local |
233 | - option httpchk GET /_status/content-cache-check HTTP/1.1\r\nHost:\ site11.local\r\nUser-Agent:\ haproxy/httpchk |
234 | + option httpchk GET /_status/content-cache-check HTTP/1.1 |
235 | + http-check send hdr Host site11.local hdr User-Agent haproxy/httpchk |
236 | http-request set-header Host site11.local |
237 | http-request set-header X-Forwarded-For %[src] |
238 | acl restricted_page query -m reg ^q=............$ |
239 | @@ -355,7 +376,8 @@ backend backend-cached-site11-local |
240 | server server_1 127.0.0.1:6090 check inter 2s rise 2 fall 60 maxconn 600 |
241 | |
242 | backend backend-site11-local |
243 | - option httpchk HEAD / HTTP/1.1\r\nHost:\ site11.local\r\nUser-Agent:\ haproxy/httpchk |
244 | + option httpchk HEAD / HTTP/1.1 |
245 | + http-check send hdr Host site11.local hdr User-Agent haproxy/httpchk |
246 | http-request set-header Host site11.local |
247 | option forwardfor except 127.0.0.1 192.168.1.1 |
248 | option forceclose |
249 | @@ -367,14 +389,16 @@ backend backend-site11-local |
250 | server server_3 127.0.1.12:80 check inter 5s rise 2 fall 5 maxconn 200 |
251 | |
252 | backend backend-cached-site12-local |
253 | - option httpchk GET /_status/content-cache-check HTTP/1.1\r\nHost:\ site12.local\r\nUser-Agent:\ haproxy/httpchk |
254 | + option httpchk GET /_status/content-cache-check HTTP/1.1 |
255 | + http-check send hdr Host site12.local hdr User-Agent haproxy/httpchk |
256 | http-request set-header Host site12.local |
257 | http-request set-header X-Forwarded-For %[src] |
258 | balance leastconn |
259 | server server_1 127.0.0.1:6091 check inter 2s rise 2 fall 60 maxconn 600 |
260 | |
261 | backend backend-site12-local |
262 | - option httpchk HEAD / HTTP/1.1\r\nHost:\ site12.local\r\nUser-Agent:\ haproxy/httpchk |
263 | + option httpchk HEAD / HTTP/1.1 |
264 | + http-check send hdr Host site12.local hdr User-Agent haproxy/httpchk |
265 | http-request set-header Host site12.local |
266 | retry-on all-retryable-errors |
267 | option redispatch 1 |
268 | 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 |
269 | index fa5df40..d557a23 100644 |
270 | --- a/tests/unit/files/haproxy_config_rendered_backends_stanzas_test_output3.txt |
271 | +++ b/tests/unit/files/haproxy_config_rendered_backends_stanzas_test_output3.txt |
272 | @@ -1,12 +1,14 @@ |
273 | |
274 | backend backend-site1-local |
275 | - option httpchk HEAD /swift/v1/AUTH_aabbccdd001122/mybucket/index.html HTTP/1.1\r\nHost:\ objectstorage.ps5.internal\r\nUser-Agent:\ haproxy/httpchk |
276 | + option httpchk HEAD /swift/v1/AUTH_aabbccdd001122/mybucket/index.html HTTP/1.1 |
277 | + http-check send hdr Host objectstorage.ps5.internal hdr User-Agent haproxy/httpchk |
278 | http-request set-header Host objectstorage.ps5.internal |
279 | balance leastconn |
280 | 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 |
281 | |
282 | backend backend-site2-local |
283 | - option httpchk HEAD /swift/v1/AUTH_aabbccdd001122/mybucket/index.html HTTP/1.1\r\nHost:\ objectstorage.ps5.internal\r\nUser-Agent:\ haproxy/httpchk |
284 | + option httpchk HEAD /swift/v1/AUTH_aabbccdd001122/mybucket/index.html HTTP/1.1 |
285 | + http-check send hdr Host objectstorage.ps5.internal hdr User-Agent haproxy/httpchk |
286 | http-request set-header Host objectstorage.ps5.internal |
287 | balance leastconn |
288 | 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 |
289 | diff --git a/tests/unit/test_haproxy.py b/tests/unit/test_haproxy.py |
290 | index 2a2f86b..67f52ec 100644 |
291 | --- a/tests/unit/test_haproxy.py |
292 | +++ b/tests/unit/test_haproxy.py |
293 | @@ -152,7 +152,10 @@ class TestLibHAProxy(unittest.TestCase): |
294 | want = f.read() |
295 | self.assertEqual(''.join(haproxy.render_stanza_backend(config)), want) |
296 | |
297 | - def test_haproxy_config_rendered_backend_stanzas_use_dns(self): |
298 | + @freezegun.freeze_time("2019-10-10", tz_offset=0) |
299 | + @mock.patch('lib.utils.package_version') |
300 | + def test_haproxy_config_rendered_backend_stanzas_use_dns(self, package_version): |
301 | + package_version.return_value = '1.8.8-1ubuntu0.10' |
302 | haproxy = HAProxy.HAProxyConf(self.tmpdir) |
303 | config = {'site1.local': {'locations': {'/': {'backends': ['archive.ubuntu.com:80']}}}} |
304 | output = 'tests/unit/files/haproxy_config_rendered_backends_stanzas_test_output2.txt' |
This merge proposal is being monitored by mergebot. Change the status to Approved to merge.