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
=== modified file 'README.md'
--- README.md 2014-11-20 00:32:58 +0000
+++ README.md 2015-02-27 15:07:15 +0000
@@ -67,6 +67,11 @@
67Virtual host templates can also be specified via relation. See the67Virtual host templates can also be specified via relation. See the
68vhost-config relation section below for more information.68vhost-config relation section below for more information.
6969
70The vhost_template_vars config allows for further customisation of the vhost
71templates. For example, you can have a single template for a particular
72service, but use vhost_template_vars to customise it slightly for
73devel/staging/production environments.
74
70### Using the reverseproxy relation75### Using the reverseproxy relation
7176
72The charm will create the service variable, with the `unit_name`,77The charm will create the service variable, with the `unit_name`,
7378
=== modified file 'config.yaml'
--- config.yaml 2014-10-16 13:12:04 +0000
+++ config.yaml 2015-02-27 15:07:15 +0000
@@ -11,6 +11,10 @@
11 type: string11 type: string
12 default: ''12 default: ''
13 description: Apache vhost template (base64 encoded).13 description: Apache vhost template (base64 encoded).
14 vhost_template_vars:
15 type: string
16 default: ''
17 description: Additional custom variables for the vhost templating, in python dict format
14 enable_modules:18 enable_modules:
15 type: string19 type: string
16 default: ''20 default: ''
1721
=== modified file 'hooks/hooks.py'
--- hooks/hooks.py 2014-10-13 07:51:42 +0000
+++ hooks/hooks.py 2015-02-27 15:07:15 +0000
@@ -11,6 +11,7 @@
11import pwd11import pwd
12import shutil12import shutil
13import os.path13import os.path
14import ast
1415
15from charmhelpers.core.hookenv import (16from charmhelpers.core.hookenv import (
16 open_port,17 open_port,
@@ -528,6 +529,9 @@
528 from jinja2 import Template529 from jinja2 import Template
529 template = Template(str(base64.b64decode(template_str)))530 template = Template(str(base64.b64decode(template_str)))
530 template_data = dict(config_data.items() + relationship_data.items())531 template_data = dict(config_data.items() + relationship_data.items())
532 if config_data.get('vhost_template_vars'):
533 extra_vars = ast.literal_eval(config_data['vhost_template_vars'])
534 template_data.update(extra_vars)
531 vhost_name = '%s_%s' % (config_data['servername'], protocol)535 vhost_name = '%s_%s' % (config_data['servername'], protocol)
532 vhost_file = site_filename(vhost_name)536 vhost_file = site_filename(vhost_name)
533 log("Writing file %s with config and relation data" % vhost_file)537 log("Writing file %s with config and relation data" % vhost_file)
534538
=== modified file 'hooks/tests/test_create_vhost.py'
--- hooks/tests/test_create_vhost.py 2014-05-20 03:34:20 +0000
+++ hooks/tests/test_create_vhost.py 2015-02-27 15:07:15 +0000
@@ -104,3 +104,31 @@
104 with open(filename, 'r') as f:104 with open(filename, 'r') as f:
105 contents = f.read()105 contents = f.read()
106 self.assertEqual(contents, template)106 self.assertEqual(contents, template)
107
108 @patch('hooks.close_port')
109 @patch('hooks.site_filename')
110 @patch('hooks.open_port')
111 @patch('hooks.subprocess.call')
112 def test_create_vhost_template_config(
113 self, mock_call, mock_open_port, mock_site_filename,
114 mock_close_port):
115 """Template passed in as config setting."""
116 template = ("one\n"
117 "two\n"
118 "{{ extra }}")
119 expected = ("one\n"
120 "two\n"
121 "three")
122 config = {"servername": "unused",
123 "vhost_template_vars": "{'extra': 'three'}",
124 "vhost_template": base64.b64encode(template)}
125 file = tempfile.NamedTemporaryFile()
126 filename = file.name
127 mock_site_filename.return_value = filename
128 hooks.create_vhost(
129 "80",
130 config_key="vhost_template",
131 config_data=config)
132 with open(filename, 'r') as f:
133 contents = f.read()
134 self.assertEqual(contents, expected)

Subscribers

People subscribed via source and target branches

to all changes: