3 #from time import sleep
5 from datetime import datetime
8 BE_PORT="<%= @be_port %>"
9 PROTOCOL="<%= @protocol %>"
22 ##############################
24 ##############################
26 command="curl -k -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\" "+PROTOCOL+"://" + BE_IP + ":" + BE_PORT + "/sdc2/rest/v1/user/jh0003"
28 proc = subprocess.Popen( command , shell=True , stdout=subprocess.PIPE )
29 (out, err) = proc.communicate()
34 def checkUser(userName):
35 command="curl -k -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\" "+PROTOCOL+"://" + BE_IP + ":" + BE_PORT + "/sdc2/rest/v1/user/" + userName
37 proc = subprocess.Popen( command , shell=True , stdout=subprocess.PIPE )
38 (out, err) = proc.communicate()
45 def createUser( firstName, lastName, userId , email_dom , role ):
46 print '[INFO] create first:[' + firstName + '], last:[' + lastName + '], Id:[' + userId + '], email:[' + userId + '@' + email_dom + '], role:[' + role +']'
47 command="curl -k -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\" "+PROTOCOL+"://" + BE_IP + ":" + BE_PORT + "/sdc2/rest/v1/user/ -d '{\"firstName\": \"" + firstName + "\", \"lastName\": \"" + lastName + "\",\"userId\": \"" + userId + "\",\"email\": \"" + userId + "@" + email_dom + "\",\"role\": \"" + role + "\"}'"
49 proc = subprocess.Popen( command , shell=True , stdout=subprocess.PIPE)
50 (out, err) = proc.communicate()
57 ##############################
59 ##############################
60 userId = [ "demo" , "op0001" , "gv0001" , "jh0003" , "jm0007" , "cs0008" ]
61 firstName = [ "demo" , "Oper" , "Giuseppe" , "Jimmy" , "Joni" , "Carlos" ]
62 lastName = [ "demo" , "P" , "Verdi" , "Hendrix" , "Mitchell" , "Santana" ]
63 role = [ "ADMIN" , "OPS" , "GOVERNOR" , "ADMIN" , "TESTER" , "DESIGNER" ]
64 email_dom = "openecomp.org"
68 ##############################
70 ##############################
73 myResult = checkBackend()
75 print '[INFO]: Backend is up and running'
79 currentTime = datetime.now()
80 print '[ERROR]: ' + currentTime.strftime('%Y/%m/%d %H:%M:%S') + bcolors.FAIL + ' Backend not responding, try #' + str(i) + bcolors.ENDC
84 print '[ERROR]: ' + time.strftime('%Y/%m/%d %H:%M:%S') + bcolors.FAIL + 'Backend is DOWN :-(' + bcolors.ENDC
88 myResult = checkUser(user)
89 pos = userId.index(user)
91 print '[INFO]: ' + user + ' already exists'
93 myResult = createUser( firstName[pos], lastName[pos], userId[pos], email_dom, role[pos] )
95 print '[INFO]: ' + userId[pos] + ' created, result: [' + myResult + ']'
97 print '[ERROR]: ' + bcolors.FAIL + userId[pos] + bcolors.ENDC + ' error creating , result: [' + myResult + ']'