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