Merge lp:~gnuoy/charm-helpers/add-peer_ips into lp:charm-helpers

Proposed by Liam Young
Status: Merged
Merged at revision: 184
Proposed branch: lp:~gnuoy/charm-helpers/add-peer_ips
Merge into: lp:charm-helpers
Diff against target: 44 lines (+23/-0)
2 files modified
charmhelpers/contrib/hahelpers/cluster.py (+9/-0)
tests/contrib/hahelpers/test_cluster_utils.py (+14/-0)
To merge this branch: bzr merge lp:~gnuoy/charm-helpers/add-peer_ips
Reviewer Review Type Date Requested Status
James Page Approve
Review via email: mp+228640@code.launchpad.net
To post a comment you must log in.
Revision history for this message
James Page (james-page) :
review: Needs Fixing
lp:~gnuoy/charm-helpers/add-peer_ips updated
185. By Liam Young

relation_list and relation_ids both return [] if none a represent so don't to guard against none. Allow the address key to be overridden

186. By Liam Young

Remove surplus round brackets

Revision history for this message
James Page (james-page) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charmhelpers/contrib/hahelpers/cluster.py'
2--- charmhelpers/contrib/hahelpers/cluster.py 2014-07-23 08:25:09 +0000
3+++ charmhelpers/contrib/hahelpers/cluster.py 2014-07-29 11:12:10 +0000
4@@ -62,6 +62,15 @@
5 return peers
6
7
8+def peer_ips(peer_relation='cluster', addr_key='private-address'):
9+ '''Return a dict of peers and their private-address'''
10+ peers = {}
11+ for r_id in relation_ids(peer_relation):
12+ for unit in relation_list(r_id):
13+ peers[unit] = relation_get(addr_key, rid=r_id, unit=unit)
14+ return peers
15+
16+
17 def oldest_peer(peers):
18 local_unit_no = int(os.getenv('JUJU_UNIT_NAME').split('/')[1])
19 for peer in peers:
20
21=== modified file 'tests/contrib/hahelpers/test_cluster_utils.py'
22--- tests/contrib/hahelpers/test_cluster_utils.py 2014-07-23 08:25:09 +0000
23+++ tests/contrib/hahelpers/test_cluster_utils.py 2014-07-29 11:12:10 +0000
24@@ -69,6 +69,20 @@
25 self.relation_list.return_value = peers
26 self.assertEquals(peers, cluster_utils.peer_units())
27
28+ def test_peer_ips(self):
29+ '''Get a dict of peers and their ips'''
30+ peers = {
31+ 'peer_node/1': '10.0.0.1',
32+ 'peer_node/2': '10.0.0.2',
33+ }
34+
35+ def _relation_get(attr, rid, unit):
36+ return peers[unit]
37+ self.relation_ids.return_value = ['cluster:0']
38+ self.relation_list.return_value = peers.keys()
39+ self.relation_get.side_effect = _relation_get
40+ self.assertEquals(peers, cluster_utils.peer_ips())
41+
42 @patch('os.getenv')
43 def test_is_oldest_peer(self, getenv):
44 '''It detects local unit is the oldest of all peers'''

Subscribers

People subscribed via source and target branches