b1132c0aeb3810c7524b67b0a721da69964da582
[sdc.git] /
1 #!/usr/bin/python
2 import subprocess
3 #from time import sleep
4 import time
5 from datetime import datetime
6
7 BE_IP="<%= @be_ip %>"
8
9 class bcolors:
10     HEADER    = '\033[95m'
11     OKBLUE    = '\033[94m'
12     OKGREEN   = '\033[92m'
13     WARNING   = '\033[93m'
14     FAIL      = '\033[91m'
15     ENDC      = '\033[0m'
16     BOLD      = '\033[1m'
17     UNDERLINE = '\033[4m'
18
19
20 ##############################
21 #    Functions
22 ##############################
23 def checkBackend():
24     command="curl -s -o /dev/null -I -w \"%{http_code}\" -i http://" + BE_IP + ":8080/sdc2/rest/v1/user/jh0003"
25
26     proc = subprocess.Popen( command , shell=True , stdout=subprocess.PIPE )
27     (out, err) = proc.communicate()
28     result = out.strip()
29     return result
30
31 ##############################
32 #    Main
33 ##############################
34
35 for i in range(1,10):
36     myResult = checkBackend()
37     if myResult == '200':
38         print '[INFO]: Backend is up and running'
39         beStat=1
40         break
41     else:
42         currentTime = datetime.now()
43         print '[ERROR]: ' + currentTime.strftime('%Y/%m/%d %H:%M:%S') + bcolors.FAIL + ' Backend not responding, try #' + str(i) + bcolors.ENDC
44         time.sleep(10)
45
46 if beStat == 0:
47     print '[ERROR]: ' + time.strftime('%Y/%m/%d %H:%M:%S') + bcolors.FAIL + 'Backend is DOWN :-(' + bcolors.ENDC
48     exit()