summaryrefslogtreecommitdiffstats
path: root/catalog-be/sdc-backend-init/chef-repo/cookbooks/sdc-catalog-be-setup/templates
diff options
context:
space:
mode:
authorYuli Shlosberg <ys9693@att.com>2018-02-15 12:04:46 +0200
committerYuli Shlosberg <ys9693@att.com>2018-02-21 17:28:40 +0200
commit958c32d2d7a3e5cbd9bc672645cdeb95a49b719a (patch)
tree1ba5b0d1dbece6daa5618a005d6281bbd5c7c1dc /catalog-be/sdc-backend-init/chef-repo/cookbooks/sdc-catalog-be-setup/templates
parent4cc47ac3abe00eda7c04b9955e56dafc819e2657 (diff)
OOM Alignment BE,FE,KBN
Change-Id: I8ff609a6be919d5709ce95af5a6a903aeb7afc43 Issue-ID: SDC-918 Signed-off-by: Yuli Shlosberg <ys9693@att.com>
Diffstat (limited to 'catalog-be/sdc-backend-init/chef-repo/cookbooks/sdc-catalog-be-setup/templates')
-rw-r--r--catalog-be/sdc-backend-init/chef-repo/cookbooks/sdc-catalog-be-setup/templates/default/check_Backend_Health.py.erb48
-rw-r--r--catalog-be/sdc-backend-init/chef-repo/cookbooks/sdc-catalog-be-setup/templates/default/consumers.py.erb91
-rw-r--r--catalog-be/sdc-backend-init/chef-repo/cookbooks/sdc-catalog-be-setup/templates/default/user.py.erb95
3 files changed, 234 insertions, 0 deletions
diff --git a/catalog-be/sdc-backend-init/chef-repo/cookbooks/sdc-catalog-be-setup/templates/default/check_Backend_Health.py.erb b/catalog-be/sdc-backend-init/chef-repo/cookbooks/sdc-catalog-be-setup/templates/default/check_Backend_Health.py.erb
new file mode 100644
index 0000000000..b1132c0aeb
--- /dev/null
+++ b/catalog-be/sdc-backend-init/chef-repo/cookbooks/sdc-catalog-be-setup/templates/default/check_Backend_Health.py.erb
@@ -0,0 +1,48 @@
+#!/usr/bin/python
+import subprocess
+#from time import sleep
+import time
+from datetime import datetime
+
+BE_IP="<%= @be_ip %>"
+
+class bcolors:
+ HEADER = '\033[95m'
+ OKBLUE = '\033[94m'
+ OKGREEN = '\033[92m'
+ WARNING = '\033[93m'
+ FAIL = '\033[91m'
+ ENDC = '\033[0m'
+ BOLD = '\033[1m'
+ UNDERLINE = '\033[4m'
+
+
+##############################
+# Functions
+##############################
+def checkBackend():
+ command="curl -s -o /dev/null -I -w \"%{http_code}\" -i http://" + BE_IP + ":8080/sdc2/rest/v1/user/jh0003"
+
+ proc = subprocess.Popen( command , shell=True , stdout=subprocess.PIPE )
+ (out, err) = proc.communicate()
+ result = out.strip()
+ return result
+
+##############################
+# Main
+##############################
+
+for i in range(1,10):
+ myResult = checkBackend()
+ if myResult == '200':
+ print '[INFO]: Backend is up and running'
+ beStat=1
+ break
+ else:
+ currentTime = datetime.now()
+ print '[ERROR]: ' + currentTime.strftime('%Y/%m/%d %H:%M:%S') + bcolors.FAIL + ' Backend not responding, try #' + str(i) + bcolors.ENDC
+ time.sleep(10)
+
+if beStat == 0:
+ print '[ERROR]: ' + time.strftime('%Y/%m/%d %H:%M:%S') + bcolors.FAIL + 'Backend is DOWN :-(' + bcolors.ENDC
+ exit() \ No newline at end of file
diff --git a/catalog-be/sdc-backend-init/chef-repo/cookbooks/sdc-catalog-be-setup/templates/default/consumers.py.erb b/catalog-be/sdc-backend-init/chef-repo/cookbooks/sdc-catalog-be-setup/templates/default/consumers.py.erb
new file mode 100644
index 0000000000..8a91c637bb
--- /dev/null
+++ b/catalog-be/sdc-backend-init/chef-repo/cookbooks/sdc-catalog-be-setup/templates/default/consumers.py.erb
@@ -0,0 +1,91 @@
+#!/usr/bin/python
+import subprocess
+#from time import sleep
+import time
+from datetime import datetime
+
+BE_IP="<%= @be_ip %>"
+
+class bcolors:
+ HEADER = '\033[95m'
+ OKBLUE = '\033[94m'
+ OKGREEN = '\033[92m'
+ WARNING = '\033[93m'
+ FAIL = '\033[91m'
+ ENDC = '\033[0m'
+ BOLD = '\033[1m'
+ UNDERLINE = '\033[4m'
+
+
+##############################
+# Functions
+##############################
+def checkBackend():
+ command="curl -s -o /dev/null -I -w \"%{http_code}\" -i http://" + BE_IP + ":8080/sdc2/rest/v1/user/jh0003"
+
+ proc = subprocess.Popen( command , shell=True , stdout=subprocess.PIPE )
+ (out, err) = proc.communicate()
+ result = out.strip()
+ return result
+
+
+def checkConsumer(consumerName):
+ 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 + ":8080/sdc2/rest/v1/consumers/" + consumerName
+
+ proc = subprocess.Popen( command , shell=True , stdout=subprocess.PIPE )
+ (out, err) = proc.communicate()
+ result = out.strip()
+ return result
+
+
+def createConsumer( consumerName, consumerSalt, consumerPass ):
+ print '[INFO] ' + consumerName
+ 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 + ":8080/sdc2/rest/v1/consumers/ -d '{\"consumerName\": '" + consumerName + "', \"consumerSalt\": '" + consumerSalt + "',\"consumerPassword\": '" + consumerPass + "'}'"
+
+ proc = subprocess.Popen( command , shell=True , stdout=subprocess.PIPE)
+
+ (out, err) = proc.communicate()
+ result = out.strip()
+ return result
+
+
+
+
+##############################
+# Definitions
+##############################
+consumersList = [ "aai" , "appc" , "dcae" , "mso" , "sdnc" , "vid" , "cognita", "clamp" , "vfc" ]
+salt = "9cd4c3ad2a6f6ce3f3414e68b5157e63"
+password = "35371c046f88c603ccba152cb3db34ec4475cb2e5713f2fc0a43bf18a5243495"
+beStat=0
+
+
+##############################
+# Main
+##############################
+
+for i in range(1,10):
+ myResult = checkBackend()
+ if myResult == '200':
+ print '[INFO]: Backend is up and running'
+ beStat=1
+ break
+ else:
+ currentTime = datetime.now()
+ print '[ERROR]: ' + currentTime.strftime('%Y/%m/%d %H:%M:%S') + bcolors.FAIL + ' Backend not responding, try #' + str(i) + bcolors.ENDC
+ time.sleep(10)
+
+if beStat == 0:
+ print '[ERROR]: ' + time.strftime('%Y/%m/%d %H:%M:%S') + bcolors.FAIL + 'Backend is DOWN :-(' + bcolors.ENDC
+ exit()
+
+for consumer in consumersList:
+ myResult = checkConsumer(consumer)
+ if myResult == '200':
+ print '[INFO]: ' + consumer + ' already exists'
+ else:
+ myResult = createConsumer( consumer, salt, password )
+ if myResult == '201':
+ print '[INFO]: ' + consumer + ' created, result: [' + myResult + ']'
+ else:
+ print '[ERROR]: ' + bcolors.FAIL + consumer + bcolors.ENDC + ' error creating , result: [' + myResult + ']'
diff --git a/catalog-be/sdc-backend-init/chef-repo/cookbooks/sdc-catalog-be-setup/templates/default/user.py.erb b/catalog-be/sdc-backend-init/chef-repo/cookbooks/sdc-catalog-be-setup/templates/default/user.py.erb
new file mode 100644
index 0000000000..83ecf904df
--- /dev/null
+++ b/catalog-be/sdc-backend-init/chef-repo/cookbooks/sdc-catalog-be-setup/templates/default/user.py.erb
@@ -0,0 +1,95 @@
+#!/usr/bin/python
+import subprocess
+#from time import sleep
+import time
+from datetime import datetime
+
+BE_IP="<%= @be_ip %>"
+
+class bcolors:
+ HEADER = '\033[95m'
+ OKBLUE = '\033[94m'
+ OKGREEN = '\033[92m'
+ WARNING = '\033[93m'
+ FAIL = '\033[91m'
+ ENDC = '\033[0m'
+ BOLD = '\033[1m'
+ UNDERLINE = '\033[4m'
+
+
+##############################
+# Functions
+##############################
+def checkBackend():
+ 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 + ":8080/sdc2/rest/v1/user/jh0003"
+
+ proc = subprocess.Popen( command , shell=True , stdout=subprocess.PIPE )
+ (out, err) = proc.communicate()
+ result = out.strip()
+ return result
+
+
+def checkUser(userName):
+ 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 + ":8080/sdc2/rest/v1/user/" + userName
+
+ proc = subprocess.Popen( command , shell=True , stdout=subprocess.PIPE )
+ (out, err) = proc.communicate()
+ result = out.strip()
+ return result
+
+
+
+
+def createUser( firstName, lastName, userId , email_dom , role ):
+ print '[INFO] create first:[' + firstName + '], last:[' + lastName + '], Id:[' + userId + '], email:[' + userId + '@' + email_dom + '], role:[' + role +']'
+ 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 + ":8080/sdc2/rest/v1/user/ -d '{\"firstName\": '" + firstName + "', \"lastName\": '" + lastName + "',\"userId\": '" + userId + "',\"email\": '" + userId + "@" + email_dom + "',\"role\": '" + role + "'}'"
+
+ proc = subprocess.Popen( command , shell=True , stdout=subprocess.PIPE)
+ (out, err) = proc.communicate()
+ result = out.strip()
+ return result
+
+
+
+
+##############################
+# Definitions
+##############################
+userId = [ "demo" , "op0001" , "gv0001" , "jh0003" , "jm0007" , "cs0008" ]
+firstName = [ "demo" , "Oper" , "Giuseppe" , "Jimmy" , "Joni" , "Carlos" ]
+lastName = [ "demo" , "P" , "Verdi" , "Hendrix" , "Mitchell" , "Santana" ]
+role = [ "ADMIN" , "OPS" , "GOVERNOR" , "ADMIN" , "TESTER" , "DESIGNER" ]
+email_dom = "openecomp.org"
+beStat=0
+
+
+##############################
+# Main
+##############################
+
+for i in range(1,10):
+ myResult = checkBackend()
+ if myResult == '200':
+ print '[INFO]: Backend is up and running'
+ beStat=1
+ break
+ else:
+ currentTime = datetime.now()
+ print '[ERROR]: ' + currentTime.strftime('%Y/%m/%d %H:%M:%S') + bcolors.FAIL + ' Backend not responding, try #' + str(i) + bcolors.ENDC
+ time.sleep(10)
+
+if beStat == 0:
+ print '[ERROR]: ' + time.strftime('%Y/%m/%d %H:%M:%S') + bcolors.FAIL + 'Backend is DOWN :-(' + bcolors.ENDC
+ exit()
+
+for user in userId:
+ myResult = checkUser(user)
+ pos = userId.index(user)
+ if myResult == '200':
+ print '[INFO]: ' + user + ' already exists'
+ else:
+ myResult = createUser( firstName[pos], lastName[pos], userId[pos], email_dom, role[pos] )
+ if myResult == '201':
+ print '[INFO]: ' + userId[pos] + ' created, result: [' + myResult + ']'
+ else:
+ print '[ERROR]: ' + bcolors.FAIL + userId[pos] + bcolors.ENDC + ' error creating , result: [' + myResult + ']'