aboutsummaryrefslogtreecommitdiffstats
path: root/miss_htbt_service/mod
diff options
context:
space:
mode:
Diffstat (limited to 'miss_htbt_service/mod')
-rw-r--r--miss_htbt_service/mod/trapd_exit.py11
-rw-r--r--miss_htbt_service/mod/trapd_get_cbs_config.py32
-rw-r--r--miss_htbt_service/mod/trapd_http_session.py6
-rw-r--r--miss_htbt_service/mod/trapd_io.py23
-rw-r--r--miss_htbt_service/mod/trapd_runtime_pid.py10
-rw-r--r--miss_htbt_service/mod/trapd_settings.py6
-rw-r--r--miss_htbt_service/mod/trapd_vnf_table.py193
7 files changed, 162 insertions, 119 deletions
diff --git a/miss_htbt_service/mod/trapd_exit.py b/miss_htbt_service/mod/trapd_exit.py
index c741fe5..aae12bb 100644
--- a/miss_htbt_service/mod/trapd_exit.py
+++ b/miss_htbt_service/mod/trapd_exit.py
@@ -1,9 +1,7 @@
# ============LICENSE_START=======================================================
-# org.onap.dcae
-# ================================================================================
-# Copyright (c) 2017-2020 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2017-2021 AT&T Intellectual Property. All rights reserved.
# Copyright (c) 2019 Pantheon.tech. All rights reserved.
-# Copyright 2020 Deutsche Telekom. All rights reserved.
+# Copyright (c) 2020 Deutsche Telekom. 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 +21,7 @@ trapc_exit_snmptrapd is responsible for removing any existing runtime PID
file, and exiting with the provided (param 1) exit code
"""
-__docformat__ = 'restructuredtext'
+__docformat__ = "restructuredtext"
import sys
import os
@@ -62,6 +60,7 @@ def cleanup_and_exit(_loc_exit_code, _pid_file_name):
rc = rm_pid(_pid_file_name)
sys.exit(_loc_exit_code)
+
# # # # # # # # # # # # #
# fx: cleanup_and_exit
# - remove pid file
@@ -89,5 +88,3 @@ def cleanup(_loc_exit_code, _pid_file_name):
if _pid_file_name is not None:
rc = 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 70dac53..f9fd4c3 100644
--- a/miss_htbt_service/mod/trapd_get_cbs_config.py
+++ b/miss_htbt_service/mod/trapd_get_cbs_config.py
@@ -1,10 +1,8 @@
# ============LICENSE_START=======================================================
-# org.onap.dcae
-# ================================================================================
# Copyright (c) 2018-2021 AT&T Intellectual Property. All rights reserved.
# Copyright (c) 2019 Pantheon.tech. All rights reserved.
-# Copyright 2020 Deutsche Telekom. All rights reserved.
-# Copyright 2021 Samsung Electronics. All rights reserved.
+# Copyright (c) 2020 Deutsche Telekom. All rights reserved.
+# Copyright (c) 2021 Samsung Electronics. 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.
@@ -25,7 +23,7 @@ env variable that specifies JSON equiv of CBS config (typically used for
testing purposes)
"""
-__docformat__ = 'restructuredtext'
+__docformat__ = "restructuredtext"
import json
import os
@@ -36,7 +34,7 @@ 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
+from mod.trapd_exit import cleanup, cleanup_and_exit
from mod.trapd_io import stdout_logger
prog_name = os.path.basename(__file__)
@@ -75,46 +73,44 @@ def get_cbs_config():
_cbs_sim_json_file = os.getenv("CBS_HTBT_JSON", "None")
except Exception as e:
stdout_logger(msg)
- cleanup(1,None)
+ cleanup(1, None)
return False
msg = "CBS_HTBT_JSON not defined - FATAL ERROR, exiting"
if _cbs_sim_json_file == "None":
stdout_logger(msg)
- cleanup(1,None)
+ cleanup(1, None)
return False
else:
- msg = ("ONAP controller override specified via CBS_HTBT_JSON: %s" %
- _cbs_sim_json_file)
+ msg = "ONAP controller override specified via CBS_HTBT_JSON: %s" % _cbs_sim_json_file
stdout_logger(msg)
- msg = "Unable to load CBS_HTBT_JSON " + _cbs_sim_json_file + \
- " (invalid json?) - FATAL ERROR, exiting"
+ 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:
stdout_logger(msg)
- cleanup_and_exit(0,None)
+ 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
+ tds.timeout_seconds = tds.c_config["publisher.http_timeout_milliseconds"] / 1000.0
except Exception as e:
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
+ tds.seconds_between_retries = tds.c_config["publisher.http_milliseconds_between_retries"] / 1000.0
except Exception as e:
- tds.seconds_between_retries = .750
+ 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']
+ tds.minimum_severity_to_log = tds.c_config["files.minimum_severity_to_log"]
except Exception as e:
tds.minimum_severity_to_log = 3
try:
- tds.publisher_retries = tds.c_config['publisher.http_retries']
+ tds.publisher_retries = tds.c_config["publisher.http_retries"]
except Exception as e:
tds.publisher_retries = 3
diff --git a/miss_htbt_service/mod/trapd_http_session.py b/miss_htbt_service/mod/trapd_http_session.py
index 0d7f220..fc7e865 100644
--- a/miss_htbt_service/mod/trapd_http_session.py
+++ b/miss_htbt_service/mod/trapd_http_session.py
@@ -1,7 +1,5 @@
# ============LICENSE_START=======================================================
-# org.onap.dcae
-# ================================================================================
-# Copyright (c) 2017-2020 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2017-2021 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,7 +19,7 @@ trapd_http_session establishes an http session for future use in publishing
messages to the dmaap cluster.
"""
-__docformat__ = 'restructuredtext'
+__docformat__ = "restructuredtext"
import os
import requests
diff --git a/miss_htbt_service/mod/trapd_io.py b/miss_htbt_service/mod/trapd_io.py
index d60f060..3e03999 100644
--- a/miss_htbt_service/mod/trapd_io.py
+++ b/miss_htbt_service/mod/trapd_io.py
@@ -1,9 +1,7 @@
# ============LICENSE_START=======================================================)
-# org.onap.dcae
-# ================================================================================
-# Copyright (c) 2018-2020 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2018-2021 AT&T Intellectual Property. All rights reserved.
# Copyright (c) 2019 Pantheon.tech. All rights reserved.
-# Copyright 2020 Deutsche Telekom. All rights reserved.
+# Copyright (c) 2020 Deutsche Telekom. 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 +19,7 @@
"""
"""
-__docformat__ = 'restructuredtext'
+__docformat__ = "restructuredtext"
# basics
import datetime
@@ -36,6 +34,7 @@ import string
import time
import traceback
import unicodedata
+
# dcae_snmptrap
import mod.trapd_settings as tds
from mod.trapd_exit import cleanup_and_exit
@@ -48,7 +47,7 @@ prog_name = os.path.basename(__file__)
# # # # # # # # # # ## # # # # # # #
-#def roll_all_logs():
+# def roll_all_logs():
# """
# roll all active logs to timestamped version, open new one
# based on frequency defined in files.roll_frequency
@@ -107,7 +106,7 @@ prog_name = os.path.basename(__file__)
# # # # # # # # # # ## # # # # # # #
-#def open_eelf_logs():
+# def open_eelf_logs():
# """
# open various (multiple ???) logs
# """
@@ -159,7 +158,7 @@ prog_name = os.path.basename(__file__)
# # # # # # # # # # ## # # # # # # #
-#def roll_file(_loc_file_name):
+# def roll_file(_loc_file_name):
# """
# move active file to timestamped archive
# """
@@ -190,7 +189,7 @@ prog_name = os.path.basename(__file__)
## # # # # # # # # # # # #
#
#
-#def open_file(_loc_file_name):
+# def open_file(_loc_file_name):
# """
# open _loc_file_name, return file handle
# """
@@ -214,7 +213,7 @@ prog_name = os.path.basename(__file__)
# """
#
#
-#def close_file(_loc_fd, _loc_filename):
+# def close_file(_loc_fd, _loc_filename):
#
# try:
#
@@ -231,7 +230,7 @@ prog_name = os.path.basename(__file__)
## is released for python via LOG-161
## # # # # # # # # # ## # # # # # # #
#
-#def ecomp_logger(_log_type, _sev, _error_code, _msg):
+# def ecomp_logger(_log_type, _sev, _error_code, _msg):
# """
# Log to ecomp-style logfiles. Logs include:
#
@@ -389,4 +388,4 @@ def stdout_logger(_msg):
t_out = datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S,%f")[:-3]
- print('%s %s' % (t_out, _msg))
+ print("%s %s" % (t_out, _msg))
diff --git a/miss_htbt_service/mod/trapd_runtime_pid.py b/miss_htbt_service/mod/trapd_runtime_pid.py
index d2db83d..47612bd 100644
--- a/miss_htbt_service/mod/trapd_runtime_pid.py
+++ b/miss_htbt_service/mod/trapd_runtime_pid.py
@@ -1,7 +1,5 @@
# ============LICENSE_START=======================================================
-# org.onap.dcae
-# ================================================================================
-# Copyright (c) 2017-2020 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2017-2021 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,7 +19,7 @@ trapd_runtime_pid maintains a 'PID file' (file that contains the
PID of currently running trap receiver)
"""
-__docformat__ = 'restructuredtext'
+__docformat__ = "restructuredtext"
import logging
import os
@@ -50,8 +48,8 @@ def save_pid(_pid_file_name):
"""
try:
- pid_fd = open(_pid_file_name, 'w')
- pid_fd.write('%d' % os.getpid())
+ pid_fd = open(_pid_file_name, "w")
+ pid_fd.write("%d" % os.getpid())
pid_fd.close()
except IOError:
print("IOError saving PID file %s :" % _pid_file_name)
diff --git a/miss_htbt_service/mod/trapd_settings.py b/miss_htbt_service/mod/trapd_settings.py
index 0c8457f..3e7f141 100644
--- a/miss_htbt_service/mod/trapd_settings.py
+++ b/miss_htbt_service/mod/trapd_settings.py
@@ -1,7 +1,5 @@
# ============LICENSE_START=======================================================)
-# org.onap.dcae
-# ================================================================================
-# Copyright (c) 2018-2020 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2018-2021 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.
@@ -19,7 +17,7 @@
"""
"""
-__docformat__ = 'restructuredtext'
+__docformat__ = "restructuredtext"
def init():
diff --git a/miss_htbt_service/mod/trapd_vnf_table.py b/miss_htbt_service/mod/trapd_vnf_table.py
index db6bd17..1b00336 100644
--- a/miss_htbt_service/mod/trapd_vnf_table.py
+++ b/miss_htbt_service/mod/trapd_vnf_table.py
@@ -1,11 +1,9 @@
# ============LICENSE_START=======================================================
-# org.onap.dcae
-# ================================================================================
-# Copyright (c) 2017-2020 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2017-2021 AT&T Intellectual Property. All rights reserved.
# Copyright (c) 2019 Pantheon.tech. All rights reserved.
-# Copyright 2020 Deutsche Telekom. All rights reserved.
-# Copyright 2021 Samsung Electronics. All rights reserved.
-# Copyright 2021 Fujitsu Ltd.
+# Copyright (c) 2020 Deutsche Telekom. All rights reserved.
+# Copyright (c) 2021 Samsung Electronics. All rights reserved.
+# Copyright (c) 2021 Fujitsu Ltd.
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -44,45 +42,47 @@ _logger = logging.getLogger(__name__)
def hb_properties():
- #Read the hbproperties.yaml for postgress and CBS related data
- s=open(hb_properties_file, 'r')
- a=yaml.full_load(s)
- ip_address = a['pg_ipAddress']
- port_num = a['pg_portNum']
- user_name = a['pg_userName']
- password = a['pg_passwd']
- dbName = a['pg_dbName']
- db_name = dbName.lower()
- cbs_polling_required = a['CBS_polling_allowed']
- cbs_polling_interval = a['CBS_polling_interval']
- 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)
+ # Read the hbproperties.yaml for postgress and CBS related data
+ s = open(hb_properties_file, "r")
+ a = yaml.full_load(s)
+ ip_address = a["pg_ipAddress"]
+ port_num = a["pg_portNum"]
+ user_name = a["pg_userName"]
+ password = a["pg_passwd"]
+ dbName = a["pg_dbName"]
+ db_name = dbName.lower()
+ cbs_polling_required = a["CBS_polling_allowed"]
+ cbs_polling_interval = a["CBS_polling_interval"]
+ 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)
try:
- _db_status=pm.db_table_creation_check(connection_db,"vnf_table_1")
+ _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)
+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")
+ _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)
+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)
try:
- _db_status=pm.db_table_creation_check(connection_db,"hb_common")
+ _db_status = pm.db_table_creation_check(connection_db, "hb_common")
except Exception as e:
return None
@@ -90,35 +90,36 @@ def verify_DB_creation_hb_common(user_name,password,ip_address,port_num,db_name)
def verify_cbspolling():
- os.environ['pytest']='test'
- os.environ['SERVICE_NAME']='mvp-dcaegen2-heartbeat-static'
+ os.environ["pytest"] = "test"
+ os.environ["SERVICE_NAME"] = "mvp-dcaegen2-heartbeat-static"
cbs.poll_cbs(10)
- os.unsetenv('pytest')
- os.unsetenv('SERVICE_NAME')
+ os.unsetenv("pytest")
+ os.unsetenv("SERVICE_NAME")
def verify_fetch_json_file():
- os.environ['pytest']='test'
- os.environ['SERVICE_NAME']='mvp-dcaegen2-heartbeat-static'
- os.environ['CONSUL_HOST']='localhost'
- os.environ['HOSTNAME']='mvp-dcaegen2-heartbeat-static'
+ os.environ["pytest"] = "test"
+ os.environ["SERVICE_NAME"] = "mvp-dcaegen2-heartbeat-static"
+ os.environ["CONSUL_HOST"] = "localhost"
+ os.environ["HOSTNAME"] = "mvp-dcaegen2-heartbeat-static"
try:
- db.fetch_json_file()
- result = True
+ db.fetch_json_file()
+ result = True
except Exception as e:
- result = False
+ result = False
print(result)
- os.unsetenv('pytest')
- os.unsetenv('SERVICE_NAME')
- os.unsetenv('CONSUL_HOST')
- os.unsetenv('HOSTNAME')
+ os.unsetenv("pytest")
+ os.unsetenv("SERVICE_NAME")
+ os.unsetenv("CONSUL_HOST")
+ os.unsetenv("HOSTNAME")
return result
+
def verify_misshtbtdmain():
- os.environ['pytest']='test'
- os.environ['SERVICE_NAME']='mvp-dcaegen2-heartbeat-static'
- os.environ['CONSUL_HOST']='localhost'
- os.environ['HOSTNAME']='mvp-dcaegen2-heartbeat-static'
+ os.environ["pytest"] = "test"
+ os.environ["SERVICE_NAME"] = "mvp-dcaegen2-heartbeat-static"
+ os.environ["CONSUL_HOST"] = "localhost"
+ os.environ["HOSTNAME"] = "mvp-dcaegen2-heartbeat-static"
try:
db.main()
@@ -126,69 +127,125 @@ def verify_misshtbtdmain():
except Exception as e:
result = False
print(result)
- os.unsetenv('pytest')
- os.unsetenv('SERVICE_NAME')
- os.unsetenv('CONSUL_HOST')
- os.unsetenv('HOSTNAME')
+ os.unsetenv("pytest")
+ os.unsetenv("SERVICE_NAME")
+ os.unsetenv("CONSUL_HOST")
+ os.unsetenv("HOSTNAME")
return result
+
def verify_dbmonitoring():
- os.environ['pytest']='test'
- os.environ['SERVICE_NAME']='mvp-dcaegen2-heartbeat-static'
- os.environ['CONSUL_HOST']='localhost'
- os.environ['HOSTNAME']='mvp-dcaegen2-heartbeat-static'
+ os.environ["pytest"] = "test"
+ os.environ["SERVICE_NAME"] = "mvp-dcaegen2-heartbeat-static"
+ os.environ["CONSUL_HOST"] = "localhost"
+ os.environ["HOSTNAME"] = "mvp-dcaegen2-heartbeat-static"
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(user_name,password,ip_address,port_num,db_name)
- dbmon.db_monitoring(hbc_pid,jsfile,user_name,password,ip_address,port_num,db_name)
+ hbc_pid, hbc_state, hbc_srcName, 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)
result = True
except Exception as e:
print("Message process error - %s" % e)
result = False
print(result)
- os.unsetenv('pytest')
- os.unsetenv('SERVICE_NAME')
- os.unsetenv('CONSUL_HOST')
- os.unsetenv('HOSTNAME')
+ os.unsetenv("pytest")
+ os.unsetenv("SERVICE_NAME")
+ os.unsetenv("CONSUL_HOST")
+ os.unsetenv("HOSTNAME")
return result
+
def verify_dbmon_startup():
try:
- p = subprocess.Popen(['./miss_htbt_service/db_monitoring.py'], stdout=subprocess.PIPE,shell=True)
+ p = subprocess.Popen(["./miss_htbt_service/db_monitoring.py"], stdout=subprocess.PIPE, shell=True)
time.sleep(1)
except Exception as e:
return None
return True
+
def verify_sendControlLoop_VNF_ONSET():
try:
pol_url = "http://10.12.5.252:3904/events/unauthenticated.DCAE_CL_OUTPUT/"
- _CL_return = dbmon.sendControlLoopEvent("ONSET", pol_url, "1.0", "vFireWall", "pscope", "VNF", "srcname1", 1541234567, "SampleCLName", "1.0", "genVnfName")
+ _CL_return = dbmon.sendControlLoopEvent(
+ "ONSET",
+ pol_url,
+ "1.0",
+ "vFireWall",
+ "pscope",
+ "VNF",
+ "srcname1",
+ 1541234567,
+ "SampleCLName",
+ "1.0",
+ "genVnfName",
+ )
except Exception as e:
return None
return _CL_return
+
def verify_sendControlLoop_VM_ONSET():
try:
pol_url = "http://10.12.5.252:3904/events/unauthenticated.DCAE_CL_OUTPUT/"
- _CL_return = dbmon.sendControlLoopEvent("ONSET", pol_url, "1.0", "vFireWall", "pscope", "VM", "srcname1", 1541234567, "SampleCLName", "1.0", "genVnfName")
+ _CL_return = dbmon.sendControlLoopEvent(
+ "ONSET",
+ pol_url,
+ "1.0",
+ "vFireWall",
+ "pscope",
+ "VM",
+ "srcname1",
+ 1541234567,
+ "SampleCLName",
+ "1.0",
+ "genVnfName",
+ )
except Exception as e:
return None
return _CL_return
+
def verify_sendControlLoop_VNF_ABATED():
try:
pol_url = "http://10.12.5.252:3904/events/unauthenticated.DCAE_CL_OUTPUT/"
- _CL_return = dbmon.sendControlLoopEvent("ABATED", pol_url, "1.0", "vFireWall", "pscope", "VNF", "srcname1", 1541234567, "SampleCLName", "1.0", "genVnfName")
+ _CL_return = dbmon.sendControlLoopEvent(
+ "ABATED",
+ pol_url,
+ "1.0",
+ "vFireWall",
+ "pscope",
+ "VNF",
+ "srcname1",
+ 1541234567,
+ "SampleCLName",
+ "1.0",
+ "genVnfName",
+ )
except Exception as e:
return None
return _CL_return
+
def verify_sendControlLoop_VM_ABATED():
try:
pol_url = "http://10.12.5.252:3904/events/unauthenticated.DCAE_CL_OUTPUT/"
- _CL_return = dbmon.sendControlLoopEvent("ABATED", pol_url, "1.0", "vFireWall", "pscope", "VM", "srcname1", 1541234567, "SampleCLName", "1.0", "genVnfName")
+ _CL_return = dbmon.sendControlLoopEvent(
+ "ABATED",
+ pol_url,
+ "1.0",
+ "vFireWall",
+ "pscope",
+ "VM",
+ "srcname1",
+ 1541234567,
+ "SampleCLName",
+ "1.0",
+ "genVnfName",
+ )
except Exception as e:
return None
return _CL_return