From 5059d590bad2a10d347f3b01223276897ec75422 Mon Sep 17 00:00:00 2001 From: Jorik Cronenberg Date: Tue, 26 Nov 2024 12:49:48 +0100 Subject: [PATCH] Add startmode migration --- src/interface.rs | 51 +++++++++++++++- .../startmode0.nmconnection | 21 +++++++ .../startmode1.nmconnection | 20 +++++++ .../startmode2.nmconnection | 21 +++++++ .../startmode3.nmconnection | 20 +++++++ tests/startmode/wicked_xml/startmode.xml | 60 +++++++++++++++++++ .../system-connections/wlan0-0.nmconnection | 1 + .../system-connections/wlan0-1.nmconnection | 1 + .../system-connections/wlan1.nmconnection | 1 + tests/wireless/wicked_xml/wireless.xml | 2 +- .../system-connections/wlan_eap0.nmconnection | 1 + .../system-connections/wlan_eap1.nmconnection | 1 + .../system-connections/wlan_eap2.nmconnection | 1 + 13 files changed, 199 insertions(+), 2 deletions(-) create mode 100644 tests/startmode/system-connections/startmode0.nmconnection create mode 100644 tests/startmode/system-connections/startmode1.nmconnection create mode 100644 tests/startmode/system-connections/startmode2.nmconnection create mode 100644 tests/startmode/system-connections/startmode3.nmconnection create mode 100644 tests/startmode/wicked_xml/startmode.xml diff --git a/src/interface.rs b/src/interface.rs index 1b48e236dd..eb63d96c7c 100644 --- a/src/interface.rs +++ b/src/interface.rs @@ -10,8 +10,9 @@ use agama_lib::network::types::Status; use agama_server::network::model::{self, IpConfig, IpRoute, Ipv4Method, Ipv6Method, MacAddress}; use cidr::IpInet; use serde::{Deserialize, Serialize}; -use serde_with::{serde_as, skip_serializing_none}; +use serde_with::{serde_as, skip_serializing_none, DeserializeFromStr, SerializeDisplay}; use std::{net::IpAddr, str::FromStr}; +use strum_macros::{Display, EnumString}; #[skip_serializing_none] #[derive(Debug, PartialEq, Default, Serialize, Deserialize)] @@ -46,6 +47,7 @@ pub struct Interface { pub infiniband_child: Option, pub tun: Option, pub tap: Option, + pub control: Control, } #[skip_serializing_none] @@ -159,6 +161,34 @@ pub struct Nexthop { pub gateway: String, } +#[derive(Debug, PartialEq, Default, Serialize, Deserialize)] +pub struct Control { + pub mode: ControlMode, +} + +#[derive( + Debug, PartialEq, Default, SerializeDisplay, DeserializeFromStr, EnumString, Clone, Display, +)] +#[strum(serialize_all = "snake_case")] +pub enum ControlMode { + #[default] + Manual, + Off, + Boot, + Hotplug, +} + +impl From for bool { + fn from(value: ControlMode) -> Self { + match value { + ControlMode::Manual => false, + ControlMode::Off => false, + ControlMode::Boot => true, + ControlMode::Hotplug => true, + } + } +} + pub struct ConnectionResult { pub connections: Vec, pub warnings: Vec, @@ -181,6 +211,7 @@ impl Interface { ip_config: ip_config.ip_config, status: Status::Down, mtu: self.link.mtu.unwrap_or_default(), + autoconnect: self.control.mode.clone().into(), ..Default::default() }; let mut connections: Vec = vec![]; @@ -513,4 +544,22 @@ mod tests { let con: model::Connection = ifc.to_connection().unwrap().connections[0].to_owned(); assert_eq!(con.firewall_zone, Some("topsecret".to_string())); } + + #[test] + fn test_startmode_to_connection() { + setup_default_migration_settings(); + let mut ifc = Interface { + control: Control { + mode: ControlMode::Manual, + }, + ..Default::default() + }; + + let con: model::Connection = ifc.to_connection().unwrap().connections[0].to_owned(); + assert_eq!(con.autoconnect, false); + + ifc.control.mode = ControlMode::Boot; + let con: model::Connection = ifc.to_connection().unwrap().connections[0].to_owned(); + assert_eq!(con.autoconnect, true); + } } diff --git a/tests/startmode/system-connections/startmode0.nmconnection b/tests/startmode/system-connections/startmode0.nmconnection new file mode 100644 index 0000000000..b5bd901559 --- /dev/null +++ b/tests/startmode/system-connections/startmode0.nmconnection @@ -0,0 +1,21 @@ +[connection] +id=startmode0 +uuid=9c634f1a-166b-4c91-b1b5-df831add1623 +type=dummy +autoconnect=false +interface-name=startmode0 + +[ethernet] + +[dummy] + +[match] + +[ipv4] +method=disabled + +[ipv6] +addr-gen-mode=default +method=auto + +[proxy] diff --git a/tests/startmode/system-connections/startmode1.nmconnection b/tests/startmode/system-connections/startmode1.nmconnection new file mode 100644 index 0000000000..fb780d5026 --- /dev/null +++ b/tests/startmode/system-connections/startmode1.nmconnection @@ -0,0 +1,20 @@ +[connection] +id=startmode1 +uuid=43c52f71-5298-4147-9950-f41ed65f9093 +type=dummy +interface-name=startmode1 + +[ethernet] + +[dummy] + +[match] + +[ipv4] +method=disabled + +[ipv6] +addr-gen-mode=default +method=auto + +[proxy] diff --git a/tests/startmode/system-connections/startmode2.nmconnection b/tests/startmode/system-connections/startmode2.nmconnection new file mode 100644 index 0000000000..dcf03ebc1d --- /dev/null +++ b/tests/startmode/system-connections/startmode2.nmconnection @@ -0,0 +1,21 @@ +[connection] +id=startmode2 +uuid=37374441-f8c1-495f-abf5-33dd859b1691 +type=dummy +autoconnect=false +interface-name=startmode2 + +[ethernet] + +[dummy] + +[match] + +[ipv4] +method=disabled + +[ipv6] +addr-gen-mode=default +method=auto + +[proxy] diff --git a/tests/startmode/system-connections/startmode3.nmconnection b/tests/startmode/system-connections/startmode3.nmconnection new file mode 100644 index 0000000000..1a56f447e5 --- /dev/null +++ b/tests/startmode/system-connections/startmode3.nmconnection @@ -0,0 +1,20 @@ +[connection] +id=startmode3 +uuid=4cddd65e-11ca-4f75-bc01-cc2f62336681 +type=dummy +interface-name=startmode3 + +[ethernet] + +[dummy] + +[match] + +[ipv4] +method=disabled + +[ipv6] +addr-gen-mode=default +method=auto + +[proxy] diff --git a/tests/startmode/wicked_xml/startmode.xml b/tests/startmode/wicked_xml/startmode.xml new file mode 100644 index 0000000000..0b4e2d78bd --- /dev/null +++ b/tests/startmode/wicked_xml/startmode.xml @@ -0,0 +1,60 @@ + + startmode0 + + manual + + + + + + true + + + true + + + + startmode1 + + boot + + + + + + true + + + true + + + + startmode2 + + off + + + + + + true + + + true + + + + startmode3 + + hotplug + + + + + + true + + + true + + diff --git a/tests/wireless/system-connections/wlan0-0.nmconnection b/tests/wireless/system-connections/wlan0-0.nmconnection index d25bca2a2f..4f435fe503 100644 --- a/tests/wireless/system-connections/wlan0-0.nmconnection +++ b/tests/wireless/system-connections/wlan0-0.nmconnection @@ -2,6 +2,7 @@ id=wlan0-0 uuid=2a262d6e-ccba-4afb-a190-ec08d0175c56 type=wifi +autoconnect=false interface-name=wlan0 [wifi] diff --git a/tests/wireless/system-connections/wlan0-1.nmconnection b/tests/wireless/system-connections/wlan0-1.nmconnection index 24f42377c7..f956aba779 100644 --- a/tests/wireless/system-connections/wlan0-1.nmconnection +++ b/tests/wireless/system-connections/wlan0-1.nmconnection @@ -2,6 +2,7 @@ id=wlan0-1 uuid=e05ab8eb-9905-4746-b81a-54e190b16354 type=wifi +autoconnect=false interface-name=wlan0 [wifi] diff --git a/tests/wireless/system-connections/wlan1.nmconnection b/tests/wireless/system-connections/wlan1.nmconnection index 919820c398..cbd2cdff67 100644 --- a/tests/wireless/system-connections/wlan1.nmconnection +++ b/tests/wireless/system-connections/wlan1.nmconnection @@ -2,6 +2,7 @@ id=wlan1 uuid=9d48ef42-2c96-4e43-8ab6-6c66385efdb6 type=wifi +autoconnect=false interface-name=wlan1 [wifi] diff --git a/tests/wireless/wicked_xml/wireless.xml b/tests/wireless/wicked_xml/wireless.xml index dc9456d647..a280a017d5 100644 --- a/tests/wireless/wicked_xml/wireless.xml +++ b/tests/wireless/wicked_xml/wireless.xml @@ -78,7 +78,7 @@ wlan2 - auto + boot diff --git a/tests/wireless_eap/system-connections/wlan_eap0.nmconnection b/tests/wireless_eap/system-connections/wlan_eap0.nmconnection index 9db4c6d0b2..16733a9095 100644 --- a/tests/wireless_eap/system-connections/wlan_eap0.nmconnection +++ b/tests/wireless_eap/system-connections/wlan_eap0.nmconnection @@ -2,6 +2,7 @@ id=wlan_eap0 uuid=62c02744-5807-445b-9636-421b1162e000 type=wifi +autoconnect=false interface-name=wlan_eap0 [wifi] diff --git a/tests/wireless_eap/system-connections/wlan_eap1.nmconnection b/tests/wireless_eap/system-connections/wlan_eap1.nmconnection index 2c04c167be..5e0de52ca3 100644 --- a/tests/wireless_eap/system-connections/wlan_eap1.nmconnection +++ b/tests/wireless_eap/system-connections/wlan_eap1.nmconnection @@ -2,6 +2,7 @@ id=wlan_eap1 uuid=f16a2831-d858-4d0c-8799-5262884c50cc type=wifi +autoconnect=false interface-name=wlan_eap1 [wifi] diff --git a/tests/wireless_eap/system-connections/wlan_eap2.nmconnection b/tests/wireless_eap/system-connections/wlan_eap2.nmconnection index 60ae940bcc..a9e4da015b 100644 --- a/tests/wireless_eap/system-connections/wlan_eap2.nmconnection +++ b/tests/wireless_eap/system-connections/wlan_eap2.nmconnection @@ -2,6 +2,7 @@ id=wlan_eap2 uuid=36eca905-1ac0-42f2-873d-f2ed783f2ce6 type=wifi +autoconnect=false interface-name=wlan_eap2 [wifi]