From 1d32d3fa83a85eee72867c2430f0bbc3c9fd8ccb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Vonheiden?= <bjoern.vonheiden@hotmail.de>
Date: Wed, 16 Sep 2020 15:04:08 +0200
Subject: [PATCH] Add reset of zookeeper

---
 execution/run_uc.py | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/execution/run_uc.py b/execution/run_uc.py
index 04d38eea7..7a2c2c695 100644
--- a/execution/run_uc.py
+++ b/execution/run_uc.py
@@ -364,6 +364,47 @@ def delete_topics(topics):
             break
     return
 
+def reset_zookeeper():
+    """Delete ZooKeeper configurations used for workload generation.
+    """
+    print('Delete ZooKeeper configurations used for workload generation')
+
+    delete_zoo_data_command = [
+        'kubectl',
+        'exec',
+        'zookeeper-client',
+        '--',
+        'bash',
+        '-c',
+        'zookeeper-shell my-confluent-cp-zookeeper:2181 deleteall /workload-generation'
+    ]
+
+    check_zoo_data_command = [
+        'kubectl',
+        'exec',
+        'zookeeper-client',
+        '--',
+        'bash',
+        '-c',
+        'zookeeper-shell my-confluent-cp-zookeeper:2181 ls /'
+        # "| awk -F[\]\[] '{print $2}'"
+    ]
+
+    output = subprocess.run(delete_zoo_data_command, capture_output=True, text=True)
+    logging.info(output.stdout)
+
+    # Wait for configuration deletion
+    while True:
+        output = subprocess.run(check_zoo_data_command, capture_output=True, text=True)
+        logging.debug(output)
+
+        if 'workload-generation' in output.stdout:
+            print('ZooKeeper reset was not successful. Retrying in 5s.')
+            time.sleep(5)
+        else:
+            logging.info('ZooKeeper reset was successful.')
+            break
+    return
 
 def stop_lag_exporter():
     """
@@ -426,6 +467,8 @@ def main():
     print('---------------------')
     delete_topics(topics)
     print('---------------------')
+    reset_zookeeper()
+    print('---------------------')
     stop_lag_exporter()
 
 
-- 
GitLab