Skip to content

Commit

Permalink
fix: Render v2 bridges correctly on network-manager with set-name (#5740
Browse files Browse the repository at this point in the history
)

Similar to the recent sysconfig fix, ensure bridges render correctly
for configs that contain `set-name`.

Fixes GH-5717
  • Loading branch information
TheRealFalcon authored Oct 11, 2024
1 parent 5f90d96 commit 9554338
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 2 deletions.
6 changes: 4 additions & 2 deletions cloudinit/net/network_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,11 +575,13 @@ def render_network_state(
# 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
Expand Down
88 changes: 88 additions & 0 deletions tests/unittests/net/network_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4996,5 +4996,93 @@
"""
),
},
"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
"""
),
},
},
}
1 change: 1 addition & 0 deletions tests/unittests/test_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -3062,6 +3062,7 @@ def test_ipv4_and_ipv6_static_config(self, yaml_file, config, caplog):
("v2-dns-no-if-ips", "yaml"),
("v2-dns-no-dhcp", "yaml"),
("v2-route-no-gateway", "yaml"),
("v2-bridges-set-name", "yaml"),
pytest.param(
"large_v2",
"yaml",
Expand Down

0 comments on commit 9554338

Please sign in to comment.