cloud-init/backport-test-openstack-Test-bond-mac-address.patch

141 lines
5.1 KiB
Diff
Raw Normal View History

2024-12-06 11:47:23 +08:00
From f8f9d19409fcbda32e119a5514fd5185bcd88b79 Mon Sep 17 00:00:00 2001
From: Brett Holman <brett.holman@canonical.com>
Date: Thu, 27 Jun 2024 11:56:58 -0600
Subject: [PATCH] test(openstack): Test bond mac address (#5369)
---
.../sources/helpers/test_openstack.py | 120 ++++++++++++++++++
1 file changed, 120 insertions(+)
diff --git a/tests/unittests/sources/helpers/test_openstack.py b/tests/unittests/sources/helpers/test_openstack.py
index 4d85ec3c6..312d66a01 100644
--- a/tests/unittests/sources/helpers/test_openstack.py
+++ b/tests/unittests/sources/helpers/test_openstack.py
@@ -112,3 +112,123 @@ class TestConvertNetJson:
assert expected == openstack.convert_net_json(
network_json=net_json, known_macs=macs
)
+
+ def test_bond_mac(self):
+ """Verify the bond mac address is assigned correctly."""
+ network_json = {
+ "links": [
+ {
+ "id": "ens1f0np0",
+ "name": "ens1f0np0",
+ "type": "phy",
+ "ethernet_mac_address": "xx:xx:xx:xx:xx:00",
+ "mtu": 9000,
+ },
+ {
+ "id": "ens1f1np1",
+ "name": "ens1f1np1",
+ "type": "phy",
+ "ethernet_mac_address": "xx:xx:xx:xx:xx:01",
+ "mtu": 9000,
+ },
+ {
+ "id": "bond0",
+ "name": "bond0",
+ "type": "bond",
+ "bond_links": ["ens1f0np0", "ens1f1np1"],
+ "mtu": 9000,
+ "ethernet_mac_address": "xx:xx:xx:xx:xx:00",
+ "bond_mode": "802.3ad",
+ "bond_xmit_hash_policy": "layer3+4",
+ "bond_miimon": 100,
+ },
+ {
+ "id": "bond0.123",
+ "name": "bond0.123",
+ "type": "vlan",
+ "vlan_link": "bond0",
+ "vlan_id": 123,
+ "vlan_mac_address": "xx:xx:xx:xx:xx:00",
+ },
+ ],
+ "networks": [
+ {
+ "id": "publicnet-ipv4",
+ "type": "ipv4",
+ "link": "bond0.123",
+ "ip_address": "x.x.x.x",
+ "netmask": "255.255.255.0",
+ "routes": [
+ {
+ "network": "0.0.0.0",
+ "netmask": "0.0.0.0",
+ "gateway": "x.x.x.1",
+ }
+ ],
+ "network_id": "00000000-0000-0000-0000-000000000000",
+ }
+ ],
+ "services": [{"type": "dns", "address": "1.1.1.1"}],
+ }
+ expected = {
+ "config": [
+ {
+ "mac_address": "xx:xx:xx:xx:xx:00",
+ "mtu": 9000,
+ "name": "ens1f0np0",
+ "subnets": [],
+ "type": "physical",
+ },
+ {
+ "mac_address": "xx:xx:xx:xx:xx:01",
+ "mtu": 9000,
+ "name": "ens1f1np1",
+ "subnets": [],
+ "type": "physical",
+ },
+ {
+ "bond_interfaces": ["ens1f0np0", "ens1f1np1"],
+ "mtu": 9000,
+ "name": "bond0",
+ "mac_address": "xx:xx:xx:xx:xx:00",
+ "params": {
+ "bond_miimon": 100,
+ "bond_mode": "802.3ad",
+ "bond_xmit_hash_policy": "layer3+4",
+ },
+ "subnets": [],
+ "type": "bond",
+ },
+ {
+ "mac_address": "xx:xx:xx:xx:xx:00",
+ "name": "bond0.123",
+ "subnets": [
+ {
+ "address": "x.x.x.x",
+ "ipv4": True,
+ "netmask": "255.255.255.0",
+ "routes": [
+ {
+ "gateway": "x.x.x.1",
+ "netmask": "0.0.0.0",
+ "network": "0.0.0.0",
+ }
+ ],
+ "type": "static",
+ }
+ ],
+ "type": "vlan",
+ "vlan_id": 123,
+ "vlan_link": "bond0",
+ },
+ {"address": "1.1.1.1", "type": "nameserver"},
+ ],
+ "version": 1,
+ }
+ macs = {
+ "xx:xx:xx:xx:xx:00": "ens1f0np0",
+ "xx:xx:xx:xx:xx:01": "ens1f1np1",
+ }
+ assert expected == openstack.convert_net_json(
+ network_json=network_json, known_macs=macs
+ )
--
2.27.0