Merge lp:~ahasenack/charms/precise/apache2/apache2-default-servername into lp:charms/apache2

Proposed by Andreas Hasenack
Status: Merged
Merged at revision: 47
Proposed branch: lp:~ahasenack/charms/precise/apache2/apache2-default-servername
Merge into: lp:charms/apache2
Diff against target: 44 lines (+16/-3)
1 file modified
hooks/hooks.py (+16/-3)
To merge this branch: bzr merge lp:~ahasenack/charms/precise/apache2/apache2-default-servername
Reviewer Review Type Date Requested Status
Marco Ceppi (community) Approve
Review via email: mp+192350@code.launchpad.net

Description of the change

If the config key "servername" is empty, fill it in with the public-address of the unit to match what the documentation says.
Since we are also using charm helpers, I updated the calls to unit-get to use the charm helper method.

To post a comment you must log in.
Revision history for this message
Andreas Hasenack (ahasenack) wrote :

I removed this from the review queue for now because I'm chasing a similar bug in haproxy, and my test deployment needs both apache2 and haproxy working.

Revision history for this message
Andreas Hasenack (ahasenack) wrote :

It's working.

Revision history for this message
Tom Haddon (mthaddon) wrote :

Is there any reason why we wouldn't want the change you've suggested to config/config_get in charm-helpers? Seems like it could certainly be an option you pass to it rather than needing to wrap the function at all.

Revision history for this message
Andreas Hasenack (ahasenack) wrote :

I don't know if such an exception is common place. It felt odd to add an exception to the generic code of charm helpers just for apache.

Revision history for this message
Marco Ceppi (marcoceppi) wrote :

I thinks this is a bit too specific for a change in config_get for charm-helpers. However, I think having a "default" key for when config-get returns either None or possibly an empty key might be useful. Either way this change LGTM. I'll merge it in and let you decided if you want to amend charm-helpers with that functionality.

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-10-10 22:47:57 +0000
3+++ hooks/hooks.py 2013-10-23 19:22:12 +0000
4@@ -16,8 +16,9 @@
5 open_port,
6 close_port,
7 log,
8- config as config_get,
9+ config as orig_config_get,
10 relations_of_type,
11+ unit_get
12 )
13 from charmhelpers.contrib.charmsupport import nrpe
14
15@@ -137,6 +138,18 @@
16 ###############################################################################
17 # Hook functions
18 ###############################################################################
19+def config_get(scope=None):
20+ """
21+ Wrapper around charm helper's config_get to replace an empty servername
22+ with the public-address.
23+ """
24+ result = orig_config_get(scope)
25+ if scope == "servername" and len(result) == 0:
26+ result = unit_get("public-address")
27+ elif type(result) is dict and "servername" in result.keys():
28+ result["servername"] = unit_get("public-address")
29+ return result
30+
31 def install_hook():
32 if not os.path.exists(default_apache2_service_config_dir):
33 os.mkdir(default_apache2_service_config_dir, 0600)
34@@ -405,8 +418,8 @@
35 # ssl_cert is SELFSIGNED so generate self-signed certificate for use.
36 if config_data['ssl_cert'] and config_data['ssl_cert'] == "SELFSIGNED":
37 os.environ['OPENSSL_CN'] = config_data['servername']
38- os.environ['OPENSSL_PUBLIC'] = run(["unit-get", "public-address"]).rstrip()
39- os.environ['OPENSSL_PRIVATE'] = run(["unit-get", "private-address"]).rstrip()
40+ os.environ['OPENSSL_PUBLIC'] = unit_get("public-address")
41+ os.environ['OPENSSL_PRIVATE'] = unit_get("private-address")
42 run(['openssl', 'req', '-new', '-x509', '-nodes', '-config',
43 os.path.join(os.environ['CHARM_DIR'], 'data', 'openssl.cnf'),
44 '-keyout', key_file, '-out', cert_file])

Subscribers

People subscribed via source and target branches