-
Notifications
You must be signed in to change notification settings - Fork 2
/
check-zoobar.py
executable file
·83 lines (64 loc) · 2.08 KB
/
check-zoobar.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env python3
import os
import sys
import atexit
import time
import subprocess
import traceback
import sqlite3
from typing import List
from stat import *
thisdir = os.path.dirname(os.path.abspath(__file__))
verbose = False
def green(s: str) -> str:
return '\033[1;32m%s\033[m' % s
def red(s: str) -> str:
return '\033[1;31m%s\033[m' % s
def log(*m: str) -> None:
print(" ".join(m), file=sys.stderr)
def log_exit(*m: str) -> None:
log(red("ERROR:"), *m)
exit(1)
def file_read(pn: str) -> str:
with open(pn) as fp:
return fp.read()
def sh(cmd: str, exit_onerr: bool = True) -> None:
if verbose: log("+", cmd)
if os.system(cmd) != 0 and exit_onerr:
log_exit("running shell command:", cmd)
def killall() -> None:
sh("killall zookld zookd zookfs zookd-exstack zookfs-exstack zookd-nxstack zookfs-nxstack >/dev/null 2>&1", exit_onerr=False)
scripts = "echo-server.py auth-server.py bank-server.py".split(" ")
for script in scripts:
sh("pkill -f 'python3 .*%s' >/dev/null 2>&1" % script, exit_onerr=False)
def setup() -> None:
log("+ removing zoobar db")
sh("rm -rf zoobar/db")
log("+ running make.. output in /tmp/make.out")
sh("make clean >/dev/null")
sh("make all >/tmp/make.out 2>&1")
sh("touch /tmp/zook-start-wait")
log("+ running zookd in the background.. output in /tmp/zookd.out")
zookd_out = open("/tmp/zookd.out", "w")
subprocess.Popen(["./zookd", "8080"], stdout=zookd_out, stderr=zookd_out)
atexit.register(killall)
sh("inotifywait -qqe delete_self -t 20 /tmp/zook-start-wait 2>/dev/null", False)
import z_client
def check_ex0() -> None:
x = z_client.check('127.0.0.1')
if not x[0]:
log(red("FAIL"), "Zoobar app functionality", x[1])
exit(1)
else:
log(green("PASS"), "Zoobar app functionality")
def main() -> None:
if '-v' in sys.argv:
global verbose
verbose = True
try:
setup()
check_ex0()
except Exception:
log_exit(traceback.format_exc())
if __name__ == "__main__":
main()