Merge lp:~nick-moffitt/charms/trusty/squid-reverseproxy/bikeshedding into lp:charms/trusty/squid-reverseproxy

Proposed by Nick Moffitt
Status: Merged
Merged at revision: 52
Proposed branch: lp:~nick-moffitt/charms/trusty/squid-reverseproxy/bikeshedding
Merge into: lp:charms/trusty/squid-reverseproxy
Prerequisite: lp:~jacekn/charms/trusty/squid-reverseproxy/squid-reverseproxy-nrpe-fix
Diff against target: 261 lines (+56/-84)
2 files modified
hooks/hooks.py (+22/-50)
templates/main_config.template (+34/-34)
To merge this branch: bzr merge lp:~nick-moffitt/charms/trusty/squid-reverseproxy/bikeshedding
Reviewer Review Type Date Requested Status
Adam Israel (community) Approve
Review Queue (community) automated testing Needs Fixing
charmers Pending
Review via email: mp+247038@code.launchpad.net

Description of the change

This is almost entirely cosmetic clean-ups I performed while trying to work out the flow of data in this charm. It shouldn't do too much, but I think it will help maintenance if this codebase is to be preserved.

I started from jacekn's nrpe fix branch, so that's listed as a prereq.

To post a comment you must log in.
Revision history for this message
Review Queue (review-queue) wrote :

This items has failed automated testing! Results available here http://reports.vapour.ws/charm-tests/charm-bundle-test-10961-results

review: Needs Fixing (automated testing)
Revision history for this message
Adam Israel (aisrael) wrote :

Hi Nick,

Thanks for your work on this charm! I've reviewed this MP and everything looks good to me. +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hooks/hooks.py'
2--- hooks/hooks.py 2015-01-20 16:13:22 +0000
3+++ hooks/hooks.py 2015-01-20 16:13:22 +0000
4@@ -146,37 +146,31 @@
5 dpkg.communicate(input=selections)
6
7
8-###############################################################################
9-# load_squid3_config: Convenience function that loads (as a string) the
10-# current squid3 configuration file.
11-# Returns a string containing the squid3 config or
12-# None
13-###############################################################################
14 def load_squid3_config(squid3_config_file="/etc/squid3/squid.conf"):
15+ """Convenience function that loads (as a string) the current squid3
16+ configuration file.
17+
18+ Returns a string containing the squid3 config or None"""
19 if os.path.isfile(squid3_config_file):
20 return open(squid3_config_file).read()
21 return
22
23
24-###############################################################################
25-# get_service_ports: Convenience function that scans the existing squid3
26-# configuration file and returns a list of the existing
27-# ports being used. This is necessary to know which ports
28-# to open and close when exposing/unexposing a service
29-###############################################################################
30 def get_service_ports(squid3_config_file="/etc/squid3/squid.conf"):
31+ """Convenience function that scans the existing squid3 configuration
32+ file and returns a list of the existing ports being used.
33+
34+ This is necessary to know which ports to open and close when
35+ exposing/unexposing a service"""
36 squid3_config = load_squid3_config(squid3_config_file)
37 if squid3_config is None:
38 return
39 return re.findall("http_port ([0-9]+)", squid3_config)
40
41
42-###############################################################################
43-# get_sitenames: Convenience function that scans the existing squid3
44-# configuration file and returns a list of the sitenames
45-# being served by the instance.
46-###############################################################################
47 def get_sitenames(squid3_config_file="/etc/squid3/squid.conf"):
48+ """Convenience function that scans the existing squid3 configuration
49+ file and returns a list of the sitenames being served by the instance."""
50 squid3_config = load_squid3_config(squid3_config_file)
51 if squid3_config is None:
52 return
53@@ -184,12 +178,9 @@
54 return list(set(sitenames))
55
56
57-###############################################################################
58-# update_service_ports: Convenience function that evaluate the old and new
59-# service ports to decide which ports need to be
60-# opened and which to close
61-###############################################################################
62 def update_service_ports(old_service_ports=None, new_service_ports=None):
63+ """Convenience function that evaluate the old and new service ports to
64+ decide which ports need to be opened and which to close"""
65 if old_service_ports is None or new_service_ports is None:
66 return
67 for port in old_service_ports:
68@@ -200,12 +191,10 @@
69 open_port(port)
70
71
72-###############################################################################
73-# pwgen: Generates a random password
74-# pwd_length: Defines the length of the password to generate
75-# default: 20
76-###############################################################################
77 def pwgen(pwd_length=20):
78+ """Generates a random password
79+ pwd_length: Defines the length of the password to generate
80+ default: 20"""
81 alphanumeric_chars = [l for l in (string.letters + string.digits)
82 if l not in 'Iil0oO1']
83 random_chars = [random.choice(alphanumeric_chars)
84@@ -222,10 +211,8 @@
85 return template.render(vars)
86
87
88-###############################################################################
89-# construct_squid3_config: Convenience function to write squid.conf
90-###############################################################################
91 def construct_squid3_config():
92+ """Convenience function to write squid.conf"""
93 config_data = config_get()
94 reverse_sites = get_reverse_sites()
95 only_direct = set()
96@@ -355,34 +342,19 @@
97 }))
98
99
100-###############################################################################
101-# service_squid3: Convenience function to start/stop/restart/reload
102-# the squid3 service
103-###############################################################################
104 def service_squid3(action=None, squid3_config=default_squid3_config):
105+ """Convenience function to start/stop/restart/reload the squid3
106+ service"""
107 if action is None or squid3_config is None:
108 return
109 elif action == "check":
110 check_cmd = ['/usr/sbin/squid3', '-f', squid3_config, '-k', 'parse']
111- retVal = subprocess.call(check_cmd)
112- if retVal == 1:
113- return False
114- elif retVal == 0:
115- return True
116- else:
117- return False
118+ return not subprocess.call(check_cmd)
119 elif action == 'status':
120 status = subprocess.check_output(['status', 'squid3'])
121- if re.search('running', status) is not None:
122- return True
123- else:
124- return False
125+ return re.search('running', status) is not None
126 elif action in ('start', 'stop', 'reload', 'restart'):
127- retVal = subprocess.call([action, 'squid3'])
128- if retVal == 0:
129- return True
130- else:
131- return False
132+ return not subprocess.call([action, 'squid3'])
133
134
135 def install_nrpe_scripts():
136
137=== modified file 'templates/main_config.template'
138--- templates/main_config.template 2014-05-02 15:23:33 +0000
139+++ templates/main_config.template 2015-01-20 16:13:22 +0000
140@@ -15,12 +15,12 @@
141
142 {% if config.snmp_community -%}
143 acl snmp_access snmp_community {{ config.snmp_community }}
144-{% for source in config.snmp_allowed_ips -%}
145+ {% for source in config.snmp_allowed_ips -%}
146 acl snmp_source src {{ source }}
147-{% if loop.last -%}
148+ {% if loop.last -%}
149 snmp_access allow snmp_access snmp_source
150-{% endif -%}
151-{% endfor -%}
152+ {% endif -%}
153+ {% endfor -%}
154 snmp_access allow localhost
155 snmp_access deny all
156 snmp_port {{ config.snmp_port }}
157@@ -60,52 +60,52 @@
158
159 # known services
160 {% if sites -%}
161-{% for sitename in sites.keys() -%}
162-{% if sitename -%}
163-{% set site_acl = "s_%s_acl" % loop.index %}
164+ {% for sitename in sites.keys() -%}
165+ {% if sitename -%}
166+ {% set site_acl = "s_%s_acl" % loop.index %}
167 acl {{ site_acl }} dstdomain {{ sitename }}
168 http_access allow accel_ports {{ site_acl }}
169 http_access allow CONNECT SSL_ports {{ site_acl }}
170-{% if sitename in only_direct -%}
171+ {% if sitename in only_direct -%}
172 always_direct allow {{ site_acl }}
173-{% else -%}
174+ {% else -%}
175 always_direct allow CONNECT SSL_ports {{ site_acl }}
176 always_direct deny {{ site_acl }}
177-{% endif -%}
178-{% if config['x_balancer_name_allowed'] -%}
179-{% set balancer_acl = "s_%s_balancer" % loop.index %}
180+ {% endif -%}
181+ {% if config['x_balancer_name_allowed'] -%}
182+ {% set balancer_acl = "s_%s_balancer" % loop.index %}
183 acl {{ balancer_acl }} req_header X-Balancer-Name {{ sitename.replace('.', '\.') }}
184 http_access allow accel_ports {{ balancer_acl }}
185 http_access allow CONNECT SSL_ports {{ balancer_acl }}
186-{% if sitename in only_direct -%}
187+ {% if sitename in only_direct -%}
188 always_direct allow {{ balancer_acl }}
189-{% else -%}
190+ {% else -%}
191 always_direct allow CONNECT SSL_ports {{ balancer_acl }}
192 always_direct deny {{ balancer_acl }}
193-{% endif -%}
194-{% endif -%}
195-{% else %} # no sitename
196+ {% endif -%}
197+ {% endif -%}
198+ {% else %} # no sitename
199 acl no_sitename_acl myport {{ config.port }}
200-{% if config.enable_https -%}
201+ {% if config.enable_https -%}
202 acl no_sitename_acl myport {{ config.https_port }}
203-{% endif -%}
204+ {% endif -%}
205 http_access allow accel_ports no_sitename_acl
206 never_direct allow no_sitename_acl
207-{% endif %}
208-{% endfor -%}
209+ {% endif %}
210+ {% endfor -%}
211 {% endif -%}
212
213 {% if config.enable_forward_proxy -%}
214 # no access retrictions
215-{% for relation in forward_relations -%}
216+ {% for relation in forward_relations -%}
217 {# acl names are limited to 31 chars (!), so using short "fwd_" prefix #}
218-{% set forward_acl = "fwd_%s" % relation['name'] -%}
219+ {% set forward_acl = "fwd_%s" % relation['name'] -%}
220 acl {{ forward_acl }} src {{ relation['private-address'] }}
221 http_access allow {{ forward_acl }}
222 http_access allow CONNECT SSL_ports {{ forward_acl }}
223 always_direct allow {{ forward_acl }}
224 always_direct allow CONNECT SSL_ports {{ forward_acl }}
225-{% endfor -%}
226+ {% endfor -%}
227 {% endif -%}
228
229 http_access allow manager localhost
230@@ -120,21 +120,21 @@
231 always_direct deny all
232
233 {% if sites -%}
234-{% for sitename in sites.keys() -%}
235-{% set sites_loop = loop -%}
236-{% for peer in sites[sitename] %}
237-{% if sitename -%}
238+ {% for sitename in sites.keys() -%}
239+ {% set sites_loop = loop -%}
240+ {% for peer in sites[sitename] %}
241+ {% if sitename -%}
242 cache_peer {{ peer.address }} parent {{ peer.port }} 0 name={{ peer.name }} no-query no-digest originserver round-robin login=PASS {{ peer.options }}
243 cache_peer_access {{ peer.name }} allow s_{{ sites_loop.index }}_acl
244-{% if config['x_balancer_name_allowed'] -%}
245+ {% if config['x_balancer_name_allowed'] -%}
246 cache_peer_access {{ peer.name }} allow s_{{ sites_loop.index }}_balancer
247-{% endif -%}
248+ {% endif -%}
249 cache_peer_access {{ peer.name }} deny all
250-{% else %}
251+ {% else %}
252 cache_peer {{ peer.address }} parent {{ peer.port }} 0 name={{ peer.name }} no-query no-digest originserver round-robin login=PASS
253 cache_peer_access {{ peer.name }} allow no_sitename_acl
254 cache_peer_access {{ peer.name }} deny all
255-{% endif -%}
256-{% endfor -%}
257-{% endfor -%}
258+ {% endif -%}
259+ {% endfor -%}
260+ {% endfor -%}
261 {% endif -%}

Subscribers

People subscribed via source and target branches

to all changes: