aboutsummaryrefslogtreecommitdiffstats
path: root/miss_htbt_service/config_notif.py
diff options
context:
space:
mode:
Diffstat (limited to 'miss_htbt_service/config_notif.py')
-rw-r--r--miss_htbt_service/config_notif.py29
1 files changed, 15 insertions, 14 deletions
diff --git a/miss_htbt_service/config_notif.py b/miss_htbt_service/config_notif.py
index 8a10a15..a1d2d8b 100644
--- a/miss_htbt_service/config_notif.py
+++ b/miss_htbt_service/config_notif.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)
# Read the hb_common table
# Update the state to RECONFIGURATION and save the hb_common table
@@ -27,8 +28,8 @@ import json
import psycopg2
from pathlib import Path
import os.path as path
-from mod.trapd_get_cbs_config import get_cbs_config
-import mod.trapd_settings as tds
+from .mod import trapd_settings as tds
+from .mod.trapd_get_cbs_config import get_cbs_config
hb_properties_file = path.abspath(path.join(__file__, "../config/hbproperties.yaml"))
@@ -39,7 +40,7 @@ def postgres_db_open(username,password,host,port,database_name):
try: #pragma: no cover
connection = psycopg2.connect(database=database_name, user = username, password = password, host = host, port =port)
except Exception as e:
- print("HB_Notif::postgress connect error:", e)
+ print("HB_Notif::postgress connect error: %s" % e)
connection = True
return connection
@@ -54,12 +55,12 @@ def db_table_creation_check(connection_db,table_name):
database_names = cur.fetchone()
if(database_names is not None):
if(table_name in database_names):
- print("HB_Notif::Postgres has already has table -", table_name)
+ print("HB_Notif::Postgres already has table - %s" % table_name)
return True
else:
- print("HB_Notif::Postgres does not have table - ", table_name)
+ print("HB_Notif::Postgres does not have table - %s" % table_name)
return False
- except (psycopg2.DatabaseError, e):
+ except psycopg2.DatabaseError as e:
print('COMMON:Error %s' % e)
finally:
cur.close()
@@ -72,7 +73,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:
return False
def read_hb_properties_default():
@@ -102,7 +103,7 @@ def read_hb_properties(jsfile):
with open(jsfile, 'r') as outfile:
cfg = json.load(outfile)
except(Exception) as err:
- print("Json file read error - %s",err)
+ print("Json file read error - %s" % err)
return read_hb_properties_default()
try:
ip_address = str(cfg['pg_ipAddress'])
@@ -113,10 +114,10 @@ def read_hb_properties(jsfile):
db_name = dbName.lower()
cbs_polling_required = str(cfg['CBS_polling_allowed'])
cbs_polling_interval = str(cfg['CBS_polling_interval'])
- if("SERVICE_NAME" in cfg.keys()):
+ if "SERVICE_NAME" in cfg:
os.environ['SERVICE_NAME'] = str(cfg['SERVICE_NAME'])
except(Exception) as err:
- print("Json file read parameter error -%s ",err)
+ print("Json file read parameter error - %s" % err)
return read_hb_properties_default()
return ip_address, port_num, user_name, password, db_name, cbs_polling_required, cbs_polling_interval
@@ -133,7 +134,7 @@ def read_hb_common(user_name,password,ip_address,port_num,db_name):
query_value = "SELECT process_id,source_name,last_accessed_time,current_state FROM hb_common;"
cur.execute(query_value)
rows = cur.fetchall()
- print("HB_Notif::hb_common contents - ", rows)
+ print("HB_Notif::hb_common contents - %s" % rows)
hbc_pid = rows[0][0]
hbc_srcName = rows[0][1]
hbc_time = rows[0][2]
@@ -171,7 +172,7 @@ def fetch_json_file():
else:
print("MSHBD:CBS Config not available, using local config")
jsfile = "../etc/config.json"
- print("Config_N: The json file is - %s", jsfile)
+ print("Config_N: The json file is - %s" % jsfile)
return jsfile
#if __name__ == "__main__":
@@ -199,5 +200,5 @@ def config_notif_run():
print("HB_Notif::Failure updating hb_common table")
commit_and_close_db(connection_db)
return False
-
+
cur.close()