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
1diff --git a/metadata.yaml b/metadata.yaml
2index c70bd26..36695fc 100644
3--- a/metadata.yaml
4+++ b/metadata.yaml
5@@ -1,7 +1,7 @@
6 name: canonical-livepatch
7 summary: Ubuntu Linux Livepatching Utility and Daemon
8 maintainer: Livepatch charm developers <livepatch-charmers@lists.launchpad.net>
9-series: ['xenial']
10+series: ['xenial', 'trusty']
11 description: |
12 This charms installs and configures the Ubuntu Linux Livepatching Utility and Daemon
13 tags:
14diff --git a/reactive/canonical_livepatch.py b/reactive/canonical_livepatch.py
15index 8333c6d..8bdb830 100644
16--- a/reactive/canonical_livepatch.py
17+++ b/reactive/canonical_livepatch.py
18@@ -7,6 +7,7 @@ from time import sleep
19 from os import path
20 from yaml import load, dump
21 from platform import release
22+from distutils.version import LooseVersion
23
24
25 def file_to_units(local_path, unit_path):
26@@ -138,9 +139,9 @@ def configure_proxies(http_proxy=None, https_proxy=None, no_proxy=None):
27 def restart_livepatch():
28 # do a clean stop of the service first, 'restart' seems fragile right now
29 cmd = [
30- '/usr/sbin/service',
31- 'snap.canonical-livepatch.canonical-livepatchd',
32- 'stop'
33+ '/bin/systemctl',
34+ 'stop',
35+ 'snap.canonical-livepatch.canonical-livepatchd.service',
36 ]
37 hookenv.log('Stopping canonical-livepatch service')
38 try:
39@@ -150,9 +151,9 @@ def restart_livepatch():
40
41 # and now try to start it again, it may fail the first time!
42 cmd = [
43- '/usr/sbin/service',
44- 'snap.canonical-livepatch.canonical-livepatchd',
45- 'start'
46+ '/bin/systemctl',
47+ 'start',
48+ 'snap.canonical-livepatch.canonical-livepatchd.service',
49 ]
50 hookenv.log('Starting canonical-livepatch service')
51 try:
52@@ -165,19 +166,7 @@ def restart_livepatch():
53 check_call(cmd, universal_newlines=True)
54
55
56-@when('snap.installed.canonical-livepatch')
57-@when_not('canonical-livepatch.connected')
58-def canonical_livepatch_connect():
59-
60- # Make sure the service is ready for us
61- wait_for_livepatch()
62-
63- set_state('canonical-livepatch.connected')
64-
65-
66-@when('canonical-livepatch.connected')
67-@when('config.changed.livepatch_key')
68-def update_key():
69+def activate_livepatch():
70 unit_update('maintenance', 'Updating API key')
71 config = hookenv.config()
72
73@@ -220,8 +209,45 @@ def update_key():
74 )
75
76
77+@when('snap.installed.canonical-livepatch')
78+@when_not('canonical-livepatch.connected')
79+def canonical_livepatch_connect():
80+ # So if we've just installed snapd on a trusty system, we will not be on
81+ # the HWE kernel yet and unfortunately need to reboot first!
82+ uname = check_output(['uname', '-r'],
83+ universal_newlines=True).strip()
84+ current = LooseVersion(uname)
85+ required = LooseVersion('4.4')
86+ if current < required:
87+ hookenv.log('We need to reboot, kernel {} is too old'.format(current))
88+ unit_update('blocked', 'A reboot is required')
89+ else:
90+ unit_update('maintenance', 'Connecting to the livepatch service')
91+ # Make sure the service is ready for us
92+ wait_for_livepatch()
93+ set_state('canonical-livepatch.connected')
94+ unit_update(
95+ 'blocked',
96+ 'Service disabled, please set livepatch_key to activate'
97+ )
98+
99+
100 @when('canonical-livepatch.connected')
101-@when('config.changed.livepatch_proxy')
102+@when_not('config.changed.livepatch_key', 'canonical-livepatch.active')
103+def init_key():
104+ # If deployed under Trusty before rebooting into the HWE kernel
105+ # the config-changed hook won't fire post-reboot as the state
106+ # isn't tracked, but we didn't initialise yet! So, handle it here
107+ activate_livepatch()
108+
109+
110+@when('canonical-livepatch.connected', 'config.changed.livepatch_key')
111+def update_key():
112+ # handle regular config-changed hooks for the livepatch key
113+ activate_livepatch()
114+
115+
116+@when('canonical-livepatch.connected', 'config.changed.livepatch_proxy')
117 def update_livepatch_proxy():
118 unit_update('maintenance', 'Configuring proxy servers')
119 config = hookenv.config()
120@@ -238,8 +264,7 @@ def update_livepatch_proxy():
121 update_key()
122
123
124-@when('snap.installed.canonical-livepatch')
125-@when('nrpe-external-master.available')
126+@when('snap.installed.canonical-livepatch', 'nrpe-external-master.available')
127 def configure_nagios(nagios):
128 if hookenv.hook_name() == 'update-status':
129 return
130@@ -282,7 +307,6 @@ def configure_nagios(nagios):
131 remove_state('canonical-livepatch.nagios-configured')
132
133
134-@when('snap.installed.canonical-livepatch')
135-@when('canonical-livepatch.active')
136+@when('snap.installed.canonical-livepatch', 'canonical-livepatch.active')
137 def update_kernel_version():
138 unit_update()
139diff --git a/tests/99-autogen b/tests/99-autogen
140index aa6f15f..7bc8f1e 100755
141--- a/tests/99-autogen
142+++ b/tests/99-autogen
143@@ -10,7 +10,7 @@ class TestDeployment(unittest.TestCase):
144 def setUpClass(cls):
145 cls.deployment = amulet.Deployment(series='xenial')
146
147- # deploy postgresql as our parent, it's a well-behaved xenial charm
148+ # deploy postgresql as our parent, it's a well-behaved charm
149 cls.deployment.add('postgresql')
150
151 # deploy our own charm

Subscribers

People subscribed via source and target branches