Merge lp:~joetalbott/charms/precise/postgresql/ensure_credentials_after_mount into lp:charms/postgresql

Proposed by Joe Talbott
Status: Merged
Merged at revision: 102
Proposed branch: lp:~joetalbott/charms/precise/postgresql/ensure_credentials_after_mount
Merge into: lp:charms/postgresql
Diff against target: 26 lines (+16/-0)
1 file modified
hooks/hooks.py (+16/-0)
To merge this branch: bzr merge lp:~joetalbott/charms/precise/postgresql/ensure_credentials_after_mount
Reviewer Review Type Date Requested Status
Stuart Bishop (community) Needs Fixing
charmers Pending
Review via email: mp+235143@code.launchpad.net

Commit message

Ensure client credentials are up-to-date after an external mountpoint is mounted.

Description of the change

When using the block-storage-broker charm to have a persistent database the postgresql charm doesn't update the client credentials after the external mountpoint is mounted.

This patch iterates through client relations and ensures the expected users have access.

To post a comment you must log in.
Revision history for this message
Stuart Bishop (stub) wrote :

Thanks for this work.

There are two minor problems with this:
1) Only the db relations are handled. db-admin relation also need to be done.
2) The passwords may have changed, since we likely don't have the plaintext around and create_user will reset them. The new passwords need to be set on the relation so the clients can react.

Revision history for this message
Stuart Bishop (stub) wrote :

I'll make these changes since they are relatively minor.

Revision history for this message
Stuart Bishop (stub) :
review: Needs Fixing

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 2014-06-16 09:38:33 +0000
3+++ hooks/hooks.py 2014-09-18 14:58:23 +0000
4@@ -940,6 +940,22 @@
5 postgresql_data_dir, pg_version(), config_data['cluster_name']))
6 update_service_port()
7 update_nrpe_checks()
8+
9+ # Ensure client credentials match in the case that an external mountpoint
10+ # has been mounted with an existing DB.
11+ for relid in hookenv.relation_ids('db'):
12+ rel = hookenv.relation_get(rid=relid, unit=hookenv.local_unit())
13+
14+ database = rel.get('database')
15+ roles = filter(None, (rel.get('roles') or '').split(","))
16+ user = rel['user']
17+ password = create_user(user)
18+ reset_user_roles(user, roles)
19+ schema_user = rel['schema_user']
20+ schema_password = create_user(schema_user)
21+ if database is not None:
22+ ensure_database(user, schema_user, database)
23+
24 if force_restart:
25 postgresql_restart()
26 postgresql_reload_or_restart()

Subscribers

People subscribed via source and target branches