From 8ea70b60efac67f8b4ad4be8b8018a946f551d06 Mon Sep 17 00:00:00 2001 From: Satoshi Fujii Date: Wed, 13 Oct 2021 09:16:09 +0000 Subject: Fix pod become unready state The original implementation used Popen but its stdout pipe became clogged because the captured output was not processed properly. As a result, readiness check failed due to health-check server not responding and the pod became unready state. Signed-off-by: Satoshi Fujii Issue-ID: DCAEGEN2-2832 Change-Id: I98259e25fe40d5374a2c4236fc20bd631673f15e --- Changelog.md | 2 ++ miss_htbt_service/check_health.py | 6 +++++- miss_htbt_service/misshtbtd.py | 14 ++++++++++++-- tests/test_trapd_vnf_table.py | 2 +- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/Changelog.md b/Changelog.md index 54a6970..ea8694a 100644 --- a/Changelog.md +++ b/Changelog.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [2.4.0] - 2021/10/12 ### Changed - [DCAEGEN2-2939] Removed unused code (config\_notif.py) +### Fixed +- [DCAEGEN2-2832] Pod become unready state ## [2.3.1.] - 2021/06/19 diff --git a/miss_htbt_service/check_health.py b/miss_htbt_service/check_health.py index a010b31..4d04210 100644 --- a/miss_htbt_service/check_health.py +++ b/miss_htbt_service/check_health.py @@ -57,9 +57,13 @@ class GetHandler(BaseHTTPRequestHandler): return -if __name__ == '__main__': +def start_health_check_server() -> None: from http.server import HTTPServer server = HTTPServer(("", 10002), GetHandler) print('Starting server at http://localhost:10002') server.serve_forever() + + +if __name__ == '__main__': + start_health_check_server() diff --git a/miss_htbt_service/misshtbtd.py b/miss_htbt_service/misshtbtd.py index 0ebffe7..ff2f3fe 100644 --- a/miss_htbt_service/misshtbtd.py +++ b/miss_htbt_service/misshtbtd.py @@ -39,6 +39,8 @@ import yaml import socket import os.path as path from pathlib import Path + +import check_health import htbtworker as heartbeat import get_logger from mod import trapd_settings as tds @@ -48,7 +50,6 @@ hb_properties_file = path.abspath(path.join(__file__, "../config/hbproperties.ya ABSOLUTE_PATH1 = path.abspath(path.join(__file__, "../htbtworker.py")) ABSOLUTE_PATH2 = path.abspath(path.join(__file__, "../db_monitoring.py")) -ABSOLUTE_PATH3 = path.abspath(path.join(__file__, "../check_health.py")) ABSOLUTE_PATH4 = path.abspath(path.join(__file__, "../cbs_polling.py")) @@ -332,9 +333,13 @@ _logger = get_logger.get_logger(__name__) def main(): + hc_proc = multiprocessing.Process(target=check_health.start_health_check_server) try: - subprocess.Popen([ABSOLUTE_PATH3], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) _logger.info("MSHBD:Execution Started") + # Start health check server + hc_proc.start() + _logger.info("MSHBD: Started health check server. PID=%d", hc_proc.pid) + job_list = [] pid_current = os.getpid() jsfile = fetch_json_file() @@ -444,6 +449,11 @@ def main(): msg = "Fatal error. Could not start missing heartbeat service due to: {0}".format(e) _logger.error(msg) + finally: + # Stop health check server + if hc_proc.pid is not None: + hc_proc.terminate() + hc_proc.join() if __name__ == '__main__': diff --git a/tests/test_trapd_vnf_table.py b/tests/test_trapd_vnf_table.py index 577a320..4f6e5e4 100644 --- a/tests/test_trapd_vnf_table.py +++ b/tests/test_trapd_vnf_table.py @@ -43,6 +43,7 @@ class test_vnf_tables(unittest.TestCase): """ global ip_address, port_num, user_name, password, db_name, cbs_polling_required, cbs_polling_interval ip_address, port_num, user_name, password, db_name, cbs_polling_required, cbs_polling_interval = hb_properties() + 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) @@ -55,7 +56,6 @@ class test_vnf_tables(unittest.TestCase): result =verify_DB_creation_hb_common(user_name,password,ip_address,port_num,db_name) self.assertEqual(result, True) - def test_cbspolling(self): result= verify_cbspolling() _logger.info(result) -- cgit 1.2.3-korg