cloud-init/backport-fix-Ensure-properties-for-bonded-interfaces-are-prop.patch
2024-12-06 11:47:57 +08:00

60 lines
2.7 KiB
Diff

From 371b2362bbd78ce53cd1b8f69d55db5855434e61 Mon Sep 17 00:00:00 2001
From: Curt Moore <curt.moore@garmin.com>
Date: Tue, 4 Jun 2024 12:45:32 -0500
Subject: [PATCH] fix: Ensure properties for bonded interfaces are properly
translated (#5367)
There is a discrepancy between the properties key name formatting in
the OpenStack network_data.json and cloudinit network-config.json
specifications. Ensure `bond_` is translated to `bond-` when the
OpenStack configuration is parsed by cloudinit.
Fixes GH-5366
Co-authored-by: Alberto Contreras <alberto.contreras@canonical.com>
---
cloudinit/sources/helpers/openstack.py | 9 ++++++++-
tests/unittests/sources/helpers/test_openstack.py | 6 +++---
2 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/cloudinit/sources/helpers/openstack.py b/cloudinit/sources/helpers/openstack.py
index 69a35db72..70998dda2 100644
--- a/cloudinit/sources/helpers/openstack.py
+++ b/cloudinit/sources/helpers/openstack.py
@@ -672,7 +672,14 @@ def convert_net_json(network_json=None, known_macs=None):
if k == "bond_links":
continue
elif k.startswith("bond"):
- params.update({k: v})
+ # There is a difference in key name formatting for
+ # bond parameters in the cloudinit and OpenStack
+ # network schemas. The keys begin with 'bond-' in the
+ # cloudinit schema but 'bond_' in OpenStack
+ # network_data.json schema. Translate them to what
+ # is expected by cloudinit.
+ translated_key = "bond-{}".format(k.split("bond_", 1)[-1])
+ params.update({translated_key: v})
# openstack does not provide a name for the bond.
# they do provide an 'id', but that is possibly non-sensical.
diff --git a/tests/unittests/sources/helpers/test_openstack.py b/tests/unittests/sources/helpers/test_openstack.py
index 312d66a01..663f6c2db 100644
--- a/tests/unittests/sources/helpers/test_openstack.py
+++ b/tests/unittests/sources/helpers/test_openstack.py
@@ -192,9 +192,9 @@ class TestConvertNetJson:
"name": "bond0",
"mac_address": "xx:xx:xx:xx:xx:00",
"params": {
- "bond_miimon": 100,
- "bond_mode": "802.3ad",
- "bond_xmit_hash_policy": "layer3+4",
+ "bond-miimon": 100,
+ "bond-mode": "802.3ad",
+ "bond-xmit_hash_policy": "layer3+4",
},
"subnets": [],
"type": "bond",
--
2.27.0