Skip to content

Commit

Permalink
fix: better registration workflow (#1938)
Browse files Browse the repository at this point in the history
## Problem

The registration workflow does not allow installing without registering
the system, even if the repositories are offline or are specified
through the `install_url` option. Thus, we need to make some changes to
the current implementation.

## Solution

Now Agama will complain if the following conditions are met:

* The product can be registered (`registration: true`).
* The base product is missing from the repositories.

If the product can be registered, but the base product is already in the
repositories, Agama will not complain. However, you can register the
product if you want to.

## The new approach

Instead of exposing information about whether the system should be
registered at the HTTP API level, we have decided to rely on
installation issues. If the conditions are not met, Agama will set an
issue.
  • Loading branch information
imobachgs authored Jan 24, 2025
2 parents d7e5108 + 83b53b0 commit f21c18d
Show file tree
Hide file tree
Showing 38 changed files with 191 additions and 174 deletions.
6 changes: 6 additions & 0 deletions products.d/agama-products.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Fri Jan 24 06:45:45 UTC 2025 - Imobach Gonzalez Sosa <[email protected]>

- Change the registration property in a product's definition to a
boolean (gh#agama-project/agama#1938).

-------------------------------------------------------------------
Thu Jan 23 10:43:32 UTC 2025 - Josef Reidinger <[email protected]>

Expand Down
2 changes: 1 addition & 1 deletion products.d/sles_160.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
id: SLES
name: SUSE Linux Enterprise Server 16.0 Beta
registration: "mandatory"
registration: true
version: "16-0"
license: "license.beta"
# ------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion products.d/sles_sap_160.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
id: SLES_SAP
name: SUSE Linux Enterprise Server for SAP Applications 16.0 Beta
archs: x86_64,aarch64,ppc
registration: "mandatory"
registration: true
version: "16-0"
license: "license.beta"
# ------------------------------------------------------------------------------
Expand Down
8 changes: 3 additions & 5 deletions rust/agama-lib/src/product/client.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) [2024] SUSE LLC
// Copyright (c) [2024-2025] SUSE LLC
//
// All Rights Reserved.
//
Expand Down Expand Up @@ -43,7 +43,7 @@ pub struct Product {
/// Product icon (e.g., "default.svg")
pub icon: String,
/// Registration requirement
pub registration: RegistrationRequirement,
pub registration: bool,
/// License ID
pub license: Option<String>,
}
Expand Down Expand Up @@ -80,9 +80,7 @@ impl<'a> ProductClient<'a> {
None => "default.svg",
};

let registration = get_property::<String>(&data, "registration")
.map(|r| RegistrationRequirement::from_str(&r).unwrap_or_default())
.unwrap_or_default();
let registration = get_property::<bool>(&data, "registration").unwrap_or(false);

let license = get_optional_property::<String>(&data, "license").unwrap_or_default();

Expand Down
2 changes: 1 addition & 1 deletion rust/agama-lib/src/proxies/issues.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ use zbus::proxy;
pub trait Issues {
/// All property
#[zbus(property)]
fn all(&self) -> zbus::Result<Vec<(String, String, u32, u32)>>;
fn all(&self) -> zbus::Result<Vec<(String, String, String, u32, u32)>>;
}
6 changes: 4 additions & 2 deletions rust/agama-server/src/web/common.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) [2024] SUSE LLC
// Copyright (c) [2024-2025] SUSE LLC
//
// All Rights Reserved.
//
Expand Down Expand Up @@ -325,11 +325,12 @@ pub struct Issue {
details: Option<String>,
source: u32,
severity: u32,
kind: String,
}

impl Issue {
pub fn from_tuple(
(description, details, source, severity): (String, String, u32, u32),
(description, kind, details, source, severity): (String, String, String, u32, u32),
) -> Self {
let details = if details.is_empty() {
None
Expand All @@ -339,6 +340,7 @@ impl Issue {

Self {
description,
kind,
details,
source,
severity,
Expand Down
6 changes: 6 additions & 0 deletions rust/package/agama.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Fri Jan 24 06:43:05 UTC 2025 - Imobach Gonzalez Sosa <[email protected]>

- Change the registration property in a product's definition to a
boolean (gh#agama-project/agama#1938).

-------------------------------------------------------------------
Wed Jan 22 14:49:56 UTC 2025 - Ladislav Slezák <[email protected]>

Expand Down
9 changes: 0 additions & 9 deletions rust/package/agama.spec
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@
# Please submit bugfixes or comments via https://bugs.opensuse.org/
#

# Require at least 1.3GB RAM per each parallel job (the size is in MB)
%global _smp_tasksize_proc 1300

# Redefine the _smp_mflags macro so it takes the amount of RAM into account
%define _smp_mflags "-j%{getncpus:proc}"

Name: agama
# This will be set by osc services, that will run after this.
Version: 0
Expand Down Expand Up @@ -135,9 +129,6 @@ package contains a systemd service to run scripts when booting the installed sys
# find vendor -type f -name \*.rs -exec chmod -x '{}' \;

%build
# just for debugging failures with low memory
cat /proc/meminfo | head -n 3

%{cargo_build}
cargo run --package xtask -- manpages
gzip out/man/*
Expand Down
9 changes: 5 additions & 4 deletions service/lib/agama/dbus/clients/with_issues.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# Copyright (c) [2023] SUSE LLC
# Copyright (c) [2023-2025] SUSE LLC
#
# All Rights Reserved.
#
Expand Down Expand Up @@ -52,9 +52,10 @@ def issues_from(dbus_object)

dbus_object[ISSUES_IFACE]["All"].map do |dbus_issue|
Issue.new(dbus_issue[0],
details: dbus_issue[1],
source: sources[dbus_issue[2]],
severity: severities[dbus_issue[3]])
kind: dbus_issue[1].to_sym,
details: dbus_issue[2],
source: sources[dbus_issue[3]],
severity: severities[dbus_issue[4]])
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions service/lib/agama/dbus/interfaces/issues.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# Copyright (c) [2023] SUSE LLC
# Copyright (c) [2023-2025] SUSE LLC
#
# All Rights Reserved.
#
Expand Down Expand Up @@ -48,9 +48,9 @@ def dbus_issues
else
0
end
severity = issue.severity == Agama::Issue::Severity::WARN ? 0 : 1
severity = (issue.severity == Agama::Issue::Severity::WARN) ? 0 : 1

[issue.description, issue.details.to_s, source, severity]
[issue.description, issue.kind.to_s, issue.details.to_s, source, severity]
end
end

Expand All @@ -64,7 +64,7 @@ def self.included(base)
base.class_eval do
dbus_interface ISSUES_INTERFACE do
# @see {#dbus_issues}
dbus_reader :dbus_issues, "a(ssuu)", dbus_name: "All"
dbus_reader :dbus_issues, "a(sssuu)", dbus_name: "All"
end
end
end
Expand Down
5 changes: 3 additions & 2 deletions service/lib/agama/dbus/software/product.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# Copyright (c) [2023] SUSE LLC
# Copyright (c) [2023-2025] SUSE LLC
#
# All Rights Reserved.
#
Expand Down Expand Up @@ -180,7 +180,7 @@ def register(reg_code, email: nil)
[1, "Product not selected yet"]
elsif backend.registration.reg_code
[2, "Product already registered"]
elsif backend.registration.requirement == Agama::Registration::Requirement::NO
elsif !backend.product.registration
[3, "Product does not require registration"]
else
connect_result(first_error_code: 4) do
Expand Down Expand Up @@ -254,6 +254,7 @@ def register_callbacks
# software related issues.
backend.registration.on_change { issues_properties_changed }
backend.registration.on_change { registration_properties_changed }
backend.on_issues_change { issues_properties_changed }
end

def registration_properties_changed
Expand Down
11 changes: 9 additions & 2 deletions service/lib/agama/issue.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# Copyright (c) [2023] SUSE LLC
# Copyright (c) [2023-2025] SUSE LLC
#
# All Rights Reserved.
#
Expand Down Expand Up @@ -55,6 +55,12 @@ class Issue
# @return [Symbol]
attr_reader :severity

# Kind of error
#
# It helps to identify the error without having to rely on the message
# @return [Symbol]
attr_reader :kind

# Defines possible sources
module Source
SYSTEM = :system
Expand All @@ -73,8 +79,9 @@ module Severity
# @param details [String, nil]
# @param source [symbol, nil]
# @param severity [symbol]
def initialize(description, details: "", source: nil, severity: Severity::WARN)
def initialize(description, kind: :generic, details: "", source: nil, severity: Severity::WARN)
@description = description
@kind = kind
@details = details
@source = source
@severity = severity
Expand Down
16 changes: 13 additions & 3 deletions service/lib/agama/software/manager.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# Copyright (c) [2021-2024] SUSE LLC
# Copyright (c) [2021-2025] SUSE LLC
#
# All Rights Reserved.
#
Expand Down Expand Up @@ -589,6 +589,7 @@ def missing_product_issue
# @return [Agama::Issue]
def missing_registration_issue
Issue.new(_("Product must be registered"),
kind: :missing_registration,
source: Issue::Source::SYSTEM,
severity: Issue::Severity::ERROR)
end
Expand All @@ -597,8 +598,17 @@ def missing_registration_issue
#
# @return [Boolean]
def missing_registration?
registration.reg_code.nil? &&
registration.requirement == Agama::Registration::Requirement::MANDATORY
return false unless product

product.registration && missing_base_product?
end

# Whether the base product is missing
#
# @return [Boolean]
def missing_base_product?
products = Y2Packager::Resolvable.find(kind: :product, name: product.name)
products.empty?
end

def pattern_exist?(pattern_name)
Expand Down
9 changes: 4 additions & 5 deletions service/lib/agama/software/product.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# Copyright (c) [2023] SUSE LLC
# Copyright (c) [2023-2025] SUSE LLC
#
# All Rights Reserved.
#
Expand Down Expand Up @@ -92,10 +92,9 @@ class Product
# @return [Array<String>]
attr_accessor :user_patterns

# Determines if the product should be registered.
# Whether the registration is enabled for the product.
#
# @see Agama::Registration::Requirement
# @return [String]
# @return [boolean]
attr_accessor :registration

# Product translations.
Expand Down Expand Up @@ -126,7 +125,7 @@ def initialize(id)
@optional_patterns = []
# nil = display all visible patterns, [] = display no patterns
@user_patterns = nil
@registration = Agama::Registration::Requirement::NO
@registration = false
@license = nil
@translations = {}
end
Expand Down
4 changes: 2 additions & 2 deletions service/lib/agama/software/product_builder.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# Copyright (c) [2023] SUSE LLC
# Copyright (c) [2023-2025] SUSE LLC
#
# All Rights Reserved.
#
Expand Down Expand Up @@ -65,7 +65,7 @@ def initialize_product(id, data, attrs)
product.name = data[:name]
product.version = data[:version]
product.icon = attrs["icon"] if attrs["icon"]
product.registration = attrs["registration"] if attrs["registration"]
product.registration = !!attrs["registration"]
product.license = attrs["license"] if attrs["license"]
product.version = attrs["version"] if attrs["version"]
end
Expand Down
6 changes: 6 additions & 0 deletions service/package/rubygem-agama-yast.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Fri Jan 24 06:42:00 UTC 2025 - Imobach Gonzalez Sosa <[email protected]>

- Use the availability of the base product to determine whether a
product requires to be registered (gh#agama-project/agama#1938).

-------------------------------------------------------------------
Tue Jan 21 19:11:04 UTC 2025 - Imobach Gonzalez Sosa <[email protected]>

Expand Down
20 changes: 10 additions & 10 deletions service/test/agama/dbus/clients/with_issues_examples.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# Copyright (c) [2023] SUSE LLC
# Copyright (c) [2023-2025] SUSE LLC
#
# All Rights Reserved.
#
Expand Down Expand Up @@ -37,36 +37,36 @@
end

let(:root_node) do
instance_double(::DBus::Node, descendant_objects: [dbus_object1, dbus_object2, dbus_object3])
instance_double(DBus::Node, descendant_objects: [dbus_object1, dbus_object2, dbus_object3])
end

let(:dbus_object1) do
instance_double(::DBus::ProxyObject,
instance_double(DBus::ProxyObject,
interfaces: ["org.opensuse.Agama1.Test", "org.opensuse.Agama1.Issues"])
end

let(:dbus_object2) do
instance_double(::DBus::ProxyObject, interfaces: ["org.opensuse.Agama1.Test"])
instance_double(DBus::ProxyObject, interfaces: ["org.opensuse.Agama1.Test"])
end

let(:dbus_object3) do
instance_double(::DBus::ProxyObject, interfaces: ["org.opensuse.Agama1.Issues"])
instance_double(DBus::ProxyObject, interfaces: ["org.opensuse.Agama1.Issues"])
end

let(:issues_interface1) { instance_double(::DBus::ProxyObjectInterface) }
let(:issues_interface1) { instance_double(DBus::ProxyObjectInterface) }

let(:issues_interface3) { instance_double(::DBus::ProxyObjectInterface) }
let(:issues_interface3) { instance_double(DBus::ProxyObjectInterface) }

let(:issues1) do
[
["Issue 1", "Details 1", 1, 0],
["Issue 2", "Details 2", 2, 1]
["Issue 1", "generic", "Details 1", 1, 0],
["Issue 2", "generic", "Details 2", 2, 1]
]
end

let(:issues3) do
[
["Issue 3", "Details 3", 1, 0]
["Issue 3", "generic", "Details 3", 1, 0]
]
end

Expand Down
Loading

0 comments on commit f21c18d

Please sign in to comment.