Merge lp:~sidnei/charms/precise/squid-reverseproxy/trunk into lp:charms/squid-reverseproxy
- Precise Pangolin (12.04)
- trunk
- Merge into trunk
Proposed by
Sidnei da Silva
Status: | Merged |
---|---|
Merged at revision: | 45 |
Proposed branch: | lp:~sidnei/charms/precise/squid-reverseproxy/trunk |
Merge into: | lp:charms/squid-reverseproxy |
Diff against target: |
405 lines (+193/-5) 6 files modified
README.md (+13/-0) config.yaml (+33/-3) hooks/hooks.py (+22/-1) hooks/tests/test_helpers.py (+93/-1) hooks/tests/test_nrpe_hooks.py (+22/-0) templates/main_config.template (+10/-0) |
To merge this branch: | bzr merge lp:~sidnei/charms/precise/squid-reverseproxy/trunk |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
David Lawson (community) | Approve | ||
Review via email: mp+198451@code.launchpad.net |
Commit message
- If there's a query string in the check path, use a GET instead of HEAD request
- If cache_size_mb is set to 0, only disable disk cache but still leave memory cache.
- Expose 'via' config setting, default to on.
Description of the change
- If there's a query string in the check path, use a GET instead of HEAD request
- If cache_size_mb is set to 0, only disable disk cache but still leave memory cache.
- Expose 'via' config setting, default to on.
To post a comment you must log in.
- 44. By Sidnei da Silva
-
Merge from alexlist's https support branch
- 45. By Sidnei da Silva
-
- Merge from trunk
Revision history for this message
David Lawson (deej) : | # |
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'README.md' | |||
2 | --- README.md 2013-02-15 07:00:58 +0000 | |||
3 | +++ README.md 2013-12-10 20:23:01 +0000 | |||
4 | @@ -63,6 +63,19 @@ | |||
5 | 63 | The options that can be configured in config.yaml should be self-explanatory. | 63 | The options that can be configured in config.yaml should be self-explanatory. |
6 | 64 | If not, please file a bug against this charm. | 64 | If not, please file a bug against this charm. |
7 | 65 | 65 | ||
8 | 66 | ## HTTPS Reverse Proxying | ||
9 | 67 | |||
10 | 68 | Assuming you have a squid3 deb compiled with --enable-ssl, you can setup a | ||
11 | 69 | single https reverse proxy. | ||
12 | 70 | |||
13 | 71 | An example of this would be: | ||
14 | 72 | |||
15 | 73 | juju set squid-reverseproxy enable_https=true ssl_key="$(base64 < /path/to/cert.key)" ssl_cert="$(base64 < /path/to/cert.crt)" | ||
16 | 74 | |||
17 | 75 | This should enable https access to the default website. | ||
18 | 76 | |||
19 | 77 | A current implementation limitation is that it doesn't support multiple https vhosts. | ||
20 | 78 | |||
21 | 66 | ## Monitoring | 79 | ## Monitoring |
22 | 67 | 80 | ||
23 | 68 | This charm provides relations that support monitoring via Nagios using | 81 | This charm provides relations that support monitoring via Nagios using |
24 | 69 | 82 | ||
25 | === modified file 'config.yaml' | |||
26 | --- config.yaml 2013-10-29 16:56:23 +0000 | |||
27 | +++ config.yaml 2013-12-10 20:23:01 +0000 | |||
28 | @@ -5,8 +5,36 @@ | |||
29 | 5 | description: Squid listening port. | 5 | description: Squid listening port. |
30 | 6 | port_options: | 6 | port_options: |
31 | 7 | type: string | 7 | type: string |
33 | 8 | default: accel vhost | 8 | default: 'accel vhost' |
34 | 9 | description: Squid listening port options | 9 | description: Squid listening port options |
35 | 10 | enable_https: | ||
36 | 11 | type: boolean | ||
37 | 12 | default: false | ||
38 | 13 | description: Enable https access for squid, requires a squid compiled with --enable-ssl, certificate and private key | ||
39 | 14 | https_port: | ||
40 | 15 | type: int | ||
41 | 16 | default: 443 | ||
42 | 17 | description: Squid https listening port | ||
43 | 18 | https_options: | ||
44 | 19 | type: string | ||
45 | 20 | default: 'accel vhost' | ||
46 | 21 | description: Options for https port | ||
47 | 22 | ssl_keyfile: | ||
48 | 23 | type: string | ||
49 | 24 | default: '/etc/squid3/ssl/cert.key' | ||
50 | 25 | description: File path to ssl key file inside deployed units | ||
51 | 26 | ssl_certfile: | ||
52 | 27 | type: string | ||
53 | 28 | default: '/etc/squid3/ssl/cert.crt' | ||
54 | 29 | description: File path to ssl cert file inside deployed units | ||
55 | 30 | ssl_key: | ||
56 | 31 | type: string | ||
57 | 32 | default: '' | ||
58 | 33 | description: Base64 encoded ssl key file | ||
59 | 34 | ssl_cert: | ||
60 | 35 | type: string | ||
61 | 36 | default: '' | ||
62 | 37 | description: Base64 encoded ssl cert file | ||
63 | 10 | log_format: | 38 | log_format: |
64 | 11 | type: string | 39 | type: string |
65 | 12 | default: '%>a %ui %un [%tl] "%rm %ru HTTP/%rv" %>Hs %<st "%{Referer}>h" "%{User-Agent}>h" %Ss:%Sh' | 40 | default: '%>a %ui %un [%tl] "%rm %ru HTTP/%rv" %>Hs %<st "%{Referer}>h" "%{User-Agent}>h" %Ss:%Sh' |
66 | @@ -22,11 +50,13 @@ | |||
67 | 22 | cache_mem_mb: | 50 | cache_mem_mb: |
68 | 23 | type: int | 51 | type: int |
69 | 24 | default: 256 | 52 | default: 256 |
71 | 25 | description: Maximum size of in-memory object cache (MB). Should be smaller than cache_size_mb. | 53 | description: > |
72 | 54 | Maximum size of in-memory object cache (MB). Should be smaller than | ||
73 | 55 | cache_size_mb. Set to zero to disable caching completely. | ||
74 | 26 | cache_size_mb: | 56 | cache_size_mb: |
75 | 27 | type: int | 57 | type: int |
76 | 28 | default: 512 | 58 | default: 512 |
78 | 29 | description: Maximum size of the on-disk object cache (MB). Set to zero to disable caching. | 59 | description: Maximum size of the on-disk object cache (MB). Set to zero to disable disk caching. |
79 | 30 | cache_dir: | 60 | cache_dir: |
80 | 31 | type: string | 61 | type: string |
81 | 32 | default: '/var/spool/squid3' | 62 | default: '/var/spool/squid3' |
82 | 33 | 63 | ||
83 | === added directory 'exec.d' | |||
84 | === modified file 'hooks/hooks.py' | |||
85 | --- hooks/hooks.py 2013-10-29 17:37:20 +0000 | |||
86 | +++ hooks/hooks.py 2013-12-10 20:23:01 +0000 | |||
87 | @@ -256,6 +256,26 @@ | |||
88 | 256 | write_squid3_config('\n'.join( | 256 | write_squid3_config('\n'.join( |
89 | 257 | (l.strip() for l in str(template).splitlines()))) | 257 | (l.strip() for l in str(template).splitlines()))) |
90 | 258 | 258 | ||
91 | 259 | # If we have https, write out ssl key and cert file | ||
92 | 260 | if config_data.get('enable_https'): | ||
93 | 261 | from base64 import b64decode | ||
94 | 262 | if config_data.get('ssl_key') is not None: | ||
95 | 263 | ssl_keyfile = config_data['ssl_keyfile'] | ||
96 | 264 | ssl_keyfile_dir = os.path.dirname(os.path.realpath(ssl_keyfile)) | ||
97 | 265 | if not os.path.exists(ssl_keyfile_dir): | ||
98 | 266 | os.makedirs(ssl_keyfile_dir) | ||
99 | 267 | ssl_key = config_data['ssl_key'] | ||
100 | 268 | with open(ssl_keyfile, 'w') as ssl_key_path: | ||
101 | 269 | ssl_key_path.write(str(b64decode(ssl_key))) | ||
102 | 270 | if config_data.get('ssl_cert') is not None: | ||
103 | 271 | ssl_certfile = config_data['ssl_certfile'] | ||
104 | 272 | ssl_certfile_dir = os.path.dirname(ssl_certfile) | ||
105 | 273 | if not os.path.exists(ssl_certfile_dir): | ||
106 | 274 | os.makedirs(ssl_certfile_dir) | ||
107 | 275 | ssl_cert = config_data['ssl_cert'] | ||
108 | 276 | with open(ssl_certfile, 'w') as ssl_cert_path: | ||
109 | 277 | ssl_cert_path.write(str(b64decode(ssl_cert))) | ||
110 | 278 | |||
111 | 259 | 279 | ||
112 | 260 | def write_squid3_config(contents): | 280 | def write_squid3_config(contents): |
113 | 261 | with open(default_squid3_config, 'w') as squid3_config: | 281 | with open(default_squid3_config, 'w') as squid3_config: |
114 | @@ -321,7 +341,8 @@ | |||
115 | 321 | for service in config_services: | 341 | for service in config_services: |
116 | 322 | path = service.get('nrpe_check_path') | 342 | path = service.get('nrpe_check_path') |
117 | 323 | if path is not None: | 343 | if path is not None: |
119 | 324 | command = 'check_http -I 127.0.0.1 -p 3128 --method=HEAD ' | 344 | method = "GET" if "?" in path else "HEAD" |
120 | 345 | command = 'check_http -I 127.0.0.1 -p 3128 --method=%s ' % method | ||
121 | 325 | service_name = service['service_name'] | 346 | service_name = service['service_name'] |
122 | 326 | if conf.get('x_balancer_name_allowed'): | 347 | if conf.get('x_balancer_name_allowed'): |
123 | 327 | command += ("-u http://localhost%s " | 348 | command += ("-u http://localhost%s " |
124 | 328 | 349 | ||
125 | === modified file 'hooks/tests/test_helpers.py' | |||
126 | --- hooks/tests/test_helpers.py 2013-10-29 16:56:23 +0000 | |||
127 | +++ hooks/tests/test_helpers.py 2013-12-10 20:23:01 +0000 | |||
128 | @@ -5,7 +5,7 @@ | |||
129 | 5 | from os.path import dirname | 5 | from os.path import dirname |
130 | 6 | 6 | ||
131 | 7 | from testtools import TestCase | 7 | from testtools import TestCase |
133 | 8 | from testtools.matchers import AfterPreprocessing, Contains | 8 | from testtools.matchers import AfterPreprocessing, Contains, Not |
134 | 9 | from mock import patch | 9 | from mock import patch |
135 | 10 | 10 | ||
136 | 11 | import hooks | 11 | import hooks |
137 | @@ -27,6 +27,14 @@ | |||
138 | 27 | Contains(normalize_whitespace(chunk)))) | 27 | Contains(normalize_whitespace(chunk)))) |
139 | 28 | return side_effect | 28 | return side_effect |
140 | 29 | 29 | ||
141 | 30 | def _assert_not_contents(self, *expected): | ||
142 | 31 | def side_effect(got): | ||
143 | 32 | for chunk in expected: | ||
144 | 33 | self.assertThat(got, AfterPreprocessing( | ||
145 | 34 | normalize_whitespace, | ||
146 | 35 | Not(Contains(normalize_whitespace(chunk))))) | ||
147 | 36 | return side_effect | ||
148 | 37 | |||
149 | 30 | def _apply_patch(self, name): | 38 | def _apply_patch(self, name): |
150 | 31 | p = patch(name) | 39 | p = patch(name) |
151 | 32 | mocked_name = p.start() | 40 | mocked_name = p.start() |
152 | @@ -47,6 +55,7 @@ | |||
153 | 47 | self.config_get.return_value = Serializable({ | 55 | self.config_get.return_value = Serializable({ |
154 | 48 | "refresh_patterns": "", | 56 | "refresh_patterns": "", |
155 | 49 | "cache_size_mb": 1024, | 57 | "cache_size_mb": 1024, |
156 | 58 | "cache_mem_mb": 256, | ||
157 | 50 | "target_objs_per_dir": 1024, | 59 | "target_objs_per_dir": 1024, |
158 | 51 | "avg_obj_size_kb": 1024, | 60 | "avg_obj_size_kb": 1024, |
159 | 52 | "via": "on", | 61 | "via": "on", |
160 | @@ -66,6 +75,7 @@ | |||
161 | 66 | self.config_get.return_value = Serializable({ | 75 | self.config_get.return_value = Serializable({ |
162 | 67 | "refresh_patterns": "", | 76 | "refresh_patterns": "", |
163 | 68 | "cache_size_mb": 1024, | 77 | "cache_size_mb": 1024, |
164 | 78 | "cache_mem_mb": 256, | ||
165 | 69 | "target_objs_per_dir": 1024, | 79 | "target_objs_per_dir": 1024, |
166 | 70 | "avg_obj_size_kb": 1024, | 80 | "avg_obj_size_kb": 1024, |
167 | 71 | "via": "off", | 81 | "via": "off", |
168 | @@ -84,6 +94,7 @@ | |||
169 | 84 | {"http://www.ubuntu.com": | 94 | {"http://www.ubuntu.com": |
170 | 85 | {"min": 0, "percent": 20, "max": 60}}), | 95 | {"min": 0, "percent": 20, "max": 60}}), |
171 | 86 | "cache_size_mb": 1024, | 96 | "cache_size_mb": 1024, |
172 | 97 | "cache_mem_mb": 256, | ||
173 | 87 | "target_objs_per_dir": 1024, | 98 | "target_objs_per_dir": 1024, |
174 | 88 | "avg_obj_size_kb": 1024, | 99 | "avg_obj_size_kb": 1024, |
175 | 89 | }) | 100 | }) |
176 | @@ -101,6 +112,7 @@ | |||
177 | 101 | {"http://www.ubuntu.com": | 112 | {"http://www.ubuntu.com": |
178 | 102 | {"min": 0, "percent": 20, "max": 60}}), | 113 | {"min": 0, "percent": 20, "max": 60}}), |
179 | 103 | "cache_size_mb": 1024, | 114 | "cache_size_mb": 1024, |
180 | 115 | "cache_mem_mb": 256, | ||
181 | 104 | "target_objs_per_dir": 1024, | 116 | "target_objs_per_dir": 1024, |
182 | 105 | "avg_obj_size_kb": 1024, | 117 | "avg_obj_size_kb": 1024, |
183 | 106 | }) | 118 | }) |
184 | @@ -120,6 +132,7 @@ | |||
185 | 120 | "options": ["override-lastmod", | 132 | "options": ["override-lastmod", |
186 | 121 | "reload-into-ims"]}}), | 133 | "reload-into-ims"]}}), |
187 | 122 | "cache_size_mb": 1024, | 134 | "cache_size_mb": 1024, |
188 | 135 | "cache_mem_mb": 256, | ||
189 | 123 | "target_objs_per_dir": 1024, | 136 | "target_objs_per_dir": 1024, |
190 | 124 | "avg_obj_size_kb": 1024, | 137 | "avg_obj_size_kb": 1024, |
191 | 125 | }) | 138 | }) |
192 | @@ -141,6 +154,7 @@ | |||
193 | 141 | "options": ["override-lastmod", | 154 | "options": ["override-lastmod", |
194 | 142 | "reload-into-ims"]}}), | 155 | "reload-into-ims"]}}), |
195 | 143 | "cache_size_mb": 1024, | 156 | "cache_size_mb": 1024, |
196 | 157 | "cache_mem_mb": 256, | ||
197 | 144 | "target_objs_per_dir": 1024, | 158 | "target_objs_per_dir": 1024, |
198 | 145 | "avg_obj_size_kb": 1024, | 159 | "avg_obj_size_kb": 1024, |
199 | 146 | }) | 160 | }) |
200 | @@ -157,6 +171,7 @@ | |||
201 | 157 | self.config_get.return_value = Serializable({ | 171 | self.config_get.return_value = Serializable({ |
202 | 158 | "refresh_patterns": "", | 172 | "refresh_patterns": "", |
203 | 159 | "cache_size_mb": 1024, | 173 | "cache_size_mb": 1024, |
204 | 174 | "cache_mem_mb": 256, | ||
205 | 160 | "target_objs_per_dir": 1024, | 175 | "target_objs_per_dir": 1024, |
206 | 161 | "avg_obj_size_kb": 1024, | 176 | "avg_obj_size_kb": 1024, |
207 | 162 | }) | 177 | }) |
208 | @@ -191,6 +206,7 @@ | |||
209 | 191 | self.config_get.return_value = Serializable({ | 206 | self.config_get.return_value = Serializable({ |
210 | 192 | "refresh_patterns": "", | 207 | "refresh_patterns": "", |
211 | 193 | "cache_size_mb": 1024, | 208 | "cache_size_mb": 1024, |
212 | 209 | "cache_mem_mb": 256, | ||
213 | 194 | "target_objs_per_dir": 1024, | 210 | "target_objs_per_dir": 1024, |
214 | 195 | "avg_obj_size_kb": 1024, | 211 | "avg_obj_size_kb": 1024, |
215 | 196 | }) | 212 | }) |
216 | @@ -231,6 +247,7 @@ | |||
217 | 231 | self.config_get.return_value = Serializable({ | 247 | self.config_get.return_value = Serializable({ |
218 | 232 | "refresh_patterns": "", | 248 | "refresh_patterns": "", |
219 | 233 | "cache_size_mb": 1024, | 249 | "cache_size_mb": 1024, |
220 | 250 | "cache_mem_mb": 256, | ||
221 | 234 | "target_objs_per_dir": 1024, | 251 | "target_objs_per_dir": 1024, |
222 | 235 | "avg_obj_size_kb": 1024, | 252 | "avg_obj_size_kb": 1024, |
223 | 236 | }) | 253 | }) |
224 | @@ -252,6 +269,7 @@ | |||
225 | 252 | self.config_get.return_value = Serializable({ | 269 | self.config_get.return_value = Serializable({ |
226 | 253 | "refresh_patterns": "", | 270 | "refresh_patterns": "", |
227 | 254 | "cache_size_mb": 1024, | 271 | "cache_size_mb": 1024, |
228 | 272 | "cache_mem_mb": 256, | ||
229 | 255 | "target_objs_per_dir": 1024, | 273 | "target_objs_per_dir": 1024, |
230 | 256 | "avg_obj_size_kb": 1024, | 274 | "avg_obj_size_kb": 1024, |
231 | 257 | "x_balancer_name_allowed": True, | 275 | "x_balancer_name_allowed": True, |
232 | @@ -279,6 +297,7 @@ | |||
233 | 279 | self.config_get.return_value = Serializable({ | 297 | self.config_get.return_value = Serializable({ |
234 | 280 | "refresh_patterns": "", | 298 | "refresh_patterns": "", |
235 | 281 | "cache_size_mb": 1024, | 299 | "cache_size_mb": 1024, |
236 | 300 | "cache_mem_mb": 256, | ||
237 | 282 | "target_objs_per_dir": 1024, | 301 | "target_objs_per_dir": 1024, |
238 | 283 | "avg_obj_size_kb": 1024, | 302 | "avg_obj_size_kb": 1024, |
239 | 284 | "x_balancer_name_allowed": True, | 303 | "x_balancer_name_allowed": True, |
240 | @@ -326,6 +345,7 @@ | |||
241 | 326 | "enable_forward_proxy": True, | 345 | "enable_forward_proxy": True, |
242 | 327 | "refresh_patterns": "", | 346 | "refresh_patterns": "", |
243 | 328 | "cache_size_mb": 1024, | 347 | "cache_size_mb": 1024, |
244 | 348 | "cache_mem_mb": 256, | ||
245 | 329 | "target_objs_per_dir": 1024, | 349 | "target_objs_per_dir": 1024, |
246 | 330 | "avg_obj_size_kb": 1024, | 350 | "avg_obj_size_kb": 1024, |
247 | 331 | }) | 351 | }) |
248 | @@ -376,10 +396,28 @@ | |||
249 | 376 | ) | 396 | ) |
250 | 377 | hooks.construct_squid3_config() | 397 | hooks.construct_squid3_config() |
251 | 378 | 398 | ||
252 | 399 | def test_squid_config_disk_cache_disabled(self): | ||
253 | 400 | self.config_get.return_value = Serializable({ | ||
254 | 401 | "refresh_patterns": "", | ||
255 | 402 | "cache_size_mb": 0, | ||
256 | 403 | "cache_mem_mb": 256, | ||
257 | 404 | "cache_dir": "/var/run/squid3", | ||
258 | 405 | "target_objs_per_dir": 16, | ||
259 | 406 | "avg_obj_size_kb": 4, | ||
260 | 407 | }) | ||
261 | 408 | self.get_reverse_sites.return_value = None | ||
262 | 409 | self.write_squid3_config.side_effect = self._assert_not_contents( | ||
263 | 410 | """ | ||
264 | 411 | cache_dir aufs | ||
265 | 412 | """, | ||
266 | 413 | ) | ||
267 | 414 | hooks.construct_squid3_config() | ||
268 | 415 | |||
269 | 379 | def test_squid_config_cache_disabled(self): | 416 | def test_squid_config_cache_disabled(self): |
270 | 380 | self.config_get.return_value = Serializable({ | 417 | self.config_get.return_value = Serializable({ |
271 | 381 | "refresh_patterns": "", | 418 | "refresh_patterns": "", |
272 | 382 | "cache_size_mb": 0, | 419 | "cache_size_mb": 0, |
273 | 420 | "cache_mem_mb": 0, | ||
274 | 383 | "target_objs_per_dir": 1024, | 421 | "target_objs_per_dir": 1024, |
275 | 384 | "avg_obj_size_kb": 1024, | 422 | "avg_obj_size_kb": 1024, |
276 | 385 | }) | 423 | }) |
277 | @@ -391,6 +429,60 @@ | |||
278 | 391 | ) | 429 | ) |
279 | 392 | hooks.construct_squid3_config() | 430 | hooks.construct_squid3_config() |
280 | 393 | 431 | ||
281 | 432 | self.write_squid3_config.side_effect = self._assert_not_contents( | ||
282 | 433 | """ | ||
283 | 434 | cache_mem | ||
284 | 435 | """, | ||
285 | 436 | ) | ||
286 | 437 | hooks.construct_squid3_config() | ||
287 | 438 | |||
288 | 439 | def test_no_https(self): | ||
289 | 440 | self.config_get.return_value = Serializable({ | ||
290 | 441 | "port": 3128, | ||
291 | 442 | "port_options": "accel vhost", | ||
292 | 443 | "enable_https": False, | ||
293 | 444 | "refresh_patterns": "", | ||
294 | 445 | "cache_size_mb": 0, | ||
295 | 446 | "cache_mem_mb": 0, | ||
296 | 447 | "target_objs_per_dir": 1024, | ||
297 | 448 | "avg_obj_size_kb": 1024, | ||
298 | 449 | }) | ||
299 | 450 | self.get_reverse_sites.return_value = None | ||
300 | 451 | self.write_squid3_config.side_effect = self._assert_contents( | ||
301 | 452 | """ | ||
302 | 453 | http_port 3128 accel vhost | ||
303 | 454 | """, | ||
304 | 455 | ) | ||
305 | 456 | hooks.construct_squid3_config() | ||
306 | 457 | |||
307 | 458 | self.write_squid3_config.side_effect = self._assert_not_contents( | ||
308 | 459 | """ | ||
309 | 460 | https_port | ||
310 | 461 | """, | ||
311 | 462 | ) | ||
312 | 463 | hooks.construct_squid3_config() | ||
313 | 464 | |||
314 | 465 | def test_with_https(self): | ||
315 | 466 | self.config_get.return_value = Serializable({ | ||
316 | 467 | "enable_https": True, | ||
317 | 468 | "https_port": 443, | ||
318 | 469 | "https_options": "accel vhost", | ||
319 | 470 | "ssl_certfile": "/path/to/cert", | ||
320 | 471 | "ssl_keyfile": "/path/to/key", | ||
321 | 472 | "refresh_patterns": "", | ||
322 | 473 | "cache_size_mb": 0, | ||
323 | 474 | "cache_mem_mb": 0, | ||
324 | 475 | "target_objs_per_dir": 1024, | ||
325 | 476 | "avg_obj_size_kb": 1024, | ||
326 | 477 | }) | ||
327 | 478 | self.get_reverse_sites.return_value = None | ||
328 | 479 | self.write_squid3_config.side_effect = self._assert_contents( | ||
329 | 480 | """ | ||
330 | 481 | https_port 443 accel vhost cert=/path/to/cert key=/path/to/key | ||
331 | 482 | """, | ||
332 | 483 | ) | ||
333 | 484 | hooks.construct_squid3_config() | ||
334 | 485 | |||
335 | 394 | 486 | ||
336 | 395 | class HelpersTest(TestCase): | 487 | class HelpersTest(TestCase): |
337 | 396 | def test_gets_config(self): | 488 | def test_gets_config(self): |
338 | 397 | 489 | ||
339 | === modified file 'hooks/tests/test_nrpe_hooks.py' | |||
340 | --- hooks/tests/test_nrpe_hooks.py 2013-08-22 02:22:04 +0000 | |||
341 | +++ hooks/tests/test_nrpe_hooks.py 2013-12-10 20:23:01 +0000 | |||
342 | @@ -255,6 +255,28 @@ | |||
343 | 255 | call().__enter__().write(expected)], | 255 | call().__enter__().write(expected)], |
344 | 256 | any_order=True) | 256 | any_order=True) |
345 | 257 | 257 | ||
346 | 258 | def test_update_nrpe_with_services_GET_if_query_string_in_path(self): | ||
347 | 259 | services = ('- {nrpe_check_path: "/?path=foo.jpg", ' | ||
348 | 260 | 'service_name: foo_com}\n') | ||
349 | 261 | config = { | ||
350 | 262 | 'nagios_context': 'test', | ||
351 | 263 | 'services': services, | ||
352 | 264 | } | ||
353 | 265 | self.patched['config'].return_value = Serializable(config) | ||
354 | 266 | self.patched['exists'].return_value = True | ||
355 | 267 | |||
356 | 268 | self.assertEqual(None, hooks.update_nrpe_checks()) | ||
357 | 269 | |||
358 | 270 | self.check_call_counts(config=1, getpwnam=1, getgrnam=1, | ||
359 | 271 | exists=5, open=4, listdir=2) | ||
360 | 272 | expected = ('command[check_squid-foo_com]=/check_http ' | ||
361 | 273 | '-I 127.0.0.1 -p 3128 --method=GET ' | ||
362 | 274 | '-u http://foo_com/?path=foo.jpg\n') | ||
363 | 275 | self.patched['open'].assert_has_calls( | ||
364 | 276 | [call('/etc/nagios/nrpe.d/check_squid-foo_com.cfg', 'w'), | ||
365 | 277 | call().__enter__().write(expected)], | ||
366 | 278 | any_order=True) | ||
367 | 279 | |||
368 | 258 | def test_update_nrpe_restarts_service(self): | 280 | def test_update_nrpe_restarts_service(self): |
369 | 259 | config = { | 281 | config = { |
370 | 260 | 'nagios_context': 'test', | 282 | 'nagios_context': 'test', |
371 | 261 | 283 | ||
372 | === modified file 'templates/main_config.template' | |||
373 | --- templates/main_config.template 2013-10-29 17:37:20 +0000 | |||
374 | +++ templates/main_config.template 2013-12-10 20:23:01 +0000 | |||
375 | @@ -1,4 +1,7 @@ | |||
376 | 1 | http_port {{ config.port }} {{ config.port_options }} | 1 | http_port {{ config.port }} {{ config.port_options }} |
377 | 2 | {% if config.enable_https -%} | ||
378 | 3 | https_port {{ config.https_port }} {{ config.https_options }} cert={{ config.ssl_certfile }} key={{ config.ssl_keyfile }} | ||
379 | 4 | {% endif -%} | ||
380 | 2 | 5 | ||
381 | 3 | acl manager proto cache_object | 6 | acl manager proto cache_object |
382 | 4 | acl localhost src 127.0.0.1/32 | 7 | acl localhost src 127.0.0.1/32 |
383 | @@ -28,8 +31,12 @@ | |||
384 | 28 | 31 | ||
385 | 29 | coredump_dir {{ config.cache_dir }} | 32 | coredump_dir {{ config.cache_dir }} |
386 | 30 | maximum_object_size {{ config.max_obj_size_kb }} KB | 33 | maximum_object_size {{ config.max_obj_size_kb }} KB |
387 | 34 | |||
388 | 31 | {% if config.cache_size_mb > 0 -%} | 35 | {% if config.cache_size_mb > 0 -%} |
389 | 32 | cache_dir aufs {{ config.cache_dir }} {{ config.cache_size_mb }} {{ config.cache_l1 }} {{ config.cache_l2 }} | 36 | cache_dir aufs {{ config.cache_dir }} {{ config.cache_size_mb }} {{ config.cache_l1 }} {{ config.cache_l2 }} |
390 | 37 | {% endif -%} | ||
391 | 38 | |||
392 | 39 | {% if config.cache_mem_mb > 0 -%} | ||
393 | 33 | cache_mem {{ config.cache_mem_mb }} MB | 40 | cache_mem {{ config.cache_mem_mb }} MB |
394 | 34 | {% else -%} | 41 | {% else -%} |
395 | 35 | cache deny all | 42 | cache deny all |
396 | @@ -39,6 +46,9 @@ | |||
397 | 39 | log_mime_hdrs on | 46 | log_mime_hdrs on |
398 | 40 | 47 | ||
399 | 41 | acl accel_ports myport {{ config.port }} | 48 | acl accel_ports myport {{ config.port }} |
400 | 49 | {% if config.enable_https -%} | ||
401 | 50 | acl accel_ports myport {{ config.https_port }} | ||
402 | 51 | {% endif -%} | ||
403 | 42 | 52 | ||
404 | 43 | {% for rp in refresh_patterns.keys() -%} | 53 | {% for rp in refresh_patterns.keys() -%} |
405 | 44 | refresh_pattern {{ rp }} {{ refresh_patterns[rp]['min'] }} {{ refresh_patterns[rp]['percent'] }}% {{ refresh_patterns[rp]['max'] }} {{ ' '.join(refresh_patterns[rp]['options']) }} | 54 | refresh_pattern {{ rp }} {{ refresh_patterns[rp]['min'] }} {{ refresh_patterns[rp]['percent'] }}% {{ refresh_patterns[rp]['max'] }} {{ ' '.join(refresh_patterns[rp]['options']) }} |