livepatch-charmers team mailing list archive
-
livepatch-charmers team
-
Mailing list archive
-
Message #00020
[Merge] ~hloeung/canonical-livepatch-charm/+git/master:master into canonical-livepatch-charm:master
Haw Loeung has proposed merging ~hloeung/canonical-livepatch-charm/+git/master:master into canonical-livepatch-charm:master.
Requested reviews:
Livepatch charm developers (livepatch-charmers)
For more details, see:
https://code.launchpad.net/~hloeung/canonical-livepatch-charm/+git/master/+merge/326295
This updates the Canonical Livepatch charm to better handle when installed on architectures where it isn't currently supported (currently only i386 and x86_64). Depends on Snap layer changes in MP:326293 [1].
[1]https://code.launchpad.net/~hloeung/layer-snap/+git/master/+merge/326293
--
Your team Livepatch charm developers is requested to review the proposed merge of ~hloeung/canonical-livepatch-charm/+git/master:master into canonical-livepatch-charm:master.
diff --git a/files/check_canonical-livepatch.py b/files/check_canonical-livepatch.py
index 74c61e5..d8564cf 100644
--- a/files/check_canonical-livepatch.py
+++ b/files/check_canonical-livepatch.py
@@ -3,9 +3,12 @@
# Copyright (C) 2016 Canonical Ltd.
import os
+import sys
import nagios_plugin
from subprocess import check_output
+supported_archs = ['i386', 'x86_64']
+
##############################################################################
@@ -14,9 +17,8 @@ def check_package_installed():
try:
check_output(cmd, universal_newlines=True)
except:
- raise nagios_plugin.CriticalError(
- "canonical-livepatch snap is not installed"
- )
+ print("canonical-livepatch snap is not installed")
+ sys.exit(2)
##############################################################################
@@ -63,15 +65,20 @@ def check_status():
if err_lines:
err = " ".join(err_lines)
- raise nagios_plugin.CriticalError(err)
+ print(err)
+ sys.exit(2)
elif wrn_lines:
wrn = " ".join(wrn_lines)
- raise nagios_plugin.WarnError(wrn)
+ print(wrn)
+ sys.exit(1)
##############################################################################
def main():
+ if os.uname()[4] not in supported_archs:
+ print("canonical-livepatch not supported on this architecture.")
+ sys.exit(1)
nagios_plugin.try_check(check_package_installed)
nagios_plugin.try_check(check_status)
print("OK - canonical-livepatch seems to be installed and working")
diff --git a/layer.yaml b/layer.yaml
index 59a22ed..c2933f2 100644
--- a/layer.yaml
+++ b/layer.yaml
@@ -13,4 +13,5 @@ options:
snap:
canonical-livepatch:
channel: stable
+ supported-architectures: ['i386', 'x86_64']
repo: lp:~livepatch-charmers/canonical-livepatch-charm/+git/canonical-livepatch-charm
diff --git a/reactive/canonical_livepatch.py b/reactive/canonical_livepatch.py
index c2fb420..31caaeb 100644
--- a/reactive/canonical_livepatch.py
+++ b/reactive/canonical_livepatch.py
@@ -4,11 +4,13 @@ from charmhelpers.core import hookenv
from charmhelpers.contrib.charmsupport import nrpe
from subprocess import check_call, check_output, CalledProcessError
from time import sleep
-from os import path
+from os import path, uname
from yaml import load, dump
from platform import release
from distutils.version import LooseVersion
+supported_archs = ['i386', 'x86_64']
+
def file_to_units(local_path, unit_path):
""" copy a file from the charm onto our unit(s) """
@@ -209,14 +211,20 @@ def activate_livepatch():
)
+@when_not('snap.installed.canonical-livepatch')
+def livepatch_supported():
+ arch = uname()[4]
+ if arch not in supported_archs:
+ hookenv.log('Livepatch does not currently support this architecture: {}'.format(arch))
+ unit_update('blocked', 'Unsupported architecture: {}'.format(arch))
+
+
@when('snap.installed.canonical-livepatch')
@when_not('canonical-livepatch.connected')
def canonical_livepatch_connect():
# So if we've just installed snapd on a trusty system, we will not be on
# the HWE kernel yet and unfortunately need to reboot first!
- uname = check_output(['uname', '-r'],
- universal_newlines=True).strip()
- current = LooseVersion(uname)
+ current = LooseVersion(uname()[2])
required = LooseVersion('4.4')
uptrack_path = '/usr/sbin/uptrack-upgrade'
if path.exists(uptrack_path):
@@ -268,7 +276,7 @@ def update_livepatch_proxy():
update_key()
-@when('snap.installed.canonical-livepatch', 'nrpe-external-master.available')
+@when('nrpe-external-master.available')
def configure_nagios(nagios):
if hookenv.hook_name() == 'update-status':
return
@@ -295,7 +303,7 @@ def configure_nagios(nagios):
# remove check from previous release with poorly formed name
nrpe_setup.remove_check(
- shortname='check_canonical-livepatch'
+ shortname='check_canonical-livepatch'
)
# use charmhelpers to create the check
Follow ups