Skip to content

Commit

Permalink
Add infiniband migration
Browse files Browse the repository at this point in the history
  • Loading branch information
jcronenberg committed Feb 8, 2024
1 parent 517f853 commit 1a072cb
Show file tree
Hide file tree
Showing 8 changed files with 304 additions and 0 deletions.
142 changes: 142 additions & 0 deletions rust/migrate-wicked/src/infiniband.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
use agama_dbus_server::network::model::{self, InfinibandConfig, InfinibandTransportMode};
use serde::{Deserialize, Deserializer, Serialize};
use std::str::FromStr;
// use serde_with::skip_serializing_none;

#[derive(Debug, PartialEq, Default, Serialize, Deserialize)]
pub struct Infiniband {
pub mode: Option<String>,
// TODO is this migratable
pub multicast: Option<String>,
}

// #[skip_serializing_none]
#[derive(Debug, PartialEq, Default, Serialize, Deserialize)]
pub struct InfinibandChild {
pub device: String,
#[serde(deserialize_with = "deserialize_pkey")]
pub pkey: u16,
pub mode: Option<String>,
// TODO is this migratable
pub multicast: Option<String>,
}

fn deserialize_pkey<'de, D>(deserializer: D) -> Result<u16, D::Error>
where
D: Deserializer<'de>,
{
let pkey_string: String = String::deserialize(deserializer)?;
let pkey_string: &str = pkey_string.trim_start_matches("0x");
Ok(u16::from_str_radix(pkey_string, 16).unwrap())
}

impl From<&Infiniband> for model::ConnectionConfig {
fn from(value: &Infiniband) -> Self {
model::ConnectionConfig::Infiniband(InfinibandConfig {
transport_mode: InfinibandTransportMode::from_str(
value
.mode
.as_ref()
.unwrap_or(&"datagram".to_string())
.as_str(),
)
.unwrap(),
..Default::default()
})
}
}

impl From<&InfinibandChild> for model::ConnectionConfig {
fn from(value: &InfinibandChild) -> Self {
model::ConnectionConfig::Infiniband(InfinibandConfig {
p_key: Some(value.pkey as i32),
parent: Some(value.device.clone()),
transport_mode: InfinibandTransportMode::from_str(
value
.mode
.as_ref()
.unwrap_or(&"datagram".to_string())
.as_str(),
)
.unwrap(),
})
}
}

#[cfg(test)]
mod tests {
use super::*;
use crate::interface::*;
use crate::MIGRATION_SETTINGS;

#[allow(dead_code)]
fn setup_default_migration_settings() {
let _ = MIGRATION_SETTINGS.set(crate::MigrationSettings {
continue_migration: false,
dry_run: false,
activate_connections: true,
});
}

#[test]
fn test_infiniband_migration() {
setup_default_migration_settings();
let infiniband_interface = Interface {
infiniband: Some(Infiniband {
mode: Some("datagram".to_string()),
multicast: Some("allowed".to_string()),
}),
..Default::default()
};

let connections = infiniband_interface.to_connection();
assert!(connections.is_ok());
let connection = &connections.unwrap().connections[0];
let model::ConnectionConfig::Infiniband(infiniband) = &connection.config else {
panic!()
};
assert_eq!(
infiniband.transport_mode,
InfinibandTransportMode::from_str("datagram").unwrap()
);
}

#[test]
fn test_infiniband_child_migration() {
setup_default_migration_settings();
let infiniband_child_interface = Interface {
infiniband_child: Some(InfinibandChild {
mode: Some("datagram".to_string()),
multicast: Some("allowed".to_string()),
pkey: 0x8001,
device: "ib0".to_string(),
}),
..Default::default()
};

let connections = infiniband_child_interface.to_connection();
assert!(connections.is_ok());
let connection = &connections.unwrap().connections[0];
let model::ConnectionConfig::Infiniband(infiniband_child) = &connection.config else {
panic!()
};
assert_eq!(
infiniband_child.transport_mode,
InfinibandTransportMode::from_str("datagram").unwrap()
);
assert_eq!(infiniband_child.p_key, Some(0x8001));
assert_eq!(infiniband_child.parent, Some("ib0".to_string()));
}

#[test]
fn test_deserialize_pkey() {
let xml = r##"
<interface-child>
<pkey>0x8001</pkey>
<device>ib0</device>
</interface-child>
"##;
let infiniband_child = quick_xml::de::from_str::<InfinibandChild>(xml).unwrap();
assert_eq!(infiniband_child.pkey, 0x8001);
}
}
10 changes: 10 additions & 0 deletions rust/migrate-wicked/src/interface.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::bond::Bond;
use crate::bridge::Bridge;
use crate::infiniband::{Infiniband, InfinibandChild};
use crate::vlan::Vlan;
use crate::wireless::Wireless;
use crate::MIGRATION_SETTINGS;
Expand Down Expand Up @@ -36,6 +37,9 @@ pub struct Interface {
pub origin: String,
pub vlan: Option<Vlan>,
pub bridge: Option<Bridge>,
pub infiniband: Option<Infiniband>,
#[serde(rename = "infiniband-child")]
pub infiniband_child: Option<InfinibandChild>,
}

#[skip_serializing_none]
Expand Down Expand Up @@ -181,6 +185,12 @@ impl Interface {
connections.push(wireless_connection);
}
}
} else if let Some(infiniband) = &self.infiniband {
connection.config = infiniband.into();
connections.push(connection)
} else if let Some(infiniband_child) = &self.infiniband_child {
connection.config = infiniband_child.into();
connections.push(connection)
} else {
connections.push(connection);
}
Expand Down
1 change: 1 addition & 0 deletions rust/migrate-wicked/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mod bond;
mod bridge;
mod infiniband;
mod interface;
mod migrate;
mod reader;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[connection]
id=ib0.8001
uuid=9b67f665-65f9-46a5-a8f2-312a25c76848
type=infiniband
interface-name=ib0.8001

[infiniband]
p-key=32769
parent=ib0
transport-mode=connected

[match]

[ipv4]
method=disabled

[ipv6]
addr-gen-mode=default
method=disabled

[proxy]
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[connection]
id=ib0.8002
uuid=01ee4005-008c-487e-a288-13bc1aca0d71
type=infiniband
interface-name=ib0.8002

[infiniband]
p-key=32770
parent=ib0
transport-mode=datagram

[match]

[ipv4]
method=disabled

[ipv6]
addr-gen-mode=default
method=disabled

[proxy]
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[connection]
id=ib0
uuid=e700a7e8-3598-4554-a8d8-8f1f494573f7
type=infiniband
interface-name=ib0

[infiniband]
transport-mode=datagram

[match]

[ipv4]
method=disabled

[ipv6]
addr-gen-mode=default
method=disabled

[proxy]
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[connection]
id=ib1
uuid=d0364ba4-f028-42b1-9bfd-c584db341c59
type=infiniband
interface-name=ib1

[infiniband]
transport-mode=datagram

[match]

[ipv4]
method=disabled

[ipv6]
addr-gen-mode=default
method=disabled

[proxy]
71 changes: 71 additions & 0 deletions rust/migrate-wicked/tests/infiniband/wicked_xml/infiniband.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<interface origin="compat:suse:/etc/sysconfig/network/ifcfg-ib0">
<name>ib0</name>
<control>
<mode>boot</mode>
</control>
<firewall/>
<infiniband/>
<link/>
<ipv4>
<enabled>false</enabled>
</ipv4>
<ipv6>
<enabled>false</enabled>
</ipv6>
</interface>
<interface origin="compat:suse:/etc/sysconfig/network/ifcfg-ib0.8001">
<name>ib0.8001</name>
<control>
<mode>boot</mode>
</control>
<firewall/>
<infiniband:child>
<device>ib0</device>
<pkey>0x8001</pkey>
<mode>connected</mode>
<multicast>allowed</multicast>
</infiniband:child>
<link/>
<ipv4>
<enabled>false</enabled>
</ipv4>
<ipv6>
<enabled>false</enabled>
</ipv6>
</interface>
<interface origin="compat:suse:/etc/sysconfig/network/ifcfg-ib0.8002">
<name>ib0.8002</name>
<control>
<mode>boot</mode>
</control>
<firewall/>
<infiniband:child>
<device>ib0</device>
<pkey>0x8002</pkey>
</infiniband:child>
<link/>
<ipv4>
<enabled>false</enabled>
</ipv4>
<ipv6>
<enabled>false</enabled>
</ipv6>
</interface>
<interface origin="compat:suse:/etc/sysconfig/network/ifcfg-ib1">
<name>ib1</name>
<control>
<mode>boot</mode>
</control>
<firewall/>
<infiniband>
<mode>datagram</mode>
<multicast>disallowed</multicast>
</infiniband>
<link/>
<ipv4>
<enabled>false</enabled>
</ipv4>
<ipv6>
<enabled>false</enabled>
</ipv6>
</interface>

0 comments on commit 1a072cb

Please sign in to comment.