diff --git a/MP1/generate_log.py b/MP1/generate_log.py index 2272e9e..9d4271c 100644 --- a/MP1/generate_log.py +++ b/MP1/generate_log.py @@ -1,7 +1,7 @@ import random machine_num = input("Enter the machine number: ") -machine_log_file = f"machine.{machine_num}.log" +machine_log_file = f"machine.{machine_num}.test.log" num_lines = int(input("Enter the number of log lines to generate: ")) log_level = ["TRACE", "DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL", "AUDIT"] @@ -20,7 +20,12 @@ log_messages = [ "System update installed.", ] +#first 11 in this log file should be extact order in log_messages list and then random from there + for i in range(num_lines): - log_entry = f"[{machine_num}-{random.randint(1000, 9999)}] [{log_level[random.randint(0, len(log_level) - 1)]}] {log_messages[random.randint(0, len(log_messages) - 1)]}\n" - with open(machine_log_file, "a") as file: - file.write(log_entry) \ No newline at end of file + if i < 11: + log_entry = f"[{machine_num}-{i}] [{log_level[i % len(log_level)]}] {log_messages[i]}\n" + else: + log_entry = f"[{machine_num}-{i}] [{log_level[random.randint(0, len(log_level) - 1)]}] {log_messages[random.randint(0, len(log_messages) - 1)]}\n" + with open(machine_log_file, "a") as file: + file.write(log_entry) \ No newline at end of file diff --git a/MP1/test.py b/MP1/test.py new file mode 100644 index 0000000..8ce66e4 --- /dev/null +++ b/MP1/test.py @@ -0,0 +1,29 @@ +import pytest +import subprocess + +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 +for i, ip in enumerate(ALL_IPS): + subprocess.run(["ssh", "asing@{ip}", "python3", "generate_log.py", str(i + 1), "100"]) + +#start the server on all the machines before running this test +for i, ip in enumerate(ALL_IPS): + subprocess.run(["ssh", "asing@{ip}", "python3", "server.py"]) + +#ssh into one machine at randome +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