From be8eee466a5d17a4cf556ad42871b2437540f6d2 Mon Sep 17 00:00:00 2001 From: Miroslav Los Date: Wed, 20 Nov 2019 16:01:08 +0100 Subject: Fix relative imports and invalid exception handling Make proper relative or absolute imports within miss_htbt_service. Use proper except Class as variable syntax. Avoid multiple parameters to print() for potential python2 usage. Add missing original AT&T license text to test modules. Add attribution to commiter's employer to modified files. Trailing whitespace fixes. Signed-off-by: Miroslav Los Issue-ID: DCAEGEN2-1939 Change-Id: Ibfc4bea3e33a512d06a41050ba5e591121eb9454 --- miss_htbt_service/htbtworker.py | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'miss_htbt_service/htbtworker.py') diff --git a/miss_htbt_service/htbtworker.py b/miss_htbt_service/htbtworker.py index 2c206ce..c02f817 100644 --- a/miss_htbt_service/htbtworker.py +++ b/miss_htbt_service/htbtworker.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 # Copyright 2018 AT&T Intellectual Property, Inc. All rights reserved. +# Copyright (c) 2019 Pantheon.tech. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -12,7 +13,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# +# # Author Prakash Hosangady(ph553f@att.com) # Simple Microservice # Tracks Heartbeat messages on input topic in DMaaP @@ -21,11 +22,11 @@ import psycopg2 import requests import os +import os.path as path import json,sys,time -import misshtbtd as db import logging -import get_logger -import os.path as path +from . import misshtbtd as db +from . import get_logger _logger = get_logger.get_logger(__name__) @@ -58,7 +59,7 @@ def process_msg(jsfile,user_name, password, ip_address, port_num, db_name): time.sleep(10) else: break - + if(os.getenv('pytest', "") == 'test'): eventnameList = ["Heartbeat_vDNS","Heartbeat_vFW","Heartbeat_xx"] connection_db = 0 @@ -66,7 +67,7 @@ def process_msg(jsfile,user_name, password, ip_address, port_num, db_name): connection_db = postgres_db_open(user_name, password, ip_address, port_num, db_name) cur = connection_db.cursor() db_query = "Select event_name from vnf_table_1" - cur.execute(db_query) + cur.execute(db_query) eventnameList = [item[0] for item in cur.fetchall()] msg="\n\nHBT:eventnameList values ", eventnameList _logger.info(msg) @@ -131,7 +132,7 @@ def process_msg(jsfile,user_name, password, ip_address, port_num, db_name): _logger.info(msg) cur.execute("CREATE TABLE vnf_table_2 (EVENT_NAME varchar , SOURCE_NAME_KEY integer , PRIMARY KEY(EVENT_NAME,SOURCE_NAME_KEY),LAST_EPO_TIME BIGINT, SOURCE_NAME varchar, CL_FLAG integer);") else: - msg="HBT:vnf_table_2 is already there" + msg="HBT:vnf_table_2 is already there" _logger.info(msg) if(eventName in eventnameList): #pragma: no cover db_query = "Select source_name_count from vnf_table_1 where event_name='%s'" %(eventName) @@ -188,9 +189,9 @@ def process_msg(jsfile,user_name, password, ip_address, port_num, db_name): commit_and_close_db(connection_db) if(os.getenv('pytest', "") != 'test'): cur.close() - + def postgres_db_open(username,password,host,port,database_name): - + if(os.getenv('pytest', "") == 'test'): return True connection = psycopg2.connect(database=database_name, user = username, password = password, host = host, port =port) @@ -209,9 +210,9 @@ def db_table_creation_check(connection_db,table_name): return True else: return False - - - except (psycopg2.DatabaseError, e): + + + except psycopg2.DatabaseError as e: msg = 'COMMON:Error %s' % e _logger.error(msg) finally: @@ -223,7 +224,7 @@ def commit_db(connection_db): try: connection_db.commit() # <--- makes sure the change is shown in the database return True - except(psycopg2.DatabaseError, e): + except psycopg2.DatabaseError as e: msg = 'COMMON:Error %s' % e _logger.error(msg) return False @@ -235,7 +236,7 @@ def commit_and_close_db(connection_db): connection_db.commit() # <--- makes sure the change is shown in the database connection_db.close() return True - except(psycopg2.DatabaseError, e): + except psycopg2.DatabaseError as e: msg = 'COMMON:Error %s' % e _logger.error(msg) return False -- cgit 1.2.3-korg