livepatch-charmers team mailing list archive
-
livepatch-charmers team
-
Mailing list archive
-
Message #00012
[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:
First pass at Trusty (14.04) support - not fully tested yet
Requested reviews:
Stuart Bishop (stub)
For more details, see:
https://code.launchpad.net/~barryprice/canonical-livepatch-charm/+git/canonical-livepatch-charm/+merge/324996
--
Your team Livepatch charm developers is subscribed to branch canonical-livepatch-charm:master.
diff --git a/metadata.yaml b/metadata.yaml
index c70bd26..36695fc 100644
--- a/metadata.yaml
+++ b/metadata.yaml
@@ -1,7 +1,7 @@
name: canonical-livepatch
summary: Ubuntu Linux Livepatching Utility and Daemon
maintainer: Livepatch charm developers <livepatch-charmers@xxxxxxxxxxxxxxxxxxx>
-series: ['xenial']
+series: ['xenial', 'trusty']
description: |
This charms installs and configures the Ubuntu Linux Livepatching Utility and Daemon
tags:
diff --git a/reactive/canonical_livepatch.py b/reactive/canonical_livepatch.py
index 8333c6d..8bdb830 100644
--- a/reactive/canonical_livepatch.py
+++ b/reactive/canonical_livepatch.py
@@ -7,6 +7,7 @@ from time import sleep
from os import path
from yaml import load, dump
from platform import release
+from distutils.version import LooseVersion
def file_to_units(local_path, unit_path):
@@ -138,9 +139,9 @@ def configure_proxies(http_proxy=None, https_proxy=None, no_proxy=None):
def restart_livepatch():
# do a clean stop of the service first, 'restart' seems fragile right now
cmd = [
- '/usr/sbin/service',
- 'snap.canonical-livepatch.canonical-livepatchd',
- 'stop'
+ '/bin/systemctl',
+ 'stop',
+ 'snap.canonical-livepatch.canonical-livepatchd.service',
]
hookenv.log('Stopping canonical-livepatch service')
try:
@@ -150,9 +151,9 @@ def restart_livepatch():
# and now try to start it again, it may fail the first time!
cmd = [
- '/usr/sbin/service',
- 'snap.canonical-livepatch.canonical-livepatchd',
- 'start'
+ '/bin/systemctl',
+ 'start',
+ 'snap.canonical-livepatch.canonical-livepatchd.service',
]
hookenv.log('Starting canonical-livepatch service')
try:
@@ -165,19 +166,7 @@ def restart_livepatch():
check_call(cmd, universal_newlines=True)
-@when('snap.installed.canonical-livepatch')
-@when_not('canonical-livepatch.connected')
-def canonical_livepatch_connect():
-
- # Make sure the service is ready for us
- wait_for_livepatch()
-
- set_state('canonical-livepatch.connected')
-
-
-@when('canonical-livepatch.connected')
-@when('config.changed.livepatch_key')
-def update_key():
+def activate_livepatch():
unit_update('maintenance', 'Updating API key')
config = hookenv.config()
@@ -220,8 +209,45 @@ def update_key():
)
+@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)
+ required = LooseVersion('4.4')
+ if current < required:
+ hookenv.log('We need to reboot, kernel {} is too old'.format(current))
+ unit_update('blocked', 'A reboot is required')
+ else:
+ unit_update('maintenance', 'Connecting to the livepatch service')
+ # Make sure the service is ready for us
+ wait_for_livepatch()
+ set_state('canonical-livepatch.connected')
+ unit_update(
+ 'blocked',
+ 'Service disabled, please set livepatch_key to activate'
+ )
+
+
@when('canonical-livepatch.connected')
-@when('config.changed.livepatch_proxy')
+@when_not('config.changed.livepatch_key', 'canonical-livepatch.active')
+def init_key():
+ # If deployed under Trusty before rebooting into the HWE kernel
+ # the config-changed hook won't fire post-reboot as the state
+ # isn't tracked, but we didn't initialise yet! So, handle it here
+ activate_livepatch()
+
+
+@when('canonical-livepatch.connected', 'config.changed.livepatch_key')
+def update_key():
+ # handle regular config-changed hooks for the livepatch key
+ activate_livepatch()
+
+
+@when('canonical-livepatch.connected', 'config.changed.livepatch_proxy')
def update_livepatch_proxy():
unit_update('maintenance', 'Configuring proxy servers')
config = hookenv.config()
@@ -238,8 +264,7 @@ def update_livepatch_proxy():
update_key()
-@when('snap.installed.canonical-livepatch')
-@when('nrpe-external-master.available')
+@when('snap.installed.canonical-livepatch', 'nrpe-external-master.available')
def configure_nagios(nagios):
if hookenv.hook_name() == 'update-status':
return
@@ -282,7 +307,6 @@ def configure_nagios(nagios):
remove_state('canonical-livepatch.nagios-configured')
-@when('snap.installed.canonical-livepatch')
-@when('canonical-livepatch.active')
+@when('snap.installed.canonical-livepatch', 'canonical-livepatch.active')
def update_kernel_version():
unit_update()
diff --git a/tests/99-autogen b/tests/99-autogen
index aa6f15f..7bc8f1e 100755
--- a/tests/99-autogen
+++ b/tests/99-autogen
@@ -10,7 +10,7 @@ class TestDeployment(unittest.TestCase):
def setUpClass(cls):
cls.deployment = amulet.Deployment(series='xenial')
- # deploy postgresql as our parent, it's a well-behaved xenial charm
+ # deploy postgresql as our parent, it's a well-behaved charm
cls.deployment.add('postgresql')
# deploy our own charm
Follow ups