Skip to content

Commit 7041400

Browse files
[config reload] Call systemctl reset-failed for snmp,telemetry,mgmt-framework services (sonic-net#1773) (sonic-net#1786)
Back port PR sonic-net#1773 to 202012 branch. #### 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. #### 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 399d370 commit 7041400

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

config/main.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -701,12 +701,16 @@ def _stop_services():
701701

702702
def _get_sonic_services():
703703
out = clicommon.run_command("systemctl list-dependencies --plain sonic.target | sed '1d'", return_cmd=True)
704-
return [unit.strip() for unit in out.splitlines()]
704+
return (unit.strip() for unit in out.splitlines())
705+
706+
707+
def _get_delayed_sonic_services():
708+
out = clicommon.run_command("systemctl list-dependencies --plain sonic-delayed.target | sed '1d'", return_cmd=True)
709+
return (unit.strip().rstrip('.timer') for unit in out.splitlines())
705710

706711

707712
def _reset_failed_services():
708-
for service in _get_sonic_services():
709-
click.echo("Resetting failed status on {}".format(service))
713+
for service in itertools.chain(_get_sonic_services(), _get_delayed_sonic_services()):
710714
clicommon.run_command("systemctl reset-failed {}".format(service))
711715

712716

tests/config_test.py

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

3030
if kwargs.get('return_cmd'):
31-
return ''
31+
if command == "systemctl list-dependencies --plain sonic-delayed.target | sed '1d'":
32+
return 'snmp.timer'
33+
elif command == "systemctl list-dependencies --plain sonic.target | sed '1d'":
34+
return 'swss'
35+
else:
36+
return ''
37+
3238

3339
class TestLoadMinigraph(object):
3440
@classmethod
@@ -48,7 +54,11 @@ def test_load_minigraph(self, get_cmd_module, setup_single_broadcom_asic):
4854
traceback.print_tb(result.exc_info[2])
4955
assert result.exit_code == 0
5056
assert "\n".join([l.rstrip() for l in result.output.split('\n')]) == load_minigraph_command_output
51-
assert mock_run_command.call_count == 7
57+
# Verify "systemctl reset-failed" is called for services under sonic.target
58+
mock_run_command.assert_any_call('systemctl reset-failed swss')
59+
# Verify "systemctl reset-failed" is called for services under sonic-delayed.target
60+
mock_run_command.assert_any_call('systemctl reset-failed snmp')
61+
assert mock_run_command.call_count == 10
5262

5363
def test_load_minigraph_with_port_config_bad_format(self, get_cmd_module, setup_single_broadcom_asic):
5464
with mock.patch(

0 commit comments

Comments
 (0)