diff --git a/config/main.py b/config/main.py index a80283f7ee..d43e79a124 100644 --- a/config/main.py +++ b/config/main.py @@ -681,11 +681,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(): + for service in itertools.chain(_get_sonic_services(), _get_delayed_sonic_services()): clicommon.run_command("systemctl reset-failed {}".format(service)) diff --git a/tests/config_test.py b/tests/config_test.py index 929ae97aa3..bbef200aac 100644 --- a/tests/config_test.py +++ b/tests/config_test.py @@ -35,7 +35,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 @@ -55,7 +61,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(