livepatch-charmers team mailing list archive
-
livepatch-charmers team
-
Mailing list archive
-
Message #00028
[Merge] ~hloeung/canonical-livepatch-charm:master into canonical-livepatch-charm:master
Haw Loeung has proposed merging ~hloeung/canonical-livepatch-charm: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/canonical-livepatch-charm/+merge/326295
This updates the Canonical Livepatch charm to better handle when installed on architectures where it isn't currently supported (currently only 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:master into canonical-livepatch-charm:master.
diff --git a/files/check_canonical-livepatch.py b/files/check_canonical-livepatch.py
index 74c61e5..facc904 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 = ['x86_64']
+
##############################################################################
@@ -13,10 +16,9 @@ def check_package_installed():
cmd = ['snap', 'list', 'canonical-livepatch']
try:
check_output(cmd, universal_newlines=True)
- except:
- raise nagios_plugin.CriticalError(
- "canonical-livepatch snap is not installed"
- )
+ except Exception:
+ 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..6c38c40 100644
--- a/layer.yaml
+++ b/layer.yaml
@@ -13,4 +13,5 @@ options:
snap:
canonical-livepatch:
channel: stable
+ supported-architectures: ['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..053099f 100644
--- a/reactive/canonical_livepatch.py
+++ b/reactive/canonical_livepatch.py
@@ -1,10 +1,11 @@
+from charms import layer
from charms.reactive import when, when_not, set_state, remove_state
from charmhelpers.core.host import write_file
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
@@ -209,14 +210,22 @@ def activate_livepatch():
)
+@when_not('snap.installed.canonical-livepatch')
+def livepatch_supported():
+ arch = uname()[4]
+ opts = layer.options('snap')
+ supported_archs = opts['canonical-livepatch'].pop('supported-architectures', None)
+ if supported_archs and arch not in supported_archs:
+ hookenv.log('Livepatch does not currently support this architecture: {}'.format(arch))
+ unit_update('blocked', 'Architecture {} is not supported by livepatch'.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 +277,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 +304,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