From 247fc866a23316f52333052af4c6c7b82f723e27 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Tue, 25 Oct 2022 21:17:12 +0000 Subject: [PATCH] Handle return codes from paramiko commands --- bootstrap-daemon/pvcbootstrapd/lib/hooks.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/bootstrap-daemon/pvcbootstrapd/lib/hooks.py b/bootstrap-daemon/pvcbootstrapd/lib/hooks.py index 8a0f255..9f492cb 100755 --- a/bootstrap-daemon/pvcbootstrapd/lib/hooks.py +++ b/bootstrap-daemon/pvcbootstrapd/lib/hooks.py @@ -69,6 +69,7 @@ def run_hook_osddb(config, targets, args): stdin, stdout, stderr = c.exec_command(pvc_cmd_string) logger.debug(stdout.readlines()) logger.debug(stderr.readlines()) + return stdout.channel.recv_exit_status() def run_hook_osd(config, targets, args): @@ -98,6 +99,7 @@ def run_hook_osd(config, targets, args): stdin, stdout, stderr = c.exec_command(pvc_cmd_string) logger.debug(stdout.readlines()) logger.debug(stderr.readlines()) + return stdout.channel.recv_exit_status() def run_hook_pool(config, targets, args): @@ -127,7 +129,7 @@ def run_hook_pool(config, targets, args): logger.debug(stderr.readlines()) # This only runs once on whatever the first node is - break + return stdout.channel.recv_exit_status() def run_hook_network(config, targets, args): @@ -191,7 +193,7 @@ def run_hook_network(config, targets, args): logger.debug(stderr.readlines()) # This only runs once on whatever the first node is - break + return stdout.channel.recv_exit_status() def run_hook_copy(config, targets, args): @@ -273,6 +275,8 @@ def run_hook_script(config, targets, args): logger.debug(stdout.readlines()) logger.debug(stderr.readlines()) + return stdout.channel.recv_exit_status() + def run_hook_webhook(config, targets, args): """ @@ -345,7 +349,9 @@ def run_hooks(config, cspec, cluster, nodes): # Run the hook function try: notifications.send_webhook(config, "begin", f"Cluster {cluster.name}: Running hook task '{hook_name}'") - hook_functions[hook_type](config, target_nodes, hook_args) + retcode = hook_functions[hook_type](config, target_nodes, hook_args) + if retcode > 0: + raise Exception(f"Hook returned with code {retcode}") notifications.send_webhook(config, "success", f"Cluster {cluster.name}: Completed hook task '{hook_name}'") except Exception as e: logger.warning(f"Error running hook: {e}")