From 313750bef0318c2204ce869fb2bdc4d4043a20e6 Mon Sep 17 00:00:00 2001 From: Satoshi Fujii Date: Tue, 15 Jun 2021 13:33:50 +0000 Subject: Remove unused code Just remove unused code Signed-off-by: Satoshi Fujii Issue-ID: DCAEGEN2-2833 Change-Id: If81a5fcb918a2683e261807d6a3da5a8648e505d --- Changelog.md | 1 + miss_htbt_service/cbs_polling.py | 2 -- miss_htbt_service/check_health.py | 1 - miss_htbt_service/config_notif.py | 1 - miss_htbt_service/db_monitoring.py | 1 - miss_htbt_service/get_logger.py | 5 ----- miss_htbt_service/misshtbtd.py | 17 ----------------- miss_htbt_service/mod/trapd_runtime_pid.py | 4 ---- miss_htbt_service/mod/trapd_vnf_table.py | 21 --------------------- tests/test_binding.py | 17 ----------------- tests/test_trapd_exit.py | 6 ------ tests/test_trapd_get_cbs_config.py | 29 ----------------------------- tests/test_trapd_http_session.py | 4 ---- tests/test_trapd_runtime_pid.py | 4 ---- tests/test_trapd_settings.py | 4 ---- tests/test_trapd_vnf_table.py | 3 --- 16 files changed, 1 insertion(+), 119 deletions(-) diff --git a/Changelog.md b/Changelog.md index 6af1cd9..40984a9 100644 --- a/Changelog.md +++ b/Changelog.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Changed - Cleanup code - Removed unused imports + - Removed unused code - Reformatted code whitespace - Add target/ to .gitignore diff --git a/miss_htbt_service/cbs_polling.py b/miss_htbt_service/cbs_polling.py index d1253c0..d2be0d9 100644 --- a/miss_htbt_service/cbs_polling.py +++ b/miss_htbt_service/cbs_polling.py @@ -48,8 +48,6 @@ def pollCBS(current_pid): 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) - # connection_db = pm.postgres_db_open(user_name,password,ip_address,port_num,db_name) - # cur = connection_db.cursor() source_name = socket.gethostname() source_name = source_name + "-" + str(os.getenv('SERVICE_NAME', "")) result = True diff --git a/miss_htbt_service/check_health.py b/miss_htbt_service/check_health.py index 739cd2b..a010b31 100644 --- a/miss_htbt_service/check_health.py +++ b/miss_htbt_service/check_health.py @@ -60,7 +60,6 @@ class GetHandler(BaseHTTPRequestHandler): if __name__ == '__main__': from http.server import HTTPServer - # from BaseHTTPServer import HTTPServer server = HTTPServer(("", 10002), GetHandler) print('Starting server at http://localhost:10002') server.serve_forever() diff --git a/miss_htbt_service/config_notif.py b/miss_htbt_service/config_notif.py index 087315d..cba898d 100644 --- a/miss_htbt_service/config_notif.py +++ b/miss_htbt_service/config_notif.py @@ -199,7 +199,6 @@ def fetch_json_file(download_json="../etc/download1.json", config_json="../etc/c return jsfile -# if __name__ == "__main__": def config_notif_run(): jsfile = fetch_json_file() ip_address, port_num, user_name, password, db_name, cbs_polling_required, cbs_polling_interval = read_hb_properties( diff --git a/miss_htbt_service/db_monitoring.py b/miss_htbt_service/db_monitoring.py index 708a2bd..8704966 100644 --- a/miss_htbt_service/db_monitoring.py +++ b/miss_htbt_service/db_monitoring.py @@ -118,7 +118,6 @@ def sendControlLoopEvent(CLType, pol_url, policy_version, policy_name, policy_sc payload = json_object msg = "DBM: CL Json object is", json_object _logger.info(msg) - # psend_url = pol_url+'DefaultGroup/1?timeout=15000' psend_url = pol_url msg = "DBM:", psend_url _logger.info(msg) diff --git a/miss_htbt_service/get_logger.py b/miss_htbt_service/get_logger.py index bc8fea0..c58a945 100644 --- a/miss_htbt_service/get_logger.py +++ b/miss_htbt_service/get_logger.py @@ -20,7 +20,6 @@ import logging.handlers '''Configures the module root logger''' root = logging.getLogger() if root.handlers: - # root.handlers.clear() del root.handlers[:] formatter = logging.Formatter('%(asctime)s | %(name)s | %(module)s | %(funcName)s | %(lineno)d | %(levelname)s | %(message)s') handler = logging.StreamHandler() @@ -32,10 +31,6 @@ root.addHandler(fhandler) root.setLevel("DEBUG") -class BadEnviornmentENVNotFound(Exception): - pass - - def get_logger(module=None): '''Returns a module-specific logger or global logger if the module is None''' return root if module is None else root.getChild(module) diff --git a/miss_htbt_service/misshtbtd.py b/miss_htbt_service/misshtbtd.py index 12d439a..1808439 100644 --- a/miss_htbt_service/misshtbtd.py +++ b/miss_htbt_service/misshtbtd.py @@ -71,14 +71,6 @@ def create_database(update_db, jsfile, ip_address, port_num, user_name, password cur.execute(query_value) else: _logger.info("MSHBD:Database already exists") - ''' - con = None - con = connect(user=user_name, host = ip_address, password=password) - database_name = db_name - con.autocommit = True - cur = con.cursor() - cur.execute('CREATE DATABASE %s IF NOT EXISTS %s' %(database_name,database_name)) - ''' cur.close() con.close() except(Exception) as err: @@ -86,12 +78,6 @@ def create_database(update_db, jsfile, ip_address, port_num, user_name, password _logger.error(msg) -# def get_pol_and_mr_urls(jsfile, pol_url, mr_url): -# with open(jsfile, 'r') as outfile: -# cfg = json.load(outfile) -# mr_url = str(cfg['streams_subscribes']['ves-heartbeat']['dmaap_info']['topic_url']) -# pol_url = str(cfg['streams_publishes']['dcae_cl_out']['dmaap_info']['topic_url']) - def read_hb_common(user_name, password, ip_address, port_num, db_name): envPytest = os.getenv('pytest', "") if (envPytest == 'test'): @@ -158,7 +144,6 @@ def create_update_vnf_table_1(jsfile, update_db, connection_db): vnf_list = [item[0] for item in cur.fetchall()] for vnf in (jhbcfg['vnfs']): nfc = vnf['eventName'] - # _logger.error("MSHBT:",nfc) validity_flag = 1 source_name_count = 0 missed = vnf['heartbeatcountmissed'] @@ -177,7 +162,6 @@ def create_update_vnf_table_1(jsfile, update_db, connection_db): 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) if (envPytest != 'test'): cur.close() _logger.info("MSHBT:Updated vnf_table_1 as per the json configuration file") @@ -261,7 +245,6 @@ def read_hb_properties(jsfile): def fetch_json_file(): if get_cbs_config(): - # current_runtime_config_file_name = tds.c_config['files.runtime_base_dir'] + "../etc/download.json" envPytest = os.getenv('pytest', "") if (envPytest == 'test'): current_runtime_config_file_name = "/tmp/opt/app/miss_htbt_service/etc/config.json" diff --git a/miss_htbt_service/mod/trapd_runtime_pid.py b/miss_htbt_service/mod/trapd_runtime_pid.py index 7194b8f..d2db83d 100644 --- a/miss_htbt_service/mod/trapd_runtime_pid.py +++ b/miss_htbt_service/mod/trapd_runtime_pid.py @@ -56,11 +56,7 @@ def save_pid(_pid_file_name): except IOError: print("IOError saving PID file %s :" % _pid_file_name) return False - # except: - # print("Error saving PID file %s :" % _pid_file_name) - # return False else: - # print("Runtime PID file: %s" % _pid_file_name) return True diff --git a/miss_htbt_service/mod/trapd_vnf_table.py b/miss_htbt_service/mod/trapd_vnf_table.py index 001b566..81f1f3b 100644 --- a/miss_htbt_service/mod/trapd_vnf_table.py +++ b/miss_htbt_service/mod/trapd_vnf_table.py @@ -61,7 +61,6 @@ def hb_properties(): 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() try: _db_status=pm.db_table_creation_check(connection_db,"vnf_table_1") except Exception as e: @@ -72,7 +71,6 @@ def verify_DB_creation_1(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) - # cur = connection_db.cursor() try: _db_status=pm.db_table_creation_check(connection_db,"vnf_table_2") except Exception as e: @@ -83,7 +81,6 @@ def verify_DB_creation_2(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) - #cur = connection_db.cursor() try: _db_status=pm.db_table_creation_check(connection_db,"hb_common") except Exception as e: @@ -95,14 +92,12 @@ def verify_DB_creation_hb_common(user_name,password,ip_address,port_num,db_name) def verify_cbsPolling_required(): _cbspolling_status = True os.environ['pytest']='test' - #os.environ['CONSUL_HOST']='10.12.6.50' # Used this IP during testing os.environ['CONSUL_HOST']='localhost' os.environ['SERVICE_NAME']='mvp-dcaegen2-heartbeat-static' try: _cbspolling_status=cf.config_notif_run() except Exception as e: print("Config_notify error - %s" % e) - #return None os.unsetenv('pytest') os.unsetenv('CONSUL_HOST') @@ -115,9 +110,6 @@ def verify_cbspolling(): try: _cbspolling=cbs.pollCBS(10) except Exception as e: - # print("CBSP error - %s" % e) - # print("CBSP error - %s" % e, file=sys.stderr) - # print("Stack: {0}".format(traceback.format_exc()), file=sys.stderr) return None os.unsetenv('pytest') @@ -127,7 +119,6 @@ def verify_cbspolling(): def verify_fetch_json_file(): os.environ['pytest']='test' os.environ['SERVICE_NAME']='mvp-dcaegen2-heartbeat-static' - #os.environ['CONSUL_HOST']='10.12.6.50' # Used this IP during testing os.environ['CONSUL_HOST']='localhost' os.environ['HOSTNAME']='mvp-dcaegen2-heartbeat-static' try: @@ -145,7 +136,6 @@ def verify_fetch_json_file(): def verify_misshtbtdmain(): os.environ['pytest']='test' os.environ['SERVICE_NAME']='mvp-dcaegen2-heartbeat-static' - #os.environ['CONSUL_HOST']='10.12.6.50' os.environ['CONSUL_HOST']='localhost' os.environ['HOSTNAME']='mvp-dcaegen2-heartbeat-static' @@ -164,7 +154,6 @@ def verify_misshtbtdmain(): def verify_dbmonitoring(): os.environ['pytest']='test' os.environ['SERVICE_NAME']='mvp-dcaegen2-heartbeat-static' - #os.environ['CONSUL_HOST']='10.12.6.50' os.environ['CONSUL_HOST']='localhost' os.environ['HOSTNAME']='mvp-dcaegen2-heartbeat-static' try: @@ -188,18 +177,14 @@ 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 - %s" % e) return None return True def verify_sendControlLoop_VNF_ONSET(): try: -# _CL_return = sendControlLoopEvent(CLType, pol_url, policy_version, policy_name, policy_scope, target_type, srcName, epoc_time, closed_control_loop_name, version, target) 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") except Exception as e: - #msg = "Message process error - ",err - #_logger.error(msg) return None return _CL_return @@ -208,8 +193,6 @@ def verify_sendControlLoop_VM_ONSET(): 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") except Exception as e: - #msg = "Message process error - ",err - #_logger.error(msg) return None return _CL_return @@ -218,8 +201,6 @@ def verify_sendControlLoop_VNF_ABATED(): 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") except Exception as e: - #msg = "Message process error - ",err - #_logger.error(msg) return None return _CL_return @@ -228,7 +209,5 @@ def verify_sendControlLoop_VM_ABATED(): 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") except Exception as e: -# msg = "Message process error - ",err -# _logger.error(msg) return None return _CL_return diff --git a/tests/test_binding.py b/tests/test_binding.py index 82e9f7f..010c63d 100644 --- a/tests/test_binding.py +++ b/tests/test_binding.py @@ -28,14 +28,12 @@ MODULE_EXTENSIONS = ('.py', '.pyc', '.pyo') # MONKEYPATCHES ##### -#mr_url = 'http://127.0.0.1:3904' mr_url = 'http://mrrouter.onap.org:3904' intopic = 'VESCOLL-VNFNJ-SECHEARTBEAT-OUTPUT' outopic = 'POLICY-HILOTCA-EVENT-OUTPUT' @httpretty.activate def test_resolve_all(): - #htbtmsg = "Find the best daily deals" 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) @@ -53,21 +51,6 @@ def test_resolve_all(): pol_body = json.dumps({"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"}}}) print("Policy URL : "+pol_url) httpretty.register_uri(httpretty.POST, pol_url, body=pol_body, status=200, content_type='text/json') - #misshtbtd.main() - #ret = htbtworker.periodic_event() - #print("Returned",ret) - #assert(ret == 1) def test_full(): p = subprocess.Popen(['./miss_htbt_service/misshtbtd.py'], stdout=subprocess.PIPE,shell=True) - #time.sleep(30) - #r = requests.get('http://localhost:10002') - #print(r.status_code) - #assert(r.status_code == 200) - #r = requests.post('http://127.0.0.1:10002',data={'number': '12524', 'health': 'good', 'action': 'show'}) - #r = requests.post('http://localhost:10002',data={'number': '12524', 'health': 'good', 'action': 'show'}) - #print(r.status_code) - #assert(r.status_code == 200) - -#def test_conifg_notif(): - #config_notif.config_notif_run() diff --git a/tests/test_trapd_exit.py b/tests/test_trapd_exit.py index 93e8f9a..35b7111 100644 --- a/tests/test_trapd_exit.py +++ b/tests/test_trapd_exit.py @@ -39,9 +39,6 @@ class test_cleanup_and_exit(unittest.TestCase): assert pytest_wrapped_sys_exit.type == SystemExit assert pytest_wrapped_sys_exit.value.code == 0 - # compare = str(result).startswith("SystemExit: 0") - # self.assertEqual(compare, True) - def test_abnormal_exit(self): """ Test exit with missing PID file exits non-zero @@ -50,6 +47,3 @@ class test_cleanup_and_exit(unittest.TestCase): result = trapd_exit.cleanup_and_exit(0,pid_file_dne) assert pytest_wrapped_sys_exit.type == SystemExit assert pytest_wrapped_sys_exit.value.code == 1 - -#if __name__ == '__main__': -# unittest.main() diff --git a/tests/test_trapd_get_cbs_config.py b/tests/test_trapd_get_cbs_config.py index ea859af..6cebef2 100644 --- a/tests/test_trapd_get_cbs_config.py +++ b/tests/test_trapd_get_cbs_config.py @@ -29,7 +29,6 @@ class test_get_cbs_config(unittest.TestCase): 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" with open(pytest_json_config, 'w') as outfile: @@ -41,32 +40,10 @@ class test_get_cbs_config(unittest.TestCase): Test that CONSUL_HOST env variable exists but fails to respond """ - #os.environ.update(CONSUL_HOST='nosuchhost') - #del os.environ['CBS_HTBT_JSON'] - #result = trapd_get_cbs_config.get_cbs_config() - #print("result: %s" % result) - #compare = str(result).startswith("{'snmptrap': ") - #self.assertEqual(compare, False) with pytest.raises(Exception) as pytest_wrapped_sys_exit: result = trapd_get_cbs_config.get_cbs_config() assert pytest_wrapped_sys_exit.type == SystemExit - # assert pytest_wrapped_sys_exit.value.code == 1 - - -# def test_cbs_override_env_invalid(self): -# """ -# """ -# #os.environ.update(CBS_HTBT_JSON='/tmp/opt/app/miss_htbt_service/etc/nosuchfile.json') -# #result = trapd_get_cbs_config.get_cbs_config() -# #print("result: %s" % result) -# #compare = str(result).startswith("{'snmptrap': ") -# #self.assertEqual(compare, False) -# -# with pytest.raises(SystemExit) as pytest_wrapped_sys_exit: -# result = trapd_get_cbs_config.get_cbs_config() -# assert pytest_wrapped_sys_exit.type == SystemExit -# assert pytest_wrapped_sys_exit.value.code == 1 def test_cbs_fallback_env_present(self): @@ -75,12 +52,6 @@ class test_get_cbs_config(unittest.TestCase): from fallback env var """ os.environ.update(CBS_HTBT_JSON='/tmp/opt/app/miss_htbt_service/etc/config.json') - #result = trapd_get_cbs_config.get_cbs_config() result = True print("result: %s" % result) - # 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 d36ced0..47380fc 100644 --- a/tests/test_trapd_http_session.py +++ b/tests/test_trapd_http_session.py @@ -31,7 +31,3 @@ class test_init_session_obj(unittest.TestCase): result = trapd_http_session.init_session_obj() compare = str(result).startswith("