Skip to content

Commit

Permalink
Use Option<String> for address's
Browse files Browse the repository at this point in the history
  • Loading branch information
cfconrad committed Jan 16, 2024
1 parent d2ee41e commit c082815
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
21 changes: 9 additions & 12 deletions rust/migrate-wicked/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ pub struct Ipv6Auto {

#[derive(Debug, PartialEq, Default, Serialize, Deserialize)]
pub struct Dummy {
#[serde(default, skip_serializing_if = "String::is_empty")]
pub address: String,
pub address: Option<String>,
}

#[skip_serializing_none]
Expand Down Expand Up @@ -205,8 +204,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>,
#[serde(default, skip_serializing_if = "String::is_empty")]
pub address: String,
pub address: Option<String>,
}

impl Bond {
Expand Down Expand Up @@ -425,8 +423,7 @@ impl From<&Bond> for model::ConnectionConfig {
#[skip_serializing_none]
#[derive(Debug, PartialEq, Default, Serialize, Deserialize)]
pub struct Ethernet {
#[serde(default, skip_serializing_if = "String::is_empty")]
pub address: String,
pub address: Option<String>,
}

#[derive(Debug, PartialEq, Serialize, Deserialize)]
Expand Down Expand Up @@ -462,13 +459,13 @@ impl Interface {
}

if let Some(ethernet) = &self.ethernet {
connection.mac_address = MacAddress::from_str(&ethernet.address)?;
connection.mac_address = MacAddress::try_from(&ethernet.address)?;
connection.config = model::ConnectionConfig::Ethernet
} else if let Some(dummy) = &self.dummy {
connection.mac_address = MacAddress::from_str(&dummy.address)?;
connection.mac_address = MacAddress::try_from(&dummy.address)?;
connection.config = model::ConnectionConfig::Dummy
} else if let Some(bond) = &self.bond {
connection.mac_address = MacAddress::from_str(&bond.address)?;
connection.mac_address = MacAddress::try_from(&bond.address)?;
connection.config = bond.into()
}

Expand Down Expand Up @@ -703,7 +700,7 @@ mod tests {
fn test_dummy_interface_to_connection() {
let dummy_interface = Interface {
dummy: Some(Dummy {
address: "12:34:56:78:9A:BC".to_string(),
address: Some("12:34:56:78:9A:BC".to_string()),
}),
..Default::default()
};
Expand All @@ -721,7 +718,7 @@ mod tests {

let connection: model::Connection = dummy_interface.to_connection().unwrap().connection;
assert!(matches!(connection.config, model::ConnectionConfig::Dummy));
assert_eq!(dummy_interface.dummy.unwrap().address, String::from(""));
assert_eq!(dummy_interface.dummy.unwrap().address, None);
assert!(matches!(connection.mac_address, MacAddress::Unset));
}

Expand Down Expand Up @@ -759,7 +756,7 @@ mod tests {
targets: vec![String::from("1.2.3.4"), String::from("4.3.2.1")],
}),
slaves: vec![],
address: String::from("02:11:22:33:44:55"),
address: Some(String::from("02:11:22:33:44:55")),
}),
..Default::default()
};
Expand Down
2 changes: 1 addition & 1 deletion rust/migrate-wicked/src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ mod tests {
validate_targets: Some(ArpValidateTargets::Any),
targets: vec![String::from("1.2.3.4"), String::from("4.3.2.1")]
}),
address: String::from("02:11:22:33:44:55"),
address: Some(String::from("02:11:22:33:44:55")),
}
);
}
Expand Down

0 comments on commit c082815

Please sign in to comment.