aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHansen, Tony (th1395) <th1395@att.com>2022-08-19 12:56:56 +0000
committerHansen, Tony (th1395) <th1395@att.com>2022-08-19 12:57:10 +0000
commitdac22d93c804780f2dc20164aeb44fc80a30890d (patch)
tree7bd19b04ffa5e8fb049068d9de79778eeed140de
parent554b15356ef100a3617f7f5415f6a35ac2b3ebba (diff)
lots of cleanup, no functional code changes
Change-Id: I9eefe4d34ae226bbd5a6f80422f89baeeaeb3471 Signed-off-by: Hansen, Tony (th1395) <th1395@att.com> Issue-ID: DCAEGEN2-2837
-rw-r--r--Changelog.md3
-rw-r--r--makefile3
-rw-r--r--miss_htbt_service/cbs_polling.py12
-rw-r--r--miss_htbt_service/db_monitoring.py20
-rw-r--r--miss_htbt_service/htbtworker.py38
-rw-r--r--miss_htbt_service/misshtbtd.py82
-rw-r--r--miss_htbt_service/mod/trapd_exit.py9
-rw-r--r--miss_htbt_service/mod/trapd_get_cbs_config.py19
-rw-r--r--miss_htbt_service/mod/trapd_http_session.py5
-rw-r--r--miss_htbt_service/mod/trapd_io.py347
-rw-r--r--miss_htbt_service/mod/trapd_runtime_pid.py6
-rw-r--r--miss_htbt_service/mod/trapd_settings.py6
-rw-r--r--miss_htbt_service/mod/trapd_vnf_table.py31
-rw-r--r--pom.xml6
-rw-r--r--pyproject.toml2
-rw-r--r--setup.py19
-rw-r--r--tests/monkey_psycopg2.py12
-rw-r--r--tests/test_binding.py23
-rw-r--r--tests/test_check_health.py5
-rw-r--r--tests/test_htbtworker.py6
-rw-r--r--tests/test_trapd_get_cbs_config.py69
-rw-r--r--tests/test_trapd_settings.py10
-rw-r--r--tests/test_trapd_vnf_table.py4
-rw-r--r--version.properties2
24 files changed, 235 insertions, 504 deletions
diff --git a/Changelog.md b/Changelog.md
index 2ecfd88..b1206ec 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
+## [2.4.1] - 2022/08/19
+- [DCAEGEN2-2837] Heartbeat ms: remove unnecessary parenthesis, use lowercase variable name
+
## [2.4.0] - 2021/10/12
### Changed
- [DCAEGEN2-2939] Removed unused code (config\_notif.py)
diff --git a/makefile b/makefile
index 494f08c..16a10c1 100644
--- a/makefile
+++ b/makefile
@@ -2,3 +2,6 @@ runtox:
. ~/bin/set_proxies; \
tox test | cat
coverage html
+
+runflake8:
+ flake8 --max-line-length 120 .
diff --git a/miss_htbt_service/cbs_polling.py b/miss_htbt_service/cbs_polling.py
index 53585ba..f837735 100644
--- a/miss_htbt_service/cbs_polling.py
+++ b/miss_htbt_service/cbs_polling.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
# ============LICENSE_START=======================================================
-# Copyright (c) 2018-2021 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2018-2022 AT&T Intellectual Property. All rights reserved.
# Copyright (c) 2019 Pantheon.tech. All rights reserved.
# Copyright (c) 2020 Deutsche Telekom. All rights reserved.
# Copyright (c) 2021 Fujitsu Ltd.
@@ -44,21 +44,21 @@ def poll_cbs(current_pid: int) -> None:
cbs_polling_required,
cbs_polling_interval,
) = db.read_hb_properties(jsfile)
- hbc_pid, hbc_state, hbc_srcName, hbc_time = db.read_hb_common(user_name, password, ip_address, port_num, db_name)
+ hbc_pid, hbc_state, hbc_src_name, hbc_time = db.read_hb_common(user_name, password, ip_address, port_num, db_name)
msg = "CBSP:Main process ID in hb_common is %d", hbc_pid
_logger.info(msg)
msg = "CBSP:My parent process ID is %d", current_pid
_logger.info(msg)
msg = "CBSP:CBS Polling interval is %d", cbs_polling_interval
_logger.info(msg)
- envPytest = os.getenv("pytest", "")
- if envPytest == "test":
+ env_pytest = os.getenv("pytest", "")
+ if env_pytest == "test":
cbs_polling_interval = "30"
time.sleep(int(cbs_polling_interval))
- hbc_pid, hbc_state, hbc_srcName, hbc_time = db.read_hb_common(user_name, password, ip_address, port_num, db_name)
+ hbc_pid, hbc_state, hbc_src_name, hbc_time = db.read_hb_common(user_name, password, ip_address, port_num, db_name)
source_name = socket.gethostname()
source_name = source_name + "-" + str(os.getenv("SERVICE_NAME", ""))
- if current_pid == int(hbc_pid) and source_name == hbc_srcName and hbc_state == "RUNNING":
+ if current_pid == int(hbc_pid) and source_name == hbc_src_name and hbc_state == "RUNNING":
_logger.info("CBSP:ACTIVE Instance:Change the state to RECONFIGURATION")
state = "RECONFIGURATION"
update_flg = 1
diff --git a/miss_htbt_service/db_monitoring.py b/miss_htbt_service/db_monitoring.py
index 32a2d5c..eac8a91 100644
--- a/miss_htbt_service/db_monitoring.py
+++ b/miss_htbt_service/db_monitoring.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
# ============LICENSE_START=======================================================
-# Copyright (c) 2018-2021 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2018-2022 AT&T Intellectual Property. All rights reserved.
# Copyright (c) 2019 Pantheon.tech. All rights reserved.
# Copyright (c) 2020 Deutsche Telekom. All rights reserved.
# Copyright (c) 2021 Fujitsu Ltd.
@@ -159,8 +159,8 @@ def db_monitoring(current_pid, json_file, user_name, password, ip_address, port_
while True:
time.sleep(20)
- envPytest = os.getenv("pytest", "")
- if envPytest == "test":
+ env_pytest = os.getenv("pytest", "")
+ if env_pytest == "test":
break
try:
@@ -172,14 +172,14 @@ def db_monitoring(current_pid, json_file, user_name, password, ip_address, port_
_logger.error(msg)
continue
- hbc_pid, hbc_state, hbc_srcName, hbc_time = db.read_hb_common(
+ hbc_pid, hbc_state, hbc_src_name, hbc_time = db.read_hb_common(
user_name, password, ip_address, port_num, db_name
)
source_name = socket.gethostname()
source_name = source_name + "-" + str(os.getenv("SERVICE_NAME", ""))
connection_db = pm.postgres_db_open(user_name, password, ip_address, port_num, db_name)
cur = connection_db.cursor()
- if int(current_pid) == int(hbc_pid) and source_name == hbc_srcName and hbc_state == "RUNNING":
+ if int(current_pid) == int(hbc_pid) and source_name == hbc_src_name and hbc_state == "RUNNING":
_logger.info("DBM: Active DB Monitoring Instance")
cur.execute("SELECT event_name FROM vnf_table_1")
vnf_list = [item[0] for item in cur.fetchall()]
@@ -222,7 +222,7 @@ def db_monitoring(current_pid, json_file, user_name, password, ip_address, port_
if len(row) == 0:
continue
epoc_time_sec = row[0][0]
- srcName = row[0][1]
+ src_name = row[0][1]
cl_flag = row[0][2]
if (epoc_time - epoc_time_sec) > comparision_time and cl_flag == 0:
sendControlLoopEvent(
@@ -232,7 +232,7 @@ def db_monitoring(current_pid, json_file, user_name, password, ip_address, port_
policy_name,
policy_scope,
target_type,
- srcName,
+ src_name,
epoc_time,
closed_control_loop_name,
version,
@@ -252,7 +252,7 @@ def db_monitoring(current_pid, json_file, user_name, password, ip_address, port_
policy_name,
policy_scope,
target_type,
- srcName,
+ src_name,
epoc_time,
closed_control_loop_name,
version,
@@ -301,6 +301,6 @@ if __name__ == "__main__":
_logger.info(msg)
while True:
db_monitoring(current_pid, jsfile, user_name, password, ip_address, port_num, db_name)
- envPytest = os.getenv("pytest", "")
- if envPytest == "test":
+ env_pytest = os.getenv("pytest", "")
+ if env_pytest == "test":
break
diff --git a/miss_htbt_service/htbtworker.py b/miss_htbt_service/htbtworker.py
index 44436a2..ac7a0d9 100644
--- a/miss_htbt_service/htbtworker.py
+++ b/miss_htbt_service/htbtworker.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
# ============LICENSE_START=======================================================
-# Copyright (c) 2018-2021 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2018-2022 AT&T Intellectual Property. All rights reserved.
# Copyright (c) 2019 Pantheon.tech. All rights reserved.
# Copyright (c) 2020 Deutsche Telekom. All rights reserved.
# Copyright (c) 2021 Fujitsu Ltd.
@@ -61,7 +61,7 @@ def process_msg(jsfile, user_name, password, ip_address, port_num, db_name):
mr_url = str(cfg["streams_subscribes"]["ves-heartbeat"]["dmaap_info"]["topic_url"])
while True:
- hbc_pid, hbc_state, hbc_srcName, hbc_time = db.read_hb_common(
+ hbc_pid, hbc_state, hbc_src_name, hbc_time = db.read_hb_common(
user_name, password, ip_address, port_num, db_name
)
if hbc_state == "RECONFIGURATION":
@@ -71,14 +71,14 @@ def process_msg(jsfile, user_name, password, ip_address, port_num, db_name):
break
if os.getenv("pytest", "") == "test":
- eventnameList = ["Heartbeat_vDNS", "Heartbeat_vFW", "Heartbeat_xx"]
+ eventname_list = ["Heartbeat_vDNS", "Heartbeat_vFW", "Heartbeat_xx"]
connection_db = 0
else:
connection_db = postgres_db_open(user_name, password, ip_address, port_num, db_name)
cur = connection_db.cursor()
cur.execute("SELECT event_name FROM vnf_table_1")
- eventnameList = [item[0] for item in cur.fetchall()]
- msg = "\n\nHBT:eventnameList values ", eventnameList
+ eventname_list = [item[0] for item in cur.fetchall()]
+ msg = "\n\nHBT:eventnameList values ", eventname_list
_logger.info(msg)
if "groupID" not in os.environ or "consumerID" not in os.environ:
get_url = mr_url + "/DefaultGroup/1?timeout=15000"
@@ -101,11 +101,11 @@ def process_msg(jsfile, user_name, password, ip_address, port_num, db_name):
res = requests.get(get_url)
msg = "HBT:", res.text
_logger.info(msg)
- inputString = res.text
+ input_string = res.text
# If mrstatus in message body indicates some information, not json msg.
- if "mrstatus" in inputString:
+ if "mrstatus" in input_string:
continue
- jlist = inputString.split("\n")
+ jlist = input_string.split("\n")
# Process the DMaaP input message retreived
error = False
for line in jlist:
@@ -132,12 +132,12 @@ def process_msg(jsfile, user_name, password, ip_address, port_num, db_name):
if lastepo > 1000000000000000:
lastepo = int(lastepo / 1000)
seqnum = jitem["event"]["commonEventHeader"]["sequence"]
- eventName = jitem["event"]["commonEventHeader"]["eventName"]
+ event_name = jitem["event"]["commonEventHeader"]["eventName"]
except Exception as err:
msg = "HBT message process error - ", err
_logger.error(msg)
continue
- msg = "HBT:Newly received HB event values ::", eventName, lastepo, srcname
+ msg = "HBT:Newly received HB event values ::", event_name, lastepo, srcname
_logger.info(msg)
if db_table_creation_check(connection_db, "vnf_table_2") is False:
msg = "HBT:Creating vnf_table_2"
@@ -156,10 +156,10 @@ def process_msg(jsfile, user_name, password, ip_address, port_num, db_name):
else:
msg = "HBT:vnf_table_2 is already there"
_logger.info(msg)
- if eventName in eventnameList: # pragma: no cover
+ if event_name in eventname_list: # pragma: no cover
if os.getenv("pytest", "") == "test":
break
- cur.execute("SELECT source_name_count FROM vnf_table_1 WHERE event_name = %s", (eventName,))
+ cur.execute("SELECT source_name_count FROM vnf_table_1 WHERE event_name = %s", (event_name,))
row = cur.fetchone()
source_name_count = row[0]
source_name_key = source_name_count + 1
@@ -168,19 +168,19 @@ def process_msg(jsfile, user_name, password, ip_address, port_num, db_name):
_logger.info("HBT: Insert entry into vnf_table_2, source_name='%s'", srcname)
cur.execute(
"INSERT INTO vnf_table_2 VALUES(%s,%s,%s,%s,%s)",
- (eventName, source_name_key, lastepo, srcname, cl_flag),
+ (event_name, source_name_key, lastepo, srcname, cl_flag),
)
cur.execute(
"UPDATE vnf_table_1 SET SOURCE_NAME_COUNT = %s where EVENT_NAME = %s",
- (source_name_key, eventName),
+ (source_name_key, event_name),
)
else: # pragma: no cover
- msg = "HBT:event name, source_name & source_name_count are", eventName, srcname, source_name_count
+ msg = "HBT:event name, source_name & source_name_count are", event_name, srcname, source_name_count
_logger.info(msg)
for source_name_key in range(source_name_count):
cur.execute(
"SELECT source_name FROM vnf_table_2 WHERE event_name = %s AND " "source_name_key = %s",
- (eventName, (source_name_key + 1)),
+ (event_name, (source_name_key + 1)),
)
row = cur.fetchall()
if len(row) == 0:
@@ -192,7 +192,7 @@ def process_msg(jsfile, user_name, password, ip_address, port_num, db_name):
cur.execute(
"UPDATE vnf_table_2 SET LAST_EPO_TIME = %s, SOURCE_NAME = %s "
"WHERE EVENT_NAME = %s AND SOURCE_NAME_KEY = %s",
- (lastepo, srcname, eventName, (source_name_key + 1)),
+ (lastepo, srcname, event_name, (source_name_key + 1)),
)
source_name_key = source_name_count
break
@@ -205,11 +205,11 @@ def process_msg(jsfile, user_name, password, ip_address, port_num, db_name):
_logger.info("HBT: Insert entry into vnf_table_2, source_name='%s'", srcname)
cur.execute(
"INSERT INTO vnf_table_2 VALUES(%s,%s,%s,%s,%s)",
- (eventName, source_name_key, lastepo, srcname, cl_flag),
+ (event_name, source_name_key, lastepo, srcname, cl_flag),
)
cur.execute(
"UPDATE vnf_table_1 SET SOURCE_NAME_COUNT = %s WHERE EVENT_NAME = %s",
- (source_name_key, eventName),
+ (source_name_key, event_name),
)
else:
_logger.info("HBT:eventName is not being monitored, Igonoring JSON message")
diff --git a/miss_htbt_service/misshtbtd.py b/miss_htbt_service/misshtbtd.py
index 5ba0860..fd1a09c 100644
--- a/miss_htbt_service/misshtbtd.py
+++ b/miss_htbt_service/misshtbtd.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
# ============LICENSE_START=======================================================
-# Copyright (c) 2017-2021 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2017-2022 AT&T Intellectual Property. All rights reserved.
# Copyright (c) 2019 Pantheon.tech. All rights reserved.
# Copyright (c) 2020 Deutsche Telekom. All rights reserved.
# Copyright (c) 2021 Samsung Electronics. All rights reserved.
@@ -83,32 +83,32 @@ def create_database(update_db, jsfile, ip_address, port_num, user_name, password
def read_hb_common(user_name, password, ip_address, port_num, db_name):
- envPytest = os.getenv("pytest", "")
- if envPytest == "test":
+ env_pytest = os.getenv("pytest", "")
+ if env_pytest == "test":
hbc_pid = 10
- hbc_srcName = "srvc_name"
+ hbc_src_name = "srvc_name"
hbc_time = 1584595881
hbc_state = "RUNNING"
- return hbc_pid, hbc_state, hbc_srcName, hbc_time
+ return hbc_pid, hbc_state, hbc_src_name, hbc_time
connection_db = heartbeat.postgres_db_open(user_name, password, ip_address, port_num, db_name)
cur = connection_db.cursor()
cur.execute("SELECT process_id, source_name, last_accessed_time, current_state FROM hb_common")
rows = cur.fetchall()
hbc_pid = rows[0][0]
- hbc_srcName = rows[0][1]
+ hbc_src_name = rows[0][1]
hbc_time = rows[0][2]
hbc_state = rows[0][3]
heartbeat.commit_and_close_db(connection_db)
cur.close()
- return hbc_pid, hbc_state, hbc_srcName, hbc_time
+ return hbc_pid, hbc_state, hbc_src_name, hbc_time
def create_update_hb_common(update_flg, process_id, state, user_name, password, ip_address, port_num, db_name):
current_time = int(round(time.time()))
source_name = socket.gethostname()
source_name = source_name + "-" + os.getenv("SERVICE_NAME", "")
- envPytest = os.getenv("pytest", "")
- if envPytest != "test":
+ env_pytest = os.getenv("pytest", "")
+ if env_pytest != "test":
connection_db = heartbeat.postgres_db_open(user_name, password, ip_address, port_num, db_name)
cur = connection_db.cursor()
if heartbeat.db_table_creation_check(connection_db, "hb_common") is False:
@@ -139,8 +139,8 @@ def create_update_vnf_table_1(jsfile, update_db, connection_db):
cfg = json.load(outfile)
hbcfg = cfg["heartbeat_config"]
jhbcfg = json.loads(hbcfg)
- envPytest = os.getenv("pytest", "")
- if envPytest == "test":
+ env_pytest = os.getenv("pytest", "")
+ if env_pytest == "test":
vnf_list = ["Heartbeat_vDNS", "Heartbeat_vFW", "Heartbeat_xx"]
else:
cur = connection_db.cursor()
@@ -176,14 +176,14 @@ def create_update_vnf_table_1(jsfile, update_db, connection_db):
missed = vnf["heartbeatcountmissed"]
intvl = vnf["heartbeatinterval"]
clloop = vnf["closedLoopControlName"]
- policyVersion = vnf["policyVersion"]
- policyName = vnf["policyName"]
- policyScope = vnf["policyScope"]
+ policy_version = vnf["policyVersion"]
+ policy_name = vnf["policyName"]
+ policy_scope = vnf["policyScope"]
target_type = vnf["target_type"]
target = vnf["target"]
version = vnf["version"]
- if envPytest == "test":
+ if env_pytest == "test":
# skip executing SQL in test
continue
if nfc not in vnf_list:
@@ -194,9 +194,9 @@ def create_update_vnf_table_1(jsfile, update_db, connection_db):
missed,
intvl,
clloop,
- policyVersion,
- policyName,
- policyScope,
+ policy_version,
+ policy_name,
+ policy_scope,
target_type,
target,
version,
@@ -214,9 +214,9 @@ def create_update_vnf_table_1(jsfile, update_db, connection_db):
missed,
intvl,
clloop,
- policyVersion,
- policyName,
- policyScope,
+ policy_version,
+ policy_name,
+ policy_scope,
target_type,
target,
version,
@@ -224,7 +224,7 @@ def create_update_vnf_table_1(jsfile, update_db, connection_db):
nfc,
),
)
- if envPytest != "test":
+ if env_pytest != "test":
cur.close()
_logger.info("MSHBT:Updated vnf_table_1 as per the json configuration file")
@@ -264,8 +264,8 @@ def read_hb_properties_default():
user_name = os.getenv("pg_userName")
password = os.getenv("pg_passwd")
- dbName = a["pg_dbName"]
- db_name = dbName.lower()
+ db_name = a["pg_dbName"]
+ db_name = db_name.lower()
cbs_polling_required = a["CBS_polling_allowed"]
cbs_polling_interval = a["CBS_polling_interval"]
s.close()
@@ -286,8 +286,8 @@ def read_hb_properties(jsfile):
port_num = str(cfg["pg_portNum"])
user_name = str(cfg["pg_userName"])
password = str(cfg["pg_passwd"])
- dbName = str(cfg["pg_dbName"])
- db_name = dbName.lower()
+ db_name = str(cfg["pg_dbName"])
+ db_name = db_name.lower()
cbs_polling_required = str(cfg["CBS_polling_allowed"])
cbs_polling_interval = str(cfg["CBS_polling_interval"])
consumer_id = str(cfg["consumerID"])
@@ -329,8 +329,8 @@ def fetch_json_file() -> str:
def create_update_db(update_db, jsfile, ip_address, port_num, user_name, password, db_name):
- envPytest = os.getenv("pytest", "")
- if envPytest != "test": # pragma: no cover
+ env_pytest = os.getenv("pytest", "")
+ if env_pytest != "test": # pragma: no cover
if update_db == 0:
create_database(update_db, jsfile, ip_address, port_num, user_name, password, db_name)
msg = "MSHBT: DB parameters -", ip_address, port_num, user_name, password, db_name
@@ -413,17 +413,17 @@ def main():
_logger.info("MSHBD:Now be in a continuous loop")
i = 0
while True:
- hbc_pid, hbc_state, hbc_srcName, hbc_time = read_hb_common(
+ hbc_pid, hbc_state, hbc_src_name, hbc_time = read_hb_common(
user_name, password, ip_address, port_num, db_name
)
- msg = "MSHBT: hb_common values ", hbc_pid, hbc_state, hbc_srcName, hbc_time
+ msg = "MSHBT: hb_common values ", hbc_pid, hbc_state, hbc_src_name, hbc_time
_logger.info(msg)
current_time = int(round(time.time()))
time_difference = current_time - hbc_time
msg = (
"MSHBD:pid,srcName,state,time,ctime,timeDiff is",
hbc_pid,
- hbc_srcName,
+ hbc_src_name,
hbc_state,
hbc_time,
current_time,
@@ -432,18 +432,18 @@ def main():
_logger.info(msg)
source_name = socket.gethostname()
source_name = source_name + "-" + str(os.getenv("SERVICE_NAME", ""))
- envPytest = os.getenv("pytest", "")
- if envPytest == "test":
+ env_pytest = os.getenv("pytest", "")
+ if env_pytest == "test":
if i == 2:
hbc_pid = pid_current
- source_name = hbc_srcName
+ source_name = hbc_src_name
hbc_state = "RECONFIGURATION"
elif i > 3:
hbc_pid = pid_current
- source_name = hbc_srcName
+ source_name = hbc_src_name
hbc_state = "RUNNING"
if time_difference < 60:
- if (int(hbc_pid) == int(pid_current)) and (source_name == hbc_srcName):
+ if (int(hbc_pid) == int(pid_current)) and (source_name == hbc_src_name):
msg = "MSHBD:config status is", hbc_state
_logger.info(msg)
if hbc_state == "RUNNING":
@@ -454,7 +454,8 @@ def main():
)
elif hbc_state == "RECONFIGURATION":
_logger.info(
- "MSHBD:Reconfiguration is in progress,Starting new processes by killing the present processes"
+ "MSHBD:Reconfiguration is in progress, "
+ "Starting new processes by killing the present processes"
)
jsfile = fetch_json_file()
update_db = 1
@@ -475,7 +476,8 @@ def main():
else:
jsfile = fetch_json_file()
msg = (
- "MSHBD:Inactive Instance:Creating HB and DBM threads if not created already. The param pssed %d and %s",
+ "MSHBD:Inactive Instance:Creating HB and DBM threads if not created already. "
+ "The param passed %d and %s",
jsfile,
pid_current,
)
@@ -483,7 +485,7 @@ def main():
job_list = create_process(job_list, jsfile, pid_current)
else:
_logger.info("MSHBD:Active instance is inactive for long time: Time to switchover")
- if (int(hbc_pid) != int(pid_current)) or (source_name != hbc_srcName):
+ if (int(hbc_pid) != int(pid_current)) or (source_name != hbc_src_name):
_logger.info("MSHBD:Initiating to become Active Instance")
if len(job_list) >= 2:
_logger.info("MSHBD:HB and DBM thread are waiting to become ACTIVE")
@@ -492,7 +494,7 @@ def main():
msg = "MSHBD: Creating HB and DBM threads. The param pssed %d and %s", jsfile, pid_current
_logger.info(msg)
job_list = create_process(job_list, jsfile, pid_current)
- hbc_pid, hbc_state, hbc_srcName, hbc_time = read_hb_common(
+ hbc_pid, hbc_state, hbc_src_name, hbc_time = read_hb_common(
user_name, password, ip_address, port_num, db_name
)
update_flg = 1
diff --git a/miss_htbt_service/mod/trapd_exit.py b/miss_htbt_service/mod/trapd_exit.py
index aae12bb..7791b31 100644
--- a/miss_htbt_service/mod/trapd_exit.py
+++ b/miss_htbt_service/mod/trapd_exit.py
@@ -1,5 +1,5 @@
# ============LICENSE_START=======================================================
-# Copyright (c) 2017-2021 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2017-2022 AT&T Intellectual Property. All rights reserved.
# Copyright (c) 2019 Pantheon.tech. All rights reserved.
# Copyright (c) 2020 Deutsche Telekom. All rights reserved.
# ================================================================================
@@ -25,8 +25,7 @@ __docformat__ = "restructuredtext"
import sys
import os
-import string
-from mod.trapd_runtime_pid import save_pid, rm_pid
+from mod.trapd_runtime_pid import rm_pid
prog_name = os.path.basename(__file__)
@@ -57,7 +56,7 @@ def cleanup_and_exit(_loc_exit_code, _pid_file_name):
# _num_params = len(locals())
if _pid_file_name is not None:
- rc = rm_pid(_pid_file_name)
+ rm_pid(_pid_file_name)
sys.exit(_loc_exit_code)
@@ -87,4 +86,4 @@ def cleanup(_loc_exit_code, _pid_file_name):
# _num_params = len(locals())
if _pid_file_name is not None:
- rc = rm_pid(_pid_file_name)
+ rm_pid(_pid_file_name)
diff --git a/miss_htbt_service/mod/trapd_get_cbs_config.py b/miss_htbt_service/mod/trapd_get_cbs_config.py
index f9fd4c3..034b32b 100644
--- a/miss_htbt_service/mod/trapd_get_cbs_config.py
+++ b/miss_htbt_service/mod/trapd_get_cbs_config.py
@@ -1,5 +1,5 @@
# ============LICENSE_START=======================================================
-# Copyright (c) 2018-2021 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2018-2022 AT&T Intellectual Property. All rights reserved.
# Copyright (c) 2019 Pantheon.tech. All rights reserved.
# Copyright (c) 2020 Deutsche Telekom. All rights reserved.
# Copyright (c) 2021 Samsung Electronics. All rights reserved.
@@ -27,11 +27,6 @@ __docformat__ = "restructuredtext"
import json
import os
-import sys
-import string
-import time
-import traceback
-import collections.abc
from onap_dcae_cbs_docker_client.client import get_config
from mod import trapd_settings as tds
from mod.trapd_exit import cleanup, cleanup_and_exit
@@ -71,7 +66,7 @@ def get_cbs_config():
try:
msg = "CBS_HTBT_JSON not defined - FATAL ERROR, exiting"
_cbs_sim_json_file = os.getenv("CBS_HTBT_JSON", "None")
- except Exception as e:
+ except Exception:
stdout_logger(msg)
cleanup(1, None)
return False
@@ -87,31 +82,31 @@ def get_cbs_config():
msg = "Unable to load CBS_HTBT_JSON " + _cbs_sim_json_file + " (invalid json?) - FATAL ERROR, exiting"
try:
tds.c_config = json.load(open(_cbs_sim_json_file))
- except Exception as e:
+ except Exception:
stdout_logger(msg)
cleanup_and_exit(0, None)
# recalc timeout, set default if not present
try:
tds.timeout_seconds = tds.c_config["publisher.http_timeout_milliseconds"] / 1000.0
- except Exception as e:
+ except Exception:
tds.timeout_seconds = 1.5
# recalc seconds_between_retries, set default if not present
try:
tds.seconds_between_retries = tds.c_config["publisher.http_milliseconds_between_retries"] / 1000.0
- except Exception as e:
+ except Exception:
tds.seconds_between_retries = 0.750
# recalc min_severity_to_log, set default if not present
try:
tds.minimum_severity_to_log = tds.c_config["files.minimum_severity_to_log"]
- except Exception as e:
+ except Exception:
tds.minimum_severity_to_log = 3
try:
tds.publisher_retries = tds.c_config["publisher.http_retries"]
- except Exception as e:
+ except Exception:
tds.publisher_retries = 3
return True
diff --git a/miss_htbt_service/mod/trapd_http_session.py b/miss_htbt_service/mod/trapd_http_session.py
index fc7e865..17eb302 100644
--- a/miss_htbt_service/mod/trapd_http_session.py
+++ b/miss_htbt_service/mod/trapd_http_session.py
@@ -1,5 +1,5 @@
# ============LICENSE_START=======================================================
-# Copyright (c) 2017-2021 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2017-2022 AT&T Intellectual Property. 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.
@@ -23,7 +23,6 @@ __docformat__ = "restructuredtext"
import os
import requests
-import traceback
prog_name = os.path.basename(__file__)
@@ -48,7 +47,7 @@ def init_session_obj():
try:
_loc_session = requests.Session()
- except Exception as e:
+ except Exception:
return None
return _loc_session
diff --git a/miss_htbt_service/mod/trapd_io.py b/miss_htbt_service/mod/trapd_io.py
index 3e03999..26445fc 100644
--- a/miss_htbt_service/mod/trapd_io.py
+++ b/miss_htbt_service/mod/trapd_io.py
@@ -1,5 +1,5 @@
# ============LICENSE_START=======================================================)
-# Copyright (c) 2018-2021 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2018-2022 AT&T Intellectual Property. All rights reserved.
# Copyright (c) 2019 Pantheon.tech. All rights reserved.
# Copyright (c) 2020 Deutsche Telekom. All rights reserved.
# ================================================================================
@@ -23,352 +23,13 @@ __docformat__ = "restructuredtext"
# basics
import datetime
-import errno
-import inspect
-import json
-import logging
-import logging.handlers
import os
-import sys
-import string
-import time
-import traceback
-import unicodedata
-
-# dcae_snmptrap
-import mod.trapd_settings as tds
-from mod.trapd_exit import cleanup_and_exit
prog_name = os.path.basename(__file__)
-
-# # # # # # # # # # # # # # # # # # #
-# fx: roll_all_logs -> roll all logs to timestamped backup
-# # # # # # # # # # ## # # # # # # #
-
-
-# def roll_all_logs():
-# """
-# roll all active logs to timestamped version, open new one
-# based on frequency defined in files.roll_frequency
-# """
-#
-# # first roll all the eelf files
-# # NOTE: this will go away when onap logging is standardized/available
-# try:
-# # open various ecomp logs - if any fails, exit
-# for fd in [tds.eelf_error_fd, tds.eelf_debug_fd, tds.eelf_audit_fd,
-# tds.eelf_metrics_fd, tds.arriving_traps_fd, tds.json_traps_fd]:
-# fd.close()
-#
-# roll_file(tds.eelf_error_file_name)
-# roll_file(tds.eelf_debug_file_name)
-# roll_file(tds.eelf_audit_file_name)
-# roll_file(tds.eelf_metrics_file_name)
-#
-# except Exception as e:
-# msg = "Error closing logs: " + str(e)
-# stdout_logger(msg)
-# cleanup_and_exit(1, tds.pid_file_name)
-#
-# reopened_successfully = open_eelf_logs()
-# if not reopened_successfully:
-# msg = "Error re-opening EELF logs during roll-over to timestamped versions - EXITING"
-# stdout_logger(msg)
-# cleanup_and_exit(1, tds.pid_file_name)
-#
-# # json log
-# roll_file(tds.json_traps_filename)
-
-## try:
-# tds.json_traps_fd = open_file(tds.json_traps_filename)
-# except Exception as e:
-# msg = ("Error opening json_log %s : %s" %
-# (json_traps_filename, str(e)))
-# stdout_logger(msg)
-# cleanup_and_exit(1, tds.pid_file_name)
-#
-# # arriving trap log
-# roll_file(tds.arriving_traps_filename)
-#
-# try:
-# tds.arriving_traps_fd = open_file(tds.arriving_traps_filename)
-# except Exception as e:
-# msg = ("Error opening arriving traps %s : %s" %
-# (arriving_traps_filename, str(e)))
-# stdout_logger(msg)
-# cleanup_and_exit(1, tds.pid_file_name)
-#
-#
-# # # # # # # # # # # # # # # # # # #
-# fx: setup_ecomp_logs -> log in eelf format until standard
-# is released for python via LOG-161
-# # # # # # # # # # ## # # # # # # #
-
-
-# def open_eelf_logs():
-# """
-# open various (multiple ???) logs
-# """
-#
-# try:
-# # open various ecomp logs - if any fails, exit
-#
-# tds.eelf_error_file_name = (
-# tds.c_config['files.eelf_base_dir'] + "/" + tds.c_config['files.eelf_error'])
-# tds.eelf_error_fd = open_file(tds.eelf_error_file_name)
-#
-# except Exception as e:
-# msg = "Error opening eelf error log : " + str(e)
-# stdout_logger(msg)
-# cleanup_and_exit(1, tds.pid_file_name)
-#
-# try:
-# tds.eelf_debug_file_name = (
-# tds.c_config['files.eelf_base_dir'] + "/" + tds.c_config['files.eelf_debug'])
-# tds.eelf_debug_fd = open_file(tds.eelf_debug_file_name)
-#
-# except Exception as e:
-# msg = "Error opening eelf debug log : " + str(e)
-# stdout_logger(msg)
-# cleanup_and_exit(1, tds.pid_file_name)
-#
-# try:
-# tds.eelf_audit_file_name = (
-# tds.c_config['files.eelf_base_dir'] + "/" + tds.c_config['files.eelf_audit'])
-# tds.eelf_audit_fd = open_file(tds.eelf_audit_file_name)
-# except Exception as e:
-# msg = "Error opening eelf audit log : " + str(e)
-# stdout_logger(msg)
-# cleanup_and_exit(1, tds.pid_file_name)
-#
-# try:
-# tds.eelf_metrics_file_name = (
-# tds.c_config['files.eelf_base_dir'] + "/" + tds.c_config['files.eelf_metrics'])
-# tds.eelf_metrics_fd = open_file(tds.eelf_metrics_file_name)
-# except Exception as e:
-# msg = "Error opening eelf metric log : " + str(e)
-# stdout_logger(msg)
-# cleanup_and_exit(1, tds.pid_file_name)
-#
-# return True
-#
-## # # # # # # # # # # # # # # # # # #
-# fx: roll_log_file -> move provided filename to timestamped version
-# # # # # # # # # # ## # # # # # # #
-
-
-# def roll_file(_loc_file_name):
-# """
-# move active file to timestamped archive
-# """
-#
-# _file_name_suffix = "%s" % (datetime.datetime.fromtimestamp(time.time()).
-# fromtimestamp(time.time()).
-# strftime('%Y-%m-%dT%H:%M:%S'))
-#
-# _loc_file_name_bak = _loc_file_name + '.' + _file_name_suffix
-#
-# # roll existing file if present
-# if os.path.isfile(_loc_file_name):
-# try:
-# os.rename(_loc_file_name, _loc_file_name_bak)
-# return True
-# except Exception as e:
-# _msg = ("ERROR: Unable to rename %s to %s"
-# % (_loc_file_name,
-# _loc_file_name_bak))
-# ecomp_logger(tds.LOG_TYPE_ERROR, tds.SEV_CRIT,
-# tds.CODE_GENERAL, _msg)
-# return False
-#
-# return False
-#
-## # # # # # # # # # # # #
-## fx: open_log_file
-## # # # # # # # # # # # #
-#
-#
-# def open_file(_loc_file_name):
-# """
-# open _loc_file_name, return file handle
-# """
-#
-# try:
-# # open append mode just in case so nothing is lost, but should be
-# # non-existent file
-# _loc_fd = open(_loc_file_name, 'a')
-# return _loc_fd
-# except Exception as e:
-# msg = "Error opening " + _loc_file_name + " append mode - " + str(e)
-# stdout_logger(msg)
-# cleanup_and_exit(1, tds.pid_file_name)
-#
-#
-## # # # # # # # # # # # #
-## fx: close_file
-## # # # # # # # # # # # #
-# """
-# close _loc_file_name, return True with success, False otherwise
-# """
-#
-#
-# def close_file(_loc_fd, _loc_filename):
-#
-# try:
-#
-# _loc_fd.close()
-# return True
-# except Exception as e:
-# msg = "Error closing %s : %s - results indeterminate" % (
-# _loc_filename, str(e))
-# ecomp_logger(tds.LOG_TYPE_ERROR, tds.SEV_FATAL, tds.CODE_GENERAL, msg)
-# return False
-#
-## # # # # # # # # # # # # # # # # # #
-## fx: ecomp_logger -> log in eelf format until standard
-## is released for python via LOG-161
-## # # # # # # # # # ## # # # # # # #
-#
-# def ecomp_logger(_log_type, _sev, _error_code, _msg):
-# """
-# Log to ecomp-style logfiles. Logs include:
-#
-# Note: this will be updated when https://jira.onap.org/browse/LOG-161
-# is closed/available; until then, we resort to a generic format with
-# valuable info in "extra=" field (?)
-#
-# :Parameters:
-# _msg -
-# :Exceptions:
-# none
-# :Keywords:
-# eelf logging
-# :Log Styles:
-#
-# :error.log:
-#
-# if CommonLogger.verbose: print("using CommonLogger.ErrorFile")
-# self._logger.log(50, '%s|%s|%s|%s|%s|%s|%s|%s|%s|%s' \
-# % (requestID, threadID, serviceName, partnerName, targetEntity, targetServiceName,
-# errorCategory, errorCode, errorDescription, detailMessage))
-#
-# error.log example:
-#
-# 2018-02-20T07:21:34,007+00:00||MainThread|snmp_log_monitor||||FATAL|900||Tue Feb 20 07:21:11 UTC 2018 CRITICAL: [a0cae74e-160e-11e8-8f9f-0242ac110002] ALL publish attempts failed to DMAPP server: dcae-mrtr-zltcrdm5bdce1.1dff83.rdm5b.tci.att.com, topic: DCAE-COLLECTOR-UCSNMP, 339 trap(s) not published in epoch_serno range: 15191112530000 - 15191112620010
-#
-# :debug.log:
-#
-# if CommonLogger.verbose: print("using CommonLogger.DebugFile")
-# self._logger.log(50, '%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s' \
-# % (requestID, threadID, serverName, serviceName, instanceUUID, upperLogLevel,
-# severity, serverIPAddress, server, IPAddress, className, timer, detailMessage))
-#
-# debug.log example:
-#
-# none available
-#
-# :audit.log:
-#
-# if CommonLogger.verbose: print("using CommonLogger.AuditFile")
-# endAuditTime, endAuditMsec = self._getTime()
-# if self._begTime is not None:
-# d = {'begtime': self._begTime, 'begmsecs': self._begMsec, 'endtime': endAuditTime,
-# 'endmsecs': endAuditMsec}
-# else:
-# d = {'begtime': endAuditTime, 'begmsecs': endAuditMsec, 'endtime': endAuditTime,
-# 'endmsecs': endAuditMsec}
-#
-# self._logger.log(50, '%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s' \
-# % (requestID, serviceInstanceID, threadID, serverName, serviceName, partnerName,
-# statusCode, responseCode, responseDescription, instanceUUID, upperLogLevel,
-# severity, serverIPAddress, timer, server, IPAddress, className, unused,
-# processKey, customField1, customField2, customField3, customField4,
-# detailMessage), extra=d)
-#
-#
-# :metrics.log:
-#
-# self._logger.log(50,'%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s' \
-# % (requestID, serviceInstanceID, threadID, serverName, serviceName, partnerName,
-# targetEntity, targetServiceName, statusCode, responseCode, responseDescription,
-# instanceUUID, upperLogLevel, severity, serverIPAddress, timer, server,
-# IPAddress,
-# className, unused, processKey, targetVirtualEntity, customField1, customField2,
-# customField3, customField4, detailMessage), extra=d)
-#
-# metrics.log example:
-#
-# none available
-#
-#
-# """
-#
-# unused = ""
-#
-# # above were various attempts at setting time string found in other
-# # libs; instead, let's keep it real:
-# t_out = datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S,%f")[:-3]
-# calling_fx = inspect.stack()[1][3]
-#
-# # DLFM: this entire module is a hack to override concept of prog logging
-# # written across multiple files (???), making diagnostics IMPOSSIBLE!
-# # Hoping to leverage ONAP logging libraries & standards when available
-#
-# # catch invalid log type
-# if _log_type < 1 or _log_type > 5:
-# msg = ("INVALID log type: %s " % _log_type)
-# _out_rec = ("%s|%s|%s|%s|%s|%s|%s|%s|%s"
-# % (calling_fx, "snmptrapd", unused, unused, unused, tds.SEV_TYPES[_sev], _error_code, unused, (msg + _msg)))
-# try:
-# tds.eelf_error_fd.write('%s|%s\n' % (t_out, str(_out_rec)))
-# except Exception as e:
-# stdout_logger(str(_out_rec))
-#
-# return False
-#
-# if _sev >= tds.minimum_severity_to_log:
-# # log to appropriate eelf log (different files ??)
-# if _log_type == tds.LOG_TYPE_ERROR:
-# _out_rec = ('%s|%s|%s|%s|%s|%s|%s|%s|%s'
-# % (calling_fx, "snmptrapd", unused, unused, unused, tds.SEV_TYPES[_sev], _error_code, unused, _msg))
-# try:
-# tds.eelf_error_fd.write('%s|%s\n' % (t_out, str(_out_rec)))
-# except Exception as e:
-# stdout_logger(str(_out_rec))
-# elif _log_type == tds.LOG_TYPE_AUDIT:
-# # log message in AUDIT format
-# _out_rec = ('%s|%s|%s|%s|%s|%s|%s|%s|%s'
-# % (calling_fx, "snmptrapd", unused, unused, unused, tds.SEV_TYPES[_sev], _error_code, unused, _msg))
-# try:
-# tds.eelf_audit_fd.write('%s|%s\n' % (t_out, str(_out_rec)))
-# except Exception as e:
-# stdout_logger(str(_out_rec))
-# elif _log_type == tds.LOG_TYPE_METRICS:
-# # log message in METRICS format
-# _out_rec = ('%s|%s|%s|%s|%s|%s|%s|%s|%s'
-# % (calling_fx, "snmptrapd", unused, unused, unused, tds.SEV_TYPES[_sev], _error_code, unused, _msg))
-# try:
-# tds.eelf_metrics_fd.write('%s|%s\n' % (t_out, str(_out_rec)))
-# except Exception as e:
-# stdout_logger(str(_out_rec))
-#
-# # DEBUG *AND* others - there *MUST BE* a single time-sequenced log for diagnostics!
-# # DLFM: too much I/O !!!
-# # always write to debug; we need ONE logfile that has time-sequence full view !!!
-# # log message in DEBUG format
-# _out_rec = ("%s|%s|%s|%s|%s|%s|%s|%s|%s"
-# % (calling_fx, "snmptrapd", unused, unused, unused, tds.SEV_TYPES[_sev], _error_code, unused, _msg))
-# try:
-# tds.eelf_debug_fd.write('%s|%s\n' % (t_out, str(_out_rec)))
-# except Exception as e:
-# stdout_logger(str(_out_rec))
-#
-# return True
-#
-## # # # # # # # # # # # #
-## fx: stdout_logger
-## # # # # # # # # # # # #
+# # # # # # # # # # # # #
+# fx: stdout_logger
+# # # # # # # # # # # # #
def stdout_logger(_msg):
diff --git a/miss_htbt_service/mod/trapd_runtime_pid.py b/miss_htbt_service/mod/trapd_runtime_pid.py
index 47612bd..823d29f 100644
--- a/miss_htbt_service/mod/trapd_runtime_pid.py
+++ b/miss_htbt_service/mod/trapd_runtime_pid.py
@@ -1,5 +1,5 @@
# ============LICENSE_START=======================================================
-# Copyright (c) 2017-2021 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2017-2022 AT&T Intellectual Property. 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.
@@ -21,11 +21,7 @@ PID of currently running trap receiver)
__docformat__ = "restructuredtext"
-import logging
import os
-import string
-import time
-import traceback
prog_name = os.path.basename(__file__)
diff --git a/miss_htbt_service/mod/trapd_settings.py b/miss_htbt_service/mod/trapd_settings.py
index 3e7f141..0f6a9a1 100644
--- a/miss_htbt_service/mod/trapd_settings.py
+++ b/miss_htbt_service/mod/trapd_settings.py
@@ -1,5 +1,5 @@
# ============LICENSE_START=======================================================)
-# Copyright (c) 2018-2021 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2018-2022 AT&T Intellectual Property. 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.
@@ -111,9 +111,9 @@ def init():
# <json log of traps published>
global json_traps_filename
- json_log_filename = ""
+ json_traps_filename = ""
global json_traps_fd
- json_fd = None
+ json_traps_fd = None
# </json log of traps published>
# <log of arriving traps >
diff --git a/miss_htbt_service/mod/trapd_vnf_table.py b/miss_htbt_service/mod/trapd_vnf_table.py
index 1b00336..f9fecbb 100644
--- a/miss_htbt_service/mod/trapd_vnf_table.py
+++ b/miss_htbt_service/mod/trapd_vnf_table.py
@@ -1,5 +1,5 @@
# ============LICENSE_START=======================================================
-# Copyright (c) 2017-2021 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2017-2022 AT&T Intellectual Property. All rights reserved.
# Copyright (c) 2019 Pantheon.tech. All rights reserved.
# Copyright (c) 2020 Deutsche Telekom. All rights reserved.
# Copyright (c) 2021 Samsung Electronics. All rights reserved.
@@ -18,7 +18,7 @@
# limitations under the License.
# ============LICENSE_END=========================================================
#
-## Author Kiran Mandal (km386e)
+# Author Kiran Mandal (km386e)
"""
trapd_vnf_table verifies the successful creation of DB Tables.
@@ -30,7 +30,6 @@ import os.path as path
import time
import subprocess
-import get_logger
import db_monitoring as dbmon
import htbtworker as pm
import misshtbtd as db
@@ -49,8 +48,8 @@ def hb_properties():
port_num = a["pg_portNum"]
user_name = a["pg_userName"]
password = a["pg_passwd"]
- dbName = a["pg_dbName"]
- db_name = dbName.lower()
+ db_name = a["pg_dbName"]
+ db_name = db_name.lower()
cbs_polling_required = a["CBS_polling_allowed"]
cbs_polling_interval = a["CBS_polling_interval"]
s.close()
@@ -61,7 +60,7 @@ def verify_DB_creation_1(user_name, password, ip_address, port_num, db_name):
connection_db = pm.postgres_db_open(user_name, password, ip_address, port_num, db_name)
try:
_db_status = pm.db_table_creation_check(connection_db, "vnf_table_1")
- except Exception as e:
+ except Exception:
return None
return _db_status
@@ -72,7 +71,7 @@ def verify_DB_creation_2(user_name, password, ip_address, port_num, db_name):
connection_db = pm.postgres_db_open(user_name, password, ip_address, port_num, db_name)
try:
_db_status = pm.db_table_creation_check(connection_db, "vnf_table_2")
- except Exception as e:
+ except Exception:
return None
return _db_status
@@ -83,7 +82,7 @@ def verify_DB_creation_hb_common(user_name, password, ip_address, port_num, db_n
connection_db = pm.postgres_db_open(user_name, password, ip_address, port_num, db_name)
try:
_db_status = pm.db_table_creation_check(connection_db, "hb_common")
- except Exception as e:
+ except Exception:
return None
return _db_status
@@ -105,7 +104,7 @@ def verify_fetch_json_file():
try:
db.fetch_json_file()
result = True
- except Exception as e:
+ except Exception:
result = False
print(result)
os.unsetenv("pytest")
@@ -124,7 +123,7 @@ def verify_misshtbtdmain():
try:
db.main()
result = True
- except Exception as e:
+ except Exception:
result = False
print(result)
os.unsetenv("pytest")
@@ -142,7 +141,7 @@ def verify_dbmonitoring():
try:
jsfile = db.fetch_json_file()
ip_address, port_num, user_name, password, db_name, cbs_polling_required, cbs_polling_interval = hb_properties()
- hbc_pid, hbc_state, hbc_srcName, hbc_time = db.read_hb_common(
+ hbc_pid, hbc_state, hbc_src_name, hbc_time = db.read_hb_common(
user_name, password, ip_address, port_num, db_name
)
dbmon.db_monitoring(hbc_pid, jsfile, user_name, password, ip_address, port_num, db_name)
@@ -162,7 +161,7 @@ def verify_dbmon_startup():
try:
p = subprocess.Popen(["./miss_htbt_service/db_monitoring.py"], stdout=subprocess.PIPE, shell=True)
time.sleep(1)
- except Exception as e:
+ except Exception:
return None
return True
@@ -183,7 +182,7 @@ def verify_sendControlLoop_VNF_ONSET():
"1.0",
"genVnfName",
)
- except Exception as e:
+ except Exception:
return None
return _CL_return
@@ -204,7 +203,7 @@ def verify_sendControlLoop_VM_ONSET():
"1.0",
"genVnfName",
)
- except Exception as e:
+ except Exception:
return None
return _CL_return
@@ -225,7 +224,7 @@ def verify_sendControlLoop_VNF_ABATED():
"1.0",
"genVnfName",
)
- except Exception as e:
+ except Exception:
return None
return _CL_return
@@ -246,6 +245,6 @@ def verify_sendControlLoop_VM_ABATED():
"1.0",
"genVnfName",
)
- except Exception as e:
+ except Exception:
return None
return _CL_return
diff --git a/pom.xml b/pom.xml
index aeb1ab6..2f6390e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<!--
-================================================================================
-Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
+============LICENSE_START=======================================================
+Copyright (c) 2017-2022 AT&T Intellectual Property. All rights reserved.
Copyright (c) 2021 Samsung Electronics. All rights reserved.
================================================================================
Licensed under the Apache License, Version 2.0 (the "License");
@@ -37,7 +37,7 @@ limitations under the License.
<groupId>org.onap.dcaegen2.services</groupId>
<artifactId>heartbeat</artifactId>
<name>dcaegen2-services-heartbeat</name>
- <version>2.4.0</version>
+ <version>2.4.1</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<sonar.sources>.</sonar.sources>
diff --git a/pyproject.toml b/pyproject.toml
new file mode 100644
index 0000000..f3a8b00
--- /dev/null
+++ b/pyproject.toml
@@ -0,0 +1,2 @@
+[tool.black]
+line-length=120
diff --git a/setup.py b/setup.py
index 297d168..39378cb 100644
--- a/setup.py
+++ b/setup.py
@@ -1,5 +1,5 @@
# ============LICENSE_START=======================================================
-# Copyright (c) 2017-2021 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2017-2022 AT&T Intellectual Property. All rights reserved.
# Copyright (c) 2021 Samsung Electronics. All rights reserved.
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,27 +15,12 @@
# limitations under the License.
# ============LICENSE_END=========================================================
-import os
-import string
-import sys
-import setuptools
from setuptools import setup, find_packages
-## #from pip.req import parse_requirements
-## try: # for pip >= 10
-## from pip._internal.req import parse_requirements
-## except ImportError: # for pip <= 9.0.3
-## from pip.req import parse_requirements
-## #from pip.download import PipSession
-## try: # for pip >= 10
-## from pip._internal.download import PipSession
-## except ImportError: # for pip <= 9.0.3
-## from pip.download import PipSession
-
setup(
name="miss_htbt_service",
description="Missing heartbeat microservice to communicate with policy-engine",
- version="2.4.0",
+ version="2.4.1",
# packages=find_packages(exclude=["tests.*", "tests"]),
packages=find_packages(),
install_requires=[
diff --git a/tests/monkey_psycopg2.py b/tests/monkey_psycopg2.py
index e993874..c87aedf 100644
--- a/tests/monkey_psycopg2.py
+++ b/tests/monkey_psycopg2.py
@@ -1,5 +1,5 @@
# ============LICENSE_START====================================================
-# Copyright (c) 2017-2021 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2017-2022 AT&T Intellectual Property. 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.
@@ -106,7 +106,7 @@ class MockConn(object):
if FORCE_CURSOR_FAILURE:
raise psycopg2.DatabaseError(f"Unable to return cursor: force_cursor_failure=<{FORCE_CURSOR_FAILURE}>")
- print(f"cursor()")
+ print("cursor()")
self.curCursor = None
return self
@@ -128,10 +128,10 @@ class MockConn(object):
raise Exception("postgres execute command throwing exception. cmd=<{}>".format(cmd))
if self.dbInfo:
- curCmdLower = cmd.lower()
+ cur_cmd_lower = cmd.lower()
for cmd, val in self.dbInfo.items():
print(f"cmd={cmd}, val={val}")
- if cmd in curCmdLower:
+ if cmd in cur_cmd_lower:
self.curCursor = val
break
@@ -140,7 +140,7 @@ class MockConn(object):
return a single row from the current cursor
"""
if not self.curCursor:
- print(f"fetchone() returning None")
+ print("fetchone() returning None")
return None
print(f"fetchone() returning {self.curCursor[0]}")
return self.curCursor[0]
@@ -150,7 +150,7 @@ class MockConn(object):
return all rows from the current cursor
"""
if not self.curCursor:
- print(f"fetchall() returning None")
+ print("fetchall() returning None")
return None
print(f"fetchall() returning {self.curCursor}")
return self.curCursor
diff --git a/tests/test_binding.py b/tests/test_binding.py
index 5ed6532..ae3221f 100644
--- a/tests/test_binding.py
+++ b/tests/test_binding.py
@@ -1,5 +1,5 @@
# ============LICENSE_START=======================================================
-# Copyright (c) 2017-2021 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2017-2022 AT&T Intellectual Property. All rights reserved.
# Copyright (c) 2019 Pantheon.tech. All rights reserved.
# Copyright (c) 2021 Samsung Electronics. All rights reserved.
# Copyright (c) 2021 Fujitsu Ltd.
@@ -45,7 +45,26 @@ def disable_proxy(monkeypatch):
@httpretty.activate
def test_resolve_all(disable_proxy):
- htbtmsg = '{"event":{"commonEventHeader":{"startEpochMicrosec":1518616063564475,"sourceId":"587c14b3-72c0-4581-b5cb-6567310b9bb7","eventId":"10048640","reportingEntityId":"587c14b3-72c0-4581-b5cb-6567310b9bb7","priority":"Normal","version":3,"reportingEntityName":"TESTVM","sequence":10048640,"domain":"heartbeat","lastEpochMicrosec":1518616063564476,"eventName":"Heartbeat_vVnf","sourceName":"TESTVM","nfNamingCode":"vVNF"}}}'
+ htbtmsg = (
+ "{"
+ '"event": {'
+ ' "commonEventHeader":{'
+ ' "startEpochMicrosec":1518616063564475,'
+ ' "sourceId":"587c14b3-72c0-4581-b5cb-6567310b9bb7",'
+ ' "eventId":"10048640",'
+ ' "reportingEntityId":"587c14b3-72c0-4581-b5cb-6567310b9bb7",'
+ ' "priority":"Normal",'
+ ' "version":3,'
+ ' "reportingEntityName":"TESTVM",'
+ ' "sequence":10048640,'
+ ' "domain":"heartbeat",'
+ ' "lastEpochMicrosec":1518616063564476,'
+ ' "eventName":"Heartbeat_vVnf",'
+ ' "sourceName":"TESTVM",'
+ ' "nfNamingCode":"vVNF"}'
+ " }"
+ "}"
+ )
send_url = mr_url + "/events/" + intopic + "/DefaultGroup/1?timeout=15000"
print(send_url)
httpretty.register_uri(httpretty.GET, send_url, body=htbtmsg)
diff --git a/tests/test_check_health.py b/tests/test_check_health.py
index d77beb1..b2ae276 100644
--- a/tests/test_check_health.py
+++ b/tests/test_check_health.py
@@ -1,5 +1,5 @@
# ============LICENSE_START=======================================================
-# Copyright (c) 2017-2021 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2017-2022 AT&T Intellectual Property. All rights reserved.
# Copyright (c) 2019 Pantheon.tech. All rights reserved.
# Copyright (c) 2021 Fujitsu Ltd.
# ================================================================================
@@ -16,7 +16,8 @@
# limitations under the License.
# ============LICENSE_END=========================================================
-# code loosely based on https://stackoverflow.com/questions/25369068/python-how-to-unit-test-a-custom-http-request-handler
+# code loosely based on
+# https://stackoverflow.com/questions/25369068/python-how-to-unit-test-a-custom-http-request-handler
from miss_htbt_service import check_health
diff --git a/tests/test_htbtworker.py b/tests/test_htbtworker.py
index 11cdc4a..78c9087 100644
--- a/tests/test_htbtworker.py
+++ b/tests/test_htbtworker.py
@@ -1,5 +1,5 @@
# ============LICENSE_START=======================================================
-# Copyright (c) 2020-2021 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2020-2022 AT&T Intellectual Property. 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.
@@ -16,7 +16,9 @@
from miss_htbt_service import htbtworker
-import os, tempfile, json
+import os
+import tempfile
+import json
def run_test(i):
diff --git a/tests/test_trapd_get_cbs_config.py b/tests/test_trapd_get_cbs_config.py
index ffb9bfb..75e2055 100644
--- a/tests/test_trapd_get_cbs_config.py
+++ b/tests/test_trapd_get_cbs_config.py
@@ -1,5 +1,5 @@
# ============LICENSE_START=======================================================
-# Copyright (c) 2017-2021 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2017-2022 AT&T Intellectual Property. All rights reserved.
# Copyright (c) 2019 Pantheon.tech. All rights reserved.
# Copyright (c) 2021 Fujitsu Ltd.
# ================================================================================
@@ -28,7 +28,72 @@ class test_get_cbs_config(unittest.TestCase):
Test the trapd_get_cbs_config mod
"""
- pytest_json_data = '{ "heartbeat_config": { "vnfs": [{ "eventName": "Heartbeat_vDNS", "heartbeatcountmissed": 3, "heartbeatinterval": 60, "closedLoopControlName": "ControlLoopEvent1", "policyVersion": "1.0.0.5", "policyName": "vFireWall", "policyScope": "resource=sampleResource,type=sampletype,CLName=sampleCLName", "target_type": "VNF", "target": "genVnfName", "version": "1.0" }, { "eventName": "Heartbeat_vFW", "heartbeatcountmissed": 3, "heartbeatinterval": 60, "closedLoopControlName": "ControlLoopEvent1", "policyVersion": "1.0.0.5", "policyName": "vFireWall", "policyScope": "resource=sampleResource,type=sampletype,CLName=sampleCLName", "target_type": "VNF", "target": "genVnfName", "version": "1.0" }, { "eventName": "Heartbeat_xx", "heartbeatcountmissed": 3, "heartbeatinterval": 60, "closedLoopControlName": "ControlLoopEvent1", "policyVersion": "1.0.0.5", "policyName": "vFireWall", "policyScope": "resource=sampleResource,type=sampletype,CLName=sampleCLName", "target_type": "VNF", "target": "genVnfName", "version": "1.0" } ] }, "streams_publishes": { "ves_heartbeat": { "dmaap_info": { "topic_url": "http://message-router:3904/events/unauthenticated.DCAE_CL_OUTPUT/" }, "type": "message_router" } }, "streams_subscribes": { "ves_heartbeat": { "dmaap_info": { "topic_url": "http://message-router:3904/events/unauthenticated.SEC_HEARTBEAT_INPUT/" }, "type": "message_router" } } }'
+ pytest_json_data = (
+ "{"
+ ' "heartbeat_config": {'
+ ' "vnfs": ['
+ " {"
+ ' "eventName": "Heartbeat_vDNS",'
+ ' "heartbeatcountmissed": 3,'
+ ' "heartbeatinterval": 60,'
+ ' "closedLoopControlName": "ControlLoopEvent1",'
+ ' "policyVersion": "1.0.0.5",'
+ ' "policyName": "vFireWall",'
+ ' "policyScope": "resource=sampleResource,'
+ " type=sampletype,"
+ ' CLName=sampleCLName",'
+ ' "target_type": "VNF",'
+ ' "target": "genVnfName",'
+ ' "version": "1.0"'
+ " },"
+ " {"
+ ' "eventName": "Heartbeat_vFW",'
+ ' "heartbeatcountmissed": 3,'
+ ' "heartbeatinterval": 60,'
+ ' "closedLoopControlName": "ControlLoopEvent1",'
+ ' "policyVersion": "1.0.0.5",'
+ ' "policyName": "vFireWall",'
+ ' "policyScope": "resource=sampleResource,'
+ " type=sampletype,"
+ ' CLName=sampleCLName",'
+ ' "target_type": "VNF",'
+ ' "target": "genVnfName",'
+ ' "version": "1.0"'
+ " },"
+ " {"
+ ' "eventName": "Heartbeat_xx",'
+ ' "heartbeatcountmissed": 3,'
+ ' "heartbeatinterval": 60,'
+ ' "closedLoopControlName": "ControlLoopEvent1",'
+ ' "policyVersion": "1.0.0.5",'
+ ' "policyName": "vFireWall",'
+ ' "policyScope": "resource=sampleResource,'
+ " type=sampletype,"
+ ' CLName=sampleCLName",'
+ ' "target_type": "VNF",'
+ ' "target": "genVnfName",'
+ ' "version": "1.0"'
+ " }"
+ " ]"
+ " },"
+ ' "streams_publishes": {'
+ ' "ves_heartbeat": {'
+ ' "dmaap_info": {'
+ ' "topic_url": "http://message-router:3904/events/unauthenticated.DCAE_CL_OUTPUT/"'
+ " },"
+ ' "type": "message_router"'
+ " }"
+ " },"
+ ' "streams_subscribes": {'
+ ' "ves_heartbeat": {'
+ ' "dmaap_info": {'
+ ' "topic_url": "http://message-router:3904/events/unauthenticated.SEC_HEARTBEAT_INPUT/"'
+ " },"
+ ' "type": "message_router"'
+ " }"
+ " }"
+ "}"
+ )
# create copy of snmptrapd.json for pytest
pytest_json_config = "/tmp/opt/app/miss_htbt_service/etc/config.json"
diff --git a/tests/test_trapd_settings.py b/tests/test_trapd_settings.py
index f3aebdd..743fa68 100644
--- a/tests/test_trapd_settings.py
+++ b/tests/test_trapd_settings.py
@@ -1,5 +1,5 @@
# ============LICENSE_START=======================================================
-# Copyright (c) 2017-2021 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2017-2022 AT&T Intellectual Property. All rights reserved.
# Copyright (c) 2019 Pantheon.tech. All rights reserved.
# Copyright (c) 2021 Fujitsu Ltd.
# ================================================================================
@@ -37,7 +37,7 @@ class test_cleanup_and_exit(unittest.TestCase):
try:
tds.no_such_var
result = True
- except:
+ except Exception:
result = False
self.assertEqual(result, False)
@@ -50,7 +50,7 @@ class test_cleanup_and_exit(unittest.TestCase):
try:
tds.c_config
result = True
- except:
+ except Exception:
result = False
self.assertEqual(result, True)
@@ -63,7 +63,7 @@ class test_cleanup_and_exit(unittest.TestCase):
try:
tds.dns_cache_ip_to_name
result = True
- except:
+ except Exception:
result = False
self.assertEqual(result, True)
@@ -76,6 +76,6 @@ class test_cleanup_and_exit(unittest.TestCase):
try:
tds.dns_cache_ip_expires
result = True
- except:
+ except Exception:
result = False
self.assertEqual(result, True)
diff --git a/tests/test_trapd_vnf_table.py b/tests/test_trapd_vnf_table.py
index b88b4d5..2e0f22a 100644
--- a/tests/test_trapd_vnf_table.py
+++ b/tests/test_trapd_vnf_table.py
@@ -1,5 +1,5 @@
# ============LICENSE_START=======================================================
-# Copyright (c) 2017-2021 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2017-2022 AT&T Intellectual Property. All rights reserved.
# Copyright (c) 2019 Pantheon.tech. All rights reserved.
# Copyright (c) 2020 Deutsche Telekom. All rights reserved.
# Copyright (c) 2021 Fujitsu Ltd.
@@ -17,7 +17,7 @@
# limitations under the License.
# ============LICENSE_END=========================================================
#
-## Author Prakask H (ph553f)
+# Author Prakask H (ph553f)
"""
test_trapd_vnf_table contains test cases related to DB Tables and cbs polling.
"""
diff --git a/version.properties b/version.properties
index c0f75b6..a88b650 100644
--- a/version.properties
+++ b/version.properties
@@ -1,6 +1,6 @@
major=2
minor=4
-patch=0
+patch=1
base_version=${major}.${minor}.${patch}
release_version=${base_version}
snapshot_version=${base_version}-SNAPSHOT