From 2856f4c8a440eba1127ac09f2b411d436c62e777 Mon Sep 17 00:00:00 2001 From: Brett Holman Date: Wed, 29 May 2024 16:08:35 -0600 Subject: [PATCH] fix(netplan): Fix predictable interface rename issue (#5339) When predictable naming is disabled, the following command may exit with a non-zero exit code. udevadm test-builtin net_setup_link This code only ran to check for udev rename races, which cannot happen when systemd renaming is disabled. Skip when disabled. Fixes GH-3950 --- cloudinit/net/netplan.py | 3 +++ tests/unittests/test_net.py | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/cloudinit/net/netplan.py b/cloudinit/net/netplan.py index 43dce44777a..5631f2295dd 100644 --- a/cloudinit/net/netplan.py +++ b/cloudinit/net/netplan.py @@ -381,6 +381,9 @@ def _net_setup_link(self, run=False): if not run: LOG.debug("netplan net_setup_link postcmd disabled") return + elif "net.ifnames=0" in util.get_cmdline(): + LOG.debug("Predictable interface names disabled.") + return setup_lnk = ["udevadm", "test-builtin", "net_setup_link"] # It's possible we can race a udev rename and attempt to run diff --git a/tests/unittests/test_net.py b/tests/unittests/test_net.py index 970f3338451..d036378880b 100644 --- a/tests/unittests/test_net.py +++ b/tests/unittests/test_net.py @@ -3397,10 +3397,13 @@ def test_netplan_render_calls_postcmds( mock_netplan_generate.assert_called_with(run=True, config_changed=True) mock_net_setup_link.assert_called_with(run=True) + @mock.patch("cloudinit.util.get_cmdline") @mock.patch("cloudinit.util.SeLinuxGuard") @mock.patch.object(netplan, "get_devicelist") @mock.patch("cloudinit.subp.subp") - def test_netplan_postcmds(self, mock_subp, mock_devlist, mock_sel): + def test_netplan_postcmds( + self, mock_subp, mock_devlist, mock_sel, m_get_cmdline + ): mock_sel.__enter__ = mock.Mock(return_value=False) mock_sel.__exit__ = mock.Mock() mock_devlist.side_effect = [["lo"]]