From 1ab755c9a148407142faf215a02835d1e9e60c37 Mon Sep 17 00:00:00 2001 From: Danilo Egea Gondolfo Date: Mon, 16 Sep 2024 11:21:27 +0100 Subject: [PATCH] Revert "apply: compare full configuration to decide to restart networkd" This reverts commit a9c1433cbf39c90eccdfb8e355c6bb93f662f135. --- netplan_cli/cli/commands/apply.py | 45 +++++++++++++++---------------- 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/netplan_cli/cli/commands/apply.py b/netplan_cli/cli/commands/apply.py index d4d4b738e..7e17cee1f 100644 --- a/netplan_cli/cli/commands/apply.py +++ b/netplan_cli/cli/commands/apply.py @@ -25,8 +25,6 @@ import glob import subprocess import shutil -import tempfile -import filecmp import time from .. import utils @@ -110,6 +108,7 @@ def command_apply(self, run_generate=True, sync=False, exit_on_error=True, state return ovs_cleanup_service = '/run/systemd/system/netplan-ovs-cleanup.service' + old_files_networkd = bool(glob.glob('/run/systemd/network/*netplan-*')) old_ovs_glob = glob.glob('/run/systemd/system/netplan-ovs-*') # Ignore netplan-ovs-cleanup.service, as it can always be there if ovs_cleanup_service in old_ovs_glob: @@ -119,32 +118,30 @@ def command_apply(self, run_generate=True, sync=False, exit_on_error=True, state nm_ifaces = utils.nm_interfaces(old_nm_glob, utils.get_interfaces()) old_files_nm = bool(old_nm_glob) - restart_networkd = False - with tempfile.TemporaryDirectory() as tmp_dir: - # needs to be a subfolder as copytree wants to create it - old_files_dir = os.path.join(tmp_dir, 'cfg') - shutil.copytree('/run/systemd/network', old_files_dir) + generator_call = [] + generate_out = None + if 'NETPLAN_PROFILE' in os.environ: + generator_call.extend(['valgrind', '--leak-check=full']) + generate_out = subprocess.STDOUT - generator_call = [] - generate_out = None - if 'NETPLAN_PROFILE' in os.environ: - generator_call.extend(['valgrind', '--leak-check=full']) - generate_out = subprocess.STDOUT - - generator_call.append(utils.get_generator_path()) - if run_generate and subprocess.call(generator_call, stderr=generate_out) != 0: - if exit_on_error: - sys.exit(os.EX_CONFIG) - else: - raise ConfigurationError("the configuration could not be generated") - - # Restart networkd if something in the configuration changed - comp = filecmp.dircmp('/run/systemd/network', old_files_dir) - if comp.left_only or comp.right_only or comp.diff_files: - restart_networkd = True + generator_call.append(utils.get_generator_path()) + if run_generate and subprocess.call(generator_call, stderr=generate_out) != 0: + if exit_on_error: + sys.exit(os.EX_CONFIG) + else: + raise ConfigurationError("the configuration could not be generated") devices = utils.get_interfaces() + # Re-start service when + # 1. We have configuration files for it + # 2. Previously we had config files for it but not anymore + # Ideally we should compare the content of the *netplan-* files before and + # after generation to minimize the number of re-starts, but the conditions + # above works too. + restart_networkd = bool(glob.glob('/run/systemd/network/*netplan-*')) + if not restart_networkd and old_files_networkd: + restart_networkd = True restart_ovs_glob = glob.glob('/run/systemd/system/netplan-ovs-*') # Ignore netplan-ovs-cleanup.service, as it can always be there if ovs_cleanup_service in restart_ovs_glob: