Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 12 additions & 2 deletions rust/agama-server/tests/server_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,18 @@ async fn test_put_config_without_mode(ctx: &mut Context) -> Result<(), Box<dyn E
.unwrap();

let response = ctx.client.send_request(request).await;
assert_eq!(response.status(), StatusCode::BAD_REQUEST);
assert_eq!(response.status(), StatusCode::OK);

let request = Request::builder()
.uri("/extended_config")
.body("".to_string())
.unwrap();

let response = ctx.client.send_request(request).await;
assert_eq!(response.status(), StatusCode::OK);

let body = body_to_string(response.into_body()).await;
assert!(body.contains(r#""product":{"id":"SLES","mode":"standard"}"#));

Ok(())
}
Expand Down Expand Up @@ -259,7 +270,6 @@ async fn test_patch_config_success(ctx: &mut Context) -> Result<(), Box<dyn Erro

let body = body_to_string(response.into_body()).await;
assert!(body.contains(r#""l10n":{"keymap":"en"}"#));
dbg!(&body);
assert!(body.contains(r#""product":{"id":"SLES","mode":"standard"}"#));

Ok(())
Expand Down
21 changes: 21 additions & 0 deletions rust/agama-software/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,26 @@ impl Service {
.map(|url| Url::parse(&url).ok())
.flatten();
}

/// Completes the configuration with the product mode if it is missing.
///
/// Agama uses the first available mode (if any) in case the user does not set one.
async fn add_product_mode(&mut self, config: &mut Config) {
let Some(product_config) = &mut config.product else {
return;
};

if product_config.mode.is_some() {
return;
}

let Some(selected_product) = &self.product else {
return;
};

let selected_product = selected_product.read().await;
product_config.mode = selected_product.mode.clone();
}
}

impl Actor for Service {
Expand Down Expand Up @@ -323,6 +343,7 @@ impl MessageHandler<message::SetConfig<Config>> for Service {

let mut config = message.config.clone().unwrap_or_default();
self.add_kernel_cmdline_defaults(&mut config);
self.add_product_mode(&mut config).await;

{
let mut state = self.state.write().await;
Expand Down
16 changes: 9 additions & 7 deletions rust/agama-utils/src/products.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ pub enum Error {
UnknownProduct(String),
#[error("Invalid mode '{1}' for product '{0}'")]
UnknownMode(String, String),
#[error("Mode required for product '{0}'")]
ModeRequired(String),
}

/// Products registry.
Expand Down Expand Up @@ -139,12 +137,15 @@ impl Registry {
/// * `id`: product ID.
/// * `mode`: product mode. Required only if the product has modes.
pub fn find(&self, id: &str, mode: Option<&str>) -> Result<ProductSpec, Error> {
let mut mode = mode.clone();
let Some(template) = self.products.iter().find(|p| p.id == id) else {
return Err(Error::UnknownProduct(id.to_string()));
};

if template.has_modes() && mode.is_none() {
return Err(Error::ModeRequired(id.to_string()));
if mode.is_none() {
if let Some(default_mode) = template.modes.first() {
mode = Some(default_mode.id.as_str());
}
}

template.to_product_spec(mode)
Expand Down Expand Up @@ -539,9 +540,10 @@ mod test {

#[test_context(Context)]
#[test]
fn test_find_product_with_required_mode(ctx: &mut Context) {
let product = ctx.registry.find("SLES", None).unwrap_err();
assert!(matches!(product, Error::ModeRequired(_)));
fn test_find_product_without_mode(ctx: &mut Context) {
let product = ctx.registry.find("SLES", None).unwrap();
assert_eq!(&product.id, "SLES");
assert_eq!(&product.mode.unwrap(), "standard");
}

#[test_context(Context)]
Expand Down
5 changes: 5 additions & 0 deletions rust/package/agama.changes
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
-------------------------------------------------------------------
Wed Jan 28 16:14:52 UTC 2026 - Imobach Gonzalez Sosa <igonzalezsosa@suse.com>

- Use the first product mode if none is given (related to jsc#PED-14307).

-------------------------------------------------------------------
Wed Jan 28 12:59:50 UTC 2026 - José Iván López González <jlopez@suse.com>

- Add agama-iscsi service and integrate iSCSI into the new HTTP API
Expand Down
Loading