X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=juju-charms%2Flayers%2Fpingpong%2Freactive%2Fpingpong.py;h=7eedc84a1a6d652cd5e199448e2da2be1f86d0ec;hb=15474010b44d32e4390b74ad633470054940a48f;hp=b5a5db965a3c7c010a9cb087582e87d450a1ed56;hpb=8f83069696a74f3fc9272a5c65d5e75e923e7ff9;p=osm%2Fdevops.git diff --git a/juju-charms/layers/pingpong/reactive/pingpong.py b/juju-charms/layers/pingpong/reactive/pingpong.py old mode 100644 new mode 100755 index b5a5db96..7eedc84a --- a/juju-charms/layers/pingpong/reactive/pingpong.py +++ b/juju-charms/layers/pingpong/reactive/pingpong.py @@ -10,26 +10,62 @@ 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(): - if all(k in cfg for k in ['mode']): - if cfg['mode'] in ['ping', 'pong']: - set_flag('pingpong.configured') - status_set('active', 'ready!') + """Verify the configuration. + + Verify that the charm has been configured + """ + + 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') +@when_not('sshproxy.configured') +def invalid_credentials(): + status_set('blocked', 'Waiting for SSH credentials.') + pass def is_ping(): @@ -63,16 +99,16 @@ def start(): remove_flag('actions.start') return + # Attempt to raise the non-mgmt interface, but ignore failures if + # the interface is already up. try: - cmd = "sudo timeout 30 /sbin/ifup eth1" + cmd = "sudo timeout 30 /sbin/ifup eth1" result, err = charms.sshproxy._run(cmd) except Exception as e: - action_fail('command failed: {}, errors: {}'.format(e, e.output)) - remove_flag('actions.start') - return + pass try: - cmd = "sudo timeout 30 /usr/bin/systemctl start {}". \ + cmd = "sudo timeout 30 /usr/bin/systemctl start {}". \ format(cfg['mode']) result, err = charms.sshproxy._run(cmd) except Exception as e: