From d9328b15d83d0938b949a4376ed3a26e6e7cfcd9 Mon Sep 17 00:00:00 2001 From: James Falcon Date: Fri, 11 Oct 2024 13:58:19 -0500 Subject: [PATCH 2/2] fix: Render v2 bridges correctly on network-manager with set-name (#5740) RH-Author: xiachen RH-MergeRequest: 113: fix: Render bridges correctly for v2 on sysconfig with set-name (#5674) RH-Jira: RHEL-38927 RH-Acked-by: Emanuele Giuseppe Esposito RH-Acked-by: Ani Sinha RH-Commit: [2/2] d98d01bd5ca50aee2ca0ef0eeec1b890ec55102d (xiachen/cloud-init-centos) Similar to the recent sysconfig fix, ensure bridges render correctly for configs that contain `set-name`. Fixes GH-5717 (cherry picked from commit 9554338e6ecf49c66324cc637eaf0fa7bf10e407) Signed-off-by: Amy Chen --- cloudinit/net/network_manager.py | 6 +- tests/unittests/test_net.py | 94 ++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+), 2 deletions(-) diff --git a/cloudinit/net/network_manager.py b/cloudinit/net/network_manager.py index 0ba210b7..f50fafa3 100644 --- a/cloudinit/net/network_manager.py +++ b/cloudinit/net/network_manager.py @@ -464,11 +464,13 @@ class Renderer(renderer.Renderer): # interfaces that have UUIDs that can be linked to from related # interfaces for iface in network_state.iter_interfaces(): - self.connections[iface["name"]] = NMConnection(iface["name"]) + conn_key = iface.get("config_id") or iface["name"] + self.connections[conn_key] = NMConnection(iface["name"]) # Now render the actual interface configuration for iface in network_state.iter_interfaces(): - conn = self.connections[iface["name"]] + conn_key = iface.get("config_id") or iface["name"] + conn = self.connections[conn_key] conn.render_interface(iface, network_state, self) # And finally write the files diff --git a/tests/unittests/test_net.py b/tests/unittests/test_net.py index 004da81a..ddb45dc6 100644 --- a/tests/unittests/test_net.py +++ b/tests/unittests/test_net.py @@ -4577,6 +4577,94 @@ iface bond0 inet6 static """ ), }, + "expected_network_manager": { + "cloud-init-baremetal.nmconnection": textwrap.dedent( + """\ + # Generated by cloud-init. Changes will be lost. + + [connection] + id=cloud-init baremetal + uuid=e63eed9a-cd1c-55de-8d5e-1e80b756a482 + autoconnect-priority=120 + type=bridge + interface-name=baremetal + + [user] + org.freedesktop.NetworkManager.origin=cloud-init + + [bridge] + + [ipv6] + method=manual + may-fail=false + address1=fc00:1:1::2/64 + + """ + ), + "cloud-init-baremetalport.nmconnection": textwrap.dedent( + """\ + # Generated by cloud-init. Changes will be lost. + + [connection] + id=cloud-init baremetal0 + uuid=8e326690-51d6-5157-ab84-e4e822b06503 + autoconnect-priority=120 + type=ethernet + slave-type=bridge + master=e63eed9a-cd1c-55de-8d5e-1e80b756a482 + + [user] + org.freedesktop.NetworkManager.origin=cloud-init + + [ethernet] + mac-address=52:54:00:BD:8F:CB + + """ + ), + "cloud-init-provisioning.nmconnection": textwrap.dedent( + """\ + # Generated by cloud-init. Changes will be lost. + + [connection] + id=cloud-init provisioning + uuid=e5bd3f1a-cdcc-55d3-a6d8-88f1ba73bd0e + autoconnect-priority=120 + type=bridge + interface-name=provisioning + + [user] + org.freedesktop.NetworkManager.origin=cloud-init + + [bridge] + + [ipv6] + method=manual + may-fail=false + address1=fc00:1:2::2/64 + + """ + ), + "cloud-init-provisioningport.nmconnection": textwrap.dedent( + """\ + # Generated by cloud-init. Changes will be lost. + + [connection] + id=cloud-init provisioning0 + uuid=d79b7b70-e9df-596f-ace7-89537db45684 + autoconnect-priority=120 + type=ethernet + slave-type=bridge + master=e5bd3f1a-cdcc-55d3-a6d8-88f1ba73bd0e + + [user] + org.freedesktop.NetworkManager.origin=cloud-init + + [ethernet] + mac-address=52:54:00:25:AE:12 + + """ + ), + }, }, } @@ -6722,6 +6810,12 @@ class TestNetworkManagerRendering(CiTestCase): entry[self.expected_name], self.expected_conf_d, found ) + def test_v2_bridges_set_name(self): + entry = NETWORK_CONFIGS["v2-bridges-set-name"] + found = self._render_and_read(network_config=yaml.load(entry["yaml"])) + self._compare_files_to_expected( + entry[self.expected_name], self.expected_conf_d, found + ) @mock.patch( "cloudinit.net.is_openvswitch_internal_interface", -- 2.39.3