Files
fa26_cs425_.group-mp_.team-01/MP1/test.py
T
2026-09-12 22:22:48 -05:00

39 lines
1.4 KiB
Python

import subprocess
import random
import sys
PORT = 5055
ALL_IPS = [
"172.22.156.3",
"172.22.158.2",
"172.22.94.2",
"172.22.156.4",
"172.22.158.3",
"172.22.94.3",
"172.22.156.5",
"172.22.158.4",
"172.22.94.4",
"172.22.156.6"
]
#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"])
#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 &"])
#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}")
#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"])