← Back to team overview

livepatch-charmers team mailing list archive

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

 

Barry Price has proposed merging ~barryprice/canonical-livepatch-charm/+git/canonical-livepatch-charm:master into canonical-livepatch-charm:master.

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

Requested reviews:
  Livepatch charm developers (livepatch-charmers)

For more details, see:
https://code.launchpad.net/~barryprice/canonical-livepatch-charm/+git/canonical-livepatch-charm/+merge/326984
-- 
Your team Livepatch charm developers is requested to review the proposed merge of ~barryprice/canonical-livepatch-charm/+git/canonical-livepatch-charm:master into canonical-livepatch-charm:master.
diff --git a/actions.yaml b/actions.yaml
new file mode 100644
index 0000000..52655b6
--- /dev/null
+++ b/actions.yaml
@@ -0,0 +1,4 @@
+activate:
+  description: Activate the Livepatch service.
+deactivate:
+  description: Deactivate the Livepatch service.
diff --git a/actions/actions.py b/actions/actions.py
new file mode 100755
index 0000000..e9bb530
--- /dev/null
+++ b/actions/actions.py
@@ -0,0 +1,68 @@
+#!/usr/bin/python3
+
+import os.path
+import sys
+import traceback
+from subprocess import check_output, CalledProcessError
+from charmhelpers.core import hookenv
+
+
+def activate():
+    config = hookenv.config()
+    livepatch_key = config.get('livepatch_key')
+
+    if livepatch_key:
+        # disable prior to enabling to work around LP#1628823
+        cmd = ['/snap/bin/canonical-livepatch', 'disable']
+        try:
+            check_output(cmd, universal_newlines=True)
+        except CalledProcessError as e:
+            hookenv.log('Unable to deactivate: {}'.format(str(e)))
+            # but let's soldier on...
+        cmd = [
+            '/snap/bin/canonical-livepatch',
+            'enable',
+            '{}'.format(livepatch_key.strip())
+        ]
+        try:
+            check_output(cmd, universal_newlines=True)
+        except CalledProcessError as e:
+            hookenv.action_fail('Unable to activate: {}'.format(str(e)))
+            return
+        else:
+            hookenv.action_set(dict(result='Activated'))
+
+    else:
+        hookenv.action_fail('Unable to activate as no key has been set')
+
+
+def deactivate():
+    cmd = ['/snap/bin/canonical-livepatch', 'disable']
+    try:
+        check_output(cmd, universal_newlines=True)
+    except CalledProcessError as e:
+        hookenv.action_fail('Unable to deactivate: {}'.format(str(e)))
+        return
+    hookenv.action_set(dict(result='Deactivated'))
+
+
+def main(argv):
+    action = os.path.basename(argv[0])
+    params = hookenv.action_get()
+    try:
+        if action == 'activate':
+            activate(params)
+        elif action == 'deactivate':
+            deactivate(params)
+        else:
+            hookenv.action_fail('Action {} not implemented'.format(action))
+    except Exception:
+        hookenv.action_fail('Unhandled exception')
+        tb = traceback.format_exc()
+        hookenv.action_set(dict(traceback=tb))
+        hookenv.log('Unhandled exception in action {}'.format(action))
+        print(tb)
+
+
+if __name__ == '__main__':
+    main(sys.argv)
diff --git a/actions/activate b/actions/activate
new file mode 120000
index 0000000..405a394
--- /dev/null
+++ b/actions/activate
@@ -0,0 +1 @@
+actions.py
\ No newline at end of file
diff --git a/actions/deactivate b/actions/deactivate
new file mode 120000
index 0000000..405a394
--- /dev/null
+++ b/actions/deactivate
@@ -0,0 +1 @@
+actions.py
\ 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):
     def setUpClass(cls):
         cls.deployment = amulet.Deployment(series='xenial')
 
-        # deploy postgresql as our parent, it's a well-behaved charm
-        cls.deployment.add('postgresql')
+        # deploy mongodb as our parent
+        cls.deployment.add('mongodb')
 
         # deploy our own charm
         cls.deployment.add('canonical-livepatch')
@@ -19,13 +19,18 @@ class TestDeployment(unittest.TestCase):
         # and deploy the nrpe subordinate to test nagios checks
         cls.deployment.add('nrpe')
 
+        # set nrpe to export its definitions
+        cls.deployment.configure('nrpe', {
+            'export_nagios_definitions': True,
+        })
+
         # relate subordinates to parent charm
         cls.deployment.relate(
-            'postgresql:juju-info',
+            'mongodb:juju-info',
             'canonical-livepatch:juju-info'
         )
         cls.deployment.relate(
-            'postgresql:nrpe-external-master',
+            'mongodb:nrpe-external-master',
             'nrpe:nrpe-external-master'
         )
 

Follow ups