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 (community) 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
1=== modified file 'config.yaml'
2--- config.yaml 2015-09-16 02:59:55 +0000
3+++ config.yaml 2015-12-06 22:48:44 +0000
4@@ -47,13 +47,6 @@
5 type: int
6 default: 8192
7 description: Maximum size of an object to be cached (KB).
8- run:
9- type: boolean
10- default: true
11- description: >
12- Run state of squid service. A value of false will stop the service currently running, or prevent
13- the service starting on installation. This is potentially useful for awaiting deployment
14- of a sub-ordinate helper service.
15 snmp_community:
16 type: string
17 default: ''
18@@ -64,6 +57,12 @@
19 default: ''
20 description: Single, or json-formatted list of, IP (with optional subnet mask) allowed to query SNMP.
21 # validator: '[0-9a-zA-z]{6,32}'
22+ wait_for_auth_helper:
23+ type: boolean
24+ default: false
25+ description: >
26+ If True, squid will not be started until an squid-auth-helper relation is joined. This is needed as
27+ Squid will fail to start if a defined auth_helper program is not available.
28 nagios_context:
29 default: "juju"
30 type: string
31
32=== modified file 'hooks/hooks.py'
33--- hooks/hooks.py 2015-09-17 22:30:08 +0000
34+++ hooks/hooks.py 2015-12-06 22:48:44 +0000
35@@ -22,7 +22,9 @@
36 default_squid3_config = "%s/squid.conf" % default_squid3_config_dir
37 default_squid3_config_cache_dir = "/var/run/squid3"
38 hook_name = os.path.basename(sys.argv[0])
39-
40+HOOK_START = False
41+HOOK_AUTH_HELPER_JOINED = False
42+STATE_DELAYED_START = False
43 ###############################################################################
44 # Supporting functions
45 ###############################################################################
46@@ -315,7 +317,9 @@
47 if action is None or squid3_config is None:
48 return(None)
49 elif action == "check":
50- retVal = subprocess.call(['/usr/sbin/squid3', '-f', squid3_config, '-k', 'parse'])
51+ utils.juju_log('INFO', 'Checking squid3 configuration...')
52+ retVal = subprocess.call(
53+ ['/usr/sbin/squid3', '-f', squid3_config, '-k', 'parse'])
54 if retVal == 1:
55 return(False)
56 elif retVal == 0:
57@@ -397,17 +401,21 @@
58
59
60 def config_changed():
61- config_data = config_get()
62- if not config_data['run']:
63- return(service_squid3('stop'))
64-
65 current_service_ports = get_service_ports()
66 construct_squid3_config()
67 update_nrpe_checks()
68
69+ updated_service_ports = get_service_ports()
70+ update_service_ports(current_service_ports, updated_service_ports)
71+
72+ config_data = config_get()
73+ if config_data['wait_for_auth_helper'] and not STATE_DELAYED_START:
74+ # unable to parse squid3 configuration without auth helper in
75+ # place.
76+ utils.juju_log('INFO', 'Squid not started, waiting for auth helper...')
77+ return
78+
79 if service_squid3('check'):
80- updated_service_ports = get_service_ports()
81- update_service_ports(current_service_ports, updated_service_ports)
82 if service_squid3('status'):
83 service_squid3('reload')
84 else:
85@@ -416,10 +424,27 @@
86 sys.exit(1)
87
88
89-def start_hook():
90+def start_hook(start=None, auth_helper=None):
91+ global HOOK_START
92+ global HOOK_AUTH_HELPER_JOINED
93+
94+ if start:
95+ HOOK_START = True
96+ if auth_helper:
97+ HOOK_AUTH_HELPER_JOINED = True
98+
99 config_data = config_get()
100- if not config_data['run']:
101- return
102+ if config_data['wait_for_auth_helper']:
103+ if HOOK_AUTH_HELPER_JOINED and HOOK_START:
104+ utils.juju_log('INFO', 'Squid auth helper available, starting...')
105+ if service_squid3('check'):
106+ STATE_DELAYED_START = True
107+ else:
108+ sys.exit(1)
109+ else:
110+ utils.juju_log('INFO', 'Waiting for auth helper...')
111+ return
112+
113 if service_squid3("status"):
114 return(service_squid3("restart"))
115 else:
116@@ -449,10 +474,11 @@
117 elif hook_name == "config-changed":
118 config_changed()
119 elif hook_name == "start":
120- start_hook()
121+ start_hook(start=True)
122 elif hook_name == "stop":
123 stop_hook()
124-
125+ elif hook_name == "squid-auth-helper-relation-joined":
126+ start_hook(auth_helper=True)
127 elif hook_name == "cached-website-relation-joined":
128 proxy_interface("joined")
129 elif hook_name == "cached-website-relation-changed":
130
131=== added symlink 'hooks/squid-auth-helper-relation-joined'
132=== target is u'hooks.py'
133=== modified file 'metadata.yaml'
134--- metadata.yaml 2013-07-11 19:15:19 +0000
135+++ metadata.yaml 2015-12-06 22:48:44 +0000
136@@ -14,6 +14,10 @@
137 sitenames: space-delimited list of vhosts to whitelist
138 categories:
139 - cache-proxy
140+requires:
141+ squid-auth-helper:
142+ interface: squid-auth-helper
143+ optional: true
144 provides:
145 cached-website:
146 interface: http

Subscribers

People subscribed via source and target branches

to all changes: