forked from agama-project/agama
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4128eff
commit 5c68a09
Showing
8 changed files
with
323 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
use agama_server::network::model::{self, InfinibandConfig, InfinibandTransportMode}; | ||
use serde::{Deserialize, Deserializer, Serialize}; | ||
use serde_with::skip_serializing_none; | ||
use std::str::FromStr; | ||
|
||
#[skip_serializing_none] | ||
#[derive(Debug, PartialEq, Default, Serialize, Deserialize)] | ||
pub struct Infiniband { | ||
pub mode: Option<String>, | ||
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>, | ||
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()); | ||
|
||
// Check multicast warning is generated | ||
assert_eq!(connections.as_ref().unwrap().warnings.len(), 1); | ||
assert_eq!( | ||
connections.as_ref().unwrap().warnings[0].to_string(), | ||
"Infiniband multicast isn't supported by NetworkManager" | ||
); | ||
|
||
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
21 changes: 21 additions & 0 deletions
21
rust/migrate-wicked/tests/infiniband/system-connections/ib0.8001.nmconnection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
21 changes: 21 additions & 0 deletions
21
rust/migrate-wicked/tests/infiniband/system-connections/ib0.8002.nmconnection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
19 changes: 19 additions & 0 deletions
19
rust/migrate-wicked/tests/infiniband/system-connections/ib0.nmconnection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
19 changes: 19 additions & 0 deletions
19
rust/migrate-wicked/tests/infiniband/system-connections/ib1.nmconnection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
71
rust/migrate-wicked/tests/infiniband/wicked_xml/infiniband.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |