X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=juju-charms%2Flayers%2Fpingpong%2Freactive%2Fpingpong.py;h=ae18076cb5915148ff0a70a5951289bc6ba957d1;hb=1423eb66b1081c9c89cdaf163fa5106cb5766abc;hp=7a91f89be85c8e004026c80420d85ac7d481de62;hpb=88ff0707bb747cbff713ae64899ab2de485d37d4;p=osm%2Fdevops.git diff --git a/juju-charms/layers/pingpong/reactive/pingpong.py b/juju-charms/layers/pingpong/reactive/pingpong.py index 7a91f89b..ae18076c 100755 --- a/juju-charms/layers/pingpong/reactive/pingpong.py +++ b/juju-charms/layers/pingpong/reactive/pingpong.py @@ -10,20 +10,42 @@ 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_not('pingpong.configured') +def not_configured(): + """Check the current configuration. + + Check the current values in config to see if we have enough + information to continue. + """ + config_changed() + + +@when('config.changed', 'sshproxy.configured') def config_changed(): + """Verify the configuration. + + 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') @@ -32,6 +54,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