-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathverify_ssd_storage.py
executable file
·53 lines (41 loc) · 1.62 KB
/
verify_ssd_storage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python3
import argparse
import os
import sys
class CustomArgumentParser(argparse.ArgumentParser):
def error(self, _):
self.print_help()
sys.exit(1)
def main():
parser = CustomArgumentParser(description='Compare server_dir and storage_dir')
parser.add_argument('server_dir', help='Path to server directory')
parser.add_argument('storage_dir', help='Path to storage directory')
parser.add_argument('-v', '--verbose', action='store_true', help='Print missing files')
args = parser.parse_args()
server_files = get_files(args.server_dir)
storage_files = get_files(args.storage_dir)
missing_files = find_missing_files(server_files, storage_files)
if args.verbose:
print_missing_files(missing_files)
print_statistics(len(server_files), len(storage_files), len(missing_files))
if len(missing_files) > 0:
print("\033[31mMissing region files found\033[0m")
sys.exit(1)
else:
print("\033[32mServer healthy\033[0m")
def get_files(dir_path):
files = [f for f in os.listdir(dir_path) if f.endswith('.linear')]
return set(files)
def find_missing_files(server_files, storage_files):
return storage_files.difference(server_files)
def print_missing_files(missing_files):
print("Missing files:")
for f in missing_files:
print(f)
def print_statistics(server_files_count, storage_files_count, missing_files_count):
print("Statistics:")
print("Server files: ", server_files_count)
print("Storage files: ", storage_files_count)
print("Missing files: ", missing_files_count)
if __name__ == "__main__":
main()