Merge lp:~paulgear/charms/trusty/ntp/fix-trusty-exceptions-psutil-1.2.x into lp:charms/trusty/ntp

Proposed by Paul Gear
Status: Merged
Merged at revision: 21
Proposed branch: lp:~paulgear/charms/trusty/ntp/fix-trusty-exceptions-psutil-1.2.x
Merge into: lp:charms/trusty/ntp
Diff against target: 33 lines (+6/-3)
1 file modified
files/nagios/check_ntpmon.py (+6/-3)
To merge this branch: bzr merge lp:~paulgear/charms/trusty/ntp/fix-trusty-exceptions-psutil-1.2.x
Reviewer Review Type Date Requested Status
Tim Van Steenburgh (community) Approve
Adam Israel (community) Approve
Review via email: mp+260080@code.launchpad.net

Description of the change

Trusty has python-psutils 1.2.x; check_ntpmon.py was written against 2.1.x. This allows the code to work with both versions of psutils.

To post a comment you must log in.
Revision history for this message
Adam Israel (aisrael) wrote :

Hi Paul,

Thanks for your work on this! I had the opportunity to review this merge proposal today. This is a pretty straightforward modification, and I'm happy to see this issue fixed. You have my +1.

Thanks again!

review: Approve
Revision history for this message
Adam Collard (adam-collard) :
22. By Paul Gear

Change name of check variable to more accurately reflect purpose

Revision history for this message
Tim Van Steenburgh (tvansteenburgh) wrote :

+1 LGTM, thanks Paul!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'files/nagios/check_ntpmon.py'
2--- files/nagios/check_ntpmon.py 2015-04-27 13:24:11 +0000
3+++ files/nagios/check_ntpmon.py 2015-05-30 22:50:13 +0000
4@@ -422,10 +422,13 @@
5 """Look for ntpd or xntpd in the process table and save its process object."""
6 if names is None:
7 names = ["ntpd", "xntpd"]
8+ # Check for old psutil per http://grodola.blogspot.com.au/2014/01/psutil-20-porting.html
9+ self.PSUTIL2 = psutil.version_info >= (2, 0)
10 self.proc = None
11 for proc in psutil.process_iter():
12 try:
13- if proc.name() in names:
14+ name = proc.name() if self.PSUTIL2 else proc.name
15+ if name in names:
16 self.proc = proc
17 break
18 except psutil.Error:
19@@ -438,7 +441,8 @@
20 return -1
21 try:
22 now = time.time()
23- start = int(self.proc.create_time())
24+ create_time = self.proc.create_time() if self.PSUTIL2 else self.proc.create_time
25+ start = int(create_time)
26 return now - start
27 except psutil.Error:
28 return -1
29@@ -541,4 +545,3 @@
30
31 if __name__ == "__main__":
32 main()
33-

Subscribers

People subscribed via source and target branches

to all changes: