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
=== modified file 'charmhelpers/core/hookenv.py'
--- charmhelpers/core/hookenv.py 2013-05-31 10:27:31 +0000
+++ charmhelpers/core/hookenv.py 2013-06-14 13:12:13 +0000
@@ -206,7 +206,7 @@
206 for reltype in relation_types():206 for reltype in relation_types():
207 relids = {}207 relids = {}
208 for relid in relation_ids(reltype):208 for relid in relation_ids(reltype):
209 units = {}209 units = {local_unit(): relation_get(unit=local_unit(), rid=relid)}
210 for unit in related_units(relid):210 for unit in related_units(relid):
211 reldata = relation_get(unit=unit, rid=relid)211 reldata = relation_get(unit=unit, rid=relid)
212 units[unit] = reldata212 units[unit] = reldata
213213
=== modified file 'tests/core/test_hookenv.py'
--- tests/core/test_hookenv.py 2013-05-31 10:27:31 +0000
+++ tests/core/test_hookenv.py 2013-06-14 13:12:13 +0000
@@ -386,12 +386,14 @@
386 call(234),386 call(234),
387 ])387 ])
388388
389 @patch('charmhelpers.core.hookenv.local_unit')
389 @patch('charmhelpers.core.hookenv.relation_types')390 @patch('charmhelpers.core.hookenv.relation_types')
390 @patch('charmhelpers.core.hookenv.relation_ids')391 @patch('charmhelpers.core.hookenv.relation_ids')
391 @patch('charmhelpers.core.hookenv.related_units')392 @patch('charmhelpers.core.hookenv.related_units')
392 @patch('charmhelpers.core.hookenv.relation_get')393 @patch('charmhelpers.core.hookenv.relation_get')
393 def test_gets_relations(self, relation_get, related_units,394 def test_gets_relations(self, relation_get, related_units,
394 relation_ids, relation_types):395 relation_ids, relation_types, local_unit):
396 local_unit.return_value = 'u0'
395 relation_types.return_value = ['t1','t2']397 relation_types.return_value = ['t1','t2']
396 relation_ids.return_value = ['i1']398 relation_ids.return_value = ['i1']
397 related_units.return_value = ['u1','u2']399 related_units.return_value = ['u1','u2']
@@ -402,12 +404,14 @@
402 self.assertEqual(result, {404 self.assertEqual(result, {
403 't1': {405 't1': {
404 'i1': {406 'i1': {
407 'u0': {'key': 'val'},
405 'u1': {'key': 'val'},408 'u1': {'key': 'val'},
406 'u2': {'key': 'val'},409 'u2': {'key': 'val'},
407 },410 },
408 },411 },
409 't2': {412 't2': {
410 'i1': {413 'i1': {
414 'u0': {'key': 'val'},
411 'u1': {'key': 'val'},415 'u1': {'key': 'val'},
412 'u2': {'key': 'val'},416 'u2': {'key': 'val'},
413 },417 },

Subscribers

People subscribed via source and target branches