Skip to content

Commit

Permalink
fix(netplan): Fix predictable interface rename issue (canonical#5339)
Browse files Browse the repository at this point in the history
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 canonicalGH-3950
  • Loading branch information
holmanb authored May 29, 2024
1 parent 2c99259 commit 2856f4c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions cloudinit/net/netplan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion tests/unittests/test_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]]
Expand Down

0 comments on commit 2856f4c

Please sign in to comment.