forked from fabric8-analytics/fabric8-analytics-data-model
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sanitycheck.py
61 lines (45 loc) · 1.53 KB
/
sanitycheck.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
"""Sanity check of the graph DB REST API."""
from graph_manager import BayesianGraph
import time
import sys
import logging
import config
logging.basicConfig()
logger = logging.getLogger(config.APP_NAME)
logger.setLevel(logging.DEBUG)
MAX_DELAY = 20 * 60 # 20 minutes
def test_http_connection():
"""Test the connection to a graph DB and the result send from the DB."""
result = BayesianGraph.execute("g.V().count()")
code, data = result
logger.info(result)
# logger.info code
# logger.info data
# logger.info data['result']['data']
assert (code is True)
assert (data['result']['data'][0] >= 0)
logger.info("Connection to HTTP endpoint: SUCCESS")
def time_remaining(start_time, current_time, max_delay=MAX_DELAY):
"""Compute the remaining time."""
return max_delay - (current_time - start_time)
def main():
"""Start the sanity check of the graph DB REST API."""
waittime = 5
start_time = time.time()
logger.info("Connecting to HTTP...")
while time_remaining(start_time, time.time()) > 0:
try:
test_http_connection()
break
except Exception as e:
logger.info("Connection to HTTP endpoint: FAILED... %s" % e)
logger.info("Retrying after %s seconds" % waittime)
time.sleep(waittime)
if time_remaining(start_time, time.time() > 0):
return sys.exit(0)
else:
return sys.exit(-1)
if __name__ == "__main__":
logger.info("Starting sanitycheck")
main()
logger.info("Ending sanitycheck")