Skip to content

Commit

Permalink
apply: re-start services also when unconfiguring
Browse files Browse the repository at this point in the history
We were not re-starting networkd/NetworkManager in the case we moved
from a configuration that created netplan files in /run to one that did
not need files there. Now we make sure we re-start the services also in
that case, by checking if there were configuration files before the
generation step. Fixes LP: #1811868.
  • Loading branch information
alfonsosanchezbeato authored and cyphermox committed Jan 15, 2019
1 parent 1ea3ec1 commit 0ef790c
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions netplan/cli/commands/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ def run(self): # pragma: nocover (covered in autopkgtest)

@staticmethod
def command_apply(run_generate=True, sync=False, exit_on_error=True): # pragma: nocover (covered in autopkgtest)
old_files_networkd = bool(glob.glob('/run/systemd/network/*netplan-*'))
old_files_nm = bool(glob.glob('/run/NetworkManager/system-connections/netplan-*'))

if run_generate and subprocess.call([utils.get_generator_path()]) != 0:
if exit_on_error:
sys.exit(os.EX_CONFIG)
Expand All @@ -53,18 +56,28 @@ def command_apply(run_generate=True, sync=False, exit_on_error=True): # pragma:
config_manager = ConfigManager()
devices = netifaces.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_nm = bool(glob.glob('/run/NetworkManager/system-connections/netplan-*'))
if not restart_nm and old_files_nm:
restart_nm = True

# stop backends
if restart_networkd:
logging.debug('netplan generated networkd configuration exists, restarting networkd')
logging.debug('netplan generated networkd configuration changed, restarting networkd')
utils.systemctl_networkd('stop', sync=sync, extra_services=['netplan-wpa@*.service'])
else:
logging.debug('no netplan generated networkd configuration exists')

if restart_nm:
logging.debug('netplan generated NM configuration exists, restarting NM')
logging.debug('netplan generated NM configuration changed, restarting NM')
if utils.nm_running():
# restarting NM does not cause new config to be applied, need to shut down devices first
for device in devices:
Expand Down

0 comments on commit 0ef790c

Please sign in to comment.