From 198ce9db1355a5d5820906c050f8b6fccbb64450 Mon Sep 17 00:00:00 2001 From: Clemens Famulla-Conrad Date: Mon, 23 Oct 2023 12:14:02 +0200 Subject: [PATCH] bond: handling hwaddr of bonding interface --- rust/agama-migrate-wicked/src/interface.rs | 29 ++++++++++++++----- rust/agama-migrate-wicked/src/reader.rs | 2 ++ .../system-connections/bond0.nmconnection | 5 +++- .../wicked_xml/bond_active-backup.xml | 1 + 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/rust/agama-migrate-wicked/src/interface.rs b/rust/agama-migrate-wicked/src/interface.rs index d571c76699..2c303d0f42 100644 --- a/rust/agama-migrate-wicked/src/interface.rs +++ b/rust/agama-migrate-wicked/src/interface.rs @@ -235,6 +235,7 @@ pub struct Bond { /* only on mode=[balance_tlb|balance_alb|balance_RR|active-backup] */ pub resend_igmp: Option, pub all_slaves_active: Option, + pub address: Option, } impl Bond { @@ -324,8 +325,8 @@ where Ok(Slaves::deserialize(deserializer)?.slave) } -impl From for HashMap { - fn from(bond: Bond) -> HashMap { +impl From for model::BondConfig { + fn from(bond: Bond) -> model::BondConfig { let mut h: HashMap = HashMap::new(); h.insert(String::from("mode"), bond.mode.to_string()); @@ -430,7 +431,13 @@ impl From for HashMap { ); } - h + model::BondConfig { + options: h, + hwaddr: match bond.address { + Some(s) => model::MacAddr::try_from(s.as_ref()).ok(), + _ => None, + }, + } } } @@ -457,7 +464,7 @@ impl From for model::Connection { if let Some(b) = ifc.bond { model::Connection::Bond(model::BondConnection { base, - bond: model::BondConfig { options: b.into() }, + bond: b.into(), }) } else { model::Connection::Ethernet(model::EthernetConnection { base }) @@ -677,9 +684,10 @@ mod tests { targets: vec![String::from("1.2.3.4"), String::from("4.3.2.1")], }), slaves: vec![], + address: Some(String::from("02:11:22:33:44:55")), }; - let bond: HashMap = bond.into(); + let bondconfig: model::BondConfig = bond.into(); let s = HashMap::from([ ("xmit_hash_policy", String::from("encap34")), ("packets_per_slave", 23.to_string()), @@ -711,18 +719,23 @@ mod tests { for (k, v) in s.iter() { assert!( - bond.contains_key(*k), + bondconfig.options.contains_key(*k), "Missing key '{}' in bond hash {:?}", *k, - bond + bondconfig ); assert_eq!( - bond.get(*k).unwrap(), + bondconfig.options.get(*k).unwrap(), v, "Unexpected value '{}' in key '{}'", *k, v ); } + + assert_eq!( + bondconfig.hwaddr.unwrap().data, + [0x02, 0x11, 0x22, 0x33, 0x44, 0x55] + ); } } diff --git a/rust/agama-migrate-wicked/src/reader.rs b/rust/agama-migrate-wicked/src/reader.rs index a41f727e57..4778006283 100644 --- a/rust/agama-migrate-wicked/src/reader.rs +++ b/rust/agama-migrate-wicked/src/reader.rs @@ -132,6 +132,7 @@ mod tests { 4.3.2.1 +
02:11:22:33:44:55
"##; @@ -175,6 +176,7 @@ mod tests { validate_targets: Some(ArpValidateTargets::Any), targets: vec![String::from("1.2.3.4"), String::from("4.3.2.1")] }), + address: Some(String::from("02:11:22:33:44:55")), } ); } diff --git a/rust/agama-migrate-wicked/tests/bond_active-backup/system-connections/bond0.nmconnection b/rust/agama-migrate-wicked/tests/bond_active-backup/system-connections/bond0.nmconnection index 07b4c46fd5..a14c852a1b 100644 --- a/rust/agama-migrate-wicked/tests/bond_active-backup/system-connections/bond0.nmconnection +++ b/rust/agama-migrate-wicked/tests/bond_active-backup/system-connections/bond0.nmconnection @@ -1,9 +1,12 @@ [connection] id=bond0 -uuid=a6902e59-964b-4651-b8d8-ffe67658ae9a +uuid=766a5c05-2ba1-45be-960d-9f2dbf89b293 type=bond interface-name=bond0 +[ethernet] +cloned-mac-address=02:00:33:44:55:11 + [bond] miimon=100 mode=active-backup diff --git a/rust/agama-migrate-wicked/tests/bond_active-backup/wicked_xml/bond_active-backup.xml b/rust/agama-migrate-wicked/tests/bond_active-backup/wicked_xml/bond_active-backup.xml index 49390563b1..b6228ab717 100644 --- a/rust/agama-migrate-wicked/tests/bond_active-backup/wicked_xml/bond_active-backup.xml +++ b/rust/agama-migrate-wicked/tests/bond_active-backup/wicked_xml/bond_active-backup.xml @@ -21,6 +21,7 @@ en1 +
02:00:33:44:55:11