Commit 8fd0235d authored by David Seaward's avatar David Seaward

use recv_exit_status to test exit status of managed paramiko commands

parent 9ae9eab6
......@@ -38,21 +38,23 @@ def get_openvpn_ssh_connection():
return ssh
def openvpn_exec(ssh, command):
def managed_exec(ssh, command):
stdin, stdout, stderr = ssh.exec_command(command)
output = "".join(stdout.readlines())
output = "".join(stdout.readlines()).strip()
if output == "":
output = "None."
error = "".join(stderr.readlines())
error = "".join(stderr.readlines()).strip()
message = "Executed: %s. Output: %s" % (command, output,)
message = "Executed: %s Output: %s" % (command, output,)
if len(error) == 0:
# on sucess, log output, otherwise raise exception
if stdout.channel.recv_exit_status() == 0:
logger.info(message)
else:
raise Exception(message + "\n" + error)
message += " Error: " + error
raise Exception(message)
def get_latest_woo1(connection, product_id):
......@@ -165,14 +167,14 @@ def activate(ssh, limit, credit_timedelta):
limit.is_active = True
if limit.service == "TUNNEL":
openvpn_exec(ssh, "./create_new_ovpn_config --generate %s" % (limit.user.get_identity(),))
managed_exec(ssh, "./create_new_ovpn_config --generate %s" % (limit.user.get_identity(),))
limit.save()
def deactivate(ssh, limit):
if limit.service == "TUNNEL":
openvpn_exec(ssh, "./create_new_ovpn_config --revoke %s" % (limit.user.get_identity(),))
managed_exec(ssh, "./create_new_ovpn_config --revoke %s" % (limit.user.get_identity(),))
limit.is_active = False
limit.save()
......@@ -262,5 +264,6 @@ def debug_connection_task():
# make connection objects
woo_connection = get_woo_connection()
ssh = get_openvpn_ssh_connection()
managed_exec(ssh, "whoami")
logger.info("Debug task with " + repr(woo_connection) + " and " + repr(ssh) + " completed successfully.")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment