cloud-init/backport-fix-Ensure-properties-for-bonded-interfaces-are-prop.patch
shixuantong ca270fa091 sync some patches
details:
chore: set recursive=False for ensure_dir if parent path is "/"
test(openstack): Test bond mac address
fix: Ensure properties for bonded interfaces are properly translated

(cherry picked from commit 0d2653ae183527e1e92b2b5bbd8dc0679aeada1e)
2024-12-06 15:08:33 +08:00

65 lines
2.9 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)
Reference:https://github.com/canonical/cloud-init/commit/371b2362bbd78ce53cd1b8f69d55db5855434e61
Conflict:test_openstack.py in cloudinit/sources/helpers/tests dir not
tests/unittests/sources/helpers.
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 ++++++++-
cloudinit/sources/helpers/tests/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 bd5714f..51e491f 100644
--- a/cloudinit/sources/helpers/openstack.py
+++ b/cloudinit/sources/helpers/openstack.py
@@ -637,7 +637,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/cloudinit/sources/helpers/tests/test_openstack.py b/cloudinit/sources/helpers/tests/test_openstack.py
index 8468cc3..2dfab85 100644
--- a/cloudinit/sources/helpers/tests/test_openstack.py
+++ b/cloudinit/sources/helpers/tests/test_openstack.py
@@ -128,9 +128,9 @@ class TestConvertNetJson(test_helpers.CiTestCase):
"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.33.0