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
diff --git a/reactive/canonical_livepatch.py b/reactive/canonical_livepatch.py
index 533e5a7..f9c1e6e 100644
--- a/reactive/canonical_livepatch.py
+++ b/reactive/canonical_livepatch.py
@@ -4,6 +4,7 @@ from charms.reactive.flags import register_trigger
4from charmhelpers.core.host import write_file, is_container4from charmhelpers.core.host import write_file, is_container
5from charmhelpers.core import hookenv5from charmhelpers.core import hookenv
6from charmhelpers.contrib.charmsupport import nrpe6from charmhelpers.contrib.charmsupport import nrpe
7from distutils.version import LooseVersion
7from os import environ, mkdir, path, uname8from os import environ, mkdir, path, uname
8from subprocess import check_call, check_output, CalledProcessError9from subprocess import check_call, check_output, CalledProcessError
9from time import sleep10from time import sleep
@@ -57,6 +58,9 @@ def get_livepatch_status():
57 livepatch_status = ''58 livepatch_status = ''
58 try:59 try:
59 livepatch_status = check_output(cmd, universal_newlines=True)60 livepatch_status = check_output(cmd, universal_newlines=True)
61 except FileNotFoundError:
62 # If the snap's not installed yet, don't crash out
63 pass
60 except CalledProcessError:64 except CalledProcessError:
61 # If the service hasn't been enabled yet, we'll get a process error - this is fine65 # If the service hasn't been enabled yet, we'll get a process error - this is fine
62 pass66 pass
@@ -173,10 +177,7 @@ def livepatch_supported():
173def install_livepatch():177def install_livepatch():
174 config = hookenv.config()178 config = hookenv.config()
175 snap_channel = config.get('snap_channel')179 snap_channel = config.get('snap_channel')
176 snap.install(180 snap.install('canonical-livepatch', **{'channel': snap_channel, })
177 'canonical-livepatch',
178 **{'channel': snap_channel, }
179 )
180181
181182
182@when('snap.installed.canonical-livepatch')183@when('snap.installed.canonical-livepatch')
@@ -209,10 +210,17 @@ def proxy_settings():
209@when('livepatch-proxy.configured')210@when('livepatch-proxy.configured')
210@when_not('canonical-livepatch.connected')211@when_not('canonical-livepatch.connected')
211def canonical_livepatch_connect():212def canonical_livepatch_connect():
213 # So if we've just installed snapd on a trusty system, we will not be on
214 # the HWE kernel yet and unfortunately need to reboot first!
215 current = LooseVersion(uname()[2])
216 required = LooseVersion('4.4')
212 uptrack_path = '/usr/sbin/uptrack-upgrade'217 uptrack_path = '/usr/sbin/uptrack-upgrade'
213 if path.exists(uptrack_path):218 if path.exists(uptrack_path):
214 hookenv.log('Ksplice/Uptrack detected, please remove it and reboot')219 hookenv.log('Ksplice/Uptrack detected, please remove it and reboot')
215 unit_update('blocked', 'Remove ksplice and then reboot')220 unit_update('blocked', 'Remove ksplice and then reboot')
221 elif current < required:
222 hookenv.log('Reboot required, kernel {} is too old'.format(current))
223 unit_update('blocked', 'A reboot is required')
216 else:224 else:
217 unit_update('maintenance', 'Connecting to the livepatch service')225 unit_update('maintenance', 'Connecting to the livepatch service')
218 # Make sure the service is ready for us226 # Make sure the service is ready for us
@@ -224,6 +232,9 @@ def canonical_livepatch_connect():
224@when('canonical-livepatch.connected')232@when('canonical-livepatch.connected')
225@when_not('config.changed.livepatch_key', 'canonical-livepatch.active')233@when_not('config.changed.livepatch_key', 'canonical-livepatch.active')
226def init_key():234def init_key():
235 # If deployed under Trusty before rebooting into the HWE kernel
236 # the config-changed hook won't fire post-reboot as the state
237 # isn't tracked, but we didn't initialise yet! So, handle it here
227 activate_livepatch()238 activate_livepatch()
228239
229240
@@ -239,10 +250,7 @@ def change_channel():
239 config = hookenv.config()250 config = hookenv.config()
240 snap_channel = config.get('snap_channel')251 snap_channel = config.get('snap_channel')
241 # refresh to the given channel252 # refresh to the given channel
242 snap.refresh(253 snap.refresh('canonical-livepatch', **{'channel': snap_channel, })
243 'canonical-livepatch',
244 **{'channel': snap_channel, }
245 )
246254
247255
248# Set up Nagios checks when the nrpe-external-master subordinate is related256# Set up Nagios checks when the nrpe-external-master subordinate is related

Subscribers

People subscribed via source and target branches