Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/system-health/health_checker/sysmonitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down
26 changes: 25 additions & 1 deletion src/system-health/tests/test_system_health.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']))
Expand Down Expand Up @@ -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())
Expand Down
Loading