Merge lp:~james-page/charm-helpers/fix_canonical_url into lp:charm-helpers

Proposed by James Page
Status: Merged
Approved by: Adam Gandelman
Approved revision: 62
Merged at revision: 64
Proposed branch: lp:~james-page/charm-helpers/fix_canonical_url
Merge into: lp:charm-helpers
Diff against target: 57 lines (+6/-4)
2 files modified
charmhelpers/contrib/hahelpers/cluster.py (+2/-1)
tests/contrib/hahelpers/test_cluster_utils.py (+4/-3)
To merge this branch: bzr merge lp:~james-page/charm-helpers/fix_canonical_url
Reviewer Review Type Date Requested Status
Charm Helper Maintainers Pending
Review via email: mp+176359@code.launchpad.net

Description of the change

Fixup canonical_url to use unit private-address when generating canonical urls for unclustered services.

The local unit hostname is not always resolvable - private-address should be!

To post a comment you must log in.

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 2013-07-12 08:18:11 +0000
3+++ charmhelpers/contrib/hahelpers/cluster.py 2013-07-23 11:52:24 +0000
4@@ -19,6 +19,7 @@
5 config as config_get,
6 INFO,
7 ERROR,
8+ unit_get,
9 )
10
11
12@@ -176,5 +177,5 @@
13 if is_clustered():
14 addr = config_get(vip_setting)
15 else:
16- addr = get_unit_hostname()
17+ addr = unit_get('private-address')
18 return '%s://%s' % (scheme, addr)
19
20=== modified file 'tests/contrib/hahelpers/test_cluster_utils.py'
21--- tests/contrib/hahelpers/test_cluster_utils.py 2013-07-12 08:18:11 +0000
22+++ tests/contrib/hahelpers/test_cluster_utils.py 2013-07-23 11:52:24 +0000
23@@ -17,6 +17,7 @@
24 'relation_get',
25 'get_unit_hostname',
26 'config_get',
27+ 'unit_get',
28 ]]
29
30 def _patch(self, method):
31@@ -233,7 +234,7 @@
32 @patch.object(cluster_utils, 'is_clustered')
33 def test_canonical_url_bare(self, is_clustered):
34 '''It constructs a URL to host with no https or cluster present'''
35- self.get_unit_hostname.return_value = 'foohost1'
36+ self.unit_get.return_value = 'foohost1'
37 is_clustered.return_value = False
38 configs = MagicMock()
39 configs.complete_contexts = MagicMock()
40@@ -244,7 +245,7 @@
41 @patch.object(cluster_utils, 'is_clustered')
42 def test_canonical_url_https_no_cluster(self, is_clustered):
43 '''It constructs a URL to host with https and no cluster present'''
44- self.get_unit_hostname.return_value = 'foohost1'
45+ self.unit_get.return_value = 'foohost1'
46 is_clustered.return_value = False
47 configs = MagicMock()
48 configs.complete_contexts = MagicMock()
49@@ -267,7 +268,7 @@
50 def test_canonical_url_cluster_no_https(self, is_clustered):
51 '''It constructs a URL to host with no https and cluster present'''
52 self.config_get.return_value = '10.0.0.1'
53- self.get_unit_hostname.return_value = 'foohost1'
54+ self.unit_get.return_value = 'foohost1'
55 is_clustered.return_value = True
56 configs = MagicMock()
57 configs.complete_contexts = MagicMock()

Subscribers

People subscribed via source and target branches