Skip to content

Commit c1c8109

Browse files
dgsudharsanqiluo-msft
authored andcommitted
[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 466807e commit c1c8109

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
@@ -710,8 +710,15 @@ def _get_sonic_services():
710710

711711

712712
def _get_delayed_sonic_services():
713-
out = clicommon.run_command("systemctl list-dependencies --plain sonic-delayed.target | sed '1d'", return_cmd=True)
714-
return (unit.strip().rstrip('.timer') for unit in out.splitlines())
713+
rc1 = clicommon.run_command("systemctl list-dependencies --plain sonic-delayed.target | sed '1d'", return_cmd=True)
714+
rc2 = clicommon.run_command("systemctl is-enabled {}".format(rc1.replace("\n", " ")), return_cmd=True)
715+
timer = [line.strip() for line in rc1.splitlines()]
716+
state = [line.strip() for line in rc2.splitlines()]
717+
services = []
718+
for unit in timer:
719+
if state[timer.index(unit)] == "enabled":
720+
services.append(unit.rstrip(".timer"))
721+
return services
715722

716723

717724
def _reset_failed_services():

tests/config_test.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ def mock_run_command_side_effect(*args, **kwargs):
3232
return 'snmp.timer'
3333
elif command == "systemctl list-dependencies --plain sonic.target | sed '1d'":
3434
return 'swss'
35+
elif command == "systemctl is-enabled snmp.timer":
36+
return 'enabled'
3537
else:
3638
return ''
3739

@@ -58,7 +60,7 @@ def test_load_minigraph(self, get_cmd_module, setup_single_broadcom_asic):
5860
mock_run_command.assert_any_call('systemctl reset-failed swss')
5961
# Verify "systemctl reset-failed" is called for services under sonic-delayed.target
6062
mock_run_command.assert_any_call('systemctl reset-failed snmp')
61-
assert mock_run_command.call_count == 10
63+
assert mock_run_command.call_count == 11
6264

6365
def test_load_minigraph_with_port_config_bad_format(self, get_cmd_module, setup_single_broadcom_asic):
6466
with mock.patch(

0 commit comments

Comments
 (0)