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
diff --git a/actions.yaml b/actions.yaml
index 52655b6..29037fd 100644
--- a/actions.yaml
+++ b/actions.yaml
@@ -2,3 +2,5 @@ activate:
2 description: Activate the Livepatch service.2 description: Activate the Livepatch service.
3deactivate:3deactivate:
4 description: Deactivate the Livepatch service.4 description: Deactivate the Livepatch service.
5refresh:
6 description: Refresh the Livepatch service.
diff --git a/actions/actions.py b/actions/actions.py
index d618758..6c956cd 100755
--- a/actions/actions.py
+++ b/actions/actions.py
@@ -1,4 +1,4 @@
1#!/usr/bin/python31#!/usr/local/sbin/charm-env python3
22
3import os.path3import os.path
4import sys4import sys
@@ -7,7 +7,7 @@ from subprocess import check_output, CalledProcessError
7from charmhelpers.core import hookenv7from charmhelpers.core import hookenv
88
99
10def activate():10def activate(params):
11 config = hookenv.config()11 config = hookenv.config()
12 livepatch_key = config.get('livepatch_key')12 livepatch_key = config.get('livepatch_key')
1313
@@ -32,7 +32,7 @@ def activate():
32 hookenv.action_fail('Unable to activate as no key has been set')32 hookenv.action_fail('Unable to activate as no key has been set')
3333
3434
35def deactivate():35def deactivate(params):
36 cmd = ['/snap/bin/canonical-livepatch', 'disable']36 cmd = ['/snap/bin/canonical-livepatch', 'disable']
37 try:37 try:
38 check_output(cmd, universal_newlines=True)38 check_output(cmd, universal_newlines=True)
@@ -42,6 +42,16 @@ def deactivate():
42 hookenv.action_set(dict(result='Deactivated'))42 hookenv.action_set(dict(result='Deactivated'))
4343
4444
45def refresh(params):
46 cmd = ['/snap/bin/canonical-livepatch', 'refresh']
47 try:
48 check_output(cmd, universal_newlines=True)
49 except CalledProcessError as e:
50 hookenv.action_fail('Unable to refresh: {}'.format(str(e)))
51 return
52 hookenv.action_set(dict(result='Refreshed'))
53
54
45def main(argv):55def main(argv):
46 action = os.path.basename(argv[0])56 action = os.path.basename(argv[0])
47 params = hookenv.action_get()57 params = hookenv.action_get()
@@ -50,6 +60,8 @@ def main(argv):
50 activate(params)60 activate(params)
51 elif action == 'deactivate':61 elif action == 'deactivate':
52 deactivate(params)62 deactivate(params)
63 elif action == 'refresh':
64 refresh(params)
53 else:65 else:
54 hookenv.action_fail('Action {} not implemented'.format(action))66 hookenv.action_fail('Action {} not implemented'.format(action))
55 except Exception:67 except Exception:
diff --git a/actions/refresh b/actions/refresh
56new file mode 12000068new file mode 120000
index 0000000..405a394
--- /dev/null
+++ b/actions/refresh
@@ -0,0 +1 @@
1actions.py
0\ No newline at end of file2\ No newline at end of file
diff --git a/files/check_canonical-livepatch.py b/files/check_canonical-livepatch.py
index 3a13062..e4eaa91 100755
--- a/files/check_canonical-livepatch.py
+++ b/files/check_canonical-livepatch.py
@@ -53,13 +53,15 @@ def check_status():
53 line = line.strip()53 line = line.strip()
54 if 'State:' in line:54 if 'State:' in line:
55 if 'apply-failed' in line:55 if 'apply-failed' in line:
56 err_lines.append('Patch failed')56 err_lines.append('Livepatch failed to apply patches. ')
57 elif 'check-failed' in line:57 elif 'check-failed' in line:
58 err_lines.append('Check failed')58 err_lines.append('Livepatch failed to check the remote service for patches. ')
59 elif 'unknown' in line:59 elif 'unknown' in line:
60 err_lines.append('Unknown error')60 err_lines.append('Livepatch reports an unknown error. ')
61 elif 'kernel-upgrade-required' in line:
62 err_lines.append('A kernel upgrade (and reboot) is required. ')
61 elif 'Machine is not enabled' in line:63 elif 'Machine is not enabled' in line:
62 err_lines.append('Machine is not enabled')64 err_lines.append('Machine is not enabled. ')
6365
64 if err_lines:66 if err_lines:
65 err = " ".join(err_lines)67 err = " ".join(err_lines)
diff --git a/tests/99-autogen b/tests/99-autogen
index f4b0af9..d7bed72 100755
--- a/tests/99-autogen
+++ b/tests/99-autogen
@@ -3,6 +3,7 @@
3import amulet3import amulet
4import unittest4import unittest
5from time import sleep5from time import sleep
6from yaml import safe_load
67
78
8class TestDeployment(unittest.TestCase):9class TestDeployment(unittest.TestCase):
@@ -97,7 +98,6 @@ class TestDeployment(unittest.TestCase):
97 '.cfg'.format(test_context_name))98 '.cfg'.format(test_context_name))
98 self.assertEqual(exit_code, 0)99 self.assertEqual(exit_code, 0)
99100
100
101 def test_channel_change(self):101 def test_channel_change(self):
102 livepatch = self.deployment.sentry['canonical-livepatch'][0]102 livepatch = self.deployment.sentry['canonical-livepatch'][0]
103103
@@ -106,10 +106,8 @@ class TestDeployment(unittest.TestCase):
106 self.assertEqual(exit_code, 0)106 self.assertEqual(exit_code, 0)
107107
108 # confirm we're tracking 'stable'108 # confirm we're tracking 'stable'
109 channel = ''109 output_yaml = safe_load(output)
110 for line in output.split('\n'):110 channel = output_yaml['tracking']
111 if line.startswith('tracking:'):
112 channel = line.strip().split(' ')[-1]
113 self.assertEqual(channel, 'stable')111 self.assertEqual(channel, 'stable')
114112
115 # change channel to 'beta'113 # change channel to 'beta'
@@ -125,13 +123,10 @@ class TestDeployment(unittest.TestCase):
125 self.assertEqual(exit_code, 0)123 self.assertEqual(exit_code, 0)
126124
127 # confirm we're tracking 'beta'125 # confirm we're tracking 'beta'
128 channel = ''126 output_yaml = safe_load(output)
129 for line in output.split('\n'):127 channel = output_yaml['tracking']
130 if line.startswith('tracking:'):
131 channel = line.strip().split(' ')[-1]
132 self.assertEqual(channel, 'beta')128 self.assertEqual(channel, 'beta')
133129
134
135 def test_nagios_servicegroup_change(self):130 def test_nagios_servicegroup_change(self):
136 livepatch = self.deployment.sentry['canonical-livepatch'][0]131 livepatch = self.deployment.sentry['canonical-livepatch'][0]
137132

Subscribers

People subscribed via source and target branches