diff --git a/config/main.py b/config/main.py index 00c0a0179777..6588bc1ef395 100644 --- a/config/main.py +++ b/config/main.py @@ -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(): diff --git a/tests/config_test.py b/tests/config_test.py index 58360703f8be..72110f805e3e 100644 --- a/tests/config_test.py +++ b/tests/config_test.py @@ -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 '' @@ -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(