Merge lp:~stub/charm-helpers/bug-1191002-local-unit-relation-data into lp:charm-helpers

Proposed by Stuart Bishop
Status: Merged
Merged at revision: 27
Proposed branch: lp:~stub/charm-helpers/bug-1191002-local-unit-relation-data
Merge into: lp:charm-helpers
Diff against target: 47 lines (+6/-2)
2 files modified
charmhelpers/core/hookenv.py (+1/-1)
tests/core/test_hookenv.py (+5/-1)
To merge this branch: bzr merge lp:~stub/charm-helpers/bug-1191002-local-unit-relation-data
Reviewer Review Type Date Requested Status
James Page Approve
Review via email: mp+169414@code.launchpad.net

Description of the change

Make hookenv.relations() return local relation information in addition to information stored by remote units.

To post a comment you must log in.
Revision history for this message
James Page (james-page) wrote :

OK - I think this works just fine - approved.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charmhelpers/core/hookenv.py'
2--- charmhelpers/core/hookenv.py 2013-05-31 10:27:31 +0000
3+++ charmhelpers/core/hookenv.py 2013-06-14 13:12:13 +0000
4@@ -206,7 +206,7 @@
5 for reltype in relation_types():
6 relids = {}
7 for relid in relation_ids(reltype):
8- units = {}
9+ units = {local_unit(): relation_get(unit=local_unit(), rid=relid)}
10 for unit in related_units(relid):
11 reldata = relation_get(unit=unit, rid=relid)
12 units[unit] = reldata
13
14=== modified file 'tests/core/test_hookenv.py'
15--- tests/core/test_hookenv.py 2013-05-31 10:27:31 +0000
16+++ tests/core/test_hookenv.py 2013-06-14 13:12:13 +0000
17@@ -386,12 +386,14 @@
18 call(234),
19 ])
20
21+ @patch('charmhelpers.core.hookenv.local_unit')
22 @patch('charmhelpers.core.hookenv.relation_types')
23 @patch('charmhelpers.core.hookenv.relation_ids')
24 @patch('charmhelpers.core.hookenv.related_units')
25 @patch('charmhelpers.core.hookenv.relation_get')
26 def test_gets_relations(self, relation_get, related_units,
27- relation_ids, relation_types):
28+ relation_ids, relation_types, local_unit):
29+ local_unit.return_value = 'u0'
30 relation_types.return_value = ['t1','t2']
31 relation_ids.return_value = ['i1']
32 related_units.return_value = ['u1','u2']
33@@ -402,12 +404,14 @@
34 self.assertEqual(result, {
35 't1': {
36 'i1': {
37+ 'u0': {'key': 'val'},
38 'u1': {'key': 'val'},
39 'u2': {'key': 'val'},
40 },
41 },
42 't2': {
43 'i1': {
44+ 'u0': {'key': 'val'},
45 'u1': {'key': 'val'},
46 'u2': {'key': 'val'},
47 },

Subscribers

People subscribed via source and target branches