Merge ~barryprice/charm-canonical-livepatch/+git/canonical-livepatch-charm:master into ~livepatch-charmers/charm-canonical-livepatch:master

Proposed by Barry Price
Status: Merged
Approved by: Barry Price
Approved revision: 4e9598e06d7e034548efdc078f57826d4273ec42
Merged at revision: d26a5d4d3281e777bce1fdcdcde5c503d1bc7312
Proposed branch: ~barryprice/charm-canonical-livepatch/+git/canonical-livepatch-charm:master
Merge into: ~livepatch-charmers/charm-canonical-livepatch:master
Diff against target: 76 lines (+11/-11)
1 file modified
files/check_canonical-livepatch.py (+11/-11)
Reviewer Review Type Date Requested Status
Stuart Bishop (community) Approve
Review via email: mp+355975@code.launchpad.net

Commit message

Port Nagios check to python3

To post a comment you must log in.
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 :

Yup

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

Change successfully merged at revision d26a5d4d3281e777bce1fdcdcde5c503d1bc7312

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/files/check_canonical-livepatch.py b/files/check_canonical-livepatch.py
2index a40936a..0d2a1a3 100755
3--- a/files/check_canonical-livepatch.py
4+++ b/files/check_canonical-livepatch.py
5@@ -1,9 +1,9 @@
6-#!/usr/bin/env python
7+#!/usr/bin/env python3
8
9 # Copyright (C) 2016 Canonical Ltd.
10
11 import os
12-import nagios_plugin
13+import nagios_plugin3
14 from subprocess import check_output, call
15 from yaml import safe_load
16
17@@ -16,7 +16,7 @@ def check_snap_installed():
18 try:
19 check_output(cmd, universal_newlines=True)
20 except Exception:
21- raise nagios_plugin.CriticalError('canonical-livepatch snap is not installed')
22+ raise nagios_plugin3.CriticalError('canonical-livepatch snap is not installed')
23
24
25 def load_status():
26@@ -35,19 +35,19 @@ def check_serious_errors():
27
28 # if it's empty, something's definitely wrong
29 if livepatch_status == '':
30- raise nagios_plugin.CriticalError('No output from canonical-livepatch status')
31+ raise nagios_plugin3.CriticalError('No output from canonical-livepatch status')
32
33 # in some cases, it's obviously not valid YAML
34 try:
35 livepatch_yaml = safe_load(livepatch_status)
36 except Exception:
37- raise nagios_plugin.CriticalError(livepatch_status.replace('\n', ' '))
38+ raise nagios_plugin3.CriticalError(livepatch_status.replace('\n', ' '))
39
40 # in other cases, it's less obvious until we try to parse
41 try:
42 livepatch_yaml['status']
43 except TypeError:
44- raise nagios_plugin.CriticalError(livepatch_status.replace('\n', ' '))
45+ raise nagios_plugin3.CriticalError(livepatch_status.replace('\n', ' '))
46
47
48 def active_kernel_version():
49@@ -80,7 +80,7 @@ def check_status():
50 errors.append(patch_state_error)
51
52 if errors:
53- raise nagios_plugin.CriticalError(' '.join(errors))
54+ raise nagios_plugin3.CriticalError(' '.join(errors))
55
56
57 def check_check_state(check_state):
58@@ -142,15 +142,15 @@ def is_container():
59 def main():
60 arch = os.uname()[4]
61 if arch not in supported_archs:
62- raise nagios_plugin.CriticalError(
63+ raise nagios_plugin3.CriticalError(
64 "canonical-livepatch not supported on this architecture ({}).".format(arch)
65 )
66 elif is_container():
67 print("canonical-livepatch not needed in OS containers.")
68 else:
69- nagios_plugin.try_check(check_snap_installed)
70- nagios_plugin.try_check(check_serious_errors)
71- nagios_plugin.try_check(check_status)
72+ nagios_plugin3.try_check(check_snap_installed)
73+ nagios_plugin3.try_check(check_serious_errors)
74+ nagios_plugin3.try_check(check_status)
75 kernel_version = active_kernel_version()
76 print("OK - canonical-livepatch is active on kernel {}".format(kernel_version))
77

Subscribers

People subscribed via source and target branches