From 81ea24a3e8fca5a11191129e92ab1b9bc985759d Mon Sep 17 00:00:00 2001 From: xudan Date: Thu, 16 Nov 2017 06:30:35 -0500 Subject: Remove redundant log when launch local DB The script launch_db.sh will print "Already Exists" logs when the DB has been initialized by the data stored in JumpHost. Ignore this kind of logs because it won't affect the launch of the DB but it will confuse users. JIRA: DOVETAIL-557 Change-Id: I23616b10bbadc49888731e943d0a4ee4425045f5 Signed-off-by: xudan --- dovetail/utils/local_db/init_db.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/dovetail/utils/local_db/init_db.py b/dovetail/utils/local_db/init_db.py index 365927b5..c67ef56d 100644 --- a/dovetail/utils/local_db/init_db.py +++ b/dovetail/utils/local_db/init_db.py @@ -16,7 +16,6 @@ db_host_ip = sys.argv[1] testapi_port = sys.argv[2] target_url = 'http://{}:{}/api/v1'.format(db_host_ip, testapi_port) -print(target_url) dir_path = os.path.dirname(os.path.realpath(__file__)) @@ -27,7 +26,15 @@ def get(url): def post(url, data): headers = {'Content-Type': 'application/json'} res = requests.post(url, data=json.dumps(data), headers=headers) - print(res.text) + try: + status_code = vars(res)["status_code"] + if (status_code == 403 and "Already Exists" in vars(res)["_content"]) \ + or status_code == 200: + return + else: + print(res.text) + except Exception as e: + print("Error: exception {}.".format(e)) def pod(): @@ -55,7 +62,6 @@ def cases(): for c in cases["testcases"]: target = '{}/projects/{}/cases'.format(target_url, c['project_name']) - print(target) post(target, c) except: print("useless data") -- cgit 1.2.3-korg