From 5a0f6e4464da00bb45d2573f6317a75f753d2dc1 Mon Sep 17 00:00:00 2001 From: Adam Israel Date: Wed, 18 Oct 2017 10:39:40 -0400 Subject: [PATCH] Add better status messages This patch adds better status messages by differentiating between configuration settings received and the verification of ssh credentials. Signed-off-by: Adam Israel --- .../layers/pingpong/reactive/pingpong.py | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/juju-charms/layers/pingpong/reactive/pingpong.py b/juju-charms/layers/pingpong/reactive/pingpong.py index 7a91f89b..2bcbc143 100755 --- a/juju-charms/layers/pingpong/reactive/pingpong.py +++ b/juju-charms/layers/pingpong/reactive/pingpong.py @@ -10,20 +10,29 @@ from charms.reactive import ( remove_state as remove_flag, set_state as set_flag, when, + when_not, ) import charms.sshproxy -from subprocess import ( - Popen, - CalledProcessError, - PIPE, -) +# from subprocess import ( +# Popen, +# CalledProcessError, +# PIPE, +# ) cfg = config() -@when('config.changed') +@when('config.changed', 'sshproxy.configured') def config_changed(): + """Verify the configuration. + Verify that the charm has been configured + """ + (validated, output) = charms.sshproxy.verify_ssh_credentials() + if not validated: + status_set('blocked', 'Unable to verify SSH credentials: {}'.format( + output + )) if all(k in cfg for k in ['mode']): if cfg['mode'] in ['ping', 'pong']: set_flag('pingpong.configured') @@ -32,6 +41,13 @@ def config_changed(): status_set('blocked', 'Waiting for configuration') +@when('config.changed') +@when_not('sshproxy.configured') +def invalid_credentials(): + status_set('blocked', 'Waiting for SSH credentials.') + pass + + def is_ping(): if cfg['mode'] == 'ping': return True -- 2.25.1