Add exception handling during config-changed hook 81/5681/2
authorAdam Israel <adam.israel@canonical.com>
Fri, 10 Nov 2017 23:17:05 +0000 (18:17 -0500)
committermarchettim <mmarchetti@sandvine.com>
Wed, 21 Feb 2018 15:24:16 +0000 (17:24 +0200)
Signed-off-by: Adam Israel <adam.israel@canonical.com>
juju-charms/layers/pingpong/reactive/pingpong.py

index ae18076..7eedc84 100755 (executable)
@@ -39,19 +39,26 @@ def config_changed():
 
     Verify that the charm has been configured
     """
-    status_set('maintenance', 'Verifying configuration data...')
-    (validated, output) = charms.sshproxy.verify_ssh_credentials()
-    if not validated:
-        status_set('blocked', 'Unable to verify SSH credentials: {}'.format(
-            output
-        ))
-        return
-    if all(k in cfg for k in ['mode']):
-        if cfg['mode'] in ['ping', 'pong']:
-            set_flag('pingpong.configured')
-            status_set('active', 'ready!')
+
+    try:
+        status_set('maintenance', 'Verifying configuration data...')
+
+        (validated, output) = charms.sshproxy.verify_ssh_credentials()
+        if not validated:
+            status_set('blocked', 'Unable to verify SSH credentials: {}'.format(
+                output
+            ))
             return
-    status_set('blocked', 'Waiting for configuration')
+
+        if all(k in cfg for k in ['mode']):
+            if cfg['mode'] in ['ping', 'pong']:
+                set_flag('pingpong.configured')
+                status_set('active', 'ready!')
+                return
+        status_set('blocked', 'Waiting for configuration')
+
+    except Exception as err:
+        status_set('blocked', 'Waiting for valid configuration ({})'.format(err))
 
 
 @when('config.changed')