From 15474010b44d32e4390b74ad633470054940a48f Mon Sep 17 00:00:00 2001 From: Adam Israel Date: Fri, 10 Nov 2017 18:17:05 -0500 Subject: [PATCH] Add exception handling during config-changed hook Signed-off-by: Adam Israel --- .../layers/pingpong/reactive/pingpong.py | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/juju-charms/layers/pingpong/reactive/pingpong.py b/juju-charms/layers/pingpong/reactive/pingpong.py index ae18076c..7eedc84a 100755 --- a/juju-charms/layers/pingpong/reactive/pingpong.py +++ b/juju-charms/layers/pingpong/reactive/pingpong.py @@ -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') -- 2.25.1