Merge lp:~johnsca/charm-helpers/hyphen-relations into lp:charm-helpers

Proposed by Cory Johns
Status: Merged
Merged at revision: 497
Proposed branch: lp:~johnsca/charm-helpers/hyphen-relations
Merge into: lp:charm-helpers
Diff against target: 35 lines (+4/-3)
2 files modified
charmhelpers/core/services/helpers.py (+2/-1)
tests/core/test_services.py (+2/-2)
To merge this branch: bzr merge lp:~johnsca/charm-helpers/hyphen-relations
Reviewer Review Type Date Requested Status
Stuart Bishop (community) Approve
Review via email: mp+259836@code.launchpad.net

Description of the change

Quick Services Framework fix to allow templates to access data for relations that have a hyphen in their name. (Having them at the top level means they can't be accessed directly, so they're now nested under a ctx object. The top-level is also maintained for backwards compatibility.)

To post a comment you must log in.
Revision history for this message
MichaƂ Sawicz (saviq) wrote :

Does the job :)

Docs could use an update?

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

Shawn and landed.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charmhelpers/core/services/helpers.py'
2--- charmhelpers/core/services/helpers.py 2015-03-19 15:00:13 +0000
3+++ charmhelpers/core/services/helpers.py 2015-05-21 19:23:17 +0000
4@@ -256,9 +256,10 @@
5
6 def __call__(self, manager, service_name, event_name):
7 service = manager.get_service(service_name)
8- context = {}
9+ context = {'ctx': {}}
10 for ctx in service.get('required_data', []):
11 context.update(ctx)
12+ context['ctx'].update(ctx)
13 templating.render(self.source, self.target, context,
14 self.owner, self.group, self.perms)
15
16
17=== modified file 'tests/core/test_services.py'
18--- tests/core/test_services.py 2015-05-20 14:31:33 +0000
19+++ tests/core/test_services.py 2015-05-21 19:23:17 +0000
20@@ -728,7 +728,7 @@
21 assert not mtemplating.render.called
22 callback(manager, 'test', 'event')
23 mtemplating.render.assert_called_once_with(
24- 'foo.yml', 'bar.yml', {'foo': 'bar'},
25+ 'foo.yml', 'bar.yml', {'foo': 'bar', 'ctx': {'foo': 'bar'}},
26 'root', 'root', 0o444)
27
28 @mock.patch.object(services.helpers, 'templating')
29@@ -743,7 +743,7 @@
30 assert not mtemplating.render.called
31 callback(manager, 'test', 'event')
32 mtemplating.render.assert_called_once_with(
33- 'foo.yml', 'bar.yml', {'foo': 'bar'},
34+ 'foo.yml', 'bar.yml', {'foo': 'bar', 'ctx': {'foo': 'bar'}},
35 'user', 'group', 0o555)
36
37

Subscribers

People subscribed via source and target branches