diff --git a/MP1/generate_log.py b/MP1/generate_log.py index 9d4271c..626e537 100644 --- a/MP1/generate_log.py +++ b/MP1/generate_log.py @@ -1,8 +1,8 @@ import random -machine_num = input("Enter the machine number: ") +machine_num = int(sys.argv[1]) machine_log_file = f"machine.{machine_num}.test.log" -num_lines = int(input("Enter the number of log lines to generate: ")) +num_lines = int(sys.argv[2]) log_level = ["TRACE", "DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL", "AUDIT"] diff --git a/MP1/test.py b/MP1/test.py index 8ce66e4..ab080d5 100644 --- a/MP1/test.py +++ b/MP1/test.py @@ -1,5 +1,5 @@ -import pytest import subprocess +import random PORT = 5055 ALL_IPS = [ @@ -16,14 +16,23 @@ ALL_IPS = [ ] #generate log files on all the machines before running this test +print("Generating log files on all machines...") for i, ip in enumerate(ALL_IPS): - subprocess.run(["ssh", "asing@{ip}", "python3", "generate_log.py", str(i + 1), "100"]) + subprocess.run(["vpn", "ssh", f"asing271@{ip}", "cd ~/fa26_cs425_.group-mp_.team-01/MP1 && python3 generate_log.py {i + 1} 100"]) #start the server on all the machines before running this test +print("Starting server on all machines...") for i, ip in enumerate(ALL_IPS): - subprocess.run(["ssh", "asing@{ip}", "python3", "server.py"]) + subprocess.run(["vpn", "ssh", f"asing271@{ip}", "cd ~/fa26_cs425_.group-mp_.team-01/MP1 && python3 server.py &"]) #ssh into one machine at randome +print("Running grep command on a random machine...") machine_num = random.randint(1, len(ALL_IPS)) -result = subprocess.run(["ssh", f"asing@{ALL_IPS[machine_num - 1]}", "grep", "ERROR", f"./machine.{machine_num}.test.log"], capture_output=True, text=True) -print(f"Machine {machine_num} grep result:\n{result.stdout}") \ No newline at end of file +result = subprocess.run(["vpn", "ssh", f"asing271@{ALL_IPS[machine_num - 1]}", "cd ~/fa26_cs425_.group-mp_.team-01/MP1 && grep 'ERROR' f'./machine.{machine_num}.test.log'"], capture_output=True, text=True) +print(f"Machine {machine_num} grep result:\n{result.stdout}") + +#delete log files on all the machines after running this test +print("Deleting log files on all machines...") +for i, ip in enumerate(ALL_IPS): + subprocess.run(["vpn", "ssh", f"asing271@{ip}", "cd ~/fa26_cs425_.group-mp_.team-01/MP1 && rm -f ./machine.*.test.log"]) + \ No newline at end of file