Skip to content

Commit

Permalink
bond: handling hwaddr of bonding interface
Browse files Browse the repository at this point in the history
  • Loading branch information
cfconrad committed Oct 23, 2023
1 parent c6a0203 commit 198ce9d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
29 changes: 21 additions & 8 deletions rust/agama-migrate-wicked/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ pub struct Bond {
/* only on mode=[balance_tlb|balance_alb|balance_RR|active-backup] */
pub resend_igmp: Option<u32>,
pub all_slaves_active: Option<bool>,
pub address: Option<String>,
}

impl Bond {
Expand Down Expand Up @@ -324,8 +325,8 @@ where
Ok(Slaves::deserialize(deserializer)?.slave)
}

impl From<Bond> for HashMap<String, String> {
fn from(bond: Bond) -> HashMap<String, String> {
impl From<Bond> for model::BondConfig {
fn from(bond: Bond) -> model::BondConfig {
let mut h: HashMap<String, String> = HashMap::new();

h.insert(String::from("mode"), bond.mode.to_string());
Expand Down Expand Up @@ -430,7 +431,13 @@ impl From<Bond> for HashMap<String, String> {
);
}

h
model::BondConfig {
options: h,
hwaddr: match bond.address {
Some(s) => model::MacAddr::try_from(s.as_ref()).ok(),
_ => None,
},
}
}
}

Expand All @@ -457,7 +464,7 @@ impl From<Interface> 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 })
Expand Down Expand Up @@ -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<String, String> = bond.into();
let bondconfig: model::BondConfig = bond.into();
let s = HashMap::from([
("xmit_hash_policy", String::from("encap34")),
("packets_per_slave", 23.to_string()),
Expand Down Expand Up @@ -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]
);
}
}
2 changes: 2 additions & 0 deletions rust/agama-migrate-wicked/src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ mod tests {
<ipv4-address>4.3.2.1</ipv4-address>
</targets>
</arpmon>
<address>02:11:22:33:44:55</address>
</bond>
</interface>
"##;
Expand Down Expand Up @@ -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")),
}
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<device>en1</device>
</slave>
</slaves>
<address>02:00:33:44:55:11</address>
</bond>
<link/>
<ipv4>
Expand Down

0 comments on commit 198ce9d

Please sign in to comment.