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

Proposed by Barry Price
Status: Superseded
Proposed branch: ~barryprice/charm-canonical-livepatch/+git/canonical-livepatch-charm:master
Merge into: ~livepatch-charmers/charm-canonical-livepatch:master
Diff against target: 135 lines (+83/-4)
5 files modified
actions.yaml (+4/-0)
actions/actions.py (+68/-0)
actions/activate (+1/-0)
actions/deactivate (+1/-0)
tests/99-autogen (+9/-4)
Reviewer Review Type Date Requested Status
Livepatch charm developers Pending
Review via email: mp+326983@code.launchpad.net

Commit message

Replace postgresql wih mongodb as our amulet test primary, add charm actions to activate/deactive livepatch on individual units

To post a comment you must log in.
0c3cc2a... by Barry Price

Replace postgresql wih mongodb as our amulet test primary, add charm actions to activate/deactive livepatch on individual units

Unmerged commits

0c3cc2a... by Barry Price

Replace postgresql wih mongodb as our amulet test primary, add charm actions to activate/deactive livepatch on individual units

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
2new file mode 100644
3index 0000000..52655b6
4--- /dev/null
5+++ b/actions.yaml
6@@ -0,0 +1,4 @@
7+activate:
8+ description: Activate the Livepatch service.
9+deactivate:
10+ description: Deactivate the Livepatch service.
11diff --git a/actions/actions.py b/actions/actions.py
12new file mode 100755
13index 0000000..e9bb530
14--- /dev/null
15+++ b/actions/actions.py
16@@ -0,0 +1,68 @@
17+#!/usr/bin/python3
18+
19+import os.path
20+import sys
21+import traceback
22+from subprocess import check_output, CalledProcessError
23+from charmhelpers.core import hookenv
24+
25+
26+def activate():
27+ config = hookenv.config()
28+ livepatch_key = config.get('livepatch_key')
29+
30+ if livepatch_key:
31+ # disable prior to enabling to work around LP#1628823
32+ cmd = ['/snap/bin/canonical-livepatch', 'disable']
33+ try:
34+ check_output(cmd, universal_newlines=True)
35+ except CalledProcessError as e:
36+ hookenv.log('Unable to deactivate: {}'.format(str(e)))
37+ # but let's soldier on...
38+ cmd = [
39+ '/snap/bin/canonical-livepatch',
40+ 'enable',
41+ '{}'.format(livepatch_key.strip())
42+ ]
43+ try:
44+ check_output(cmd, universal_newlines=True)
45+ except CalledProcessError as e:
46+ hookenv.action_fail('Unable to activate: {}'.format(str(e)))
47+ return
48+ else:
49+ hookenv.action_set(dict(result='Activated'))
50+
51+ else:
52+ hookenv.action_fail('Unable to activate as no key has been set')
53+
54+
55+def deactivate():
56+ cmd = ['/snap/bin/canonical-livepatch', 'disable']
57+ try:
58+ check_output(cmd, universal_newlines=True)
59+ except CalledProcessError as e:
60+ hookenv.action_fail('Unable to deactivate: {}'.format(str(e)))
61+ return
62+ hookenv.action_set(dict(result='Deactivated'))
63+
64+
65+def main(argv):
66+ action = os.path.basename(argv[0])
67+ params = hookenv.action_get()
68+ try:
69+ if action == 'activate':
70+ activate(params)
71+ elif action == 'deactivate':
72+ deactivate(params)
73+ else:
74+ hookenv.action_fail('Action {} not implemented'.format(action))
75+ except Exception:
76+ hookenv.action_fail('Unhandled exception')
77+ tb = traceback.format_exc()
78+ hookenv.action_set(dict(traceback=tb))
79+ hookenv.log('Unhandled exception in action {}'.format(action))
80+ print(tb)
81+
82+
83+if __name__ == '__main__':
84+ main(sys.argv)
85diff --git a/actions/activate b/actions/activate
86new file mode 120000
87index 0000000..405a394
88--- /dev/null
89+++ b/actions/activate
90@@ -0,0 +1 @@
91+actions.py
92\ No newline at end of file
93diff --git a/actions/deactivate b/actions/deactivate
94new file mode 120000
95index 0000000..405a394
96--- /dev/null
97+++ b/actions/deactivate
98@@ -0,0 +1 @@
99+actions.py
100\ No newline at end of file
101diff --git a/tests/99-autogen b/tests/99-autogen
102index 7bc8f1e..c7c1dfd 100755
103--- a/tests/99-autogen
104+++ b/tests/99-autogen
105@@ -10,8 +10,8 @@ class TestDeployment(unittest.TestCase):
106 def setUpClass(cls):
107 cls.deployment = amulet.Deployment(series='xenial')
108
109- # deploy postgresql as our parent, it's a well-behaved charm
110- cls.deployment.add('postgresql')
111+ # deploy mongodb as our parent
112+ cls.deployment.add('mongodb')
113
114 # deploy our own charm
115 cls.deployment.add('canonical-livepatch')
116@@ -19,13 +19,18 @@ class TestDeployment(unittest.TestCase):
117 # and deploy the nrpe subordinate to test nagios checks
118 cls.deployment.add('nrpe')
119
120+ # set nrpe to export its definitions
121+ cls.deployment.configure('nrpe', {
122+ 'export_nagios_definitions': True,
123+ })
124+
125 # relate subordinates to parent charm
126 cls.deployment.relate(
127- 'postgresql:juju-info',
128+ 'mongodb:juju-info',
129 'canonical-livepatch:juju-info'
130 )
131 cls.deployment.relate(
132- 'postgresql:nrpe-external-master',
133+ 'mongodb:nrpe-external-master',
134 'nrpe:nrpe-external-master'
135 )
136

Subscribers

People subscribed via source and target branches