Merge lp:~blr/charms/precise/squid-forwardproxy/rutabaga-auth-helper into lp:~canonical-launchpad-branches/charms/precise/squid-forwardproxy/trunk

Proposed by Kit Randel
Status: Merged
Merged at revision: 34
Proposed branch: lp:~blr/charms/precise/squid-forwardproxy/rutabaga-auth-helper
Merge into: lp:~canonical-launchpad-branches/charms/precise/squid-forwardproxy/trunk
Diff against target: 146 lines (+49/-20)
3 files modified
config.yaml (+6/-7)
hooks/hooks.py (+39/-13)
metadata.yaml (+4/-0)
To merge this branch: bzr merge lp:~blr/charms/precise/squid-forwardproxy/rutabaga-auth-helper
Reviewer Review Type Date Requested Status
Colin Watson Approve
Review via email: mp+278920@code.launchpad.net

Commit message

* Add wait_for_auth_helper config value, allowing delayed config_changed hook until auth-helper-relation-joined.
* Remove 'run' config.

To post a comment you must log in.
52. By Kit Randel

Rename auth-helper to squid-auth-helper.

53. By Kit Randel

Avoid mutating state of wait_for_auth_helper.

54. By Kit Randel

Prevent config parsing if not STATE_STARTED.

55. By Kit Randel

Update service ports independantly of configuration parsing in config_changed().

56. By Kit Randel

Set initial HOOK_START value to False.

Revision history for this message
Colin Watson (cjwatson) :
review: Approve
57. By Kit Randel

Add logging...

58. By Kit Randel

* Remove juju/general-info relations
* Add additional auth-helper relation symlinks.

59. By Kit Randel

Only squid-auth-helper-relation-joined implemented.

60. By Kit Randel

Manage hook state more consistently.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'config.yaml'
--- config.yaml 2015-09-16 02:59:55 +0000
+++ config.yaml 2015-12-06 22:48:44 +0000
@@ -47,13 +47,6 @@
47 type: int47 type: int
48 default: 819248 default: 8192
49 description: Maximum size of an object to be cached (KB).49 description: Maximum size of an object to be cached (KB).
50 run:
51 type: boolean
52 default: true
53 description: >
54 Run state of squid service. A value of false will stop the service currently running, or prevent
55 the service starting on installation. This is potentially useful for awaiting deployment
56 of a sub-ordinate helper service.
57 snmp_community:50 snmp_community:
58 type: string51 type: string
59 default: ''52 default: ''
@@ -64,6 +57,12 @@
64 default: ''57 default: ''
65 description: Single, or json-formatted list of, IP (with optional subnet mask) allowed to query SNMP.58 description: Single, or json-formatted list of, IP (with optional subnet mask) allowed to query SNMP.
66 # validator: '[0-9a-zA-z]{6,32}'59 # validator: '[0-9a-zA-z]{6,32}'
60 wait_for_auth_helper:
61 type: boolean
62 default: false
63 description: >
64 If True, squid will not be started until an squid-auth-helper relation is joined. This is needed as
65 Squid will fail to start if a defined auth_helper program is not available.
67 nagios_context:66 nagios_context:
68 default: "juju"67 default: "juju"
69 type: string68 type: string
7069
=== modified file 'hooks/hooks.py'
--- hooks/hooks.py 2015-09-17 22:30:08 +0000
+++ hooks/hooks.py 2015-12-06 22:48:44 +0000
@@ -22,7 +22,9 @@
22default_squid3_config = "%s/squid.conf" % default_squid3_config_dir22default_squid3_config = "%s/squid.conf" % default_squid3_config_dir
23default_squid3_config_cache_dir = "/var/run/squid3"23default_squid3_config_cache_dir = "/var/run/squid3"
24hook_name = os.path.basename(sys.argv[0])24hook_name = os.path.basename(sys.argv[0])
2525HOOK_START = False
26HOOK_AUTH_HELPER_JOINED = False
27STATE_DELAYED_START = False
26###############################################################################28###############################################################################
27# Supporting functions29# Supporting functions
28###############################################################################30###############################################################################
@@ -315,7 +317,9 @@
315 if action is None or squid3_config is None:317 if action is None or squid3_config is None:
316 return(None)318 return(None)
317 elif action == "check":319 elif action == "check":
318 retVal = subprocess.call(['/usr/sbin/squid3', '-f', squid3_config, '-k', 'parse'])320 utils.juju_log('INFO', 'Checking squid3 configuration...')
321 retVal = subprocess.call(
322 ['/usr/sbin/squid3', '-f', squid3_config, '-k', 'parse'])
319 if retVal == 1:323 if retVal == 1:
320 return(False)324 return(False)
321 elif retVal == 0:325 elif retVal == 0:
@@ -397,17 +401,21 @@
397401
398402
399def config_changed():403def config_changed():
400 config_data = config_get()
401 if not config_data['run']:
402 return(service_squid3('stop'))
403
404 current_service_ports = get_service_ports()404 current_service_ports = get_service_ports()
405 construct_squid3_config()405 construct_squid3_config()
406 update_nrpe_checks()406 update_nrpe_checks()
407407
408 updated_service_ports = get_service_ports()
409 update_service_ports(current_service_ports, updated_service_ports)
410
411 config_data = config_get()
412 if config_data['wait_for_auth_helper'] and not STATE_DELAYED_START:
413 # unable to parse squid3 configuration without auth helper in
414 # place.
415 utils.juju_log('INFO', 'Squid not started, waiting for auth helper...')
416 return
417
408 if service_squid3('check'):418 if service_squid3('check'):
409 updated_service_ports = get_service_ports()
410 update_service_ports(current_service_ports, updated_service_ports)
411 if service_squid3('status'):419 if service_squid3('status'):
412 service_squid3('reload')420 service_squid3('reload')
413 else:421 else:
@@ -416,10 +424,27 @@
416 sys.exit(1)424 sys.exit(1)
417425
418426
419def start_hook():427def start_hook(start=None, auth_helper=None):
428 global HOOK_START
429 global HOOK_AUTH_HELPER_JOINED
430
431 if start:
432 HOOK_START = True
433 if auth_helper:
434 HOOK_AUTH_HELPER_JOINED = True
435
420 config_data = config_get()436 config_data = config_get()
421 if not config_data['run']:437 if config_data['wait_for_auth_helper']:
422 return438 if HOOK_AUTH_HELPER_JOINED and HOOK_START:
439 utils.juju_log('INFO', 'Squid auth helper available, starting...')
440 if service_squid3('check'):
441 STATE_DELAYED_START = True
442 else:
443 sys.exit(1)
444 else:
445 utils.juju_log('INFO', 'Waiting for auth helper...')
446 return
447
423 if service_squid3("status"):448 if service_squid3("status"):
424 return(service_squid3("restart"))449 return(service_squid3("restart"))
425 else:450 else:
@@ -449,10 +474,11 @@
449 elif hook_name == "config-changed":474 elif hook_name == "config-changed":
450 config_changed()475 config_changed()
451 elif hook_name == "start":476 elif hook_name == "start":
452 start_hook()477 start_hook(start=True)
453 elif hook_name == "stop":478 elif hook_name == "stop":
454 stop_hook()479 stop_hook()
455480 elif hook_name == "squid-auth-helper-relation-joined":
481 start_hook(auth_helper=True)
456 elif hook_name == "cached-website-relation-joined":482 elif hook_name == "cached-website-relation-joined":
457 proxy_interface("joined")483 proxy_interface("joined")
458 elif hook_name == "cached-website-relation-changed":484 elif hook_name == "cached-website-relation-changed":
459485
=== added symlink 'hooks/squid-auth-helper-relation-joined'
=== target is u'hooks.py'
=== modified file 'metadata.yaml'
--- metadata.yaml 2013-07-11 19:15:19 +0000
+++ metadata.yaml 2015-12-06 22:48:44 +0000
@@ -14,6 +14,10 @@
14 sitenames: space-delimited list of vhosts to whitelist14 sitenames: space-delimited list of vhosts to whitelist
15categories:15categories:
16 - cache-proxy16 - cache-proxy
17requires:
18 squid-auth-helper:
19 interface: squid-auth-helper
20 optional: true
17provides:21provides:
18 cached-website:22 cached-website:
19 interface: http23 interface: http

Subscribers

People subscribed via source and target branches

to all changes: