Skip to content

[config reload][202012] Call systemctl reset-failed for snmp,telemetry,mgmt-f… #1786

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,12 +701,16 @@ def _stop_services():

def _get_sonic_services():
out = clicommon.run_command("systemctl list-dependencies --plain sonic.target | sed '1d'", return_cmd=True)
return [unit.strip() for unit in out.splitlines()]
return (unit.strip() for unit in out.splitlines())


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())


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


Expand Down
14 changes: 12 additions & 2 deletions tests/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ def mock_run_command_side_effect(*args, **kwargs):
click.echo(click.style("Running command: ", fg='cyan') + click.style(command, fg='green'))

if kwargs.get('return_cmd'):
return ''
if command == "systemctl list-dependencies --plain sonic-delayed.target | sed '1d'":
return 'snmp.timer'
elif command == "systemctl list-dependencies --plain sonic.target | sed '1d'":
return 'swss'
else:
return ''


class TestLoadMinigraph(object):
@classmethod
Expand All @@ -48,7 +54,11 @@ def test_load_minigraph(self, get_cmd_module, setup_single_broadcom_asic):
traceback.print_tb(result.exc_info[2])
assert result.exit_code == 0
assert "\n".join([l.rstrip() for l in result.output.split('\n')]) == load_minigraph_command_output
assert mock_run_command.call_count == 7
# Verify "systemctl reset-failed" is called for services under sonic.target
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

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