Merge lp:~mew/charm-helpers/private-ip into lp:charm-helpers

Proposed by Matthew Wedgwood
Status: Merged
Approved by: Haw Loeung
Approved revision: 14
Merged at revision: 19
Proposed branch: lp:~mew/charm-helpers/private-ip
Merge into: lp:charm-helpers
Diff against target: 31 lines (+10/-0)
2 files modified
charmhelpers/core/hookenv.py (+4/-0)
tests/core/test_hookenv.py (+6/-0)
To merge this branch: bzr merge lp:~mew/charm-helpers/private-ip
Reviewer Review Type Date Requested Status
Haw Loeung Approve
Matthew Wedgwood (community) Needs Fixing
Review via email: mp+166731@code.launchpad.net

Commit message

Provide an easy way to get the unit's IP

Description of the change

Provide an easy way to get the unit's IP

To post a comment you must log in.
Revision history for this message
Haw Loeung (hloeung) wrote :

Looks good to me, +1

review: Approve
Revision history for this message
Matthew Wedgwood (mew) wrote :

-1, try harder.

Should use the existing "unit_get" python function rather than calling out to "unit-get"

review: Needs Fixing
lp:~mew/charm-helpers/private-ip updated
15. By Matthew Wedgwood

Use existing unit_get function

Revision history for this message
Haw Loeung (hloeung) wrote :

Looks good, +1

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 08:31:56 +0000
3+++ charmhelpers/core/hookenv.py 2013-05-31 10:29:28 +0000
4@@ -234,6 +234,10 @@
5 return subprocess.check_output(_args).strip()
6
7
8+def unit_private_ip():
9+ return unit_get('private-address')
10+
11+
12 class UnregisteredHookError(Exception):
13 pass
14
15
16=== modified file 'tests/core/test_hookenv.py'
17--- tests/core/test_hookenv.py 2013-05-31 08:37:38 +0000
18+++ tests/core/test_hookenv.py 2013-05-31 10:29:28 +0000
19@@ -135,6 +135,12 @@
20
21 self.assertEqual(hookenv.local_unit(), 'foo')
22
23+ @patch('charmhelpers.core.hookenv.unit_get')
24+ def test_gets_unit_private_ip(self, _unitget):
25+ _unitget.return_value = 'foo'
26+ self.assertEqual("foo", hookenv.unit_private_ip())
27+ _unitget.assert_called_with('private-address')
28+
29 @patch('charmhelpers.core.hookenv.os')
30 def test_checks_that_is_running_in_relation_hook(self, os_):
31 os_.environ = {

Subscribers

People subscribed via source and target branches