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: Barry Price
Approved revision: 114d235902f67f84696b95a7a4aa1dd3586391e0
Merged at revision: 6189420d461cdcbe9a144e322a96800c4159d503
Proposed branch: ~barryprice/charm-canonical-livepatch/+git/canonical-livepatch-charm:master
Merge into: ~livepatch-charmers/charm-canonical-livepatch:master
Diff against target: 144 lines (+29/-17)
5 files modified
actions.yaml (+2/-0)
actions/actions.py (+15/-3)
actions/refresh (+1/-0)
files/check_canonical-livepatch.py (+6/-4)
tests/99-autogen (+5/-10)
Reviewer Review Type Date Requested Status
Stuart Bishop (community) Approve
Review via email: mp+355063@code.launchpad.net

Commit message

Improve NRPE error reporting, use YAML module for snap channel parsing, add a refresh action

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. Some potentially spurious whitespace, commented on inline.

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

Change successfully merged at revision 6189420d461cdcbe9a144e322a96800c4159d503

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/actions.yaml b/actions.yaml
2index 52655b6..29037fd 100644
3--- a/actions.yaml
4+++ b/actions.yaml
5@@ -2,3 +2,5 @@ activate:
6 description: Activate the Livepatch service.
7 deactivate:
8 description: Deactivate the Livepatch service.
9+refresh:
10+ description: Refresh the Livepatch service.
11diff --git a/actions/actions.py b/actions/actions.py
12index d618758..6c956cd 100755
13--- a/actions/actions.py
14+++ b/actions/actions.py
15@@ -1,4 +1,4 @@
16-#!/usr/bin/python3
17+#!/usr/local/sbin/charm-env python3
18
19 import os.path
20 import sys
21@@ -7,7 +7,7 @@ from subprocess import check_output, CalledProcessError
22 from charmhelpers.core import hookenv
23
24
25-def activate():
26+def activate(params):
27 config = hookenv.config()
28 livepatch_key = config.get('livepatch_key')
29
30@@ -32,7 +32,7 @@ def activate():
31 hookenv.action_fail('Unable to activate as no key has been set')
32
33
34-def deactivate():
35+def deactivate(params):
36 cmd = ['/snap/bin/canonical-livepatch', 'disable']
37 try:
38 check_output(cmd, universal_newlines=True)
39@@ -42,6 +42,16 @@ def deactivate():
40 hookenv.action_set(dict(result='Deactivated'))
41
42
43+def refresh(params):
44+ cmd = ['/snap/bin/canonical-livepatch', 'refresh']
45+ try:
46+ check_output(cmd, universal_newlines=True)
47+ except CalledProcessError as e:
48+ hookenv.action_fail('Unable to refresh: {}'.format(str(e)))
49+ return
50+ hookenv.action_set(dict(result='Refreshed'))
51+
52+
53 def main(argv):
54 action = os.path.basename(argv[0])
55 params = hookenv.action_get()
56@@ -50,6 +60,8 @@ def main(argv):
57 activate(params)
58 elif action == 'deactivate':
59 deactivate(params)
60+ elif action == 'refresh':
61+ refresh(params)
62 else:
63 hookenv.action_fail('Action {} not implemented'.format(action))
64 except Exception:
65diff --git a/actions/refresh b/actions/refresh
66new file mode 120000
67index 0000000..405a394
68--- /dev/null
69+++ b/actions/refresh
70@@ -0,0 +1 @@
71+actions.py
72\ No newline at end of file
73diff --git a/files/check_canonical-livepatch.py b/files/check_canonical-livepatch.py
74index 3a13062..e4eaa91 100755
75--- a/files/check_canonical-livepatch.py
76+++ b/files/check_canonical-livepatch.py
77@@ -53,13 +53,15 @@ def check_status():
78 line = line.strip()
79 if 'State:' in line:
80 if 'apply-failed' in line:
81- err_lines.append('Patch failed')
82+ err_lines.append('Livepatch failed to apply patches. ')
83 elif 'check-failed' in line:
84- err_lines.append('Check failed')
85+ err_lines.append('Livepatch failed to check the remote service for patches. ')
86 elif 'unknown' in line:
87- err_lines.append('Unknown error')
88+ err_lines.append('Livepatch reports an unknown error. ')
89+ elif 'kernel-upgrade-required' in line:
90+ err_lines.append('A kernel upgrade (and reboot) is required. ')
91 elif 'Machine is not enabled' in line:
92- err_lines.append('Machine is not enabled')
93+ err_lines.append('Machine is not enabled. ')
94
95 if err_lines:
96 err = " ".join(err_lines)
97diff --git a/tests/99-autogen b/tests/99-autogen
98index f4b0af9..d7bed72 100755
99--- a/tests/99-autogen
100+++ b/tests/99-autogen
101@@ -3,6 +3,7 @@
102 import amulet
103 import unittest
104 from time import sleep
105+from yaml import safe_load
106
107
108 class TestDeployment(unittest.TestCase):
109@@ -97,7 +98,6 @@ class TestDeployment(unittest.TestCase):
110 '.cfg'.format(test_context_name))
111 self.assertEqual(exit_code, 0)
112
113-
114 def test_channel_change(self):
115 livepatch = self.deployment.sentry['canonical-livepatch'][0]
116
117@@ -106,10 +106,8 @@ class TestDeployment(unittest.TestCase):
118 self.assertEqual(exit_code, 0)
119
120 # confirm we're tracking 'stable'
121- channel = ''
122- for line in output.split('\n'):
123- if line.startswith('tracking:'):
124- channel = line.strip().split(' ')[-1]
125+ output_yaml = safe_load(output)
126+ channel = output_yaml['tracking']
127 self.assertEqual(channel, 'stable')
128
129 # change channel to 'beta'
130@@ -125,13 +123,10 @@ class TestDeployment(unittest.TestCase):
131 self.assertEqual(exit_code, 0)
132
133 # confirm we're tracking 'beta'
134- channel = ''
135- for line in output.split('\n'):
136- if line.startswith('tracking:'):
137- channel = line.strip().split(' ')[-1]
138+ output_yaml = safe_load(output)
139+ channel = output_yaml['tracking']
140 self.assertEqual(channel, 'beta')
141
142-
143 def test_nagios_servicegroup_change(self):
144 livepatch = self.deployment.sentry['canonical-livepatch'][0]
145

Subscribers

People subscribed via source and target branches