From 93176718922ff81df55188bccd064ed31991eea9 Mon Sep 17 00:00:00 2001 From: William Tsai Date: Fri, 13 Feb 2026 17:08:01 -0800 Subject: [PATCH] Include generated services in Sysmonitor Signed-off-by: William Tsai --- .../health_checker/sysmonitor.py | 2 +- src/system-health/tests/test_system_health.py | 26 ++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/system-health/health_checker/sysmonitor.py b/src/system-health/health_checker/sysmonitor.py index e3f1e86afb7..31af7de258d 100755 --- a/src/system-health/health_checker/sysmonitor.py +++ b/src/system-health/health_checker/sysmonitor.py @@ -327,7 +327,7 @@ def get_unit_status(self, event): #Raise syslog for service state change logger.log_info("{} service state changed to [{}/{}]".format(event, active_state, sub_state)) - if status == "enabled" or status == "enabled-runtime" or status == "static": + if status in ("enabled", "enabled-runtime", "static", "generated"): if fail_reason == "success": fail_reason = "-" if (active_state == "active" and sub_state == "exited"): diff --git a/src/system-health/tests/test_system_health.py b/src/system-health/tests/test_system_health.py index c0b28787395..90ce0c42bc2 100644 --- a/src/system-health/tests/test_system_health.py +++ b/src/system-health/tests/test_system_health.py @@ -789,7 +789,9 @@ def test_get_app_ready_status(mock_config_db, mock_run, mock_docker_client): mock_srv_props={ 'mock_radv.service':{'Type': 'simple', 'Result': 'success', 'Id': 'mock_radv.service', 'LoadState': 'loaded', 'ActiveState': 'active', 'SubState': 'running', 'UnitFileState': 'enabled'}, -'mock_bgp.service':{'Type': 'simple', 'Result': 'success', 'Id': 'mock_bgp.service', 'LoadState': 'loaded', 'ActiveState': 'inactive', 'SubState': 'dead', 'UnitFileState': 'enabled'} +'mock_bgp.service':{'Type': 'simple', 'Result': 'success', 'Id': 'mock_bgp.service', 'LoadState': 'loaded', 'ActiveState': 'inactive', 'SubState': 'dead', 'UnitFileState': 'enabled'}, +'mock_swss_generated.service':{'Type': 'simple', 'Result': 'success', 'Id': 'mock_swss_generated.service', 'LoadState': 'loaded', 'ActiveState': 'active', 'SubState': 'running', 'UnitFileState': 'generated'}, +'mock_syncd_generated.service':{'Type': 'simple', 'Result': 'success', 'Id': 'mock_syncd_generated.service', 'LoadState': 'loaded', 'ActiveState': 'inactive', 'SubState': 'dead', 'UnitFileState': 'generated'} } @patch('health_checker.sysmonitor.Sysmonitor.get_all_service_list', MagicMock(return_value=['mock_snmp.service', 'mock_bgp.service', 'mock_ns.service'])) @@ -858,6 +860,28 @@ def test_get_unit_status_not_ok(): assert result == 'NOT OK' +@patch('health_checker.sysmonitor.Sysmonitor.run_systemctl_show', MagicMock(return_value=mock_srv_props['mock_swss_generated.service'])) +@patch('health_checker.sysmonitor.Sysmonitor.get_app_ready_status', MagicMock(return_value=('Up','-','-'))) +@patch('health_checker.sysmonitor.Sysmonitor.post_unit_status', MagicMock()) +def test_get_unit_status_generated_running_ok(): + """Test that active/running services with UnitFileState=generated are reported as OK.""" + sysmon = Sysmonitor() + result = sysmon.get_unit_status('mock_swss_generated.service') + print("get_unit_status for generated running service:{}".format(result)) + assert result == 'OK' + + +@patch('health_checker.sysmonitor.Sysmonitor.run_systemctl_show', MagicMock(return_value=mock_srv_props['mock_syncd_generated.service'])) +@patch('health_checker.sysmonitor.Sysmonitor.get_app_ready_status', MagicMock(return_value=('Up','-','-'))) +@patch('health_checker.sysmonitor.Sysmonitor.post_unit_status', MagicMock()) +def test_get_unit_status_generated_inactive_not_ok(): + """Test that inactive services with UnitFileState=generated are reported as NOT OK.""" + sysmon = Sysmonitor() + result = sysmon.get_unit_status('mock_syncd_generated.service') + print("get_unit_status for generated inactive service:{}".format(result)) + assert result == 'NOT OK' + + @patch('health_checker.sysmonitor.Sysmonitor.get_all_service_list', MagicMock(return_value=['mock_snmp.service', 'mock_ns.service'])) @patch('health_checker.sysmonitor.Sysmonitor.get_unit_status', MagicMock(return_value= 'OK')) @patch('health_checker.sysmonitor.Sysmonitor.publish_system_status', MagicMock())