Merge lp:~lazypower/charm-helpers/payload-tracking into lp:charm-helpers

Proposed by Charles Butler
Status: Merged
Merged at revision: 501
Proposed branch: lp:~lazypower/charm-helpers/payload-tracking
Merge into: lp:charm-helpers
Diff against target: 73 lines (+52/-0)
2 files modified
charmhelpers/core/hookenv.py (+34/-0)
tests/core/test_hookenv.py (+18/-0)
To merge this branch: bzr merge lp:~lazypower/charm-helpers/payload-tracking
Reviewer Review Type Date Requested Status
Matt Bruzek Approve
Review via email: mp+279927@code.launchpad.net

Description of the change

Adds the payload tracking commands to charmhelpers.core.hookenv

adds:
 - payload_register
 - payload_unregister
 - payload_status_set

To post a comment you must log in.
Revision history for this message
Matt Bruzek (mbruzek) wrote :

+1 LGTM

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 2015-11-23 08:58:18 +0000
3+++ charmhelpers/core/hookenv.py 2015-12-08 17:50:38 +0000
4@@ -878,6 +878,40 @@
5 subprocess.check_call(cmd)
6
7
8+@translate_exc(from_exc=OSError, to_exc=NotImplementedError)
9+def payload_register(ptype, klass, pid):
10+ """ is used while a hook is running to let Juju know that a
11+ payload has been started."""
12+ cmd = ['payload-register']
13+ for x in [ptype, klass, pid]:
14+ cmd.append(x)
15+ subprocess.check_call(cmd)
16+
17+
18+@translate_exc(from_exc=OSError, to_exc=NotImplementedError)
19+def payload_unregister(klass, pid):
20+ """ is used while a hook is running to let Juju know
21+ that a payload has been manually stopped. The <class> and <id> provided
22+ must match a payload that has been previously registered with juju using
23+ payload-register."""
24+ cmd = ['payload-unregister']
25+ for x in [klass, pid]:
26+ cmd.append(x)
27+ subprocess.check_call(cmd)
28+
29+
30+@translate_exc(from_exc=OSError, to_exc=NotImplementedError)
31+def payload_status_set(klass, pid, status):
32+ """is used to update the current status of a registered payload.
33+ The <class> and <id> provided must match a payload that has been previously
34+ registered with juju using payload-register. The <status> must be one of the
35+ follow: starting, started, stopping, stopped"""
36+ cmd = ['payload-status-set']
37+ for x in [klass, pid, status]:
38+ cmd.append(x)
39+ subprocess.check_call(cmd)
40+
41+
42 @cached
43 def juju_version():
44 """Full version string (eg. '1.23.3.1-trusty-amd64')"""
45
46=== modified file 'tests/core/test_hookenv.py'
47--- tests/core/test_hookenv.py 2015-10-26 10:22:43 +0000
48+++ tests/core/test_hookenv.py 2015-12-08 17:50:38 +0000
49@@ -1171,6 +1171,24 @@
50 check_output_.return_value = b'true'
51 self.assertTrue(hookenv.is_leader())
52
53+ @patch('subprocess.check_call')
54+ def test_payload_register(self, check_call_):
55+ hookenv.payload_register('monitoring', 'docker', 'abc123')
56+ check_call_.assert_called_with(['payload-register', 'monitoring',
57+ 'docker', 'abc123'])
58+
59+ @patch('subprocess.check_call')
60+ def test_payload_unregister(self, check_call_):
61+ hookenv.payload_unregister('monitoring', 'abc123')
62+ check_call_.assert_called_with(['payload-unregister', 'monitoring',
63+ 'abc123'])
64+
65+ @patch('subprocess.check_call')
66+ def test_payload_status_set(self, check_call_):
67+ hookenv.payload_status_set('monitoring', 'abc123', 'Running')
68+ check_call_.assert_called_with(['payload-status-set', 'monitoring',
69+ 'abc123', 'Running'])
70+
71
72 class HooksTest(TestCase):
73 def setUp(self):

Subscribers

People subscribed via source and target branches