diff --git a/MP1/client.py b/MP1/client.py index 20a2906..c1a6a3f 100644 --- a/MP1/client.py +++ b/MP1/client.py @@ -40,7 +40,7 @@ def receive_message(sock): received_data = receive_exact(sock, message_length) return received_data.decode('utf-8') -def grep_all_ips(ips, cmd): +def grep_all_ips(ips, cmd, if_unit_test): match_count = [] for i, ip in enumerate(ips): @@ -48,7 +48,10 @@ def grep_all_ips(ips, cmd): client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) client_socket.connect((ip, PORT)) - full_cmd = cmd + f" ./machine.{i + 1}.log" + if if_unit_test: + full_cmd = cmd + f" ./machine.{i + 1}.test.log" + else: + full_cmd = cmd + f" ./machine.{i + 1}.log" send_message(client_socket, full_cmd) data = receive_message(client_socket) @@ -69,8 +72,9 @@ def grep_all_ips(ips, cmd): return match_count #main -cmd = "grep " + " ".join(sys.argv[1:]) -match_count = grep_all_ips(ALL_IPS, cmd) +#if unit test flag exists, then use the test log files instead of the actual log files +cmd = "grep " + " ".join([arg for arg in sys.argv[1:] if arg != "-t"]) +match_count = grep_all_ips(ALL_IPS, cmd, if_unit_test=[x for x in sys.argv].count("-t") > 0) print("=========================== SUMMARY ===========================") for i, count in enumerate(match_count): diff --git a/MP1/test.py b/MP1/test.py index d20c24e..a8874c5 100644 --- a/MP1/test.py +++ b/MP1/test.py @@ -19,20 +19,22 @@ 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(["vpn", "ssh", f"asing271@{ip}", "cd ~/fa26_cs425_.group-mp_.team-01/MP1 && python3 generate_log.py {i + 1} 100"]) + subprocess.run(["vpn", "ssh", f"asing271@{ip}", f"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(["vpn", "ssh", f"asing271@{ip}", "cd ~/fa26_cs425_.group-mp_.team-01/MP1 && python3 server.py &"]) +# print("Starting server on all machines...") +# for i, ip in enumerate(ALL_IPS): +# print(f"Starting server on machine {i + 1} ({ip})...") +# subprocess.run([ +# "vpn", "ssh", f"asing271@{ip}", "cd ~/fa26_cs425_.group-mp_.team-01/MP1 && setsid -f python3 server.py > server.log 2>&1 < /dev/null"]) #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(["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}") +# print("Running grep command on a random machine...") +# machine_num = random.randint(1, len(ALL_IPS)) +# result = subprocess.run(["vpn", "ssh", f"asing271@{ALL_IPS[machine_num - 1]}", f"cd ~/fa26_cs425_.group-mp_.team-01/MP1 && grepp '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"]) +# 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"])