Skip to content

Commit 055ed4f

Browse files
authored
[config reload] Fixing config reload when timer based delayed services are disabled (#1967)
#### What I did When timer based delayed services like mgmt-framework, telemetry and snmp are disabled and config reload is execute it fails Failed to reset failed state of unit mgmt-framework.service: Unit mgmt-framework.service not loaded. The reason is these services don't get masked like regular services and these are derived from timers. So when reset-failed is tried on these services it leads to exception. #### How I did it When the feature related to these services are disabled their timers would be masked and wouldn't be "enabled". So when deriving the services from timers the services which are not enabled will be skipped. #### How to verify it Disable services like mgmt-framework, snmp and telemetry and execute config reload. The config reload should execute without failure
1 parent 30f5dd6 commit 055ed4f

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

config/main.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -732,8 +732,15 @@ def _get_sonic_services():
732732

733733

734734
def _get_delayed_sonic_services():
735-
out = clicommon.run_command("systemctl list-dependencies --plain sonic-delayed.target | sed '1d'", return_cmd=True)
736-
return (unit.strip().rstrip('.timer') for unit in out.splitlines())
735+
rc1 = clicommon.run_command("systemctl list-dependencies --plain sonic-delayed.target | sed '1d'", return_cmd=True)
736+
rc2 = clicommon.run_command("systemctl is-enabled {}".format(rc1.replace("\n", " ")), return_cmd=True)
737+
timer = [line.strip() for line in rc1.splitlines()]
738+
state = [line.strip() for line in rc2.splitlines()]
739+
services = []
740+
for unit in timer:
741+
if state[timer.index(unit)] == "enabled":
742+
services.append(unit.rstrip(".timer"))
743+
return services
737744

738745

739746
def _reset_failed_services():

tests/config_test.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ def mock_run_command_side_effect(*args, **kwargs):
8484
return 'snmp.timer'
8585
elif command == "systemctl list-dependencies --plain sonic.target | sed '1d'":
8686
return 'swss'
87+
elif command == "systemctl is-enabled snmp.timer":
88+
return 'enabled'
8789
else:
8890
return ''
8991

@@ -164,7 +166,7 @@ def test_load_minigraph(self, get_cmd_module, setup_single_broadcom_asic):
164166
mock_run_command.assert_any_call('systemctl reset-failed swss')
165167
# Verify "systemctl reset-failed" is called for services under sonic-delayed.target
166168
mock_run_command.assert_any_call('systemctl reset-failed snmp')
167-
assert mock_run_command.call_count == 10
169+
assert mock_run_command.call_count == 11
168170

169171
def test_load_minigraph_with_port_config_bad_format(self, get_cmd_module, setup_single_broadcom_asic):
170172
with mock.patch(

0 commit comments

Comments
 (0)