Merge lp:~bloodearnest/charms/precise/apache2/vhost-template-vars into lp:charms/apache2

Proposed by Simon Davy
Status: Work in progress
Proposed branch: lp:~bloodearnest/charms/precise/apache2/vhost-template-vars
Merge into: lp:charms/apache2
Diff against target: 88 lines (+41/-0)
4 files modified
README.md (+5/-0)
config.yaml (+4/-0)
hooks/hooks.py (+4/-0)
hooks/tests/test_create_vhost.py (+28/-0)
To merge this branch: bzr merge lp:~bloodearnest/charms/precise/apache2/vhost-template-vars
Reviewer Review Type Date Requested Status
Adam Israel (community) Needs Fixing
Review Queue (community) automated testing Needs Fixing
charmers Pending
Review via email: mp+251268@code.launchpad.net

Commit message

Add vhost_template_vars, as per trusty branch

Description of the change

Add vhost_template_vars, as per trusty branch

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-11066-results

review: Needs Fixing (automated testing)
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-11076-results

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

Hi Simon,

Thanks for your work on improving the apache2 charm. It appears that the test_create_vhost_template_config test has been duplicated, which is causing a lint error. The other automated test failures, relating to self-signed certificates, is a problem upstream and won't stand in the way of this merge, once the lint error is corrected.

review: Approve
Revision history for this message
Adam Israel (aisrael) wrote :

Sorry, I meant to mark as needs fixing.

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

I've moved this to Work In Progress, when ready for another review please move to Needs Review

Unmerged revisions

62. By Simon Davy

add vhost_template_vars, merge from trusty

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'README.md'
2--- README.md 2014-11-20 00:32:58 +0000
3+++ README.md 2015-02-27 15:07:15 +0000
4@@ -67,6 +67,11 @@
5 Virtual host templates can also be specified via relation. See the
6 vhost-config relation section below for more information.
7
8+The vhost_template_vars config allows for further customisation of the vhost
9+templates. For example, you can have a single template for a particular
10+service, but use vhost_template_vars to customise it slightly for
11+devel/staging/production environments.
12+
13 ### Using the reverseproxy relation
14
15 The charm will create the service variable, with the `unit_name`,
16
17=== modified file 'config.yaml'
18--- config.yaml 2014-10-16 13:12:04 +0000
19+++ config.yaml 2015-02-27 15:07:15 +0000
20@@ -11,6 +11,10 @@
21 type: string
22 default: ''
23 description: Apache vhost template (base64 encoded).
24+ vhost_template_vars:
25+ type: string
26+ default: ''
27+ description: Additional custom variables for the vhost templating, in python dict format
28 enable_modules:
29 type: string
30 default: ''
31
32=== modified file 'hooks/hooks.py'
33--- hooks/hooks.py 2014-10-13 07:51:42 +0000
34+++ hooks/hooks.py 2015-02-27 15:07:15 +0000
35@@ -11,6 +11,7 @@
36 import pwd
37 import shutil
38 import os.path
39+import ast
40
41 from charmhelpers.core.hookenv import (
42 open_port,
43@@ -528,6 +529,9 @@
44 from jinja2 import Template
45 template = Template(str(base64.b64decode(template_str)))
46 template_data = dict(config_data.items() + relationship_data.items())
47+ if config_data.get('vhost_template_vars'):
48+ extra_vars = ast.literal_eval(config_data['vhost_template_vars'])
49+ template_data.update(extra_vars)
50 vhost_name = '%s_%s' % (config_data['servername'], protocol)
51 vhost_file = site_filename(vhost_name)
52 log("Writing file %s with config and relation data" % vhost_file)
53
54=== modified file 'hooks/tests/test_create_vhost.py'
55--- hooks/tests/test_create_vhost.py 2014-05-20 03:34:20 +0000
56+++ hooks/tests/test_create_vhost.py 2015-02-27 15:07:15 +0000
57@@ -104,3 +104,31 @@
58 with open(filename, 'r') as f:
59 contents = f.read()
60 self.assertEqual(contents, template)
61+
62+ @patch('hooks.close_port')
63+ @patch('hooks.site_filename')
64+ @patch('hooks.open_port')
65+ @patch('hooks.subprocess.call')
66+ def test_create_vhost_template_config(
67+ self, mock_call, mock_open_port, mock_site_filename,
68+ mock_close_port):
69+ """Template passed in as config setting."""
70+ template = ("one\n"
71+ "two\n"
72+ "{{ extra }}")
73+ expected = ("one\n"
74+ "two\n"
75+ "three")
76+ config = {"servername": "unused",
77+ "vhost_template_vars": "{'extra': 'three'}",
78+ "vhost_template": base64.b64encode(template)}
79+ file = tempfile.NamedTemporaryFile()
80+ filename = file.name
81+ mock_site_filename.return_value = filename
82+ hooks.create_vhost(
83+ "80",
84+ config_key="vhost_template",
85+ config_data=config)
86+ with open(filename, 'r') as f:
87+ contents = f.read()
88+ self.assertEqual(contents, expected)

Subscribers

People subscribed via source and target branches

to all changes: