Skip to content

Commit

Permalink
[config reload] Fixing config reload when timer based delayed service…
Browse files Browse the repository at this point in the history
…s are disabled (sonic-net#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
  • Loading branch information
dgsudharsan authored Jan 6, 2022
1 parent 30f5dd6 commit 055ed4f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
11 changes: 9 additions & 2 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,8 +732,15 @@ def _get_sonic_services():


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


def _reset_failed_services():
Expand Down
4 changes: 3 additions & 1 deletion tests/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ def mock_run_command_side_effect(*args, **kwargs):
return 'snmp.timer'
elif command == "systemctl list-dependencies --plain sonic.target | sed '1d'":
return 'swss'
elif command == "systemctl is-enabled snmp.timer":
return 'enabled'
else:
return ''

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

def test_load_minigraph_with_port_config_bad_format(self, get_cmd_module, setup_single_broadcom_asic):
with mock.patch(
Expand Down

0 comments on commit 055ed4f

Please sign in to comment.