3 #from time import sleep
5 from datetime import datetime
18 ##############################
20 ##############################
22 command="curl -s -o /dev/null -I -w \"%{http_code}\" -i http://localhost:8080/sdc2/rest/v1/user/jh0003"
24 proc = subprocess.Popen( command , shell=True , stdout=subprocess.PIPE )
25 (out, err) = proc.communicate()
30 def checkUser(userName):
31 command="curl -s -o /dev/null -I -w \"%{http_code}\" -i -H \"Accept: application/json; charset=UTF-8\" -H \"Content-Type: application/json\" -H \"USER_ID: jh0003\" http://localhost:8080/sdc2/rest/v1/user/" + userName
33 proc = subprocess.Popen( command , shell=True , stdout=subprocess.PIPE )
34 (out, err) = proc.communicate()
41 def createUser( firstName, lastName, userId , email_dom , role ):
42 print '[INFO] create first:[' + firstName + '], last:[' + lastName + '], Id:[' + userId + '], email:[' + userId + '@' + email_dom + '], role:[' + role +']'
43 command="curl -s -o /dev/null -w \"%{http_code}\" -X POST -i -H \"Accept: application/json; charset=UTF-8\" -H \"Content-Type: application/json\" -H \"USER_ID: jh0003\" http://localhost:8080/sdc2/rest/v1/user/ -d '{\"firstName\": '" + firstName + "', \"lastName\": '" + lastName + "',\"userId\": '" + userId + "',\"email\": '" + userId + "@" + email_dom + "',\"role\": '" + role + "'}'"
45 proc = subprocess.Popen( command , shell=True , stdout=subprocess.PIPE)
46 (out, err) = proc.communicate()
53 ##############################
55 ##############################
56 userId = [ "demo" , "op0001" , "gv0001" , "jh0003" , "jm0007" , "cs0008" ]
57 firstName = [ "demo" , "Oper" , "Giuseppe" , "Jimmy" , "Joni" , "Carlos" ]
58 lastName = [ "demo" , "P" , "Verdi" , "Hendrix" , "Mitchell" , "Santana" ]
59 role = [ "ADMIN" , "OPS" , "ADMIN" , "GOVERNOR" , "TESTER" , "DESIGNER" ]
60 email_dom = "openecomp.org"
64 ##############################
66 ##############################
69 myResult = checkBackend()
71 print '[INFO]: Backend is up and running'
75 currentTime = datetime.now()
76 print '[ERROR]: ' + currentTime.strftime('%Y/%m/%d %H:%M:%S') + bcolors.FAIL + ' Backend not responding, try #' + str(i) + bcolors.ENDC
80 print '[ERROR]: ' + time.strftime('%Y/%m/%d %H:%M:%S') + bcolors.FAIL + 'Backend is DOWN :-(' + bcolors.ENDC
84 myResult = checkUser(user)
85 pos = userId.index(user)
87 print '[INFO]: ' + user + ' already exists'
89 myResult = createUser( firstName[pos], lastName[pos], userId[pos], email_dom, role[pos] )
91 print '[INFO]: ' + userId[pos] + ' created, result: [' + myResult + ']'
93 print '[ERROR]: ' + bcolors.FAIL + userId[pos] + bcolors.ENDC + ' error creating , result: [' + myResult + ']'