← 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:
Reformat to 120 character lines

Requested reviews:
  Livepatch charm developers (livepatch-charmers)

For more details, see:
https://code.launchpad.net/~barryprice/canonical-livepatch-charm/+git/canonical-livepatch-charm/+merge/332337
-- 
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/actions.py b/actions/actions.py
index e9bb530..d618758 100755
--- a/actions/actions.py
+++ b/actions/actions.py
@@ -19,11 +19,7 @@ def activate():
         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())
-        ]
+        cmd = ['/snap/bin/canonical-livepatch', 'enable', '{}'.format(livepatch_key.strip())]
         try:
             check_output(cmd, universal_newlines=True)
         except CalledProcessError as e:
diff --git a/reactive/canonical_livepatch.py b/reactive/canonical_livepatch.py
index 8b39eab..e176c45 100644
--- a/reactive/canonical_livepatch.py
+++ b/reactive/canonical_livepatch.py
@@ -27,32 +27,21 @@ def file_to_units(local_path, unit_path):
 
 
 def wait_for_path(file_path, timeout=30):
-    hookenv.log('Waiting for up to {}s for {}'.format(
-        timeout,
-        file_path)
-    )
+    hookenv.log('Waiting for up to {}s for {}'.format(timeout, file_path))
     seconds_waited = 0
     interval = 1
     while not (path.exists(file_path)):
-        hookenv.log('{} does not exist - waiting {}s'.format(
-            file_path,
-            interval)
-        )
+        hookenv.log('{} does not exist - waiting {}s'.format(file_path, interval))
         sleep(interval)
         seconds_waited += interval
         if seconds_waited >= timeout:
-            hookenv.log(
-                'Giving up waiting for {}'.format(file_path),
-                hookenv.ERROR
-            )
+            hookenv.log('Giving up waiting for {}'.format(file_path), hookenv.ERROR)
             return
     return
 
 
 def wait_for_livepatch():
-    wait_for_path(
-        '/var/snap/canonical-livepatch/current/livepatchd-priv.sock'
-    )
+    wait_for_path('/var/snap/canonical-livepatch/current/livepatchd-priv.sock')
 
 
 def unit_update(status=None, message=None):
@@ -60,10 +49,7 @@ def unit_update(status=None, message=None):
         hookenv.status_set(status, message)
     else:
         patch_details = get_patch_details()
-        hookenv.status_set(
-                'active',
-                'Running kernel {}, patchState: {}'.format(*patch_details)
-        )
+        hookenv.status_set('active', 'Running kernel {}, patchState: {}'.format(*patch_details))
 
 
 def get_patch_details():
@@ -90,10 +76,7 @@ def get_patch_details():
                 kernel = k['kernel']
                 patch_state = k['livepatch']['patchState']
     except Exception:
-        hookenv.log(
-            'Unable to find patching details in status yaml',
-            hookenv.ERROR
-        )
+        hookenv.log('Unable to find patching details in status yaml', hookenv.ERROR)
         return kernel, patch_state
 
     return kernel, patch_state
@@ -105,10 +88,7 @@ def get_yaml_if_exists(path_to_yaml):
             try:
                 conf_yaml = load(stream)
             except Exception:
-                hookenv.log(
-                    'Unable to load YAML from {}'.format(path_to_yaml),
-                    hookenv.ERROR
-                )
+                hookenv.log('Unable to load YAML from {}'.format(path_to_yaml), hookenv.ERROR)
     else:
         conf_yaml = {}
 
@@ -149,11 +129,7 @@ def configure_proxies(http_proxy=None, https_proxy=None, no_proxy=None):
 
 def restart_livepatch():
     # do a clean stop of the service first, 'restart' seems fragile right now
-    cmd = [
-        '/bin/systemctl',
-        'stop',
-        'snap.canonical-livepatch.canonical-livepatchd.service',
-    ]
+    cmd = ['/bin/systemctl', 'stop', 'snap.canonical-livepatch.canonical-livepatchd.service']
     hookenv.log('Stopping canonical-livepatch service')
     try:
         check_call(cmd, universal_newlines=True)
@@ -161,19 +137,12 @@ def restart_livepatch():
         hookenv.log('Failed to stop the service', hookenv.ERROR)
 
     # and now try to start it again, it may fail the first time!
-    cmd = [
-        '/bin/systemctl',
-        'start',
-        'snap.canonical-livepatch.canonical-livepatchd.service',
-    ]
+    cmd = ['/bin/systemctl', 'start', 'snap.canonical-livepatch.canonical-livepatchd.service']
     hookenv.log('Starting canonical-livepatch service')
     try:
         check_call(cmd, universal_newlines=True)
     except CalledProcessError:
-        hookenv.log(
-            'Failed to start the service - waiting 5s and then trying again',
-            hookenv.ERROR
-        )
+        hookenv.log('Failed to start the service - waiting 5s and then trying again', hookenv.ERROR)
         sleep(5)
         check_call(cmd, universal_newlines=True)
 
@@ -186,66 +155,37 @@ def activate_livepatch():
     if livepatch_key:
         # disable prior to enabling to work around LP#1628823
         cmd = ['/snap/bin/canonical-livepatch', 'disable']
-        hookenv.log(
-            'Disabling canonical-livepatch ahead of key change '
-            'to work around LP#1628823'
-        )
+        hookenv.log('Disabling canonical-livepatch ahead of key change to work around LP#1628823')
         try:
             check_output(cmd, universal_newlines=True)
         except CalledProcessError as e:
-            hookenv.log(
-                'Unable to deactivate: {}'.format(str(e)),
-                hookenv.ERROR
-            )
-
-        cmd = [
-            '/snap/bin/canonical-livepatch',
-            'enable',
-            '{}'.format(livepatch_key.strip())
-        ]
+            hookenv.log('Unable to deactivate: {}'.format(str(e)), hookenv.ERROR)
+
+        cmd = ['/snap/bin/canonical-livepatch', 'enable', '{}'.format(livepatch_key.strip())]
         hookenv.log('Activating canonical-livepatch with your key')
         try:
             check_output(cmd, universal_newlines=True)
         except CalledProcessError as e:
-            hookenv.log(
-                'Unable to activate: {}'.format(str(e)),
-                hookenv.ERROR
-            )
+            hookenv.log('Unable to activate: {}'.format(str(e)), hookenv.ERROR)
             remove_state('canonical-livepatch.active')
             unit_update('blocked', 'Activation failed')
         else:
             set_state('canonical-livepatch.active')
             unit_update()
     else:
-        hookenv.log(
-            'Unable to activate canonical-livepatch as no key has been set',
-            hookenv.ERROR
-        )
+        hookenv.log('Unable to activate canonical-livepatch as no key has been set', hookenv.ERROR)
         remove_state('canonical-livepatch.active')
-        unit_update(
-            'blocked',
-            'Service disabled, please set livepatch_key to activate'
-        )
+        unit_update('blocked', 'Service disabled, please set livepatch_key to activate')
 
 
 @when_not('snap.installed.canonical-livepatch')
 def livepatch_supported():
     arch = uname()[4]
     opts = layer.options('snap')
-    supported_archs = opts['canonical-livepatch'].pop(
-        'supported-architectures',
-        None
-    )
+    supported_archs = opts['canonical-livepatch'].pop('supported-architectures', None)
     if supported_archs and arch not in supported_archs:
-        hookenv.log(
-            'Livepatch does not currently support {} architecture'.format(
-                arch
-            )
-        )
-        unit_update(
-            'blocked',
-            'Architecture {} is not supported by livepatch'.format(arch)
-        )
+        hookenv.log('Livepatch does not currently support {} architecture'.format(arch))
+        unit_update('blocked', 'Architecture {} is not supported by livepatch'.format(arch))
     if is_container():
         hookenv.log('OS container detected, livepatch is not needed')
         unit_update('blocked', 'Livepatch is not needed in OS containers')
@@ -270,10 +210,7 @@ def canonical_livepatch_connect():
         # Make sure the service is ready for us
         wait_for_livepatch()
         set_state('canonical-livepatch.connected')
-        unit_update(
-            'blocked',
-            'Service disabled, please set livepatch_key to activate'
-        )
+        unit_update('blocked', 'Service disabled, please set livepatch_key to activate')
 
 
 @when('canonical-livepatch.connected')

Follow ups