From e4a26bc8a15f287ee7c15f89f3143286c1bce427 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Vonheiden?= <bjoern.vonheiden@hotmail.de> Date: Tue, 22 Sep 2020 15:31:11 +0200 Subject: [PATCH] integrate the atexit method in run uc py --- execution/run_uc.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/execution/run_uc.py b/execution/run_uc.py index 25c463be8..db350b671 100644 --- a/execution/run_uc.py +++ b/execution/run_uc.py @@ -1,4 +1,5 @@ import argparse # parse arguments from cli +import atexit # used to clear resources at exit of program (e.g. ctrl-c) from kubernetes import client, config # kubernetes api from kubernetes.stream import stream import logging # logging @@ -483,6 +484,7 @@ def reset_cluster(wg, app_svc, app_svc_monitor, app_jmx, app_deploy, topics): """ Stop the applications, delete topics, reset zookeeper and stop lag exporter. """ + print('Reset cluster') stop_applications(wg, app_svc, app_svc_monitor, app_jmx, app_deploy) print('---------------------') delete_topics(topics) @@ -491,7 +493,6 @@ def reset_cluster(wg, app_svc, app_svc_monitor, app_jmx, app_deploy, topics): print('---------------------') stop_lag_exporter() - def main(): load_variables() print('---------------------') @@ -507,15 +508,20 @@ def main(): ('aggregation-feedback', args.partitions), ('configuration', 1)] + # Check for reset options if args.reset_only: - print('Reset only cluster') + # Only reset cluster an then end program reset_cluster(wg, app_svc, app_svc_monitor, app_jmx, app_deploy, topics) sys.exit() if args.reset: - print('Reset cluster before execution') + # Reset cluster before execution + print('Reset only mode') reset_cluster(wg, app_svc, app_svc_monitor, app_jmx, app_deploy, topics) print('---------------------') + # Register the reset operation so that is executed at the end of program + atexit.register(reset_cluster, wg, app_svc, app_svc_monitor, app_jmx, app_deploy, topics) + create_topics(topics) print('---------------------') @@ -532,7 +538,8 @@ def main(): wait_execution() print('---------------------') - reset_cluster(wg, app_svc, app_svc_monitor, app_jmx, app_deploy, topics) + # Cluster is resetted with atexit method + # reset_cluster(wg, app_svc, app_svc_monitor, app_jmx, app_deploy, topics) if __name__ == '__main__': -- GitLab