Skip to content

Commit

Permalink
Revert "apply: compare full configuration to decide to restart networkd"
Browse files Browse the repository at this point in the history
This reverts commit a9c1433.
  • Loading branch information
daniloegea committed Sep 23, 2024
1 parent cac4b12 commit 1ab755c
Showing 1 changed file with 21 additions and 24 deletions.
45 changes: 21 additions & 24 deletions netplan_cli/cli/commands/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
import glob
import subprocess
import shutil
import tempfile
import filecmp
import time

from .. import utils
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down

0 comments on commit 1ab755c

Please sign in to comment.