import yaml import subprocess import time def update_yaml(maxJobs, churn, interval): yaml_path = "./edge-infra/config/pallets/edge/datasync/couchdb/generic/couchdb-server.yaml" with open(yaml_path, 'r') as file: data = yaml.safe_load(file) data['spec']['replicator']['maxJobs'] = maxJobs data['spec']['replicator']['maxChurn'] = churn data['spec']['replicator']['interval'] = interval with open(yaml_path, 'w') as file: yaml.dump(data, file) def run_port_forward(): while True: print("Running kubectl port-forward...") process = subprocess.Popen(["kubectl", "port-forward", "-n", "data-sync-couchdb", "data-sync-couchdb-0", "5984:5984"]) # Wait for a few seconds to see if the command succeeds time.sleep(10) # Check if the process is still running if process.poll() is None: print("kubectl port-forward started successfully.") return else: print("kubectl port-forward hasn't started. Retrying in 10 seconds...") command = "kill -9 $(lsof -t -i:5984)" process = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True) time.sleep(10) def run_cleanup_script(skip=False): if skip: return True try: subprocess.run(["./cleanup.sh"], timeout=220) except: print("Cleanup script timed out after 2 minutes.") return False return True def run_speedHelper_script(maxJobs, churn, interval, username, password, serverURL): subprocess.run(["python3", "speedHelper.py", "--maxjobs", str(maxJobs), "--churn", str(churn), "--interval", str(interval), "-u", username, "-p", password, "-s", serverURL, "-db", database]) if __name__ == "__main__": # Define the values intervalArr = [5000, 10000, 15000, 40000, 60000] churnArr = [50, 100, 500] maxJobsArr = [50, 80, 10000] for interval in intervalArr: for churn in churnArr: for maxJobs in maxJobsArr: if churn < maxJobs: username = "" password = "" serverURL = "" # "http://localhost:5984/" database = "" skipCleanup = False # Run the cleanup script if run_cleanup_script(skip=skipCleanup): # Run the task3 script if not(skipCleanup): time.sleep(120) run_port_forward() time.sleep(10) run_speedHelper_script(maxJobs, churn, interval, username, password, serverURL)