diff --git a/config/main.py b/config/main.py index debb1c4355..3f21fe1788 100644 --- a/config/main.py +++ b/config/main.py @@ -977,6 +977,12 @@ def _stop_services(): except subprocess.CalledProcessError as err: pass + # Get the list of dependencies for sonic.target to fetch timer units + for service in _get_sonic_services(): + if service.endswith('.timer'): + # Stop the timer unit + clicommon.run_command(['sudo', 'systemctl', 'stop', service], display_cmd=True) + click.echo("Stopping SONiC target ...") clicommon.run_command(['sudo', 'systemctl', 'stop', 'sonic.target', '--job-mode', 'replace-irreversibly']) diff --git a/tests/config_test.py b/tests/config_test.py index 8ad4e8b4a5..5d85d117a0 100644 --- a/tests/config_test.py +++ b/tests/config_test.py @@ -53,6 +53,7 @@ load_minigraph_command_output="""\ Acquired lock on {0} Disabling container and routeCheck monitoring ... +Running command: sudo systemctl stop featured.timer Stopping SONiC target ... Running command: /usr/local/bin/sonic-cfggen -H -m --write-to-db Running command: config qos reload --no-dynamic-buffer --no-delay @@ -70,6 +71,7 @@ load_minigraph_command_bypass_lock_output = """\ Bypass lock on {} +Running command: sudo systemctl stop featured.timer Stopping SONiC target ... Running command: /usr/local/bin/sonic-cfggen -H -m --write-to-db Running command: config qos reload --no-dynamic-buffer --no-delay @@ -81,6 +83,7 @@ load_minigraph_platform_plugin_command_output="""\ Acquired lock on {0} +Running command: sudo systemctl stop featured.timer Stopping SONiC target ... Running command: /usr/local/bin/sonic-cfggen -H -m --write-to-db Running command: config qos reload --no-dynamic-buffer --no-delay @@ -165,6 +168,7 @@ RELOAD_CONFIG_DB_OUTPUT = """\ Acquired lock on {0} +Running command: sudo systemctl stop featured.timer Stopping SONiC target ... Running command: /usr/local/bin/sonic-cfggen -j /tmp/config.json --write-to-db Restarting SONiC target ... @@ -178,6 +182,7 @@ RELOAD_CONFIG_DB_BYPASS_LOCK_OUTPUT = """\ Bypass lock on {0} +Running command: sudo systemctl stop featured.timer Stopping SONiC target ... Running command: /usr/local/bin/sonic-cfggen -j /tmp/config.json --write-to-db Restarting SONiC target ... @@ -186,6 +191,7 @@ RELOAD_YANG_CFG_OUTPUT = """\ Acquired lock on {0} +Running command: sudo systemctl stop featured.timer Stopping SONiC target ... Running command: /usr/local/bin/sonic-cfggen -Y /tmp/config.json --write-to-db Restarting SONiC target ... @@ -195,6 +201,7 @@ RELOAD_MASIC_CONFIG_DB_OUTPUT = """\ Acquired lock on {0} +Running command: sudo systemctl stop featured.timer Stopping SONiC target ... Running command: /usr/local/bin/sonic-cfggen -j /tmp/config.json --write-to-db Running command: /usr/local/bin/sonic-cfggen -j /tmp/config0.json -n asic0 --write-to-db @@ -219,6 +226,7 @@ reload_config_masic_onefile_output = """\ Acquired lock on {0} +Running command: sudo systemctl stop featured.timer Stopping SONiC target ... Restarting SONiC target ... Reloading Monit configuration ... @@ -227,6 +235,7 @@ reload_config_masic_onefile_gen_sysinfo_output = """\ Acquired lock on {0} +Running command: sudo systemctl stop featured.timer Stopping SONiC target ... Running command: /usr/local/bin/sonic-cfggen -H -k Mellanox-SN3800-D112C8 --write-to-db Running command: /usr/local/bin/sonic-cfggen -H -k multi_asic -n asic0 --write-to-db @@ -307,7 +316,7 @@ def mock_run_command_side_effect(*args, **kwargs): if command == "systemctl list-dependencies --plain sonic-delayed.target | sed '1d'": return 'snmp.timer', 0 elif command == "systemctl list-dependencies --plain sonic.target": - return 'sonic.target\nswss', 0 + return 'sonic.target\nswss\nfeatured.timer', 0 elif command == "systemctl is-enabled snmp.timer": return 'enabled', 0 elif command == 'cat /var/run/dhclient.eth0.pid': @@ -1058,7 +1067,7 @@ def test_load_minigraph(self, mock_check_call, get_cmd_module, setup_single_broa (load_minigraph_command_output.format(config.SYSTEM_RELOAD_LOCK)) # Verify "systemctl reset-failed" is called for services under sonic.target mock_run_command.assert_any_call(['systemctl', 'reset-failed', 'swss']) - assert mock_run_command.call_count == 16 + assert mock_run_command.call_count == 19 @mock.patch('sonic_py_common.device_info.get_paths_to_platform_and_hwsku_dirs', mock.MagicMock(return_value=("dummy_path", None))) @@ -1102,7 +1111,7 @@ def test_load_minigraph_bypass_lock(self, get_cmd_module, setup_single_broadcom_ assert result.exit_code == 0 assert result.output == \ load_minigraph_command_bypass_lock_output.format(config.SYSTEM_RELOAD_LOCK) - assert mock_run_command.call_count == 12 + assert mock_run_command.call_count == 15 finally: flock.release_flock(fd) @@ -1120,7 +1129,7 @@ def test_load_minigraph_platform_plugin(self, get_cmd_module, setup_single_broad (load_minigraph_platform_plugin_command_output.format(config.SYSTEM_RELOAD_LOCK)) # Verify "systemctl reset-failed" is called for services under sonic.target mock_run_command.assert_any_call(['systemctl', 'reset-failed', 'swss']) - assert mock_run_command.call_count == 12 + assert mock_run_command.call_count == 15 @mock.patch('sonic_py_common.device_info.get_paths_to_platform_and_hwsku_dirs', mock.MagicMock(return_value=(load_minigraph_platform_false_path, None))) def test_load_minigraph_platform_plugin_fail(self, get_cmd_module, setup_single_broadcom_asic):