Merge lp:~blr/charms/precise/squid-forwardproxy/port-fix into lp:~canonical-launchpad-branches/charms/precise/squid-forwardproxy/trunk

Proposed by Kit Randel on 2015-09-17
Status: Merged
Merged at revision: 32
Proposed branch: lp:~blr/charms/precise/squid-forwardproxy/port-fix
Merge into: lp:~canonical-launchpad-branches/charms/precise/squid-forwardproxy/trunk
Prerequisite: lp:~blr/charms/precise/squid-forwardproxy/trunk
Diff against target: 50 lines (+7/-2)
1 file modified
hooks/hooks.py (+7/-2)
To merge this branch: bzr merge lp:~blr/charms/precise/squid-forwardproxy/port-fix
Reviewer Review Type Date Requested Status
William Grant code Approve on 2015-09-17
charmers 2015-09-17 Pending
Review via email: mp+271571@code.launchpad.net

Commit message

Ensure port is opened and make update_service_port behaviour clearer.

Description of the change

The charm attempts to avoid closing and reopening preserved ports on config_changed, however as there is no explicit open_port() call on the install hook, the default port is never opened.

To post a comment you must log in.
William Grant (wgrant) :
review: Approve (code)
42. By Kit Randel on 2015-09-17

Use sentence case for log messages.

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-09-17 22:30:32 +0000
3+++ hooks/hooks.py 2015-09-17 22:30:33 +0000
4@@ -167,6 +167,7 @@
5 def open_port(port=None, protocol="TCP"):
6 if port is None:
7 return(None)
8+ utils.juju_log('INFO', 'Opening port: %d' % int(port))
9 return(subprocess.call(['open-port', "%d/%s" %
10 (int(port), protocol)]))
11
12@@ -178,6 +179,7 @@
13 def close_port(port=None, protocol="TCP"):
14 if port is None:
15 return(None)
16+ utils.juju_log('INFO', 'Closing port: %d' % int(port))
17 return(subprocess.call(['close-port', "%d/%s" %
18 (int(port), protocol)]))
19
20@@ -188,13 +190,14 @@
21 # opened and which to close
22 #------------------------------------------------------------------------------
23 def update_service_ports(old_service_ports=None, new_service_ports=None):
24+ preserved_ports = set(old_service_ports).intersection(new_service_ports)
25 if old_service_ports is None or new_service_ports is None:
26 return(None)
27 for port in old_service_ports:
28- if port not in new_service_ports:
29+ if port not in preserved_ports:
30 close_port(port)
31 for port in new_service_ports:
32- if port not in old_service_ports:
33+ if port not in preserved_ports:
34 open_port(port)
35
36
37@@ -380,6 +383,7 @@
38 # Hook functions
39 ###############################################################################
40 def install_hook():
41+ config_data = config_get()
42 for f in glob.glob('exec.d/*/charm-pre-install'):
43 if os.path.isfile(f) and os.access(f, os.X_OK):
44 subprocess.check_call(['sh', '-c', f])
45@@ -388,6 +392,7 @@
46 if not os.path.exists(default_squid3_config_cache_dir):
47 os.mkdir(default_squid3_config_cache_dir, 0600)
48 shutil.copy2('%s/files/default.squid3' % (os.environ['CHARM_DIR']), '/etc/default/squid3')
49+ open_port(config_data['port'])
50 return (utils.install_unattended('squid3', 'python-jinja2'))
51
52

Subscribers

People subscribed via source and target branches

to all changes: