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

Proposed by Barry Price
Status: Merged
Approved by: Haw Loeung
Approved revision: 5f813f4764a5cdb862c3066285579dfd11fa4c93
Merged at revision: 7d1fda5047a8c5452e257fcd243f5f9fe74b869e
Proposed branch: ~barryprice/charm-canonical-livepatch/+git/canonical-livepatch-charm:master
Merge into: ~livepatch-charmers/charm-canonical-livepatch:master
Diff against target: 151 lines (+50/-26)
3 files modified
metadata.yaml (+1/-1)
reactive/canonical_livepatch.py (+48/-24)
tests/99-autogen (+1/-1)
Reviewer Review Type Date Requested Status
Haw Loeung Approve
Stuart Bishop (community) Approve
Review via email: mp+324996@code.launchpad.net

Commit message

First pass at Trusty (14.04) support - amulet tests pass under both Xenial (the preferred default) and Trusty.

To post a comment you must log in.
Revision history for this message
Stuart Bishop (stub) wrote :

Looks good!

review: Approve
Revision history for this message
Haw Loeung (hloeung) :
Revision history for this message
Haw Loeung (hloeung) wrote :

LGTM too, +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/metadata.yaml b/metadata.yaml
index c70bd26..36695fc 100644
--- a/metadata.yaml
+++ b/metadata.yaml
@@ -1,7 +1,7 @@
1name: canonical-livepatch1name: canonical-livepatch
2summary: Ubuntu Linux Livepatching Utility and Daemon2summary: Ubuntu Linux Livepatching Utility and Daemon
3maintainer: Livepatch charm developers <livepatch-charmers@lists.launchpad.net>3maintainer: Livepatch charm developers <livepatch-charmers@lists.launchpad.net>
4series: ['xenial']4series: ['xenial', 'trusty']
5description: |5description: |
6 This charms installs and configures the Ubuntu Linux Livepatching Utility and Daemon6 This charms installs and configures the Ubuntu Linux Livepatching Utility and Daemon
7tags:7tags:
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
7from os import path7from os import path
8from yaml import load, dump8from yaml import load, dump
9from platform import release9from platform import release
10from distutils.version import LooseVersion
1011
1112
12def file_to_units(local_path, unit_path):13def file_to_units(local_path, unit_path):
@@ -138,9 +139,9 @@ def configure_proxies(http_proxy=None, https_proxy=None, no_proxy=None):
138def restart_livepatch():139def restart_livepatch():
139 # do a clean stop of the service first, 'restart' seems fragile right now140 # do a clean stop of the service first, 'restart' seems fragile right now
140 cmd = [141 cmd = [
141 '/usr/sbin/service',142 '/bin/systemctl',
142 'snap.canonical-livepatch.canonical-livepatchd',143 'stop',
143 'stop'144 'snap.canonical-livepatch.canonical-livepatchd.service',
144 ]145 ]
145 hookenv.log('Stopping canonical-livepatch service')146 hookenv.log('Stopping canonical-livepatch service')
146 try:147 try:
@@ -150,9 +151,9 @@ def restart_livepatch():
150151
151 # and now try to start it again, it may fail the first time!152 # and now try to start it again, it may fail the first time!
152 cmd = [153 cmd = [
153 '/usr/sbin/service',154 '/bin/systemctl',
154 'snap.canonical-livepatch.canonical-livepatchd',155 'start',
155 'start'156 'snap.canonical-livepatch.canonical-livepatchd.service',
156 ]157 ]
157 hookenv.log('Starting canonical-livepatch service')158 hookenv.log('Starting canonical-livepatch service')
158 try:159 try:
@@ -165,19 +166,7 @@ def restart_livepatch():
165 check_call(cmd, universal_newlines=True)166 check_call(cmd, universal_newlines=True)
166167
167168
168@when('snap.installed.canonical-livepatch')169def activate_livepatch():
169@when_not('canonical-livepatch.connected')
170def canonical_livepatch_connect():
171
172 # Make sure the service is ready for us
173 wait_for_livepatch()
174
175 set_state('canonical-livepatch.connected')
176
177
178@when('canonical-livepatch.connected')
179@when('config.changed.livepatch_key')
180def update_key():
181 unit_update('maintenance', 'Updating API key')170 unit_update('maintenance', 'Updating API key')
182 config = hookenv.config()171 config = hookenv.config()
183172
@@ -220,8 +209,45 @@ def update_key():
220 )209 )
221210
222211
212@when('snap.installed.canonical-livepatch')
213@when_not('canonical-livepatch.connected')
214def canonical_livepatch_connect():
215 # So if we've just installed snapd on a trusty system, we will not be on
216 # the HWE kernel yet and unfortunately need to reboot first!
217 uname = check_output(['uname', '-r'],
218 universal_newlines=True).strip()
219 current = LooseVersion(uname)
220 required = LooseVersion('4.4')
221 if current < required:
222 hookenv.log('We need to reboot, kernel {} is too old'.format(current))
223 unit_update('blocked', 'A reboot is required')
224 else:
225 unit_update('maintenance', 'Connecting to the livepatch service')
226 # Make sure the service is ready for us
227 wait_for_livepatch()
228 set_state('canonical-livepatch.connected')
229 unit_update(
230 'blocked',
231 'Service disabled, please set livepatch_key to activate'
232 )
233
234
223@when('canonical-livepatch.connected')235@when('canonical-livepatch.connected')
224@when('config.changed.livepatch_proxy')236@when_not('config.changed.livepatch_key', 'canonical-livepatch.active')
237def init_key():
238 # If deployed under Trusty before rebooting into the HWE kernel
239 # the config-changed hook won't fire post-reboot as the state
240 # isn't tracked, but we didn't initialise yet! So, handle it here
241 activate_livepatch()
242
243
244@when('canonical-livepatch.connected', 'config.changed.livepatch_key')
245def update_key():
246 # handle regular config-changed hooks for the livepatch key
247 activate_livepatch()
248
249
250@when('canonical-livepatch.connected', 'config.changed.livepatch_proxy')
225def update_livepatch_proxy():251def update_livepatch_proxy():
226 unit_update('maintenance', 'Configuring proxy servers')252 unit_update('maintenance', 'Configuring proxy servers')
227 config = hookenv.config()253 config = hookenv.config()
@@ -238,8 +264,7 @@ def update_livepatch_proxy():
238 update_key()264 update_key()
239265
240266
241@when('snap.installed.canonical-livepatch')267@when('snap.installed.canonical-livepatch', 'nrpe-external-master.available')
242@when('nrpe-external-master.available')
243def configure_nagios(nagios):268def configure_nagios(nagios):
244 if hookenv.hook_name() == 'update-status':269 if hookenv.hook_name() == 'update-status':
245 return270 return
@@ -282,7 +307,6 @@ def configure_nagios(nagios):
282 remove_state('canonical-livepatch.nagios-configured')307 remove_state('canonical-livepatch.nagios-configured')
283308
284309
285@when('snap.installed.canonical-livepatch')310@when('snap.installed.canonical-livepatch', 'canonical-livepatch.active')
286@when('canonical-livepatch.active')
287def update_kernel_version():311def update_kernel_version():
288 unit_update()312 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):
10 def setUpClass(cls):10 def setUpClass(cls):
11 cls.deployment = amulet.Deployment(series='xenial')11 cls.deployment = amulet.Deployment(series='xenial')
1212
13 # deploy postgresql as our parent, it's a well-behaved xenial charm13 # deploy postgresql as our parent, it's a well-behaved charm
14 cls.deployment.add('postgresql')14 cls.deployment.add('postgresql')
1515
16 # deploy our own charm16 # deploy our own charm

Subscribers

People subscribed via source and target branches