Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt iSCSI handling to the new architecture #1187

Merged
merged 26 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
4e4d354
Add XML files for ISCSI-related interfaces
imobachgs Apr 22, 2024
e35b1e3
rust: add an ISCSIClient
imobachgs Apr 25, 2024
d5999c1
rust: add a basic HTTP API for iSCSI handling
imobachgs Apr 26, 2024
8883fae
rust: add tests for get_*_property functions
imobachgs May 6, 2024
da32772
rust: add an UpdateFromDBus trait
imobachgs May 6, 2024
dc04603
rust: add a function to convert non-owned to owned hashmaps
imobachgs May 6, 2024
4f7b24b
rust: add a stream of added/changed/removed D-Bus objects
imobachgs May 6, 2024
657b10c
rust: implement UpdateFromDBus for ISCSINode
imobachgs May 6, 2024
fd9c915
rust: emit iSCSI events
imobachgs May 6, 2024
cdb5a75
rust: simplify the ISCSI events handling
imobachgs May 7, 2024
cafa402
rust: set the initiator name and the node startup
imobachgs May 8, 2024
9b5bd6a
rust: emit ISCSI Initiator changes
imobachgs May 8, 2024
f07f7bf
web: adapt the ISCSI client to the new HTTP API
imobachgs May 8, 2024
ff9f6ec
web: adapt the ISCSI client tests
imobachgs May 8, 2024
95d36f6
rust: refactor the extraction of the ISCSINode ID
imobachgs May 8, 2024
48c7921
rust: ISCSINodeStream reads the existing nodes
imobachgs May 8, 2024
1ff3f1d
web: improve error handling on iSCSI login
imobachgs May 8, 2024
5e39371
rust: remove unwrap calls from the initiator stream
imobachgs May 8, 2024
3d0273c
rust: add OpenAPI for the iSCSI API
imobachgs May 8, 2024
209eeb0
doc: update the documentation of the D-Bus API
imobachgs May 8, 2024
5a8ec55
Merge branch 'more_storage_http_api' into http-iscsi
imobachgs May 10, 2024
8aff3f1
rust: document a missing argument
imobachgs May 10, 2024
5124bd6
rust: minor documentation fix
imobachgs May 10, 2024
6f0bca6
web: extend storage.js documentation
imobachgs May 10, 2024
4aac331
Merge branch 'master' into http-iscsi
imobachgs May 13, 2024
ba35ce8
doc: update changes files
imobachgs May 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions doc/dbus/bus/org.opensuse.Agama.Storage1.ISCSI.Node.bus.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node name="/org/opensuse/Agama/Storage1/iscsi_nodes/1">
<interface name="org.freedesktop.DBus.Properties">
<method name="Get">
<arg name="interface_name" direction="in" type="s"/>
<arg name="property_name" direction="in" type="s"/>
<arg name="value" direction="out" type="v"/>
</method>
<method name="Set">
<arg name="interface_name" direction="in" type="s"/>
<arg name="property_name" direction="in" type="s"/>
<arg name="val" direction="in" type="v"/>
</method>
<method name="GetAll">
<arg name="interface_name" direction="in" type="s"/>
<arg name="value" direction="out" type="a{sv}"/>
</method>
<signal name="PropertiesChanged">
<arg name="interface" type="s"/>
<arg name="changed_properties" type="a{sv}"/>
<arg name="invalidated_properties" type="as"/>
</signal>
</interface>
<interface name="org.freedesktop.DBus.Introspectable">
<method name="Introspect">
<arg name="xml_data" direction="out" type="s"/>
</method>
</interface>
<interface name="org.opensuse.Agama.Storage1.ISCSI.Node">
<method name="Login">
<arg name="options" direction="in" type="a{sv}"/>
<arg name="result" direction="out" type="u"/>
</method>
<method name="Logout">
<arg name="result" direction="out" type="u"/>
</method>
<property type="s" name="Target" access="read"/>
<property type="s" name="Address" access="read"/>
<property type="u" name="Port" access="read"/>
<property type="s" name="Interface" access="read"/>
<property type="b" name="IBFT" access="read"/>
<property type="b" name="Connected" access="read"/>
<property type="s" name="Startup" access="readwrite"/>
</interface>
</node>
1 change: 1 addition & 0 deletions doc/dbus/bus/org.opensuse.Agama.Storage1.bus.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<node name="/org/opensuse/Agama/Storage1">
<node name="iscsi_nodes" />
<node name="zfcp_controllers" />
<node name="zfcp_disks" />
<interface name="org.freedesktop.DBus.Introspectable">
Expand Down
21 changes: 21 additions & 0 deletions doc/dbus/org.opensuse.Agama.Storage1.ISCSI.Initiator.doc.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node name="/org/opensuse/Agama/Storage1">
<node name="iscsi_nodes" />
<node name="zfcp_controllers" />
<node name="zfcp_disks" />
<interface name="org.opensuse.Agama.Storage1.ISCSI.Initiator">
<method name="Discover">
<arg name="address" direction="in" type="s"/>
<arg name="port" direction="in" type="u"/>
<arg name="options" direction="in" type="a{sv}"/>
<arg name="result" direction="out" type="u"/>
</method>
<method name="Delete">
<arg name="node" direction="in" type="o"/>
<arg name="result" direction="out" type="u"/>
</method>
<property type="s" name="InitiatorName" access="readwrite"/>
<property type="b" name="IBFT" access="read"/>
</interface>
</node>
20 changes: 20 additions & 0 deletions doc/dbus/org.opensuse.Agama.Storage1.ISCSI.Node.doc.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node name="/org/opensuse/Agama/Storage1/iscsi_nodes/1">
<interface name="org.opensuse.Agama.Storage1.ISCSI.Node">
<method name="Login">
<arg name="options" direction="in" type="a{sv}"/>
<arg name="result" direction="out" type="u"/>
</method>
<method name="Logout">
<arg name="result" direction="out" type="u"/>
</method>
<property type="s" name="Target" access="read"/>
<property type="s" name="Address" access="read"/>
<property type="u" name="Port" access="read"/>
<property type="s" name="Interface" access="read"/>
<property type="b" name="IBFT" access="read"/>
<property type="b" name="Connected" access="read"/>
<property type="s" name="Startup" access="readwrite"/>
</interface>
</node>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node name="/org/opensuse/Agama/Storage1">
<node name="iscsi_nodes" />
<node name="zfcp_controllers" />
<node name="zfcp_disks" />
<!--
Expand Down
1 change: 1 addition & 0 deletions doc/dbus/org.opensuse.Agama.Storage1.doc.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node name="/org/opensuse/Agama/Storage1">
<node name="iscsi_nodes" />
<node name="zfcp_controllers" />
<node name="zfcp_disks" />
<interface name="org.opensuse.Agama.Storage1">
Expand Down
80 changes: 79 additions & 1 deletion rust/agama-lib/src/dbus.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::collections::HashMap;
use zbus::zvariant::{self, OwnedValue, Value};
use zbus::zvariant::{self, OwnedObjectPath, OwnedValue, Value};

/// Nested hash to send to D-Bus.
pub type NestedHash<'a> = HashMap<&'a str, HashMap<&'a str, zvariant::Value<'a>>>;
Expand Down Expand Up @@ -43,3 +43,81 @@ where
Ok(None)
}
}

#[macro_export]
macro_rules! property_from_dbus {
($self:ident, $field:ident, $key:expr, $dbus:ident, $type:ty) => {
if let Some(v) = get_optional_property($dbus, $key)? {
$self.$field = v;
}
};
}

/// Converts a hash map containing zbus non-owned values to hash map with owned ones.
///
/// NOTE: we could follow a different approach like building our own type (e.g.
/// using the newtype idiom) and offering a better API.
///
/// * `source`: hash map containing non-onwed values ([zbus::zvariant::Value]).
pub fn to_owned_hash(source: &HashMap<&str, Value<'_>>) -> HashMap<String, OwnedValue> {
let mut owned = HashMap::new();
for (key, value) in source.iter() {
if let Ok(owned_value) = value.try_into() {
owned.insert(key.to_string(), owned_value);
}
}
owned
}

/// Extracts the object ID from the path.
///
/// TODO: should we merge this feature with the "DeviceSid"?
pub fn extract_id_from_path(path: &OwnedObjectPath) -> Result<u32, zvariant::Error> {
path.as_str()
.rsplit_once("/")
.and_then(|(_, id)| id.parse::<u32>().ok())
.ok_or_else(|| {
zvariant::Error::Message(format!("Could not extract the ID from {}", path.as_str()))
})
}

#[cfg(test)]
mod tests {
use std::collections::HashMap;

use zbus::zvariant::{self, OwnedValue, Str};

use crate::dbus::{get_optional_property, get_property};

#[test]
fn test_get_property() {
let data: HashMap<String, OwnedValue> = HashMap::from([
("Id".to_string(), (1 as u8).into()),
("Device".to_string(), Str::from_static("/dev/sda").into()),
]);
let id: u8 = get_property(&data, "Id").unwrap();
assert_eq!(id, 1);

let device: String = get_property(&data, "Device").unwrap();
assert_eq!(device, "/dev/sda".to_string());
}

#[test]
fn test_get_property_wrong_type() {
let data: HashMap<String, OwnedValue> =
HashMap::from([("Id".to_string(), (1 as u8).into())]);
let result: Result<u16, _> = get_property(&data, "Id");
assert_eq!(result, Err(zvariant::Error::IncorrectType));
}

#[test]
fn test_get_optional_property() {
let data: HashMap<String, OwnedValue> =
HashMap::from([("Id".to_string(), (1 as u8).into())]);
let id: Option<u8> = get_optional_property(&data, "Id").unwrap();
assert_eq!(id, Some(1));

let device: Option<String> = get_optional_property(&data, "Device").unwrap();
assert_eq!(device, None);
}
}
5 changes: 4 additions & 1 deletion rust/agama-lib/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ pub mod proxies;
mod settings;
mod store;

pub use client::StorageClient;
pub use client::{
iscsi::{ISCSIAuth, ISCSIClient, ISCSIInitiator, ISCSINode},
StorageClient,
};
pub use settings::StorageSettings;
pub use store::StorageStore;
1 change: 1 addition & 0 deletions rust/agama-lib/src/storage/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use zbus::fdo::ObjectManagerProxy;
use zbus::names::{InterfaceName, OwnedInterfaceName};
use zbus::zvariant::{OwnedObjectPath, OwnedValue};
use zbus::Connection;
pub mod iscsi;

type DbusObject = (
OwnedObjectPath,
Expand Down
Loading
Loading