Merge ~hloeung/content-cache-charm:master into content-cache-charm:master
- Git
- lp:~hloeung/content-cache-charm
- master
- Merge into master
Proposed by
Haw Loeung
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Haw Loeung | ||||
Approved revision: | 7d3dec5ae404b4db32d11d65cb1114c5ac532031 | ||||
Merged at revision: | cc8cc0a95958ba26a89f2d4b56fba481669c88e8 | ||||
Proposed branch: | ~hloeung/content-cache-charm:master | ||||
Merge into: | content-cache-charm:master | ||||
Diff against target: |
286 lines (+84/-7) 13 files modified
lib/haproxy.py (+29/-5) reactive/content_cache.py (+4/-0) tests/unit/files/config_test_config.txt (+5/-0) tests/unit/files/content_cache_rendered_haproxy_test_output.txt (+1/-0) tests/unit/files/content_cache_rendered_haproxy_test_output3.txt (+1/-1) tests/unit/files/content_cache_rendered_haproxy_test_output_auto_maxconns.txt (+1/-0) tests/unit/files/content_cache_rendered_haproxy_test_output_processes_and_threads.txt (+1/-0) tests/unit/files/haproxy_config_rendered_listen_stanzas_test_output.txt (+1/-0) tests/unit/files/haproxy_config_rendered_listen_stanzas_test_output2.txt (+1/-1) tests/unit/files/haproxy_config_rendered_listen_stanzas_test_output3.txt (+14/-0) tests/unit/files/haproxy_config_rendered_test_output.txt (+1/-0) tests/unit/files/haproxy_config_rendered_test_output2.txt (+1/-0) tests/unit/test_haproxy.py (+24/-0) |
||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Stuart Bishop (community) | Approve | ||
Content Cache Charmers | Pending | ||
Review via email: mp+388637@code.launchpad.net |
Commit message
Allow specifying default site - LP:1863170
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
Stuart Bishop (stub) wrote : | # |
This all seems good.
review:
Approve
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote : | # |
Change successfully merged at revision cc8cc0a95958ba2
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 1d5721e..6516216 100644 | |||
3 | --- a/lib/haproxy.py | |||
4 | +++ b/lib/haproxy.py | |||
5 | @@ -77,6 +77,9 @@ class HAProxyConf: | |||
6 | 77 | # We use a different flag/config here so it's only enabled | 77 | # We use a different flag/config here so it's only enabled |
7 | 78 | # on the HTTP, and not the HTTPS, stanza. | 78 | # on the HTTP, and not the HTTPS, stanza. |
8 | 79 | new['0.0.0.0:80'][site_name] = {'enable-redirect-http-to-https': True} | 79 | new['0.0.0.0:80'][site_name] = {'enable-redirect-http-to-https': True} |
9 | 80 | if 'default' in config[site]: | ||
10 | 81 | new['0.0.0.0:80'][site_name]['default'] = config[site]['default'] | ||
11 | 82 | |||
12 | 80 | port = config[site].get('port', default_port) | 83 | port = config[site].get('port', default_port) |
13 | 81 | name = '{}:{}'.format(listen_address, port) | 84 | name = '{}:{}'.format(listen_address, port) |
14 | 82 | new.setdefault(name, {}) | 85 | new.setdefault(name, {}) |
15 | @@ -98,11 +101,11 @@ class HAProxyConf: | |||
16 | 98 | new[name][new_site]['port'] = port | 101 | new[name][new_site]['port'] = port |
17 | 99 | return new | 102 | return new |
18 | 100 | 103 | ||
20 | 101 | def render_stanza_listen(self, config): | 104 | def render_stanza_listen(self, config): # NOQA: C901 |
21 | 102 | listen_stanza = """ | 105 | listen_stanza = """ |
22 | 103 | listen {name} | 106 | listen {name} |
23 | 104 | {bind_config} | 107 | {bind_config} |
25 | 105 | {backend_config}""" | 108 | {backend_config}{default_backend}""" |
26 | 106 | backend_conf = '{indent}use_backend backend-{backend} if {{ hdr(Host) -i {site_name} }}\n' | 109 | backend_conf = '{indent}use_backend backend-{backend} if {{ hdr(Host) -i {site_name} }}\n' |
27 | 107 | redirect_conf = '{indent}redirect scheme https code 301 if {{ hdr(Host) -i {site_name} }} !{{ ssl_fc }}\n' | 110 | redirect_conf = '{indent}redirect scheme https code 301 if {{ hdr(Host) -i {site_name} }} !{{ ssl_fc }}\n' |
28 | 108 | 111 | ||
29 | @@ -116,10 +119,12 @@ listen {name} | |||
30 | 116 | (address, port) = utils.ip_addr_port_split(address_port) | 119 | (address, port) = utils.ip_addr_port_split(address_port) |
31 | 117 | 120 | ||
32 | 118 | backend_config = [] | 121 | backend_config = [] |
33 | 122 | default_backend = '' | ||
34 | 119 | tls_cert_bundle_paths = [] | 123 | tls_cert_bundle_paths = [] |
35 | 120 | redirect_http_to_https = False | 124 | redirect_http_to_https = False |
36 | 121 | for site, site_conf in config[address_port].items(): | 125 | for site, site_conf in config[address_port].items(): |
37 | 122 | site_name = site_conf.get('site-name', site) | 126 | site_name = site_conf.get('site-name', site) |
38 | 127 | default_site = site_conf.get('default', False) | ||
39 | 123 | redirect_http_to_https = site_conf.get('enable-redirect-http-to-https', False) | 128 | redirect_http_to_https = site_conf.get('enable-redirect-http-to-https', False) |
40 | 124 | 129 | ||
41 | 125 | if len(config[address_port].keys()) == 1: | 130 | if len(config[address_port].keys()) == 1: |
42 | @@ -138,11 +143,19 @@ listen {name} | |||
43 | 138 | # HTTP -> HTTPS redirect | 143 | # HTTP -> HTTPS redirect |
44 | 139 | if redirect_http_to_https: | 144 | if redirect_http_to_https: |
45 | 140 | backend_config.append(redirect_conf.format(site_name=site_name, indent=INDENT)) | 145 | backend_config.append(redirect_conf.format(site_name=site_name, indent=INDENT)) |
46 | 146 | if default_site: | ||
47 | 147 | default_backend = "{indent}redirect prefix https://{site_name}\n".format( | ||
48 | 148 | site_name=site_name, indent=INDENT | ||
49 | 149 | ) | ||
50 | 141 | else: | 150 | else: |
51 | 142 | backend_name = self._generate_stanza_name( | 151 | backend_name = self._generate_stanza_name( |
52 | 143 | site_conf.get('locations', {}).get('backend-name') or site | 152 | site_conf.get('locations', {}).get('backend-name') or site |
53 | 144 | ) | 153 | ) |
54 | 145 | backend_config.append(backend_conf.format(backend=backend_name, site_name=site_name, indent=INDENT)) | 154 | backend_config.append(backend_conf.format(backend=backend_name, site_name=site_name, indent=INDENT)) |
55 | 155 | if default_site: | ||
56 | 156 | default_backend = "{indent}default_backend backend-{backend}\n".format( | ||
57 | 157 | backend=backend_name, indent=INDENT | ||
58 | 158 | ) | ||
59 | 146 | 159 | ||
60 | 147 | tls_config = '' | 160 | tls_config = '' |
61 | 148 | if tls_cert_bundle_paths: | 161 | if tls_cert_bundle_paths: |
62 | @@ -151,8 +164,15 @@ listen {name} | |||
63 | 151 | alpn_protos = 'h2,http/1.1' | 164 | alpn_protos = 'h2,http/1.1' |
64 | 152 | tls_config = ' ssl {} alpn {}'.format(certs, alpn_protos) | 165 | tls_config = ' ssl {} alpn {}'.format(certs, alpn_protos) |
65 | 153 | 166 | ||
68 | 154 | if len(backend_config) == 1 and not redirect_http_to_https: | 167 | if len(backend_config) == 1: |
69 | 155 | backend_config = ['{indent}default_backend backend-{backend}\n'.format(backend=name, indent=INDENT)] | 168 | if redirect_http_to_https: |
70 | 169 | backend_config = [] | ||
71 | 170 | default_backend = "{indent}redirect prefix https://{site_name}\n".format( | ||
72 | 171 | site_name=site_name, indent=INDENT | ||
73 | 172 | ) | ||
74 | 173 | else: | ||
75 | 174 | backend_config = [] | ||
76 | 175 | default_backend = "{indent}default_backend backend-{backend}\n".format(backend=name, indent=INDENT) | ||
77 | 156 | 176 | ||
78 | 157 | bind_config = '{indent}bind {address_port}{tls}'.format( | 177 | bind_config = '{indent}bind {address_port}{tls}'.format( |
79 | 158 | address_port=address_port, tls=tls_config, indent=INDENT | 178 | address_port=address_port, tls=tls_config, indent=INDENT |
80 | @@ -162,7 +182,11 @@ listen {name} | |||
81 | 162 | bind_config += '\n{indent}bind :::{port}{tls}'.format(port=port, tls=tls_config, indent=INDENT) | 182 | bind_config += '\n{indent}bind :::{port}{tls}'.format(port=port, tls=tls_config, indent=INDENT) |
82 | 163 | 183 | ||
83 | 164 | output = listen_stanza.format( | 184 | output = listen_stanza.format( |
85 | 165 | name=name, backend_config=''.join(backend_config), bind_config=bind_config, indent=INDENT, | 185 | name=name, |
86 | 186 | backend_config=''.join(backend_config), | ||
87 | 187 | bind_config=bind_config, | ||
88 | 188 | default_backend=default_backend, | ||
89 | 189 | indent=INDENT, | ||
90 | 166 | ) | 190 | ) |
91 | 167 | rendered_output.append(output) | 191 | rendered_output.append(output) |
92 | 168 | 192 | ||
93 | diff --git a/reactive/content_cache.py b/reactive/content_cache.py | |||
94 | index e5967a8..fc6b637 100644 | |||
95 | --- a/reactive/content_cache.py | |||
96 | +++ b/reactive/content_cache.py | |||
97 | @@ -227,6 +227,10 @@ def configure_haproxy(): # NOQA: C901 LP#1825084 | |||
98 | 227 | cached_site = 'cached-{}'.format(site) | 227 | cached_site = 'cached-{}'.format(site) |
99 | 228 | new_conf[cached_site] = {'site-name': site_conf.get('site-name') or site, 'locations': {}} | 228 | new_conf[cached_site] = {'site-name': site_conf.get('site-name') or site, 'locations': {}} |
100 | 229 | 229 | ||
101 | 230 | default_site = site_conf.get('default') | ||
102 | 231 | if default_site: | ||
103 | 232 | new_conf[cached_site]['default'] = default_site | ||
104 | 233 | |||
105 | 230 | default_port = 80 | 234 | default_port = 80 |
106 | 231 | tls_cert_bundle_path = site_conf.get('tls-cert-bundle-path') | 235 | tls_cert_bundle_path = site_conf.get('tls-cert-bundle-path') |
107 | 232 | if tls_cert_bundle_path: | 236 | if tls_cert_bundle_path: |
108 | diff --git a/tests/unit/files/config_test_config.txt b/tests/unit/files/config_test_config.txt | |||
109 | index fb0e4fb..25d69c9 100644 | |||
110 | --- a/tests/unit/files/config_test_config.txt | |||
111 | +++ b/tests/unit/files/config_test_config.txt | |||
112 | @@ -12,6 +12,8 @@ site1.local: | |||
113 | 12 | - X-Origin-Key: Sae6oob2aethuosh | 12 | - X-Origin-Key: Sae6oob2aethuosh |
114 | 13 | - X-Some-Header-1: something one two three | 13 | - X-Some-Header-1: something one two three |
115 | 14 | - X-Some-Header-2: something:one:two:three | 14 | - X-Some-Header-2: something:one:two:three |
116 | 15 | # Test multiple default sites, last one wins. | ||
117 | 16 | default: True | ||
118 | 15 | 17 | ||
119 | 16 | # Test 2: TLS/SSL as well as backends (HTTPS), with custom backend-maxconn | 18 | # Test 2: TLS/SSL as well as backends (HTTPS), with custom backend-maxconn |
120 | 17 | site2.local: | 19 | site2.local: |
121 | @@ -33,9 +35,12 @@ site2.local: | |||
122 | 33 | /my-local-content2/: | 35 | /my-local-content2/: |
123 | 34 | extra-config: | 36 | extra-config: |
124 | 35 | - root /var/www/html | 37 | - root /var/www/html |
125 | 38 | # Test default site with only a single backend. | ||
126 | 39 | default: True | ||
127 | 36 | 40 | ||
128 | 37 | # Test 3: No port, just backends (HTTP), with custom cache-maxconn | 41 | # Test 3: No port, just backends (HTTP), with custom cache-maxconn |
129 | 38 | site3.local: | 42 | site3.local: |
130 | 43 | default: True | ||
131 | 39 | locations: | 44 | locations: |
132 | 40 | /: | 45 | /: |
133 | 41 | backends: | 46 | backends: |
134 | diff --git a/tests/unit/files/content_cache_rendered_haproxy_test_output.txt b/tests/unit/files/content_cache_rendered_haproxy_test_output.txt | |||
135 | index 357f5bd..d6f703b 100644 | |||
136 | --- a/tests/unit/files/content_cache_rendered_haproxy_test_output.txt | |||
137 | +++ b/tests/unit/files/content_cache_rendered_haproxy_test_output.txt | |||
138 | @@ -77,6 +77,7 @@ listen combined-80 | |||
139 | 77 | use_backend backend-cached-site5 if { hdr(Host) -i site5.local } | 77 | use_backend backend-cached-site5 if { hdr(Host) -i site5.local } |
140 | 78 | use_backend backend-cached-site6-local if { hdr(Host) -i site6.local } | 78 | use_backend backend-cached-site6-local if { hdr(Host) -i site6.local } |
141 | 79 | use_backend backend-cached-site9-local if { hdr(Host) -i site9.local } | 79 | use_backend backend-cached-site9-local if { hdr(Host) -i site9.local } |
142 | 80 | default_backend backend-cached-site3-local | ||
143 | 80 | 81 | ||
144 | 81 | listen site1-local | 82 | listen site1-local |
145 | 82 | bind 127.0.0.1:8080 | 83 | bind 127.0.0.1:8080 |
146 | diff --git a/tests/unit/files/content_cache_rendered_haproxy_test_output3.txt b/tests/unit/files/content_cache_rendered_haproxy_test_output3.txt | |||
147 | index 017645d..c82bf5c 100644 | |||
148 | --- a/tests/unit/files/content_cache_rendered_haproxy_test_output3.txt | |||
149 | +++ b/tests/unit/files/content_cache_rendered_haproxy_test_output3.txt | |||
150 | @@ -70,7 +70,7 @@ listen stats | |||
151 | 70 | listen redirect-site1-local | 70 | listen redirect-site1-local |
152 | 71 | bind 0.0.0.0:80 | 71 | bind 0.0.0.0:80 |
153 | 72 | bind :::80 | 72 | bind :::80 |
155 | 73 | redirect scheme https code 301 if { hdr(Host) -i site1.local } !{ ssl_fc } | 73 | redirect prefix https://site1.local |
156 | 74 | 74 | ||
157 | 75 | listen cached-site1-local | 75 | listen cached-site1-local |
158 | 76 | bind 0.0.0.0:443 ssl crt /var/lib/haproxy/certs alpn h2,http/1.1 | 76 | bind 0.0.0.0:443 ssl crt /var/lib/haproxy/certs alpn h2,http/1.1 |
159 | diff --git a/tests/unit/files/content_cache_rendered_haproxy_test_output_auto_maxconns.txt b/tests/unit/files/content_cache_rendered_haproxy_test_output_auto_maxconns.txt | |||
160 | index 472b1f8..151a1d4 100644 | |||
161 | --- a/tests/unit/files/content_cache_rendered_haproxy_test_output_auto_maxconns.txt | |||
162 | +++ b/tests/unit/files/content_cache_rendered_haproxy_test_output_auto_maxconns.txt | |||
163 | @@ -77,6 +77,7 @@ listen combined-80 | |||
164 | 77 | use_backend backend-cached-site5 if { hdr(Host) -i site5.local } | 77 | use_backend backend-cached-site5 if { hdr(Host) -i site5.local } |
165 | 78 | use_backend backend-cached-site6-local if { hdr(Host) -i site6.local } | 78 | use_backend backend-cached-site6-local if { hdr(Host) -i site6.local } |
166 | 79 | use_backend backend-cached-site9-local if { hdr(Host) -i site9.local } | 79 | use_backend backend-cached-site9-local if { hdr(Host) -i site9.local } |
167 | 80 | default_backend backend-cached-site3-local | ||
168 | 80 | 81 | ||
169 | 81 | listen site1-local | 82 | listen site1-local |
170 | 82 | bind 127.0.0.1:8080 | 83 | bind 127.0.0.1:8080 |
171 | diff --git a/tests/unit/files/content_cache_rendered_haproxy_test_output_processes_and_threads.txt b/tests/unit/files/content_cache_rendered_haproxy_test_output_processes_and_threads.txt | |||
172 | index ab7d065..77106e2 100644 | |||
173 | --- a/tests/unit/files/content_cache_rendered_haproxy_test_output_processes_and_threads.txt | |||
174 | +++ b/tests/unit/files/content_cache_rendered_haproxy_test_output_processes_and_threads.txt | |||
175 | @@ -78,6 +78,7 @@ listen combined-80 | |||
176 | 78 | use_backend backend-cached-site5 if { hdr(Host) -i site5.local } | 78 | use_backend backend-cached-site5 if { hdr(Host) -i site5.local } |
177 | 79 | use_backend backend-cached-site6-local if { hdr(Host) -i site6.local } | 79 | use_backend backend-cached-site6-local if { hdr(Host) -i site6.local } |
178 | 80 | use_backend backend-cached-site9-local if { hdr(Host) -i site9.local } | 80 | use_backend backend-cached-site9-local if { hdr(Host) -i site9.local } |
179 | 81 | default_backend backend-cached-site3-local | ||
180 | 81 | 82 | ||
181 | 82 | listen site1-local | 83 | listen site1-local |
182 | 83 | bind 127.0.0.1:8080 | 84 | bind 127.0.0.1:8080 |
183 | diff --git a/tests/unit/files/haproxy_config_rendered_listen_stanzas_test_output.txt b/tests/unit/files/haproxy_config_rendered_listen_stanzas_test_output.txt | |||
184 | index c86468b..6a0b4a4 100644 | |||
185 | --- a/tests/unit/files/haproxy_config_rendered_listen_stanzas_test_output.txt | |||
186 | +++ b/tests/unit/files/haproxy_config_rendered_listen_stanzas_test_output.txt | |||
187 | @@ -9,6 +9,7 @@ listen combined-80 | |||
188 | 9 | use_backend backend-site5 if { hdr(Host) -i site5.local } | 9 | use_backend backend-site5 if { hdr(Host) -i site5.local } |
189 | 10 | use_backend backend-site6-local if { hdr(Host) -i site6.local } | 10 | use_backend backend-site6-local if { hdr(Host) -i site6.local } |
190 | 11 | use_backend backend-site9-local if { hdr(Host) -i site9.local } | 11 | use_backend backend-site9-local if { hdr(Host) -i site9.local } |
191 | 12 | default_backend backend-site3-local | ||
192 | 12 | 13 | ||
193 | 13 | listen site2-local | 14 | listen site2-local |
194 | 14 | bind 0.0.0.0:443 ssl crt /etc/haproxy/site2-bundle.crt alpn h2,http/1.1 | 15 | bind 0.0.0.0:443 ssl crt /etc/haproxy/site2-bundle.crt alpn h2,http/1.1 |
195 | diff --git a/tests/unit/files/haproxy_config_rendered_listen_stanzas_test_output2.txt b/tests/unit/files/haproxy_config_rendered_listen_stanzas_test_output2.txt | |||
196 | index b84b56e..2e12427 100644 | |||
197 | --- a/tests/unit/files/haproxy_config_rendered_listen_stanzas_test_output2.txt | |||
198 | +++ b/tests/unit/files/haproxy_config_rendered_listen_stanzas_test_output2.txt | |||
199 | @@ -2,7 +2,7 @@ | |||
200 | 2 | listen redirect-site1-local | 2 | listen redirect-site1-local |
201 | 3 | bind 0.0.0.0:80 | 3 | bind 0.0.0.0:80 |
202 | 4 | bind :::80 | 4 | bind :::80 |
204 | 5 | redirect scheme https code 301 if { hdr(Host) -i site1.local } !{ ssl_fc } | 5 | redirect prefix https://site1.local |
205 | 6 | 6 | ||
206 | 7 | listen site1-local | 7 | listen site1-local |
207 | 8 | bind 0.0.0.0:443 ssl crt /var/lib/haproxy/certs alpn h2,http/1.1 | 8 | bind 0.0.0.0:443 ssl crt /var/lib/haproxy/certs alpn h2,http/1.1 |
208 | diff --git a/tests/unit/files/haproxy_config_rendered_listen_stanzas_test_output3.txt b/tests/unit/files/haproxy_config_rendered_listen_stanzas_test_output3.txt | |||
209 | 9 | new file mode 100644 | 9 | new file mode 100644 |
210 | index 0000000..e2614b3 | |||
211 | --- /dev/null | |||
212 | +++ b/tests/unit/files/haproxy_config_rendered_listen_stanzas_test_output3.txt | |||
213 | @@ -0,0 +1,14 @@ | |||
214 | 1 | |||
215 | 2 | listen combined-80 | ||
216 | 3 | bind 0.0.0.0:80 | ||
217 | 4 | bind :::80 | ||
218 | 5 | redirect scheme https code 301 if { hdr(Host) -i site1.local } !{ ssl_fc } | ||
219 | 6 | redirect scheme https code 301 if { hdr(Host) -i site2.local } !{ ssl_fc } | ||
220 | 7 | redirect prefix https://site2.local | ||
221 | 8 | |||
222 | 9 | listen combined-443 | ||
223 | 10 | bind 0.0.0.0:443 ssl crt /var/lib/haproxy/certs alpn h2,http/1.1 | ||
224 | 11 | bind :::443 ssl crt /var/lib/haproxy/certs alpn h2,http/1.1 | ||
225 | 12 | use_backend backend-site1-local if { hdr(Host) -i site1.local } | ||
226 | 13 | use_backend backend-site2-local if { hdr(Host) -i site2.local } | ||
227 | 14 | default_backend backend-site2-local | ||
228 | diff --git a/tests/unit/files/haproxy_config_rendered_test_output.txt b/tests/unit/files/haproxy_config_rendered_test_output.txt | |||
229 | index 7e9dff0..8b98792 100644 | |||
230 | --- a/tests/unit/files/haproxy_config_rendered_test_output.txt | |||
231 | +++ b/tests/unit/files/haproxy_config_rendered_test_output.txt | |||
232 | @@ -78,6 +78,7 @@ listen combined-80 | |||
233 | 78 | use_backend backend-site5 if { hdr(Host) -i site5.local } | 78 | use_backend backend-site5 if { hdr(Host) -i site5.local } |
234 | 79 | use_backend backend-site6-local if { hdr(Host) -i site6.local } | 79 | use_backend backend-site6-local if { hdr(Host) -i site6.local } |
235 | 80 | use_backend backend-site9-local if { hdr(Host) -i site9.local } | 80 | use_backend backend-site9-local if { hdr(Host) -i site9.local } |
236 | 81 | default_backend backend-site3-local | ||
237 | 81 | 82 | ||
238 | 82 | listen site2-local | 83 | listen site2-local |
239 | 83 | bind 0.0.0.0:443 ssl crt /etc/haproxy/site2-bundle.crt alpn h2,http/1.1 | 84 | bind 0.0.0.0:443 ssl crt /etc/haproxy/site2-bundle.crt alpn h2,http/1.1 |
240 | diff --git a/tests/unit/files/haproxy_config_rendered_test_output2.txt b/tests/unit/files/haproxy_config_rendered_test_output2.txt | |||
241 | index d9ee515..d0efd57 100644 | |||
242 | --- a/tests/unit/files/haproxy_config_rendered_test_output2.txt | |||
243 | +++ b/tests/unit/files/haproxy_config_rendered_test_output2.txt | |||
244 | @@ -78,6 +78,7 @@ listen combined-80 | |||
245 | 78 | use_backend backend-site5 if { hdr(Host) -i site5.local } | 78 | use_backend backend-site5 if { hdr(Host) -i site5.local } |
246 | 79 | use_backend backend-site6-local if { hdr(Host) -i site6.local } | 79 | use_backend backend-site6-local if { hdr(Host) -i site6.local } |
247 | 80 | use_backend backend-site9-local if { hdr(Host) -i site9.local } | 80 | use_backend backend-site9-local if { hdr(Host) -i site9.local } |
248 | 81 | default_backend backend-site3-local | ||
249 | 81 | 82 | ||
250 | 82 | listen site2-local | 83 | listen site2-local |
251 | 83 | bind 0.0.0.0:443 ssl crt /etc/haproxy/site2-bundle.crt alpn h2,http/1.1 | 84 | bind 0.0.0.0:443 ssl crt /etc/haproxy/site2-bundle.crt alpn h2,http/1.1 |
252 | diff --git a/tests/unit/test_haproxy.py b/tests/unit/test_haproxy.py | |||
253 | index cac29ca..9fc9604 100644 | |||
254 | --- a/tests/unit/test_haproxy.py | |||
255 | +++ b/tests/unit/test_haproxy.py | |||
256 | @@ -104,6 +104,30 @@ class TestLibHAProxy(unittest.TestCase): | |||
257 | 104 | want = f.read() | 104 | want = f.read() |
258 | 105 | self.assertEqual(''.join(haproxy.render_stanza_listen(config)), want) | 105 | self.assertEqual(''.join(haproxy.render_stanza_listen(config)), want) |
259 | 106 | 106 | ||
260 | 107 | def test_haproxy_config_rendered_listen_stanzas_redirect_default_site(self): | ||
261 | 108 | haproxy = HAProxy.HAProxyConf(self.tmpdir) | ||
262 | 109 | config = { | ||
263 | 110 | 'site1.local': { | ||
264 | 111 | 'locations': {'/': {'backends': ['192.168.1.1:8080']}}, | ||
265 | 112 | 'port': 443, | ||
266 | 113 | 'redirect-http-to-https': True, | ||
267 | 114 | 'site-name': 'site1.local', | ||
268 | 115 | 'tls-cert-bundle-path': '/var/lib/haproxy/certs', | ||
269 | 116 | }, | ||
270 | 117 | 'site2.local': { | ||
271 | 118 | 'default': True, | ||
272 | 119 | 'locations': {'/': {'backends': ['192.168.1.1:8080']}}, | ||
273 | 120 | 'port': 443, | ||
274 | 121 | 'redirect-http-to-https': True, | ||
275 | 122 | 'site-name': 'site2.local', | ||
276 | 123 | 'tls-cert-bundle-path': '/var/lib/haproxy/certs', | ||
277 | 124 | }, | ||
278 | 125 | } | ||
279 | 126 | output = 'tests/unit/files/haproxy_config_rendered_listen_stanzas_test_output3.txt' | ||
280 | 127 | with open(output, 'r', encoding='utf-8') as f: | ||
281 | 128 | want = f.read() | ||
282 | 129 | self.assertEqual(''.join(haproxy.render_stanza_listen(config)), want) | ||
283 | 130 | |||
284 | 107 | @freezegun.freeze_time("2019-03-22", tz_offset=0) | 131 | @freezegun.freeze_time("2019-03-22", tz_offset=0) |
285 | 108 | def test_haproxy_config_rendered_backend_stanzas(self): | 132 | def test_haproxy_config_rendered_backend_stanzas(self): |
286 | 109 | haproxy = HAProxy.HAProxyConf(self.tmpdir) | 133 | haproxy = HAProxy.HAProxyConf(self.tmpdir) |
This merge proposal is being monitored by mergebot. Change the status to Approved to merge.