aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/resources/scripts/sdcBePy/common
diff options
context:
space:
mode:
authork.kedron <k.kedron@partner.samsung.com>2020-06-04 10:46:47 +0200
committerk.kedron <k.kedron@partner.samsung.com>2020-06-24 11:16:53 +0200
commitfca8a0b1af32083b8ea025135b120091aec9714f (patch)
tree4bb568ca92ad037801937d1cf2264b4dff923c52 /catalog-be/src/main/resources/scripts/sdcBePy/common
parent7027b33eb41947e6799392d392283b09110158d1 (diff)
Refactoring the check backend, create consumers
Continue refactoring: - added script for healthCheck, create new consumers - also update chef recipes to use new script Issue-ID: SDC-2784 Signed-off-by: Krystian Kedron <k.kedron@partner.samsung.com> Change-Id: I158d816362f91f74b217fe85112cf7c14da8f1ec
Diffstat (limited to 'catalog-be/src/main/resources/scripts/sdcBePy/common')
-rw-r--r--catalog-be/src/main/resources/scripts/sdcBePy/common/healthCheck.py55
-rwxr-xr-xcatalog-be/src/main/resources/scripts/sdcBePy/common/sdcBeProxy.py10
2 files changed, 65 insertions, 0 deletions
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/common/healthCheck.py b/catalog-be/src/main/resources/scripts/sdcBePy/common/healthCheck.py
new file mode 100644
index 0000000000..7d8558d644
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/common/healthCheck.py
@@ -0,0 +1,55 @@
+#!/usr/bin/env python3
+import sys
+import time
+from argparse import ArgumentParser
+from datetime import datetime
+
+from sdcBePy.common.bColors import BColors
+from sdcBePy.common.sdcBeProxy import SdcBeProxy
+
+colors = BColors()
+
+RETRY_TIME = 10
+RETRY_ATTEMPTS = 10
+
+
+def check_backend(sdc_be_proxy=None, reply_append_count=1, be_host=None, be_port=None, scheme=None, debug=False):
+ if sdc_be_proxy is None:
+ sdc_be_proxy = SdcBeProxy(be_host, be_port, scheme, debug=debug)
+
+ for i in range(1, reply_append_count + 1):
+ if sdc_be_proxy.check_backend() == 200:
+ print('[INFO]: Backend is up and running')
+ return True
+ else:
+ print('[WARRING]: ' + datetime.now().strftime('%Y/%m/%d %H:%M:%S') + colors.FAIL
+ + ' Backend not responding, try #' + str(i) + colors.END_C)
+ time.sleep(RETRY_TIME)
+
+ return False
+
+
+def run(be_host, be_port, protocol):
+ if not check_backend(reply_append_count=RETRY_ATTEMPTS, be_host=be_host, be_port=be_port, scheme=protocol):
+ print('[ERROR]: ' + time.strftime('%Y/%m/%d %H:%M:%S') + colors.FAIL + ' Backend is DOWN :-(' + colors.END_C)
+ sys.exit()
+
+
+def get_args():
+ parser = ArgumentParser()
+
+ parser.add_argument('-i', '--ip', required=True)
+ parser.add_argument('-p', '--port', required=True)
+ parser.add_argument('--https', action='store_true')
+
+ args = parser.parse_args()
+
+ return [args.ip, args.port, 'https' if args.https else 'http']
+
+
+def main():
+ run(*get_args())
+
+
+if __name__ == '__main__':
+ main()
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/common/sdcBeProxy.py b/catalog-be/src/main/resources/scripts/sdcBePy/common/sdcBeProxy.py
index 48261704f7..6fea657fab 100755
--- a/catalog-be/src/main/resources/scripts/sdcBePy/common/sdcBeProxy.py
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/common/sdcBeProxy.py
@@ -35,6 +35,16 @@ class SdcBeProxy:
'role': role
}))
+ def check_consumer(self, consumer_name):
+ return self.con.get("/sdc2/rest/v1/consumers/" + consumer_name)
+
+ def create_consumer(self, consumer_name, slat, password):
+ return self.con.post("/sdc2/rest/v1/consumers/", json.dumps({
+ 'consumerName': consumer_name,
+ 'consumerSalt': slat,
+ 'consumerPassword': password
+ }))
+
def post_file(self, path, multi_part_form_data):
return self.con.post_file(path, multi_part_form_data)