Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[202211][system-health] When disabling a feature the SYSTEM_READY|SYSTEM_STAT… #15437

Merged
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
8 changes: 7 additions & 1 deletion src/system-health/health_checker/sysmonitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,13 @@ def check_unit_status(self, event):
#then it should be removed from STATE_DB & set
if event in self.dnsrvs_name:
self.dnsrvs_name.remove(event)


if len(self.dnsrvs_name) == 0:
astate = "UP"
else:
astate = "DOWN"
self.publish_system_status(astate)

srv_name,last = event.split('.')
# stop on service maybe propagated to timers and in that case,
# the state_db entry for the service should not be deleted
Expand Down
7 changes: 5 additions & 2 deletions src/system-health/tests/mock_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ def keys(self, db_id, pattern):

def get_all(self, db_id, key):
return MockConnector.data[key]


def exists(self, db_id, key):
return key in MockConnector.data

def set(self, db_id, key, field, value):
self.data[key] = {}
self.data[key][field] = value

def hmset(self, db_id, key, fieldsvalues):
self.data[key] = {}
for field,value in fieldsvalues.items():
Expand Down
25 changes: 25 additions & 0 deletions src/system-health/tests/test_system_health.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,31 @@ def test_check_unit_status():
assert 'mock_bgp.service' in sysmon.dnsrvs_name


@patch('health_checker.sysmonitor.Sysmonitor.get_all_service_list', MagicMock(side_effect=[
['mock_snmp.service', 'mock_bgp.service', 'mock_ns.service'],
['mock_snmp.service', 'mock_ns.service']
]))
@patch('health_checker.sysmonitor.Sysmonitor.run_systemctl_show', MagicMock(return_value=mock_srv_props['mock_bgp.service']))
@patch('health_checker.sysmonitor.Sysmonitor.get_app_ready_status', MagicMock(return_value=('Down','-','-')))
@patch('health_checker.sysmonitor.Sysmonitor.post_unit_status', MagicMock())
@patch('health_checker.sysmonitor.Sysmonitor.print_console_message', MagicMock())
def test_system_status_up_after_service_removed():
sysmon = Sysmonitor()
sysmon.publish_system_status('UP')

sysmon.check_unit_status('mock_bgp.service')
assert 'mock_bgp.service' in sysmon.dnsrvs_name
result = swsscommon.SonicV2Connector.get(MockConnector, 0, "SYSTEM_READY|SYSTEM_STATE", 'Status')
print("system status result before service was removed from system: {}".format(result))
assert result == "DOWN"

sysmon.check_unit_status('mock_bgp.service')
assert 'mock_bgp.service' not in sysmon.dnsrvs_name
result = swsscommon.SonicV2Connector.get(MockConnector, 0, "SYSTEM_READY|SYSTEM_STATE", 'Status')
print("system status result after service was removed from system: {}".format(result))
assert result == "UP"


@patch('health_checker.sysmonitor.Sysmonitor.get_all_service_list', MagicMock(return_value=['mock_snmp.service']))
def test_check_unit_status_timer():
sysmon = Sysmonitor()
Expand Down