Merge lp:~stub/charms/precise/postgresql/cleanups into lp:charms/postgresql

Proposed by Stuart Bishop
Status: Merged
Merge reported by: Stuart Bishop
Merged at revision: not available
Proposed branch: lp:~stub/charms/precise/postgresql/cleanups
Merge into: lp:charms/postgresql
Prerequisite: lp:~stub/charms/precise/postgresql/charm-helpers
Diff against target: 122 lines (+22/-17)
1 file modified
hooks/hooks.py (+22/-17)
To merge this branch: bzr merge lp:~stub/charms/precise/postgresql/cleanups
Reviewer Review Type Date Requested Status
Stuart Bishop (community) Approve
Review via email: mp+190332@code.launchpad.net

Description of the change

lint cleanup and updates for new charm-helpers

To post a comment you must log in.
Revision history for this message
Stuart Bishop (stub) :
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 2013-09-23 09:39:17 +0000
3+++ hooks/hooks.py 2013-10-10 10:52:47 +0000
4@@ -18,6 +18,7 @@
5 import yaml
6 from yaml.constructor import ConstructorError
7
8+from charmhelpers import fetch
9 from charmhelpers.core import hookenv, host
10 from charmhelpers.core.hookenv import (
11 CRITICAL, ERROR, WARNING, INFO, DEBUG,
12@@ -25,10 +26,13 @@
13
14 hooks = hookenv.Hooks()
15
16-# jinja2 may not be importable until the install hook has installed the
17-# required packages.
18+
19 def Template(*args, **kw):
20- """jinja2.Template with deferred jinja2 import"""
21+ """jinja2.Template with deferred jinja2 import.
22+
23+ jinja2 may not be importable until the install hook has installed the
24+ required packages.
25+ """
26 from jinja2 import Template
27 return Template(*args, **kw)
28
29@@ -251,7 +255,7 @@
30 run('pg_ctlcluster -force {version} {cluster_name} '
31 'restart'.format(**config_data))
32 success = True
33- except subprocess.CalledProcessError as e:
34+ except subprocess.CalledProcessError:
35 success = False
36 else:
37 success = host.service_start('postgresql')
38@@ -400,7 +404,7 @@
39
40
41 def generate_postgresql_hba(
42- postgresql_hba, user=None, schema_user=None, database=None):
43+ postgresql_hba, user=None, schema_user=None, database=None):
44 '''Create the pg_hba.conf file.'''
45
46 # Per Bug #1117542, when generating the postgresql_hba file we
47@@ -505,13 +509,12 @@
48 admin_ip_list = [config_data["admin_addresses"]]
49
50 for admin_ip in admin_ip_list:
51- admin_host = {'database':'all',
52- 'user':'all',
53- 'private-address':munge_address(admin_ip),
54- }
55+ admin_host = {
56+ 'database': 'all',
57+ 'user': 'all',
58+ 'private-address': munge_address(admin_ip)}
59 relation_data.append(admin_host)
60
61-
62 pg_hba_template = Template(open("templates/pg_hba.conf.tmpl").read())
63 host.write_file(
64 postgresql_hba, pg_hba_template.render(access_list=relation_data),
65@@ -547,8 +550,8 @@
66
67 recovery_conf = Template(
68 open("templates/recovery.conf.tmpl").read()).render({
69- 'host': master_host,
70- 'password': local_state['replication_password']})
71+ 'host': master_host,
72+ 'password': local_state['replication_password']})
73 log(recovery_conf, DEBUG)
74 host.write_file(
75 os.path.join(postgresql_cluster_dir, 'recovery.conf'),
76@@ -728,7 +731,7 @@
77 log("postgresql_stop() failed - can't migrate data.", ERROR)
78 return False
79 if not os.path.exists(os.path.join(
80- new_pg_version_cluster_dir, "PG_VERSION")):
81+ new_pg_version_cluster_dir, "PG_VERSION")):
82 log("migrating PG data {}/ -> {}/".format(
83 data_directory_path, new_pg_version_cluster_dir), WARNING)
84 # void copying PID file to perm storage (shouldn't be any...)
85@@ -826,8 +829,8 @@
86 "python-psycopg2", "postgresql-contrib", "postgresql-plpython",
87 "postgresql-%s-debversion" % config_data["version"]]
88 packages.extend((hookenv.config('extra-packages') or '').split())
89- packages = host.filter_installed_packages(packages)
90- host.apt_install(packages, fatal=True)
91+ packages = fetch.filter_installed_packages(packages)
92+ fetch.apt_install(packages, fatal=True)
93
94 if not 'state' in local_state:
95 # Fresh installation. Because this function is invoked by both
96@@ -1063,7 +1066,7 @@
97 # A more complex approach is for the first database unit that joins
98 # the relation to generate the usernames and passwords and publish
99 # this to the relation. Subsequent units can retrieve this
100-# information and republish it. Of course, the master unit also
101+# information and republish it. Of course, the master unit also
102 # creates the database and users when it joins the relation.
103 # This approach should work reliably on the server side. However,
104 # there is a window from when a slave unit joins a client relation
105@@ -1101,6 +1104,7 @@
106 # slave replication-relation-changed (noop; slave not yet joined db rel)
107 # slave db-relation-joined (republish)
108
109+
110 @hooks.hook('db-relation-joined', 'db-relation-changed')
111 def db_relation_joined_changed():
112 if local_state['state'] == 'hot standby':
113@@ -1706,7 +1710,8 @@
114 postgresql_stop()
115 log("Cloning master {}".format(master_unit))
116
117- cmd = ['sudo', '-E', # -E needed to locate pgpass file.
118+ cmd = [
119+ 'sudo', '-E', # -E needed to locate pgpass file.
120 '-u', 'postgres', 'pg_basebackup', '-D', postgresql_cluster_dir,
121 '--xlog', '--checkpoint=fast', '--no-password',
122 '-h', master_host, '-p', '5432', '--username=juju_replication']

Subscribers

People subscribed via source and target branches