4 files changed
+24
-19
No files matched your search
+15
-8
@@ -1,8 +1,10 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
import socket
|
import socket
|
||||||
import sys
|
import sys
|
||||||
|
import time
|
||||||
|
import shlex
|
||||||
|
|
||||||
PORT = 5055
|
PORT = 5056
|
||||||
ALL_IPS = [
|
ALL_IPS = [
|
||||||
"172.22.156.3",
|
"172.22.156.3",
|
||||||
"172.22.158.2",
|
"172.22.158.2",
|
||||||
@@ -48,10 +50,9 @@ def grep_all_ips(ips, cmd, if_unit_test):
|
|||||||
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
client_socket.connect((ip, PORT))
|
client_socket.connect((ip, PORT))
|
||||||
|
|
||||||
if if_unit_test:
|
filename = f"machine.{i + 1}.test.log" if if_unit_test else f"machine.{i + 1}.log"
|
||||||
full_cmd = cmd + f" ./machine.{i + 1}.test.log"
|
|
||||||
else:
|
full_cmd = shlex.join(cmd + [filename])
|
||||||
full_cmd = cmd + f" ./machine.{i + 1}.log"
|
|
||||||
|
|
||||||
send_message(client_socket, full_cmd)
|
send_message(client_socket, full_cmd)
|
||||||
data = receive_message(client_socket)
|
data = receive_message(client_socket)
|
||||||
@@ -73,8 +74,12 @@ def grep_all_ips(ips, cmd, if_unit_test):
|
|||||||
|
|
||||||
#main
|
#main
|
||||||
#if unit test flag exists, then use the test log files instead of the actual log files
|
#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"])
|
cmd = ["grep", *[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)
|
#track time
|
||||||
|
start_time = time.perf_counter()
|
||||||
|
is_unit_test = "-t" in sys.argv
|
||||||
|
match_count = grep_all_ips(ALL_IPS, cmd, if_unit_test=is_unit_test)
|
||||||
|
end_time = time.perf_counter()
|
||||||
|
|
||||||
print("=========================== SUMMARY ===========================")
|
print("=========================== SUMMARY ===========================")
|
||||||
for i, count in enumerate(match_count):
|
for i, count in enumerate(match_count):
|
||||||
@@ -88,5 +93,7 @@ for i, count in enumerate(match_count):
|
|||||||
print(f"machine.{i + 1}.test.log: {count} matches")
|
print(f"machine.{i + 1}.test.log: {count} matches")
|
||||||
else:
|
else:
|
||||||
print(f"machine.{i + 1}.log: {count} matches")
|
print(f"machine.{i + 1}.log: {count} matches")
|
||||||
print(f"Total matches: {max(0, sum(match_count))}")
|
total_matches = sum(count for count in match_count if count > 0)
|
||||||
|
print(f"Total matches: {total_matches}")
|
||||||
print("===============================================================")
|
print("===============================================================")
|
||||||
|
print(f"Time taken: {end_time - start_time:.2f} seconds")
|
||||||
@@ -3,13 +3,13 @@
|
|||||||
if [[ "$1" == "all" ]]; then
|
if [[ "$1" == "all" ]]; then
|
||||||
for i in {1..10}; do
|
for i in {1..10}; do
|
||||||
echo "Killing server$i..."
|
echo "Killing server$i..."
|
||||||
ssh -o BatchMode=yes "server$i" "fuser -k -9 5055/tcp"
|
ssh -o BatchMode=yes "server$i" "fuser -k -9 5056/tcp"
|
||||||
echo ""
|
echo ""
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
for i in "$@"; do
|
for i in "$@"; do
|
||||||
echo "Killing server$i..."
|
echo "Killing server$i..."
|
||||||
ssh -o BatchMode=yes "server$i" "fuser -k -9 5055/tcp"
|
ssh -o BatchMode=yes "server$i" "fuser -k -9 5056/tcp"
|
||||||
echo ""
|
echo ""
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
+5
-7
@@ -5,7 +5,7 @@ import subprocess
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
HOST = "0.0.0.0"
|
HOST = "0.0.0.0"
|
||||||
PORT = 5055
|
PORT = 5056
|
||||||
|
|
||||||
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
|
||||||
@@ -44,6 +44,7 @@ while True:
|
|||||||
conn, addr = server_socket.accept()
|
conn, addr = server_socket.accept()
|
||||||
print(f"Connected by {addr}")
|
print(f"Connected by {addr}")
|
||||||
|
|
||||||
|
try:
|
||||||
command = receive_message(conn)
|
command = receive_message(conn)
|
||||||
if command is None:
|
if command is None:
|
||||||
conn.close()
|
conn.close()
|
||||||
@@ -51,18 +52,15 @@ while True:
|
|||||||
|
|
||||||
command_args = shlex.split(command)
|
command_args = shlex.split(command)
|
||||||
|
|
||||||
if not command_args or command_args[0] != "grep":
|
|
||||||
response = "Invalid command. Please use the 'grep' command."
|
|
||||||
send_message(conn, response)
|
|
||||||
conn.close()
|
|
||||||
continue
|
|
||||||
|
|
||||||
command_args.insert(1, "-n")
|
command_args.insert(1, "-n")
|
||||||
|
|
||||||
result = subprocess.run(command_args, cwd=SCRIPT_DIR, capture_output=True, text=True)
|
result = subprocess.run(command_args, cwd=SCRIPT_DIR, capture_output=True, text=True)
|
||||||
|
|
||||||
send_message(conn, result.stdout + result.stderr)
|
send_message(conn, result.stdout + result.stderr)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
None
|
||||||
|
finally:
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
server_socket.close()
|
server_socket.close()
|
||||||
+2
-2
@@ -304,9 +304,9 @@ print(f"Running grep command on a {machine_num} random machine...")
|
|||||||
for i in tests:
|
for i in tests:
|
||||||
result = subprocess.run(["ssh", f"asing271@{ALL_IPS[machine_num - 1]}", f"cd ~/fa26_cs425_.group-mp_.team-01/MP1 && grepp {i} -t"], capture_output=True, text=True)
|
result = subprocess.run(["ssh", f"asing271@{ALL_IPS[machine_num - 1]}", f"cd ~/fa26_cs425_.group-mp_.team-01/MP1 && grepp {i} -t"], capture_output=True, text=True)
|
||||||
if result.stdout.strip() == results[tests.index(i)].strip():
|
if result.stdout.strip() == results[tests.index(i)].strip():
|
||||||
print("PASS {i} test")
|
print(f"PASS {i} test")
|
||||||
else:
|
else:
|
||||||
print("FAIL {i} test")
|
print(f"FAIL {i} test")
|
||||||
|
|
||||||
#delete log files on all the machines after running this test
|
#delete log files on all the machines after running this test
|
||||||
print("Deleting log files on all machines...")
|
print("Deleting log files on all machines...")
|
||||||
|
|||||||
Reference in new issue
Block a user