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

Proposed by Barry Price
Status: Merged
Merged at revision: db28bb9e14e9af53c98ab41669bf2703f21ea488
Proposed branch: ~barryprice/charm-canonical-livepatch/+git/canonical-livepatch-charm:master
Merge into: ~livepatch-charmers/charm-canonical-livepatch:master
Diff against target: 228 lines (+26/-89)
3 files modified
Makefile (+4/-0)
actions/actions.py (+1/-5)
reactive/canonical_livepatch.py (+21/-84)
Reviewer Review Type Date Requested Status
Stuart Bishop (community) Approve
Review via email: mp+332337@code.launchpad.net

Commit message

Reformat to 120 character lines

To post a comment you must log in.
Revision history for this message
Tom Haddon (mthaddon) wrote :

This looks fine, but I think it'd be worth encoding the 120 character line limit with a "make lint"

Revision history for this message
Stuart Bishop (stub) wrote :

:-P

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/Makefile b/Makefile
2new file mode 100644
3index 0000000..07b57c9
4--- /dev/null
5+++ b/Makefile
6@@ -0,0 +1,4 @@
7+#!/usr/bin/make
8+
9+lint:
10+ @flake8 --max-line-length=120
11diff --git a/actions/actions.py b/actions/actions.py
12index e9bb530..d618758 100755
13--- a/actions/actions.py
14+++ b/actions/actions.py
15@@ -19,11 +19,7 @@ def activate():
16 except CalledProcessError as e:
17 hookenv.log('Unable to deactivate: {}'.format(str(e)))
18 # but let's soldier on...
19- cmd = [
20- '/snap/bin/canonical-livepatch',
21- 'enable',
22- '{}'.format(livepatch_key.strip())
23- ]
24+ cmd = ['/snap/bin/canonical-livepatch', 'enable', '{}'.format(livepatch_key.strip())]
25 try:
26 check_output(cmd, universal_newlines=True)
27 except CalledProcessError as e:
28diff --git a/reactive/canonical_livepatch.py b/reactive/canonical_livepatch.py
29index 8b39eab..e176c45 100644
30--- a/reactive/canonical_livepatch.py
31+++ b/reactive/canonical_livepatch.py
32@@ -27,32 +27,21 @@ def file_to_units(local_path, unit_path):
33
34
35 def wait_for_path(file_path, timeout=30):
36- hookenv.log('Waiting for up to {}s for {}'.format(
37- timeout,
38- file_path)
39- )
40+ hookenv.log('Waiting for up to {}s for {}'.format(timeout, file_path))
41 seconds_waited = 0
42 interval = 1
43 while not (path.exists(file_path)):
44- hookenv.log('{} does not exist - waiting {}s'.format(
45- file_path,
46- interval)
47- )
48+ hookenv.log('{} does not exist - waiting {}s'.format(file_path, interval))
49 sleep(interval)
50 seconds_waited += interval
51 if seconds_waited >= timeout:
52- hookenv.log(
53- 'Giving up waiting for {}'.format(file_path),
54- hookenv.ERROR
55- )
56+ hookenv.log('Giving up waiting for {}'.format(file_path), hookenv.ERROR)
57 return
58 return
59
60
61 def wait_for_livepatch():
62- wait_for_path(
63- '/var/snap/canonical-livepatch/current/livepatchd-priv.sock'
64- )
65+ wait_for_path('/var/snap/canonical-livepatch/current/livepatchd-priv.sock')
66
67
68 def unit_update(status=None, message=None):
69@@ -60,10 +49,7 @@ def unit_update(status=None, message=None):
70 hookenv.status_set(status, message)
71 else:
72 patch_details = get_patch_details()
73- hookenv.status_set(
74- 'active',
75- 'Running kernel {}, patchState: {}'.format(*patch_details)
76- )
77+ hookenv.status_set('active', 'Running kernel {}, patchState: {}'.format(*patch_details))
78
79
80 def get_patch_details():
81@@ -90,10 +76,7 @@ def get_patch_details():
82 kernel = k['kernel']
83 patch_state = k['livepatch']['patchState']
84 except Exception:
85- hookenv.log(
86- 'Unable to find patching details in status yaml',
87- hookenv.ERROR
88- )
89+ hookenv.log('Unable to find patching details in status yaml', hookenv.ERROR)
90 return kernel, patch_state
91
92 return kernel, patch_state
93@@ -105,10 +88,7 @@ def get_yaml_if_exists(path_to_yaml):
94 try:
95 conf_yaml = load(stream)
96 except Exception:
97- hookenv.log(
98- 'Unable to load YAML from {}'.format(path_to_yaml),
99- hookenv.ERROR
100- )
101+ hookenv.log('Unable to load YAML from {}'.format(path_to_yaml), hookenv.ERROR)
102 else:
103 conf_yaml = {}
104
105@@ -149,11 +129,7 @@ def configure_proxies(http_proxy=None, https_proxy=None, no_proxy=None):
106
107 def restart_livepatch():
108 # do a clean stop of the service first, 'restart' seems fragile right now
109- cmd = [
110- '/bin/systemctl',
111- 'stop',
112- 'snap.canonical-livepatch.canonical-livepatchd.service',
113- ]
114+ cmd = ['/bin/systemctl', 'stop', 'snap.canonical-livepatch.canonical-livepatchd.service']
115 hookenv.log('Stopping canonical-livepatch service')
116 try:
117 check_call(cmd, universal_newlines=True)
118@@ -161,19 +137,12 @@ def restart_livepatch():
119 hookenv.log('Failed to stop the service', hookenv.ERROR)
120
121 # and now try to start it again, it may fail the first time!
122- cmd = [
123- '/bin/systemctl',
124- 'start',
125- 'snap.canonical-livepatch.canonical-livepatchd.service',
126- ]
127+ cmd = ['/bin/systemctl', 'start', 'snap.canonical-livepatch.canonical-livepatchd.service']
128 hookenv.log('Starting canonical-livepatch service')
129 try:
130 check_call(cmd, universal_newlines=True)
131 except CalledProcessError:
132- hookenv.log(
133- 'Failed to start the service - waiting 5s and then trying again',
134- hookenv.ERROR
135- )
136+ hookenv.log('Failed to start the service - waiting 5s and then trying again', hookenv.ERROR)
137 sleep(5)
138 check_call(cmd, universal_newlines=True)
139
140@@ -186,66 +155,37 @@ def activate_livepatch():
141 if livepatch_key:
142 # disable prior to enabling to work around LP#1628823
143 cmd = ['/snap/bin/canonical-livepatch', 'disable']
144- hookenv.log(
145- 'Disabling canonical-livepatch ahead of key change '
146- 'to work around LP#1628823'
147- )
148+ hookenv.log('Disabling canonical-livepatch ahead of key change to work around LP#1628823')
149 try:
150 check_output(cmd, universal_newlines=True)
151 except CalledProcessError as e:
152- hookenv.log(
153- 'Unable to deactivate: {}'.format(str(e)),
154- hookenv.ERROR
155- )
156-
157- cmd = [
158- '/snap/bin/canonical-livepatch',
159- 'enable',
160- '{}'.format(livepatch_key.strip())
161- ]
162+ hookenv.log('Unable to deactivate: {}'.format(str(e)), hookenv.ERROR)
163+
164+ cmd = ['/snap/bin/canonical-livepatch', 'enable', '{}'.format(livepatch_key.strip())]
165 hookenv.log('Activating canonical-livepatch with your key')
166 try:
167 check_output(cmd, universal_newlines=True)
168 except CalledProcessError as e:
169- hookenv.log(
170- 'Unable to activate: {}'.format(str(e)),
171- hookenv.ERROR
172- )
173+ hookenv.log('Unable to activate: {}'.format(str(e)), hookenv.ERROR)
174 remove_state('canonical-livepatch.active')
175 unit_update('blocked', 'Activation failed')
176 else:
177 set_state('canonical-livepatch.active')
178 unit_update()
179 else:
180- hookenv.log(
181- 'Unable to activate canonical-livepatch as no key has been set',
182- hookenv.ERROR
183- )
184+ hookenv.log('Unable to activate canonical-livepatch as no key has been set', hookenv.ERROR)
185 remove_state('canonical-livepatch.active')
186- unit_update(
187- 'blocked',
188- 'Service disabled, please set livepatch_key to activate'
189- )
190+ unit_update('blocked', 'Service disabled, please set livepatch_key to activate')
191
192
193 @when_not('snap.installed.canonical-livepatch')
194 def livepatch_supported():
195 arch = uname()[4]
196 opts = layer.options('snap')
197- supported_archs = opts['canonical-livepatch'].pop(
198- 'supported-architectures',
199- None
200- )
201+ supported_archs = opts['canonical-livepatch'].pop('supported-architectures', None)
202 if supported_archs and arch not in supported_archs:
203- hookenv.log(
204- 'Livepatch does not currently support {} architecture'.format(
205- arch
206- )
207- )
208- unit_update(
209- 'blocked',
210- 'Architecture {} is not supported by livepatch'.format(arch)
211- )
212+ hookenv.log('Livepatch does not currently support {} architecture'.format(arch))
213+ unit_update('blocked', 'Architecture {} is not supported by livepatch'.format(arch))
214 if is_container():
215 hookenv.log('OS container detected, livepatch is not needed')
216 unit_update('blocked', 'Livepatch is not needed in OS containers')
217@@ -270,10 +210,7 @@ def canonical_livepatch_connect():
218 # Make sure the service is ready for us
219 wait_for_livepatch()
220 set_state('canonical-livepatch.connected')
221- unit_update(
222- 'blocked',
223- 'Service disabled, please set livepatch_key to activate'
224- )
225+ unit_update('blocked', 'Service disabled, please set livepatch_key to activate')
226
227
228 @when('canonical-livepatch.connected')

Subscribers

People subscribed via source and target branches