aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--miss_htbt_service/cbs_polling.py14
-rw-r--r--miss_htbt_service/config_notif.py29
-rw-r--r--miss_htbt_service/db_monitoring.py18
-rw-r--r--miss_htbt_service/htbtworker.py29
-rw-r--r--miss_htbt_service/misshtbtd.py46
-rw-r--r--miss_htbt_service/mod/trapd_exit.py3
-rw-r--r--miss_htbt_service/mod/trapd_get_cbs_config.py7
-rw-r--r--miss_htbt_service/mod/trapd_io.py5
-rw-r--r--miss_htbt_service/mod/trapd_vnf_table.py50
-rw-r--r--tests/test_binding.py10
-rw-r--r--tests/test_trapd_exit.py29
-rw-r--r--tests/test_trapd_get_cbs_config.py37
-rw-r--r--tests/test_trapd_http_session.py29
-rw-r--r--tests/test_trapd_runtime_pid.py39
-rw-r--r--tests/test_trapd_settings.py34
-rw-r--r--tests/test_trapd_vnf_table.py33
-rw-r--r--tox.ini1
17 files changed, 262 insertions, 151 deletions
diff --git a/miss_htbt_service/cbs_polling.py b/miss_htbt_service/cbs_polling.py
index 233cdb5..01f30bb 100644
--- a/miss_htbt_service/cbs_polling.py
+++ b/miss_htbt_service/cbs_polling.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)
# CBS Polling
# Set the hb_common table with state="RECONFIGURATION" periodically
@@ -24,12 +25,13 @@ import string
import sys
import os
import socket
-import htbtworker as pm
-import misshtbtd as db
import logging
-import get_logger
+from . import htbtworker as pm
+from . import misshtbtd as db
+from . import get_logger
+
_logger = get_logger.get_logger(__name__)
-
+
def pollCBS(current_pid):
jsfile = db.fetch_json_file()
@@ -58,7 +60,7 @@ def pollCBS(current_pid):
db.create_update_hb_common(update_flg, hbc_pid, state, user_name,password,ip_address,port_num,db_name)
else:
_logger.info("CBSP:Inactive instance or hb_common state is not RUNNING")
- return result
+ return result
if __name__ == "__main__":
current_pid = sys.argv[1]
while(True):
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()
diff --git a/miss_htbt_service/db_monitoring.py b/miss_htbt_service/db_monitoring.py
index fd00f8a..95b2dbe 100644
--- a/miss_htbt_service/db_monitoring.py
+++ b/miss_htbt_service/db_monitoring.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,25 +13,24 @@
# 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)
# DB Monitoring
# Tracks Heartbeat messages on each of the VNFs stored in postgres DB
# and generates Missing Heartbeat signal for Policy Engine
-import requests
import math
import sched, datetime, time
import json
import string
import sys
import os
+import logging
import socket
import requests
-import htbtworker as pm
-import misshtbtd as db
-import logging
-import get_logger
+from . import htbtworker as pm
+from . import misshtbtd as db
+from . import get_logger
_logger = get_logger.get_logger(__name__)
@@ -206,11 +206,11 @@ def db_monitoring(current_pid,json_file,user_name,password,ip_address,port_num,d
update_query = "UPDATE vnf_table_2 SET CL_FLAG=%d where EVENT_NAME ='%s' and source_name_key=%d" %(cl_flag,event_name,(source_name_key+1))
cur.execute(update_query)
connection_db.commit()
-
+
else: #pragma: no cover
msg="DBM:DB Monitoring is ignored for %s since validity flag is 0" %(event_name)
_logger.info(msg)
-
+
delete_query_table2 = "DELETE FROM vnf_table_2 WHERE EVENT_NAME = '%s';" %(event_name)
cur.execute(delete_query_table2)
delete_query = "DELETE FROM vnf_table_1 WHERE EVENT_NAME = '%s';" %(event_name)
@@ -225,7 +225,7 @@ def db_monitoring(current_pid,json_file,user_name,password,ip_address,port_num,d
pm.commit_and_close_db(connection_db)
cur.close()
break;
-
+
if __name__ == "__main__":
_logger.info("DBM: DBM Process started")
current_pid = sys.argv[1]
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
diff --git a/miss_htbt_service/misshtbtd.py b/miss_htbt_service/misshtbtd.py
index f1a8688..790ab6a 100644
--- a/miss_htbt_service/misshtbtd.py
+++ b/miss_htbt_service/misshtbtd.py
@@ -1,6 +1,7 @@
#!/usr/bin/env python3
# ============LICENSE_START=======================================================
# Copyright (c) 2017-2018 AT&T Intellectual Property. 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.
@@ -21,7 +22,7 @@
# configuration file from CBS
# - Creates heartbeat worker process that receives the Heartbeat messages from VNF
# - Creates DB Monitoring process that generates Control loop event
-# - Download the CBS configuration and populate the DB
+# - Download the CBS configuration and populate the DB
#
# Author Prakash Hosangady(ph553f@att.com)
import traceback
@@ -36,17 +37,18 @@ import logging
import subprocess
import yaml
import socket
-import get_logger
-from pathlib import Path
-import mod.trapd_settings as tds
-import htbtworker as heartbeat
import os.path as path
+from pathlib import Path
+
+from . import htbtworker as heartbeat
+from . import get_logger
+from .mod import trapd_settings as tds
+from .mod.trapd_runtime_pid import save_pid, rm_pid
+from .mod.trapd_get_cbs_config import get_cbs_config
+from .mod.trapd_exit import cleanup_and_exit
+from .mod.trapd_http_session import init_session_obj
hb_properties_file = path.abspath(path.join(__file__, "../config/hbproperties.yaml"))
-from mod.trapd_runtime_pid import save_pid, rm_pid
-from mod.trapd_get_cbs_config import get_cbs_config
-from mod.trapd_exit import cleanup_and_exit
-from mod.trapd_http_session import init_session_obj
ip_address = "localhost"
port_num = 5432
user_name = "postgres"
@@ -144,7 +146,7 @@ def create_update_hb_common(update_flg, process_id, state, user_name,password,ip
cur.execute(query_value)
heartbeat.commit_and_close_db(connection_db)
cur.close()
-
+
def create_update_vnf_table_1(jsfile,update_db,connection_db):
with open(jsfile, 'r') as outfile:
cfg = json.load(outfile)
@@ -171,7 +173,7 @@ def create_update_vnf_table_1(jsfile,update_db,connection_db):
#_logger.error("MSHBT:",nfc)
validity_flag = 1
source_name_count = 0
- missed = vnf['heartbeatcountmissed']
+ missed = vnf['heartbeatcountmissed']
intvl = vnf['heartbeatinterval']
clloop = vnf['closedLoopControlName']
policyVersion = vnf['policyVersion']
@@ -180,11 +182,11 @@ def create_update_vnf_table_1(jsfile,update_db,connection_db):
target_type = vnf['target_type']
target = vnf['target']
version = vnf['version']
-
- if(nfc not in vnf_list):
+
+ if(nfc not in vnf_list):
query_value = "INSERT INTO vnf_table_1 VALUES('%s',%d,%d,'%s','%s','%s','%s','%s','%s','%s',%d,%d);" %(nfc,missed,intvl,clloop,policyVersion,policyName,policyScope,target_type, target,version,source_name_count,validity_flag)
else:
- query_value = "UPDATE vnf_table_1 SET HEARTBEAT_MISSED_COUNT='%d',HEARTBEAT_INTERVAL='%d', CLOSED_CONTROL_LOOP_NAME='%s',POLICY_VERSION='%s',POLICY_NAME='%s', POLICY_SCOPE='%s',TARGET_TYPE='%s', TARGET='%s',VERSION='%s',VALIDITY_FLAG='%d' where EVENT_NAME='%s'" %(missed,intvl,clloop,policyVersion,policyName,policyScope,target_type,target,version,validity_flag,nfc)
+ query_value = "UPDATE vnf_table_1 SET HEARTBEAT_MISSED_COUNT='%d',HEARTBEAT_INTERVAL='%d', CLOSED_CONTROL_LOOP_NAME='%s',POLICY_VERSION='%s',POLICY_NAME='%s', POLICY_SCOPE='%s',TARGET_TYPE='%s', TARGET='%s',VERSION='%s',VALIDITY_FLAG='%d' where EVENT_NAME='%s'" %(missed,intvl,clloop,policyVersion,policyName,policyScope,target_type,target,version,validity_flag,nfc)
if (envPytest != 'test'):
cur.execute(query_value)
#heartbeat.commit_and_close_db(connection_db)
@@ -200,7 +202,7 @@ def hb_cbs_polling_process(pid_current):
# subprocess.call(["python3.6",ABSOLUTE_PATH4 , str(pid_current) ])
sys.stdout.flush()
_logger.info("MSHBT:Creaated CBS polling process")
- return
+ return
def hb_worker_process(config_file_path):
my_file = Path("./miss_htbt_service/htbtworker.py")
# if my_file.is_file():
@@ -251,8 +253,8 @@ def read_hb_properties(jsfile):
msg = "CBS Json file load error - ",err
_logger.error(msg)
return read_hb_properties_default()
-
- try:
+
+ try:
ip_address = str(cfg['pg_ipAddress'])
port_num = str(cfg['pg_portNum'])
user_name = str(cfg['pg_userName'])
@@ -265,7 +267,7 @@ def read_hb_properties(jsfile):
group_id = str(cfg['groupID'])
os.environ['consumerID'] = consumer_id
os.environ['groupID'] = group_id
- if("SERVICE_NAME" in cfg.keys()):
+ if "SERVICE_NAME" in cfg:
os.environ['SERVICE_NAME'] = str(cfg['SERVICE_NAME'])
except(Exception) as err:
msg = "CBS Json file read parameter error - ",err
@@ -343,7 +345,7 @@ def main():
job_list = []
pid_current = os.getpid()
jsfile = fetch_json_file()
- ip_address, port_num, user_name, password, db_name, cbs_polling_required, cbs_polling_interval = read_hb_properties(jsfile)
+ ip_address, port_num, user_name, password, db_name, cbs_polling_required, cbs_polling_interval = read_hb_properties(jsfile)
msg = "MSHBT:HB Properties -", ip_address, port_num, user_name, password, db_name, cbs_polling_required, cbs_polling_interval
_logger.info(msg)
if(cbs_polling_required == 'True'):
@@ -397,7 +399,7 @@ def main():
state = "RUNNING"
update_flg = 1
create_update_hb_common(update_flg, pid_current, state, user_name,password,ip_address,port_num,db_name)
-
+
else:
_logger.info("MSHBD:Inactive Instance: Process IDs are different, Keep Looping")
if(len(job_list)>=2):
@@ -442,12 +444,12 @@ def main():
job_list[0].join()
job_list.remove(job_list[0])
break
-
+
except (Exception) as e:
msg = "MSHBD:Exception as %s" %(str(traceback.format_exc()))
_logger.error(msg)
- msg = "Fatal error. Could not start missing heartbeat service due to: {0}".format(e)
+ msg = "Fatal error. Could not start missing heartbeat service due to: {0}".format(e)
_logger.error(msg)
if __name__ == '__main__':
diff --git a/miss_htbt_service/mod/trapd_exit.py b/miss_htbt_service/mod/trapd_exit.py
index 6247f4b..80ed1b0 100644
--- a/miss_htbt_service/mod/trapd_exit.py
+++ b/miss_htbt_service/mod/trapd_exit.py
@@ -2,6 +2,7 @@
# org.onap.dcae
# ================================================================================
# Copyright (c) 2017-2018 AT&T Intellectual Property. 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.
@@ -28,7 +29,7 @@ __docformat__ = 'restructuredtext'
import sys
import os
import string
-from mod.trapd_runtime_pid import save_pid, rm_pid
+from .trapd_runtime_pid import save_pid, rm_pid
prog_name = os.path.basename(__file__)
diff --git a/miss_htbt_service/mod/trapd_get_cbs_config.py b/miss_htbt_service/mod/trapd_get_cbs_config.py
index 47ba223..86e621f 100644
--- a/miss_htbt_service/mod/trapd_get_cbs_config.py
+++ b/miss_htbt_service/mod/trapd_get_cbs_config.py
@@ -2,6 +2,7 @@
# org.onap.dcae
# ================================================================================
# Copyright (c) 2018 AT&T Intellectual Property. 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.
@@ -33,10 +34,10 @@ import string
import time
import traceback
import collections
-import mod.trapd_settings as tds
from onap_dcae_cbs_docker_client.client import get_config
-from mod.trapd_exit import cleanup,cleanup_and_exit
-from mod.trapd_io import stdout_logger
+from . import trapd_settings as tds
+from .trapd_exit import cleanup,cleanup_and_exit
+from .trapd_io import stdout_logger
prog_name = os.path.basename(__file__)
diff --git a/miss_htbt_service/mod/trapd_io.py b/miss_htbt_service/mod/trapd_io.py
index 1c40346..063f3ee 100644
--- a/miss_htbt_service/mod/trapd_io.py
+++ b/miss_htbt_service/mod/trapd_io.py
@@ -2,6 +2,7 @@
# org.onap.dcae
# ================================================================================
# Copyright (c) 2018 AT&T Intellectual Property. 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.
@@ -37,8 +38,8 @@ import time
import traceback
import unicodedata
# dcae_snmptrap
-import mod.trapd_settings as tds
-from mod.trapd_exit import cleanup_and_exit
+from . import trapd_settings as tds
+from .trapd_exit import cleanup_and_exit
prog_name = os.path.basename(__file__)
diff --git a/miss_htbt_service/mod/trapd_vnf_table.py b/miss_htbt_service/mod/trapd_vnf_table.py
index b180bf5..56aedbb 100644
--- a/miss_htbt_service/mod/trapd_vnf_table.py
+++ b/miss_htbt_service/mod/trapd_vnf_table.py
@@ -2,6 +2,7 @@
# org.onap.dcae
# ================================================================================
# Copyright (c) 2017-2018 AT&T Intellectual Property. 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.
@@ -27,20 +28,21 @@ trapd_vnf_table verifies the successful creation of DB Tables.
import psycopg2
import os
import sys
-import htbtworker as pm
-import misshtbtd as db
-import config_notif as cf
-import cbs_polling as cbs
import logging
-import get_logger
import yaml
import os.path as path
-import db_monitoring as dbmon
import json
-from onap_dcae_cbs_docker_client.client import get_config
-import unittest
import time
import subprocess
+from onap_dcae_cbs_docker_client.client import get_config
+
+from .. import get_logger
+from .. import db_monitoring as dbmon
+from .. import htbtworker as pm
+from .. import misshtbtd as db
+from .. import config_notif as cf
+from .. import cbs_polling as cbs
+
prog_name = os.path.basename(__file__)
hb_properties_file = path.abspath(path.join(__file__, "../../config/hbproperties.yaml"))
@@ -52,8 +54,8 @@ def hb_properties():
a=yaml.load(s)
ip_address = a['pg_ipAddress']
port_num = a['pg_portNum']
- user_name = a['pg_userName']
- password = a['pg_passwd']
+ user_name = a['pg_userName']
+ password = a['pg_passwd']
dbName = a['pg_dbName']
db_name = dbName.lower()
cbs_polling_required = a['CBS_polling_allowed']
@@ -61,7 +63,7 @@ def hb_properties():
s.close()
return ip_address, port_num, user_name, password, db_name, cbs_polling_required, cbs_polling_interval
-
+
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)
# cur = connection_db.cursor()
@@ -69,9 +71,9 @@ def verify_DB_creation_1(user_name,password,ip_address,port_num,db_name):
_db_status=pm.db_table_creation_check(connection_db,"vnf_table_1")
except Exception as e:
return None
-
+
return _db_status
-
+
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)
@@ -80,9 +82,9 @@ def verify_DB_creation_2(user_name,password,ip_address,port_num,db_name):
_db_status=pm.db_table_creation_check(connection_db,"vnf_table_2")
except Exception as e:
return None
-
+
return _db_status
-
+
def verify_DB_creation_hb_common(user_name,password,ip_address,port_num,db_name):
connection_db = pm.postgres_db_open(user_name,password,ip_address,port_num,db_name)
@@ -91,10 +93,10 @@ def verify_DB_creation_hb_common(user_name,password,ip_address,port_num,db_name)
_db_status=pm.db_table_creation_check(connection_db,"hb_common")
except Exception as e:
return None
-
+
return _db_status
-
-
+
+
def verify_cbsPolling_required():
_cbspolling_status = True
os.environ['pytest']='test'
@@ -104,9 +106,9 @@ def verify_cbsPolling_required():
try:
_cbspolling_status=cf.config_notif_run()
except Exception as e:
- print("Config_notify error - ",e)
+ print("Config_notify error - %s" % e)
#return None
-
+
os.unsetenv('pytest')
os.unsetenv('CONSUL_HOST')
os.unsetenv('SERVICE_NAME')
@@ -118,9 +120,9 @@ def verify_cbspolling():
try:
_cbspolling=cbs.pollCBS(10)
except Exception as e:
- #print("CBSP error - ",e)
+ #print("CBSP error - %s" % e)
return None
-
+
os.unsetenv('pytest')
os.unsetenv('SERVICE_NAME')
return _cbspolling
@@ -175,7 +177,7 @@ def verify_dbmonitoring():
dbmon.db_monitoring(hbc_pid,jsfile,user_name,password,ip_address,port_num,db_name)
result = True
except Exception as e:
- print("Message process error - ",e)
+ print("Message process error - %s" % e)
result = False
print(result)
os.unsetenv('pytest')
@@ -189,7 +191,7 @@ def verify_dbmon_startup():
p = subprocess.Popen(['./miss_htbt_service/db_monitoring.py'], stdout=subprocess.PIPE,shell=True)
time.sleep(1)
except Exception as e:
- #print( "Message process error - ",e)
+ #print("Message process error - %s" % e)
return None
return True
diff --git a/tests/test_binding.py b/tests/test_binding.py
index 56a5ece..0ef6c5d 100644
--- a/tests/test_binding.py
+++ b/tests/test_binding.py
@@ -1,5 +1,6 @@
# ============LICENSE_START=======================================================
# Copyright (c) 2017-2018 AT&T Intellectual Property. 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.
@@ -21,11 +22,6 @@ import io
import requests
import httpretty
import sys
-from miss_htbt_service import htbtworker
-from miss_htbt_service import misshtbtd
-from miss_htbt_service import db_monitoring
-#from miss_htbt_service import config_notif
-from trapd_vnf_table import hb_properties
import subprocess
import pytest
import json
@@ -35,6 +31,10 @@ import imp
import time
from pip._internal import main as _main
from onap_dcae_cbs_docker_client.client import get_config
+from miss_htbt_service import htbtworker
+from miss_htbt_service import misshtbtd
+from miss_htbt_service import db_monitoring
+from miss_htbt_service.mod.trapd_vnf_table import hb_properties
import unittest
diff --git a/tests/test_trapd_exit.py b/tests/test_trapd_exit.py
index d73fd62..4fa8586 100644
--- a/tests/test_trapd_exit.py
+++ b/tests/test_trapd_exit.py
@@ -1,22 +1,41 @@
+# ============LICENSE_START=======================================================
+# Copyright (c) 2017-2018 AT&T Intellectual Property. 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.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# 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.
+# ============LICENSE_END=========================================================
+#
+# ECOMP is a trademark and service mark of AT&T Intellectual Property.
+
import pytest
import unittest
import sys
-import trapd_exit
+from miss_htbt_service.mod import trapd_exit
pid_file="/tmp/test_pid_file"
pid_file_dne="/tmp/test_pid_file_NOT"
-
+
class test_cleanup_and_exit(unittest.TestCase):
"""
Test the cleanup_and_exit mod
"""
-
+
def test_normal_exit(self):
"""
Test normal exit works as expected
"""
open(pid_file, 'w')
-
+
with pytest.raises(SystemExit) as pytest_wrapped_sys_exit:
result = trapd_exit.cleanup_and_exit(0,pid_file)
assert pytest_wrapped_sys_exit.type == SystemExit
@@ -24,7 +43,7 @@ class test_cleanup_and_exit(unittest.TestCase):
# compare = str(result).startswith("SystemExit: 0")
# self.assertEqual(compare, True)
-
+
def test_abnormal_exit(self):
"""
Test exit with missing PID file exits non-zero
diff --git a/tests/test_trapd_get_cbs_config.py b/tests/test_trapd_get_cbs_config.py
index 1719319..92d0dde 100644
--- a/tests/test_trapd_get_cbs_config.py
+++ b/tests/test_trapd_get_cbs_config.py
@@ -1,14 +1,33 @@
+# ============LICENSE_START=======================================================
+# Copyright (c) 2017-2018 AT&T Intellectual Property. 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.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# 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.
+# ============LICENSE_END=========================================================
+#
+# ECOMP is a trademark and service mark of AT&T Intellectual Property.
+
import pytest
import unittest
import os
import sys
from onap_dcae_cbs_docker_client.client import get_config
-from trapd_exit import cleanup_and_exit
-from trapd_io import stdout_logger
-import trapd_settings as tds
-import trapd_get_cbs_config
-
+from miss_htbt_service.mod.trapd_exit import cleanup_and_exit
+from miss_htbt_service.mod.trapd_io import stdout_logger
+from miss_htbt_service.mod import trapd_settings as tds
+from miss_htbt_service.mod import trapd_get_cbs_config
+
class test_get_cbs_config(unittest.TestCase):
"""
Test the trapd_get_cbs_config mod
@@ -22,7 +41,7 @@ class test_get_cbs_config(unittest.TestCase):
with open(pytest_json_config, 'w') as outfile:
outfile.write(pytest_json_data)
-
+
def test_cbs_env_present(self):
"""
Test that CONSUL_HOST env variable exists but fails to
@@ -40,7 +59,7 @@ class test_get_cbs_config(unittest.TestCase):
assert pytest_wrapped_sys_exit.type == SystemExit
# assert pytest_wrapped_sys_exit.value.code == 1
-
+
# def test_cbs_override_env_invalid(self):
# """
# """
@@ -55,7 +74,7 @@ class test_get_cbs_config(unittest.TestCase):
# assert pytest_wrapped_sys_exit.type == SystemExit
# assert pytest_wrapped_sys_exit.value.code == 1
-
+
def test_cbs_fallback_env_present(self):
"""
Test that CBS fallback env variable exists and we can get config
@@ -68,6 +87,6 @@ class test_get_cbs_config(unittest.TestCase):
# compare = str(result).startswith("{'snmptrap': ")
# self.assertEqual(compare, True)
self.assertEqual(result, True)
-
+
#if __name__ == '__main__':
# unittest.main()
diff --git a/tests/test_trapd_http_session.py b/tests/test_trapd_http_session.py
index c2a5f6b..00ee867 100644
--- a/tests/test_trapd_http_session.py
+++ b/tests/test_trapd_http_session.py
@@ -1,13 +1,32 @@
+# ============LICENSE_START=======================================================
+# Copyright (c) 2017-2018 AT&T Intellectual Property. 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.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# 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.
+# ============LICENSE_END=========================================================
+#
+# ECOMP is a trademark and service mark of AT&T Intellectual Property.
+
import pytest
import unittest
import sys
-import trapd_http_session
-
+from miss_htbt_service.mod import trapd_http_session
+
class test_init_session_obj(unittest.TestCase):
"""
Test the init_session_obj mod
"""
-
+
def test_correct_usage(self):
"""
Test that attempt to create http session object works
@@ -15,7 +34,7 @@ class test_init_session_obj(unittest.TestCase):
result = trapd_http_session.init_session_obj()
compare = str(result).startswith("<requests.sessions.Session object at")
self.assertEqual(compare, True)
-
-
+
+
#if __name__ == '__main__':
# unittest.main()
diff --git a/tests/test_trapd_runtime_pid.py b/tests/test_trapd_runtime_pid.py
index 61900ba..222ce58 100644
--- a/tests/test_trapd_runtime_pid.py
+++ b/tests/test_trapd_runtime_pid.py
@@ -1,35 +1,52 @@
+# ============LICENSE_START=======================================================
+# Copyright (c) 2017-2018 AT&T Intellectual Property. 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.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# 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.
+# ============LICENSE_END=========================================================
+#
+# ECOMP is a trademark and service mark of AT&T Intellectual Property.
+
import pytest
import unittest
-#import trapd_runtime_pid
import sys
-#from /home/ubuntu/HB_Nov5/miss_htbt_service/mod/ import trapd_io
-import trapd_runtime_pid
-import trapd_io
+from miss_htbt_service.mod import trapd_runtime_pid
+from miss_htbt_service.mod import trapd_io
class test_save_pid(unittest.TestCase):
"""
Test the save_pid mod
"""
-
+
def test_correct_usage(self):
"""
Test that attempt to create pid file in standard location works
"""
result = trapd_runtime_pid.save_pid('/tmp/snmptrap_test_pid_file')
self.assertEqual(result, True)
-
+
def test_missing_directory(self):
"""
Test that attempt to create pid file in missing dir fails
"""
result = trapd_runtime_pid.save_pid('/bogus/directory/for/snmptrap_test_pid_file')
self.assertEqual(result, False)
-
+
class test_rm_pid(unittest.TestCase):
"""
Test the rm_pid mod
"""
-
+
def test_correct_usage(self):
"""
Test that attempt to remove pid file in standard location works
@@ -39,14 +56,14 @@ class test_rm_pid(unittest.TestCase):
self.assertEqual(result, True)
result = trapd_runtime_pid.rm_pid('/tmp/snmptrap_test_pid_file')
self.assertEqual(result, True)
-
+
def test_missing_file(self):
"""
Test that attempt to rm non-existent pid file fails
"""
result = trapd_runtime_pid.rm_pid('/tmp/snmptrap_test_pid_file_9999')
self.assertEqual(result, False)
-
-
+
+
#if __name__ == '__main__':
# unittest.main()
diff --git a/tests/test_trapd_settings.py b/tests/test_trapd_settings.py
index 05b4449..53b24c8 100644
--- a/tests/test_trapd_settings.py
+++ b/tests/test_trapd_settings.py
@@ -1,17 +1,37 @@
+# ============LICENSE_START=======================================================
+# Copyright (c) 2017-2018 AT&T Intellectual Property. 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.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# 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.
+# ============LICENSE_END=========================================================
+#
+# ECOMP is a trademark and service mark of AT&T Intellectual Property.
+
import pytest
import unittest
-import test_trapd_exit
+
+from miss_htbt_service.mod import trapd_settings as tds
+
pid_file="/tmp/test_pid_file"
pid_file_dne="/tmp/test_pid_file_NOT"
-import trapd_settings as tds
class test_cleanup_and_exit(unittest.TestCase):
"""
Test for presense of required vars
"""
-
+
def test_nonexistent_dict(self):
"""
@@ -25,7 +45,7 @@ class test_cleanup_and_exit(unittest.TestCase):
result = False
self.assertEqual(result, False)
-
+
def test_config_dict(self):
"""
Test config dict
@@ -37,10 +57,10 @@ class test_cleanup_and_exit(unittest.TestCase):
except:
result = False
self.assertEqual(result, True)
-
+
def test_dns_cache_ip_to_name(self):
"""
- Test dns cache name dict
+ Test dns cache name dict
"""
tds.init()
@@ -53,7 +73,7 @@ class test_cleanup_and_exit(unittest.TestCase):
def test_dns_cache_ip_expires(self):
"""
- Test dns cache ip expires dict
+ Test dns cache ip expires dict
"""
tds.init()
diff --git a/tests/test_trapd_vnf_table.py b/tests/test_trapd_vnf_table.py
index 9e11ce9..f38d4af 100644
--- a/tests/test_trapd_vnf_table.py
+++ b/tests/test_trapd_vnf_table.py
@@ -2,6 +2,7 @@
# org.onap.dcae
# ================================================================================
# Copyright (c) 2017-2018 AT&T Intellectual Property. 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.
@@ -27,11 +28,17 @@ import unittest
import sys
import pytest
import logging
-import misshtbtd as db
-import htbtworker as pm
-import db_monitoring as dbmon
-import get_logger
-from trapd_vnf_table import verify_DB_creation_1,verify_DB_creation_2,verify_DB_creation_hb_common,verify_cbsPolling_required,hb_properties,verify_cbspolling,verify_sendControlLoop_VNF_ONSET, verify_sendControlLoop_VM_ONSET, verify_sendControlLoop_VNF_ABATED, verify_sendControlLoop_VM_ABATED, verify_fetch_json_file, verify_misshtbtdmain, verify_dbmonitoring, verify_dbmon_startup
+from miss_htbt_service import misshtbtd as db
+from miss_htbt_service import htbtworker as pm
+from miss_htbt_service import db_monitoring as dbmon
+from miss_htbt_service import get_logger
+from miss_htbt_service.mod.trapd_vnf_table import (
+ verify_DB_creation_1, verify_DB_creation_2, verify_DB_creation_hb_common,
+ verify_cbsPolling_required, hb_properties, verify_cbspolling,
+ verify_sendControlLoop_VNF_ONSET, verify_sendControlLoop_VM_ONSET,
+ verify_sendControlLoop_VNF_ABATED, verify_sendControlLoop_VM_ABATED,
+ verify_fetch_json_file, verify_misshtbtdmain, verify_dbmonitoring,
+ verify_dbmon_startup)
_logger = get_logger.get_logger(__name__)
@@ -45,20 +52,20 @@ class test_vnf_tables(unittest.TestCase):
def test_validate_vnf_table_1(self):
result =verify_DB_creation_1(user_name,password,ip_address,port_num,db_name)
self.assertEqual(result, True)
-
+
def test_validate_vnf_table_2(self):
result =verify_DB_creation_2(user_name,password,ip_address,port_num,db_name)
self.assertEqual(result, True)
-
+
def test_validate_hb_common(self):
result =verify_DB_creation_hb_common(user_name,password,ip_address,port_num,db_name)
self.assertEqual(result, True)
-
+
def test_validate_cbspolling_required(self):
result = verify_cbsPolling_required()
self.assertEqual(result, True)
-
+
def test_cbspolling(self):
result= verify_cbspolling()
_logger.info(result)
@@ -87,22 +94,22 @@ class test_vnf_tables(unittest.TestCase):
def test_sendControlLoop_VNF_ONSET(self):
result= verify_sendControlLoop_VNF_ONSET()
_logger.info(result)
- self.assertEqual(result, True)
+ self.assertEqual(result, True)
def test_sendControlLoop_VM_ONSET(self):
result= verify_sendControlLoop_VM_ONSET()
_logger.info(result)
- self.assertEqual(result, True)
+ self.assertEqual(result, True)
def test_sendControlLoop_VNF_ABATED(self):
result= verify_sendControlLoop_VNF_ABATED()
_logger.info(result)
- self.assertEqual(result, True)
+ self.assertEqual(result, True)
def test_sendControlLoop_VM_ABATED(self):
result= verify_sendControlLoop_VM_ABATED()
_logger.info(result)
- self.assertEqual(result, True)
+ self.assertEqual(result, True)
#if __name__ == '__main__':
# unittest.main()
diff --git a/tox.ini b/tox.ini
index 8d2d63b..fcec640 100644
--- a/tox.ini
+++ b/tox.ini
@@ -9,7 +9,6 @@ deps=
coverage
pytest-cov
setenv =
- PYTHONPATH={toxinidir}/miss_htbt_service:{toxinidir}/miss_htbt_service/mod:{toxinidir}/tests
CBS_HTBT_JSON={toxinidir}/etc/config.json
recreate = True
commands=