Merge ~shaner/charm-thruk-agent:master into ~nagios-charmers/charm-thruk-agent:master

Proposed by Shane Peters
Status: Merged
Approved by: Stuart Bishop
Approved revision: c0153b9f114cc2b44145c5a85396e3e3b39663eb
Merged at revision: 9447b49a0ba39bfd59fd9125ab5421eab71b9f90
Proposed branch: ~shaner/charm-thruk-agent:master
Merge into: ~nagios-charmers/charm-thruk-agent:master
Diff against target: 81 lines (+24/-2)
4 files modified
hooks/actions.py (+4/-0)
hooks/services.py (+5/-1)
hooks/thruk_helpers.py (+14/-1)
hooks/update-status (+1/-0)
Reviewer Review Type Date Requested Status
Stuart Bishop (community) Approve
Canonical IS Reviewers Pending
Review via email: mp+361690@code.launchpad.net

Commit message

enable status updates

To post a comment you must log in.
Revision history for this message
Shane Peters (shaner) wrote :

While this works fine, I haven't worked with ServiceManager before so there might be a better approach. Give it a test and let me know!

Revision history for this message
Shane Peters (shaner) wrote :
Revision history for this message
Shane Peters (shaner) wrote :
Revision history for this message
Alvaro Uria (aluria) wrote :

Added Canonical IS Reviewers per internal discussion.

Revision history for this message
Stuart Bishop (stub) wrote :

This charm needs to be reworked into charms.reactive, but that is beyond the scope of this MP. From my recollection of ServiceManager, this is the cleanest way to wait for the socket.

This all looks good. Per inline comment, I suspect you should be using 'waiting' instead of 'blocked' when the socket is not available. 'waiting' is when the charm is expected to resolve itself. 'blocked' means an action needs to be performed by somebody before things will resolve.

Confirm and/or change the pending status, and good for landing.

review: Approve
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
Stuart Bishop (stub) wrote :

@Shane - let us know here when you are happy, and someone in Canonical IS can land this for you and republish the charm.

Revision history for this message
Shane Peters (shaner) wrote :

Hi Stuart, Thanks for the review. I was a bit torn between which one to use (waiting|blocked) but decided to go with blocked as would likely require the operator to enable the livestatus socket option in the nagios charm.

I'm comfortable with the existing code as it is. Certainly would agree it needs to be reworked into an reactive charm, time permitting.

Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision 9447b49a0ba39bfd59fd9125ab5421eab71b9f90

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/hooks/actions.py b/hooks/actions.py
2index d75affd..a72e9a6 100644
3--- a/hooks/actions.py
4+++ b/hooks/actions.py
5@@ -98,3 +98,7 @@ def update_ppa(service_name):
6 apt_update(fatal=True)
7 package_list = ["thruk", "pwgen", "apache2-utils"]
8 apt_install(packages=package_list, fatal=True)
9+
10+
11+def update_status(service_name):
12+ hookenv.status_set('active', 'ready')
13diff --git a/hooks/services.py b/hooks/services.py
14index 36b9a17..b21febe 100644
15--- a/hooks/services.py
16+++ b/hooks/services.py
17@@ -16,7 +16,10 @@ def manage():
18 'provided_data': [
19 thruk_helpers.ThrukAgentRelation()
20 ],
21- 'required_data': [thruk_helpers.ThrukInfo()],
22+ 'required_data': [
23+ thruk_helpers.ThrukInfo(),
24+ thruk_helpers.CheckLivestatusSocket(),
25+ ],
26 'data_ready': [
27 helpers.render_template(
28 source='thruk_local.conf',
29@@ -26,6 +29,7 @@ def manage():
30 actions.fix_livestatus_perms,
31 actions.thruk_set_password,
32 actions.notify_thrukmaster_relation,
33+ actions.update_status,
34 ],
35 },
36 {
37diff --git a/hooks/thruk_helpers.py b/hooks/thruk_helpers.py
38index df208e5..70619ce 100644
39--- a/hooks/thruk_helpers.py
40+++ b/hooks/thruk_helpers.py
41@@ -3,6 +3,8 @@
42 from charmhelpers.core import hookenv
43 from charmhelpers.core.services import helpers
44
45+import os
46+import sys
47 import hashlib
48
49
50@@ -45,6 +47,18 @@ class ThrukInfo(dict):
51 self['thruk_id'] = m.hexdigest()
52
53
54+class CheckLivestatusSocket(dict):
55+ def __bool__(self):
56+ if not os.path.exists(hookenv.config('livestatus_path')):
57+ hookenv.status_set('blocked',
58+ 'nagios livestatus socket missing')
59+ return False
60+ return True
61+
62+ def __nonzero__(self):
63+ return self.__bool__()
64+
65+
66 class NEMRelation(helpers.RelationContext):
67 name = 'nrpe-external-master'
68 interface = 'nrpe-external-master'
69@@ -58,4 +72,3 @@ class NEMRelation(helpers.RelationContext):
70 if not hookenv.relation_ids(self.name):
71 return
72 self['nrpe_external_master'] = self[self.name]
73-
74diff --git a/hooks/update-status b/hooks/update-status
75new file mode 120000
76index 0000000..9416ca6
77--- /dev/null
78+++ b/hooks/update-status
79@@ -0,0 +1 @@
80+hooks.py
81\ No newline at end of file

Subscribers

People subscribed via source and target branches