Skip to content

Commit

Permalink
Change netplan apply to workaround LP#2058976
Browse files Browse the repository at this point in the history
  • Loading branch information
alfonsosanchezbeato committed Apr 19, 2024
1 parent 353a77c commit f4d5b1c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ install:
/bin/cp -a static/* $(DESTDIR)
mkdir -p $(DESTDIR)/install-data
/bin/cp -r $(CRAFT_STAGE)/local-debs $(DESTDIR)/install-data/local-debs
/bin/cp -r patch $(DESTDIR)/install-data
# customize
set -eux; for f in ./hooks/[0-9]*.chroot; do \
base="$$(basename "$${f}")"; \
Expand Down
6 changes: 6 additions & 0 deletions hooks/032-apply-patches.chroot
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

set -eux

# Apply netplan patch (workaround for LP#2058976
patch -p0 -i /install-data/patch/netplan-apply.diff
31 changes: 31 additions & 0 deletions patch/netplan-apply.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
--- ./usr/share/netplan/netplan/cli/commands/apply.py 2024-04-19 10:02:42.065447958 +0100
+++ ./usr/share/netplan/netplan/cli/commands/apply.py 2024-04-19 10:04:34.325809194 +0100
@@ -270,15 +270,20 @@
# exclude the special 'netplan-ovs-cleanup.service' unit
netplan_ovs = [os.path.basename(f) for f in glob.glob('/run/systemd/system/*.wants/netplan-ovs-*.service')
if not f.endswith('/' + OVS_CLEANUP_SERVICE)]
- # Run 'systemctl start' command synchronously, to avoid race conditions
+ # Run 'systemctl (re)start' command synchronously, to avoid race conditions
# with 'oneshot' systemd service units, e.g. netplan-ovs-*.service.
- try:
- utils.networkctl_reload()
- utils.networkctl_reconfigure(utils.networkd_interfaces())
- except subprocess.CalledProcessError:
- # (re-)start systemd-networkd if it is not running, yet
- logging.warning('Falling back to a hard restart of systemd-networkd.service')
- utils.systemctl('restart', ['systemd-networkd.service'], sync=True)
+ #
+ # In the past, calls to networkctl_reload/networkctl_reconfigure
+ # were tried, but due maybe to systemd-networkd bugs, they were not
+ # working as expected: the interface was getting initially the
+ # expected state, but after some minutes it ignored the state of
+ # /run/systemd/network/ and used the configuration read when the
+ # service was started. This happened in the case of removed
+ # .network files. Looking at files in
+ # /run/systemd/netif/links/<num>, the internal state seemed to keep
+ # removed files in NETWORK_FILE= (see LP#2058976).
+ logging.info('Restarting systemd-networkd.service')
+ utils.systemctl('restart', ['systemd-networkd.service'], sync=True)
# 1st: execute OVS cleanup, to avoid races while applying OVS config
utils.systemctl('start', [OVS_CLEANUP_SERVICE], sync=True)
# 2nd: start all other services

0 comments on commit f4d5b1c

Please sign in to comment.