← 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:
Write our actual live status for the nagios check, instead of an empty file (which the latest check script would see as an error)

Requested reviews:
  Livepatch charm developers (livepatch-charmers)

For more details, see:
https://code.launchpad.net/~barryprice/canonical-livepatch-charm/+git/canonical-livepatch-charm/+merge/355912
-- 
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/files/canonical-livepatch-status.txt b/files/canonical-livepatch-status.txt
deleted file mode 100644
index e69de29..0000000
--- a/files/canonical-livepatch-status.txt
+++ /dev/null
diff --git a/reactive/canonical_livepatch.py b/reactive/canonical_livepatch.py
index 03c1903..4a542da 100644
--- a/reactive/canonical_livepatch.py
+++ b/reactive/canonical_livepatch.py
@@ -53,19 +53,23 @@ def unit_update(status=None, message=None):
         hookenv.status_set('active', 'Running kernel {}, patchState: {}'.format(*patch_details))
 
 
-def get_patch_details():
-    kernel = patch_state = 'unknown'
-
+def get_livepatch_status():
     cmd = ['/snap/bin/canonical-livepatch', 'status']
     try:
-        livepatch_state = check_output(cmd, universal_newlines=True)
+        livepatch_status = check_output(cmd, universal_newlines=True)
     except CalledProcessError as e:
         hookenv.log('Unable to get status: {}'.format(str(e)), hookenv.ERROR)
-        return kernel, patch_state
+        return None
+    return livepatch_status
+
+
+def get_patch_details():
+    kernel = patch_state = 'unknown'
+    patch_state = get_livepatch_status()
 
     # status will usually pass YAML (but not always!)
     try:
-        status_yaml = safe_load(livepatch_state)
+        status_yaml = safe_load(patch_state)
     except Exception:
         hookenv.log('Unable to parse status yaml', hookenv.ERROR)
         return kernel, patch_state
@@ -247,11 +251,15 @@ def configure_nagios(nagios):
         'files/check_canonical-livepatch.py',
         '/usr/lib/nagios/plugins/check_canonical-livepatch.py',
     )
-    # don't overwrite an existing status file
+    # write our current status to disk for the check
     if not path.exists('/var/lib/nagios/canonical-livepatch-status.txt'):
-        file_to_units(
-            'files/canonical-livepatch-status.txt',
-            '/var/lib/nagios/canonical-livepatch-status.txt',
+        current_status = get_livepatch_status()
+        perms = 0o644
+        write_file(
+            path='/var/lib/nagios/canonical-livepatch-status.txt',
+            content=current_status,
+            owner='root',
+            perms=perms,
         )
 
     # remove check from previous release with poorly formed name

References