3 #from time import sleep
5 from datetime import datetime
8 BE_PORT="<%= @be_port %>"
21 ##############################
23 ##############################
25 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://" + BE_IP + ":" + BE_PORT + "/sdc2/rest/v1/user/jh0003"
27 proc = subprocess.Popen( command , shell=True , stdout=subprocess.PIPE )
28 (out, err) = proc.communicate()
33 def checkUser(userName):
34 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://" + BE_IP + ":" + BE_PORT + "/sdc2/rest/v1/user/" + userName
36 proc = subprocess.Popen( command , shell=True , stdout=subprocess.PIPE )
37 (out, err) = proc.communicate()
44 def createUser( firstName, lastName, userId , email_dom , role ):
45 print '[INFO] create first:[' + firstName + '], last:[' + lastName + '], Id:[' + userId + '], email:[' + userId + '@' + email_dom + '], role:[' + role +']'
46 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://" + BE_IP + ":" + BE_PORT + "/sdc2/rest/v1/user/ -d '{\"firstName\": '" + firstName + "', \"lastName\": '" + lastName + "',\"userId\": '" + userId + "',\"email\": '" + userId + "@" + email_dom + "',\"role\": '" + role + "'}'"
48 proc = subprocess.Popen( command , shell=True , stdout=subprocess.PIPE)
49 (out, err) = proc.communicate()
56 ##############################
58 ##############################
59 userId = [ "demo" , "op0001" , "gv0001" , "jh0003" , "jm0007" , "cs0008" ]
60 firstName = [ "demo" , "Oper" , "Giuseppe" , "Jimmy" , "Joni" , "Carlos" ]
61 lastName = [ "demo" , "P" , "Verdi" , "Hendrix" , "Mitchell" , "Santana" ]
62 role = [ "ADMIN" , "OPS" , "GOVERNOR" , "ADMIN" , "TESTER" , "DESIGNER" ]
63 email_dom = "openecomp.org"
67 ##############################
69 ##############################
72 myResult = checkBackend()
74 print '[INFO]: Backend is up and running'
78 currentTime = datetime.now()
79 print '[ERROR]: ' + currentTime.strftime('%Y/%m/%d %H:%M:%S') + bcolors.FAIL + ' Backend not responding, try #' + str(i) + bcolors.ENDC
83 print '[ERROR]: ' + time.strftime('%Y/%m/%d %H:%M:%S') + bcolors.FAIL + 'Backend is DOWN :-(' + bcolors.ENDC
87 myResult = checkUser(user)
88 pos = userId.index(user)
90 print '[INFO]: ' + user + ' already exists'
92 myResult = createUser( firstName[pos], lastName[pos], userId[pos], email_dom, role[pos] )
94 print '[INFO]: ' + userId[pos] + ' created, result: [' + myResult + ']'
96 print '[ERROR]: ' + bcolors.FAIL + userId[pos] + bcolors.ENDC + ' error creating , result: [' + myResult + ']'