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

Proposed by Barry Price
Status: Merged
Approved by: Barry Price
Approved revision: 05ef8570911739c49f8dad51de1e871d590446b8
Merged at revision: 94997e25ea249a3138a0f2d1d8a208d6b596a646
Proposed branch: ~barryprice/charm-canonical-livepatch/+git/trusty-handlers:master
Merge into: ~livepatch-charmers/charm-canonical-livepatch:master
Diff against target: 74 lines (+16/-8)
1 file modified
reactive/canonical_livepatch.py (+16/-8)
Reviewer Review Type Date Requested Status
Stuart Bishop (community) Approve
Canonical IS Reviewers Pending
Review via email: mp+363795@code.launchpad.net

Commit message

Reinstate special handlers for Trusty (reverses commits 1b039b3 and a471703)

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 :

Looks good. Might want to look into layer:status for future work, per inline comments.

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

Change successfully merged at revision 94997e25ea249a3138a0f2d1d8a208d6b596a646

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/reactive/canonical_livepatch.py b/reactive/canonical_livepatch.py
2index 533e5a7..f9c1e6e 100644
3--- a/reactive/canonical_livepatch.py
4+++ b/reactive/canonical_livepatch.py
5@@ -4,6 +4,7 @@ from charms.reactive.flags import register_trigger
6 from charmhelpers.core.host import write_file, is_container
7 from charmhelpers.core import hookenv
8 from charmhelpers.contrib.charmsupport import nrpe
9+from distutils.version import LooseVersion
10 from os import environ, mkdir, path, uname
11 from subprocess import check_call, check_output, CalledProcessError
12 from time import sleep
13@@ -57,6 +58,9 @@ def get_livepatch_status():
14 livepatch_status = ''
15 try:
16 livepatch_status = check_output(cmd, universal_newlines=True)
17+ except FileNotFoundError:
18+ # If the snap's not installed yet, don't crash out
19+ pass
20 except CalledProcessError:
21 # If the service hasn't been enabled yet, we'll get a process error - this is fine
22 pass
23@@ -173,10 +177,7 @@ def livepatch_supported():
24 def install_livepatch():
25 config = hookenv.config()
26 snap_channel = config.get('snap_channel')
27- snap.install(
28- 'canonical-livepatch',
29- **{'channel': snap_channel, }
30- )
31+ snap.install('canonical-livepatch', **{'channel': snap_channel, })
32
33
34 @when('snap.installed.canonical-livepatch')
35@@ -209,10 +210,17 @@ def proxy_settings():
36 @when('livepatch-proxy.configured')
37 @when_not('canonical-livepatch.connected')
38 def canonical_livepatch_connect():
39+ # So if we've just installed snapd on a trusty system, we will not be on
40+ # the HWE kernel yet and unfortunately need to reboot first!
41+ current = LooseVersion(uname()[2])
42+ required = LooseVersion('4.4')
43 uptrack_path = '/usr/sbin/uptrack-upgrade'
44 if path.exists(uptrack_path):
45 hookenv.log('Ksplice/Uptrack detected, please remove it and reboot')
46 unit_update('blocked', 'Remove ksplice and then reboot')
47+ elif current < required:
48+ hookenv.log('Reboot required, kernel {} is too old'.format(current))
49+ unit_update('blocked', 'A reboot is required')
50 else:
51 unit_update('maintenance', 'Connecting to the livepatch service')
52 # Make sure the service is ready for us
53@@ -224,6 +232,9 @@ def canonical_livepatch_connect():
54 @when('canonical-livepatch.connected')
55 @when_not('config.changed.livepatch_key', 'canonical-livepatch.active')
56 def init_key():
57+ # If deployed under Trusty before rebooting into the HWE kernel
58+ # the config-changed hook won't fire post-reboot as the state
59+ # isn't tracked, but we didn't initialise yet! So, handle it here
60 activate_livepatch()
61
62
63@@ -239,10 +250,7 @@ def change_channel():
64 config = hookenv.config()
65 snap_channel = config.get('snap_channel')
66 # refresh to the given channel
67- snap.refresh(
68- 'canonical-livepatch',
69- **{'channel': snap_channel, }
70- )
71+ snap.refresh('canonical-livepatch', **{'channel': snap_channel, })
72
73
74 # Set up Nagios checks when the nrpe-external-master subordinate is related

Subscribers

People subscribed via source and target branches