From: Adam Israel Date: Fri, 10 Nov 2017 23:17:05 +0000 (-0500) Subject: Add exception handling during config-changed hook X-Git-Tag: v3.0.3~9 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F81%2F5681%2F2;p=osm%2Fdevops.git Add exception handling during config-changed hook Signed-off-by: Adam Israel --- 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')