Skip to content

Commit f5ce87a

Browse files
[config reload] Call systemctl reset-failed for snmp,telemetry,mgmt-framework services (sonic-net#1773)
#### What I did When issue `config reload -y` or `config load_minigraph -y` command, most of the sonic services will be reset by command `systemctl reset-failed <service_name>`. The purpose is to avoid services reach to its start retry limit and cannot be started. However, `systemctl reset-failed` only resets those services belong to sonic.target, snmp, telemetry and mgmt-framework are not part of them. So if we run `config reload -y` or `config load_minigraph -y` continues, snmp, telemetry and mgmt-framework services might enter into failed state. This PR is to fix the issue. I would like to cherry-pick this fix to 202012 branch, but this fix also depends on PR sonic-net#7846. So if we decide to cherry-pick this PR to 202012, we need cherry-pick sonic-net#7846 first. #### How I did it Also call `systemctl reset-failed` for services like snmp, telemetry and mgmt-framework. #### How to verify it Manual test.
1 parent 6fd0675 commit f5ce87a

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

config/main.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -691,11 +691,16 @@ def _stop_services():
691691

692692
def _get_sonic_services():
693693
out = clicommon.run_command("systemctl list-dependencies --plain sonic.target | sed '1d'", return_cmd=True)
694-
return [unit.strip() for unit in out.splitlines()]
694+
return (unit.strip() for unit in out.splitlines())
695+
696+
697+
def _get_delayed_sonic_services():
698+
out = clicommon.run_command("systemctl list-dependencies --plain sonic-delayed.target | sed '1d'", return_cmd=True)
699+
return (unit.strip().rstrip('.timer') for unit in out.splitlines())
695700

696701

697702
def _reset_failed_services():
698-
for service in _get_sonic_services():
703+
for service in itertools.chain(_get_sonic_services(), _get_delayed_sonic_services()):
699704
clicommon.run_command("systemctl reset-failed {}".format(service))
700705

701706

tests/config_test.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,13 @@ def mock_run_command_side_effect(*args, **kwargs):
3535
click.echo(click.style("Running command: ", fg='cyan') + click.style(command, fg='green'))
3636

3737
if kwargs.get('return_cmd'):
38-
return ''
38+
if command == "systemctl list-dependencies --plain sonic-delayed.target | sed '1d'":
39+
return 'snmp.timer'
40+
elif command == "systemctl list-dependencies --plain sonic.target | sed '1d'":
41+
return 'swss'
42+
else:
43+
return ''
44+
3945

4046
class TestLoadMinigraph(object):
4147
@classmethod
@@ -55,7 +61,11 @@ def test_load_minigraph(self, get_cmd_module, setup_single_broadcom_asic):
5561
traceback.print_tb(result.exc_info[2])
5662
assert result.exit_code == 0
5763
assert "\n".join([l.rstrip() for l in result.output.split('\n')]) == load_minigraph_command_output
58-
assert mock_run_command.call_count == 7
64+
# Verify "systemctl reset-failed" is called for services under sonic.target
65+
mock_run_command.assert_any_call('systemctl reset-failed swss')
66+
# Verify "systemctl reset-failed" is called for services under sonic-delayed.target
67+
mock_run_command.assert_any_call('systemctl reset-failed snmp')
68+
assert mock_run_command.call_count == 10
5969

6070
def test_load_minigraph_with_port_config_bad_format(self, get_cmd_module, setup_single_broadcom_asic):
6171
with mock.patch(

0 commit comments

Comments
 (0)