解释

解释

我在跑步Ubuntu 18.04我的 netplan 配置突然停止工作。当我运行

sudo netplan apply

出现以下消息并且我失去连接

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.

我的配置文件

01-网络管理器-全部.yaml

如下:

# 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]

有谁有同样的问题吗?

我自己运行最后一个命令时的输出如下:

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.

输出

sudo netplan--调试应用

如下:

** (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.

答案1

我很确定您的错误是由于 NetworkManager 特定代码中的错误造成的netplan apply

为了修复该错误,我编写了一个简单的补丁,您可以通过将整个块粘贴到终端中来应用它:

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

一旦完成了这些,你的sudo netplan --debug apply命令应该每次运行都成功,而不是每次运行都成功。

请注意,这是一个临时修复如果更新,则将撤消此操作netplan.io。如需永久修复,请按照启动板错误 #1810043


解释

当使用 NetworkManager 渲染器时,中的逻辑NetplanApply.command_apply()告诉nmcli断开先前填充的设备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)

这意味着,devices之前设置的变量devices = netifaces.interfaces()可能会因运行后更多设备而过时,而实际存在的设备却不够用nmcli device disconnect

补丁程序通过容忍丢失的设备或设备别名(不会显示在中/sys/class/net/)来修复此错误,nmcli device disconnect以便即将推出的设备udevadm test-builtin net_setup_link /sys/class/net/XXX可以与剩余的设备一起使用:

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)

我请求将补丁合并到CanonicalLtd/netplan#86

相关内容