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
3 changes: 0 additions & 3 deletions service/lib/agama/dbus/storage/manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,6 @@ def calculate_guided_proposal(settings_dbus)

# List of disks available for installation
#
# Each device is represented by an array containing the name of the device and the label to
# represent that device in the UI when further information is needed.
#
# @return [Array<::DBus::ObjectPath>]
def available_devices
proposal.available_devices.map { |d| system_devices_tree.path_for(d) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def shrink_all?(partition_config)
# @return [Boolean]
def search_all?(partition_config)
!partition_config.search.nil? &&
partition_config.search.always_match? &&
!partition_config.search.condition? &&
partition_config.search.max.nil?
end
end
Expand Down
23 changes: 8 additions & 15 deletions service/lib/agama/storage/config_solver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
# find current contact information at www.suse.com.

require "agama/storage/config_solvers"
require "y2storage/disk_analyzer"

module Agama
module Storage
Expand All @@ -34,13 +33,10 @@ module Storage
# generated from a profile.
class ConfigSolver
# @param product_config [Agama::Config] configuration of the product to install
# @param devicegraph [Y2Storage::Devicegraph] initial layout of the system
# @param disk_analyzer [Y2Storage::DiskAnalyzer, nil] extra information about the initial
# layout of the system
def initialize(product_config, devicegraph, disk_analyzer: nil)
# @param storage_system [Storage::System]
def initialize(product_config, storage_system)
@product_config = product_config
@devicegraph = devicegraph
@disk_analyzer = disk_analyzer || Y2Storage::DiskAnalyzer.new(devicegraph)
@storage_system = storage_system
end

# Solves the config according to the product and the system.
Expand All @@ -52,22 +48,19 @@ def solve(config)
ConfigSolvers::Boot.new(product_config).solve(config)
ConfigSolvers::Encryption.new(product_config).solve(config)
ConfigSolvers::Filesystem.new(product_config).solve(config)
ConfigSolvers::DrivesSearch.new(devicegraph, disk_analyzer).solve(config)
ConfigSolvers::MdRaidsSearch.new(devicegraph, disk_analyzer).solve(config)
ConfigSolvers::DrivesSearch.new(storage_system).solve(config)
ConfigSolvers::MdRaidsSearch.new(storage_system).solve(config)
# Sizes must be solved once the searches are solved.
ConfigSolvers::Size.new(product_config, devicegraph).solve(config)
ConfigSolvers::Size.new(product_config).solve(config)
end

private

# @return [Agama::Config]
attr_reader :product_config

# @return [Y2Storage::Devicegraph]
attr_reader :devicegraph

# @return [Y2Storage::DiskAnalyzer]
attr_reader :disk_analyzer
# @return [Storage::System]
attr_reader :storage_system
end
end
end
6 changes: 4 additions & 2 deletions service/lib/agama/storage/config_solvers/base.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# Copyright (c) [2024] SUSE LLC
# Copyright (c) [2024-2025] SUSE LLC
#
# All Rights Reserved.
#
Expand Down Expand Up @@ -33,9 +33,11 @@ def initialize(product_config)

# Solves a given config.
#
# @note Derived classes must implement this method.
#
# @param _config [Config]
def solve(_config)
raise "#solve is not defined"
raise NotImplementedError
end

private
Expand Down
25 changes: 6 additions & 19 deletions service/lib/agama/storage/config_solvers/drives_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,10 @@ class DrivesSearch < DevicesSearch
include SearchMatchers
include WithPartitionsSearch

# @param devicegraph [Y2Storage::Devicegraph]
# @param disk_analyzer [Y2Storage::DiskAnalyzer]
def initialize(devicegraph, disk_analyzer)
# @param storage_system [Storage::System]
def initialize(storage_system)
super()
@devicegraph = devicegraph
@disk_analyzer = disk_analyzer
@storage_system = storage_system
end

# Solves the search of the drive configs and solves the searches of their partitions.
Expand All @@ -46,18 +44,15 @@ def initialize(devicegraph, disk_analyzer)
# @param config [Storage::Config]
# @return [Storage::Config]
def solve(config)
config.drives = super(config.drives, candidate_drives)
config.drives = super(config.drives, storage_system.candidate_drives)
solve_partitions_search(config.drives)
config
end

private

# @return [Y2Storage::Devicegraph]
attr_reader :devicegraph

# @return [Y2Storage::DiskAnalyzer]
attr_reader :disk_analyzer
# @return [Storage::System]
attr_reader :storage_system

# @see DevicesSearch#match_condition?
# @param drive_config [Configs::Drive]
Expand All @@ -67,14 +62,6 @@ def solve(config)
def match_condition?(drive_config, drive)
match_name?(drive_config, drive) && match_size?(drive_config, drive)
end

# Candidate drives for solving the search of drive configs.
#
# @return [Array<Y2Storage::Drive, Y2Storage::StrayBlkDevice>]
def candidate_drives
drives = devicegraph.disk_devices + devicegraph.stray_blk_devices
drives.select { |d| disk_analyzer.candidate_device?(d) }
end
end
end
end
Expand Down
24 changes: 6 additions & 18 deletions service/lib/agama/storage/config_solvers/md_raids_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,10 @@ class MdRaidsSearch < DevicesSearch
include SearchMatchers
include WithPartitionsSearch

# @param devicegraph [Y2Storage::Devicegraph]
# @param disk_analyzer [Y2Storage::DiskAnalyzer]
def initialize(devicegraph, disk_analyzer)
# @param storage_system [Storage::System]
def initialize(storage_system)
super()
@devicegraph = devicegraph
@disk_analyzer = disk_analyzer
@storage_system = storage_system
end

# Solves the search of the MD RAID configs and solves the searches of their partitions.
Expand All @@ -46,18 +44,15 @@ def initialize(devicegraph, disk_analyzer)
# @param config [Storage::Config]
# @return [Storage::Config]
def solve(config)
config.md_raids = super(config.md_raids, candidate_md_raids)
config.md_raids = super(config.md_raids, storage_system.candidate_md_raids)
solve_partitions_search(config.md_raids)
config
end

private

# @return [Y2Storage::Devicegraph]
attr_reader :devicegraph

# @return [Y2Storage::DiskAnalyzer]
attr_reader :disk_analyzer
# @return [Storage::System]
attr_reader :storage_system

# @see DevicesSearch#match_condition?
# @param md_raid_config [Configs::MdRaid]
Expand All @@ -67,13 +62,6 @@ def solve(config)
def match_condition?(md_raid_config, md_raid)
match_name?(md_raid_config, md_raid) && match_size?(md_raid_config, md_raid)
end

# Candidate MD RAIDs for solving the search of the configs.
#
# @return [Array<Y2Storage::Md]
def candidate_md_raids
devicegraph.md_raids.select { |d| disk_analyzer.candidate_device?(d) }
end
end
end
end
Expand Down
10 changes: 0 additions & 10 deletions service/lib/agama/storage/config_solvers/size.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@ module ConfigSolvers
#
# It assigns proper size values according to the product and the system.
class Size < Base
# @param product_config [Agama::Config]
# @param devicegraph [Y2Storage::Devicegraph]
def initialize(product_config, devicegraph)
super(product_config)
@devicegraph = devicegraph
end

# Solves all the size configs within a given config.
#
# @note The config object is modified.
Expand All @@ -50,9 +43,6 @@ def solve(config)

private

# @return [Y2Storage::Devicegraph]
attr_reader :devicegraph

def solve_default_sizes
configs_with_default_product_size.each { |c| solve_default_product_size(c) }
configs_with_default_device_size.each { |c| solve_default_device_size(c) }
Expand Down
7 changes: 4 additions & 3 deletions service/lib/agama/storage/configs/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,12 @@ def solve(device = nil)
@solved = true
end

# Whether the search does not define any specific condition.
# Whether the search defines any condition.
#
# @return [Boolean]
def always_match?
name.nil?
def condition?
condition = name || size || partition_number
!condition.nil?
end

# Whether the section containing the search should be skipped
Expand Down
27 changes: 12 additions & 15 deletions service/lib/agama/storage/proposal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
require "agama/storage/model_support_checker"
require "agama/storage/proposal_settings"
require "agama/storage/proposal_strategies"
require "agama/storage/system"
require "json"
require "yast"
require "y2storage"
Expand Down Expand Up @@ -70,7 +71,7 @@ def on_calculate(&block)
#
# @return [Array<Y2Storage::Device>]
def available_devices
disk_analyzer&.candidate_disks || []
storage_system.candidate_drives
end

# Storage config according to the JSON schema from the current proposal.
Expand Down Expand Up @@ -116,10 +117,7 @@ def solve_model(model_json)
.new(model_json, product_config: product_config)
.convert

ConfigSolver
.new(product_config, storage_manager.probed, disk_analyzer: disk_analyzer)
.solve(config)

ConfigSolver.new(product_config, storage_system).solve(config)
ConfigConversions::ToModel.new(config).convert
end

Expand Down Expand Up @@ -169,7 +167,7 @@ def calculate_from_model(model_json)
def calculate_guided(settings)
logger.info("Calculating proposal with guided strategy: #{settings.inspect}")
reset
@strategy = ProposalStrategies::Guided.new(product_config, logger, settings)
@strategy = ProposalStrategies::Guided.new(product_config, storage_system, settings, logger)
calculate
end

Expand All @@ -181,7 +179,7 @@ def calculate_agama(config)
logger.info("Calculating proposal with agama strategy: #{config.inspect}")
reset
@source_config = config.copy
@strategy = ProposalStrategies::Agama.new(product_config, logger, config)
@strategy = ProposalStrategies::Agama.new(product_config, storage_system, config, logger)
calculate
end

Expand All @@ -195,7 +193,8 @@ def calculate_autoyast(partitioning)
reset
# Ensures keys are strings.
partitioning = JSON.parse(partitioning.to_json)
@strategy = ProposalStrategies::Autoyast.new(product_config, logger, partitioning)
@strategy = ProposalStrategies::Autoyast
.new(product_config, storage_system, partitioning, logger)
calculate
end

Expand Down Expand Up @@ -336,18 +335,16 @@ def calculate
success?
end

# @return [Storage::System]
def storage_system
@storage_system ||= Storage::System.new
end

# @return [Y2Storage::Proposal::Base, nil]
def proposal
storage_manager.proposal
end

# @return [Y2Storage::DiskAnalyzer, nil] nil if the system is not probed yet.
def disk_analyzer
return unless storage_manager.probed?

storage_manager.probed_disk_analyzer
end

# @return [Y2Storage::StorageManager]
def storage_manager
Y2Storage::StorageManager.instance
Expand Down
18 changes: 10 additions & 8 deletions service/lib/agama/storage/proposal_strategies/agama.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# Copyright (c) [2024] SUSE LLC
# Copyright (c) [2024-2025] SUSE LLC
#
# All Rights Reserved.
#
Expand Down Expand Up @@ -34,12 +34,13 @@ class Agama < Base
alias_method :settings, :config

# @param product_config [Agama::Config]
# @param logger [Logger]
# @param storage_system [Storage::System]
# @param config [Agama::Storage::Config]
def initialize(product_config, logger, config)
# @param logger [Logger]
def initialize(product_config, storage_system, config, logger)
textdomain "agama"

super(product_config, logger)
super(product_config, storage_system, logger)
@config = config
end

Expand Down Expand Up @@ -67,11 +68,12 @@ def issues
#
# @return [Y2Storage::AgamaProposal]
def agama_proposal
Y2Storage::AgamaProposal.new(config,
Y2Storage::AgamaProposal.new(
config,
storage_system,
product_config: product_config,
devicegraph: probed_devicegraph,
disk_analyzer: disk_analyzer,
issues_list: [])
issues_list: []
)
end
end
end
Expand Down
13 changes: 7 additions & 6 deletions service/lib/agama/storage/proposal_strategies/autoyast.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# Copyright (c) [2024] SUSE LLC
# Copyright (c) [2024-2025] SUSE LLC
#
# All Rights Reserved.
#
Expand Down Expand Up @@ -31,12 +31,13 @@ class Autoyast < Base
include Yast::I18n

# @param product_config [Config] Product config
# @param logger [Logger]
# @param storage_system [Storage::System]
# @param partitioning [Array<Hash>]
def initialize(product_config, logger, partitioning)
# @param logger [Logger]
def initialize(product_config, storage_system, partitioning, logger)
textdomain "agama"

super(product_config, logger)
super(product_config, storage_system, logger)
@partitioning = partitioning
end

Expand All @@ -52,8 +53,8 @@ def calculate
proposal = Y2Storage::AutoinstProposal.new(
partitioning: partitioning,
proposal_settings: proposal_settings,
devicegraph: probed_devicegraph,
disk_analyzer: disk_analyzer,
devicegraph: storage_system.devicegraph,
disk_analyzer: storage_system.analyzer,
issues_list: ay_issues
)
proposal.propose
Expand Down
Loading