Ubuntu 18.04 netplan with bridge

2

I am running Ubuntu 18.04 and my netplan configuration has suddenly stopped working. When I run

sudo netplan apply

the following messages appear and I lose connection

Traceback (most recent call last):
  File "/usr/sbin/netplan", line 23, in <module>
    netplan.main()
  File "/usr/share/netplan/netplan/cli/core.py", line 50, in main
    self.run_command()
  File "/usr/share/netplan/netplan/cli/utils.py", line 130, in run_command
    self.func()
  File "/usr/share/netplan/netplan/cli/commands/apply.py", line 43, in run
    self.run_command()
  File "/usr/share/netplan/netplan/cli/utils.py", line 130, in run_command
    self.func()
  File "/usr/share/netplan/netplan/cli/commands/apply.py", line 106, in command_apply
    stderr=subprocess.DEVNULL)
  File "/usr/lib/python3.6/subprocess.py", line 291, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['udevadm', 'test-builtin', 'net_setup_link', '/sys/class/net/br0']' returned non-zero exit status 4.

My configuration file

01-network-manager-all.yaml

is the following:

# Let NetworkManager manage all devices on this system
network:
  version: 2
  renderer: NetworkManager
  ethernets:
    enp6s0:
      dhcp4: no
#      addresses: [192.168.2.6/24]
#      gateway4: 192.168.2.1
#      nameservers:
#        addresses: [192.168.2.1]
      match:
        macaddress: 70:85:C2:43:68:6D
      wakeonlan: true
      dhcp6: no
  bridges:
    br0:
      interfaces: [enp6s0]
      dhcp4: no
      addresses: [192.168.2.6/24]
      gateway4: 192.168.2.1
      nameservers:
        addresses: [192.168.2.1]

Does anyone has the same problem?

The output of the last command when I run it myself is the following:

calling: test-builtin
Load module index
Parsed configuration file /lib/systemd/network/99-default.link
Parsed configuration file /run/systemd/network/10-netplan-enp6s0.link
Created link configuration context.
ID_NET_DRIVER=bridge
Config file /lib/systemd/network/99-default.link applies to device br0
link_config: autonegotiation is unset or enabled, the speed and duplex are not writable.
ID_NET_LINK_FILE=/lib/systemd/network/99-default.link
Unload module index
Unloaded link configuration context.

The output of

sudo netplan --debug apply

is the following:

** (generate:15678): DEBUG: 17:00:44.797: Processing input file /etc/netplan/01-network-manager-all.yaml..
** (generate:15678): DEBUG: 17:00:44.797: starting new processing pass
** (generate:15678): DEBUG: 17:00:44.797: br0: setting default backend to 2
** (generate:15678): DEBUG: 17:00:44.797: Configuration is valid
** (generate:15678): DEBUG: 17:00:44.797: enp6s0: setting default backend to 2
** (generate:15678): DEBUG: 17:00:44.797: Configuration is valid
** (generate:15678): DEBUG: 17:00:44.797: Generating output files..
** (generate:15678): DEBUG: 17:00:44.797: networkd: definition enp6s0 is not for us (backend 2)
** (generate:15678): DEBUG: 17:00:44.797: networkd: definition br0 is not for us (backend 2)
DEBUG:netplan generated networkd configuration changed, restarting networkd
DEBUG:netplan generated NM configuration changed, restarting NM
DEBUG:enp6s0 not found in {}
DEBUG:br0 not found in {}
DEBUG:Merged config:
network:
  bonds: {}
  bridges:
    br0:
      addresses:
      - 192.168.2.6/24
      dhcp4: false
      gateway4: 192.168.2.1
      interfaces:
      - enp6s0
      nameservers:
        addresses:
        - 192.168.2.1
  ethernets:
    enp6s0:
      dhcp4: false
      dhcp6: false
      match:
        macaddress: 70:85:C2:43:68:6D
      wakeonlan: true
  vlans: {}
  wifis: {}

DEBUG:Skipping non-physical interface: lo
DEBUG:Skipping composite member enp6s0
DEBUG:Skipping non-physical interface: virbr1
DEBUG:Skipping non-physical interface: virbr1-nic
DEBUG:Skipping non-physical interface: virbr2
DEBUG:Skipping non-physical interface: virbr2-nic
DEBUG:Skipping non-physical interface: virbr0
DEBUG:Skipping non-physical interface: virbr0-nic
DEBUG:Skipping non-physical interface: br0
DEBUG:{}
DEBUG:netplan triggering .link rules for lo
DEBUG:netplan triggering .link rules for enp6s0
DEBUG:netplan triggering .link rules for virbr1
DEBUG:netplan triggering .link rules for virbr1-nic
DEBUG:netplan triggering .link rules for virbr2
DEBUG:netplan triggering .link rules for virbr2-nic
DEBUG:netplan triggering .link rules for virbr0
DEBUG:netplan triggering .link rules for virbr0-nic
DEBUG:netplan triggering .link rules for br0
Traceback (most recent call last):
  File "/usr/sbin/netplan", line 23, in <module>
    netplan.main()
  File "/usr/share/netplan/netplan/cli/core.py", line 50, in main
    self.run_command()
  File "/usr/share/netplan/netplan/cli/utils.py", line 130, in run_command
    self.func()
  File "/usr/share/netplan/netplan/cli/commands/apply.py", line 43, in run
    self.run_command()
  File "/usr/share/netplan/netplan/cli/utils.py", line 130, in run_command
    self.func()
  File "/usr/share/netplan/netplan/cli/commands/apply.py", line 106, in command_apply
    stderr=subprocess.DEVNULL)
  File "/usr/lib/python3.6/subprocess.py", line 291, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['udevadm', 'test-builtin', 'net_setup_link', '/sys/class/net/br0']' returned non-zero exit status 4.

emergon

Posted 2019-05-11T13:06:18.503

Reputation: 23

Answers

0

I'm pretty sure your error is due to a bug in the NetworkManager-specific code of netplan apply.

To fix the bug, I wrote a simple patch, which you can apply by pasting this whole block into your terminal:

sudo patch /usr/share/netplan/netplan/cli/commands/apply.py << EOF
--- /usr/share/netplan/netplan/cli/commands/apply.original.py
+++ /usr/share/netplan/netplan/cli/commands/apply.py
@@ -99,11 +99,14 @@
         # if the interface is up, we can still apply some .link file changes
         for device in devices:
             logging.debug('netplan triggering .link rules for %s', device)
-            subprocess.check_call(['udevadm', 'test-builtin',
-                                   'net_setup_link',
-                                   '/sys/class/net/' + device],
-                                  stdout=subprocess.DEVNULL,
-                                  stderr=subprocess.DEVNULL)
+            try:
+                subprocess.check_call(['udevadm', 'test-builtin',
+                                       'net_setup_link',
+                                       '/sys/class/net/' + device],
+                                      stdout=subprocess.DEVNULL,
+                                      stderr=subprocess.DEVNULL)
+            except subprocess.CalledProcessError:
+                logging.debug('Ignoring device without syspath: %s', device)

         # apply renames to "down" devices
         for iface, settings in changes.items():
EOF

Once you have done that, your sudo netplan --debug apply command should succeed every run instead of every other run.

Note that this is a temporary fix that will be undone if the netplan.io is updated. For a permanent fix, please follow Launchpad bug #1810043.


Explanation

When using the NetworkManager renderer, the logic in NetplanApply.command_apply() tells nmcli to disconnect the devices previously populated by netifaces.interfaces():

# restarting NM does not cause new config to be applied, need to shut down devices first
for device in devices:
    # ignore failures here -- some/many devices might not be managed by NM
    try:
        utils.nmcli(['device', 'disconnect', device])
    except subprocess.CalledProcessError:
        pass

utils.systemctl_network_manager('stop', sync=sync)

This means that the devices variable, set earlier by devices = netifaces.interfaces(), may be out-of-date with more devices than actually exist after nmcli device disconnect runs.

The patch fixes this bug by tolerating missing devices or device aliases (which wouldn't show up in /sys/class/net/) after nmcli device disconnect so that the upcoming udevadm test-builtin net_setup_link /sys/class/net/XXX works with whatever devices remain:

for device in devices:
    logging.debug('netplan triggering .link rules for %s', device)
    subprocess.check_call(['udevadm', 'test-builtin',
                           'net_setup_link',
                           '/sys/class/net/' + device],
                          stdout=subprocess.DEVNULL,
                          stderr=subprocess.DEVNULL)

I requested that the patch be merged in CanonicalLtd/netplan#86.

Deltik

Posted 2019-05-11T13:06:18.503

Reputation: 16 807

Thank you very much. Your help is highly appreciated. – emergon – 2019-05-11T18:24:03.733