summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/resources/scripts/sdcBePy/consumers/run.py
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/consumers/run.py
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/consumers/run.py')
-rw-r--r--catalog-be/src/main/resources/scripts/sdcBePy/consumers/run.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/consumers/run.py b/catalog-be/src/main/resources/scripts/sdcBePy/consumers/run.py
new file mode 100644
index 0000000000..59a0b610d8
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/consumers/run.py
@@ -0,0 +1,35 @@
+import time
+
+from sdcBePy.common.healthCheck import check_backend, RETRY_ATTEMPTS, get_args
+from sdcBePy.common.sdcBeProxy import SdcBeProxy
+from sdcBePy.consumers.models.consumerCandidateList import get_consumers
+from sdcBePy.users.run import colors
+
+
+def be_consumers_init(be_ip, be_port, protocol, consumer_candidate_list):
+ sdc_be_proxy = SdcBeProxy(be_ip, be_port, protocol)
+ if check_backend(sdc_be_proxy, RETRY_ATTEMPTS):
+ for consumer in consumer_candidate_list:
+ if sdc_be_proxy.check_user(consumer.consumer_name) != 200:
+ result = sdc_be_proxy.create_consumer(*consumer.get_parameters())
+ if result == 201:
+ print('[INFO]: ' + consumer.consumer_name +
+ ' created, result: [' + str(result) + ']')
+ else:
+ print('[ERROR]: ' + colors.FAIL + consumer.consumer_name + colors.END_C +
+ ' error creating , result: [' + str(result) + ']')
+ else:
+ print('[INFO]: ' + consumer.consumer_name + ' already exists')
+ else:
+ print('[ERROR]: ' + time.strftime('%Y/%m/%d %H:%M:%S') + colors.FAIL
+ + ' Backend is DOWN :-(' + colors.END_C)
+ raise Exception("Cannot communicate with the backend!")
+
+
+def main():
+ be_ip, be_port, protocol = get_args()
+ be_consumers_init(be_ip, be_port, protocol, get_consumers())
+
+
+if __name__ == '__main__':
+ main()