livepatch-charmers team mailing list archive
-
livepatch-charmers team
-
Mailing list archive
-
Message #00226
[Merge] ~barryprice/canonical-livepatch-charm/+git/canonical-livepatch-charm:master into canonical-livepatch-charm:master
Barry Price has proposed merging ~barryprice/canonical-livepatch-charm/+git/canonical-livepatch-charm:master into canonical-livepatch-charm:master.
Commit message:
Port Nagios check to python3
Requested reviews:
Livepatch charm developers (livepatch-charmers)
For more details, see:
https://code.launchpad.net/~barryprice/canonical-livepatch-charm/+git/canonical-livepatch-charm/+merge/355975
--
Your team Livepatch charm developers is requested to review the proposed merge of ~barryprice/canonical-livepatch-charm/+git/canonical-livepatch-charm:master into canonical-livepatch-charm:master.
diff --git a/files/check_canonical-livepatch.py b/files/check_canonical-livepatch.py
index a40936a..0d2a1a3 100755
--- a/files/check_canonical-livepatch.py
+++ b/files/check_canonical-livepatch.py
@@ -1,9 +1,9 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
# Copyright (C) 2016 Canonical Ltd.
import os
-import nagios_plugin
+import nagios_plugin3
from subprocess import check_output, call
from yaml import safe_load
@@ -16,7 +16,7 @@ def check_snap_installed():
try:
check_output(cmd, universal_newlines=True)
except Exception:
- raise nagios_plugin.CriticalError('canonical-livepatch snap is not installed')
+ raise nagios_plugin3.CriticalError('canonical-livepatch snap is not installed')
def load_status():
@@ -35,19 +35,19 @@ def check_serious_errors():
# if it's empty, something's definitely wrong
if livepatch_status == '':
- raise nagios_plugin.CriticalError('No output from canonical-livepatch status')
+ raise nagios_plugin3.CriticalError('No output from canonical-livepatch status')
# in some cases, it's obviously not valid YAML
try:
livepatch_yaml = safe_load(livepatch_status)
except Exception:
- raise nagios_plugin.CriticalError(livepatch_status.replace('\n', ' '))
+ raise nagios_plugin3.CriticalError(livepatch_status.replace('\n', ' '))
# in other cases, it's less obvious until we try to parse
try:
livepatch_yaml['status']
except TypeError:
- raise nagios_plugin.CriticalError(livepatch_status.replace('\n', ' '))
+ raise nagios_plugin3.CriticalError(livepatch_status.replace('\n', ' '))
def active_kernel_version():
@@ -80,7 +80,7 @@ def check_status():
errors.append(patch_state_error)
if errors:
- raise nagios_plugin.CriticalError(' '.join(errors))
+ raise nagios_plugin3.CriticalError(' '.join(errors))
def check_check_state(check_state):
@@ -142,15 +142,15 @@ def is_container():
def main():
arch = os.uname()[4]
if arch not in supported_archs:
- raise nagios_plugin.CriticalError(
+ raise nagios_plugin3.CriticalError(
"canonical-livepatch not supported on this architecture ({}).".format(arch)
)
elif is_container():
print("canonical-livepatch not needed in OS containers.")
else:
- nagios_plugin.try_check(check_snap_installed)
- nagios_plugin.try_check(check_serious_errors)
- nagios_plugin.try_check(check_status)
+ nagios_plugin3.try_check(check_snap_installed)
+ nagios_plugin3.try_check(check_serious_errors)
+ nagios_plugin3.try_check(check_status)
kernel_version = active_kernel_version()
print("OK - canonical-livepatch is active on kernel {}".format(kernel_version))
Follow ups