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
diff --git a/actions.yaml b/actions.yaml
0new file mode 1006440new file mode 100644
index 0000000..52655b6
--- /dev/null
+++ b/actions.yaml
@@ -0,0 +1,4 @@
1activate:
2 description: Activate the Livepatch service.
3deactivate:
4 description: Deactivate the Livepatch service.
diff --git a/actions/actions.py b/actions/actions.py
0new file mode 1007555new file mode 100755
index 0000000..e9bb530
--- /dev/null
+++ b/actions/actions.py
@@ -0,0 +1,68 @@
1#!/usr/bin/python3
2
3import os.path
4import sys
5import traceback
6from subprocess import check_output, CalledProcessError
7from charmhelpers.core import hookenv
8
9
10def activate():
11 config = hookenv.config()
12 livepatch_key = config.get('livepatch_key')
13
14 if livepatch_key:
15 # disable prior to enabling to work around LP#1628823
16 cmd = ['/snap/bin/canonical-livepatch', 'disable']
17 try:
18 check_output(cmd, universal_newlines=True)
19 except CalledProcessError as e:
20 hookenv.log('Unable to deactivate: {}'.format(str(e)))
21 # but let's soldier on...
22 cmd = [
23 '/snap/bin/canonical-livepatch',
24 'enable',
25 '{}'.format(livepatch_key.strip())
26 ]
27 try:
28 check_output(cmd, universal_newlines=True)
29 except CalledProcessError as e:
30 hookenv.action_fail('Unable to activate: {}'.format(str(e)))
31 return
32 else:
33 hookenv.action_set(dict(result='Activated'))
34
35 else:
36 hookenv.action_fail('Unable to activate as no key has been set')
37
38
39def deactivate():
40 cmd = ['/snap/bin/canonical-livepatch', 'disable']
41 try:
42 check_output(cmd, universal_newlines=True)
43 except CalledProcessError as e:
44 hookenv.action_fail('Unable to deactivate: {}'.format(str(e)))
45 return
46 hookenv.action_set(dict(result='Deactivated'))
47
48
49def main(argv):
50 action = os.path.basename(argv[0])
51 params = hookenv.action_get()
52 try:
53 if action == 'activate':
54 activate(params)
55 elif action == 'deactivate':
56 deactivate(params)
57 else:
58 hookenv.action_fail('Action {} not implemented'.format(action))
59 except Exception:
60 hookenv.action_fail('Unhandled exception')
61 tb = traceback.format_exc()
62 hookenv.action_set(dict(traceback=tb))
63 hookenv.log('Unhandled exception in action {}'.format(action))
64 print(tb)
65
66
67if __name__ == '__main__':
68 main(sys.argv)
diff --git a/actions/activate b/actions/activate
0new file mode 12000069new file mode 120000
index 0000000..405a394
--- /dev/null
+++ b/actions/activate
@@ -0,0 +1 @@
1actions.py
0\ No newline at end of file2\ No newline at end of file
diff --git a/actions/deactivate b/actions/deactivate
1new file mode 1200003new file mode 120000
index 0000000..405a394
--- /dev/null
+++ b/actions/deactivate
@@ -0,0 +1 @@
1actions.py
0\ No newline at end of file2\ No newline at end of file
diff --git a/tests/99-autogen b/tests/99-autogen
index 7bc8f1e..c7c1dfd 100755
--- a/tests/99-autogen
+++ b/tests/99-autogen
@@ -10,8 +10,8 @@ class TestDeployment(unittest.TestCase):
10 def setUpClass(cls):10 def setUpClass(cls):
11 cls.deployment = amulet.Deployment(series='xenial')11 cls.deployment = amulet.Deployment(series='xenial')
1212
13 # deploy postgresql as our parent, it's a well-behaved charm13 # deploy mongodb as our parent
14 cls.deployment.add('postgresql')14 cls.deployment.add('mongodb')
1515
16 # deploy our own charm16 # deploy our own charm
17 cls.deployment.add('canonical-livepatch')17 cls.deployment.add('canonical-livepatch')
@@ -19,13 +19,18 @@ class TestDeployment(unittest.TestCase):
19 # and deploy the nrpe subordinate to test nagios checks19 # and deploy the nrpe subordinate to test nagios checks
20 cls.deployment.add('nrpe')20 cls.deployment.add('nrpe')
2121
22 # set nrpe to export its definitions
23 cls.deployment.configure('nrpe', {
24 'export_nagios_definitions': True,
25 })
26
22 # relate subordinates to parent charm27 # relate subordinates to parent charm
23 cls.deployment.relate(28 cls.deployment.relate(
24 'postgresql:juju-info',29 'mongodb:juju-info',
25 'canonical-livepatch:juju-info'30 'canonical-livepatch:juju-info'
26 )31 )
27 cls.deployment.relate(32 cls.deployment.relate(
28 'postgresql:nrpe-external-master',33 'mongodb:nrpe-external-master',
29 'nrpe:nrpe-external-master'34 'nrpe:nrpe-external-master'
30 )35 )
3136

Subscribers

People subscribed via source and target branches