Skip to content

Commit

Permalink
WIP: reorganizing tests and adding temporary fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ancorgs committed Jul 26, 2023
1 parent 86b9ef1 commit 6469521
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 327 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def initialize(settings, config:)
# @return [Agama::Storage::ProposalSettings]
def convert
ProposalSettings.new.tap do |target|
boot_devices_conversion(target)
boot_device_conversion(target)
lvm_conversion(target)
encryption_conversion(target)
space_policy_conversion(target)
Expand Down Expand Up @@ -101,14 +101,14 @@ def fallbacks_conversion(target)
# @param mount_path [String]
# @return [Array<String>]
def volumes_with_min_size_fallback(mount_path)
specs = settings.volumes.select { |s| s.min_size_fallback == mount_path }
specs = settings.volumes.select { |s| s.fallback_for_min_size == mount_path }
specs.map(&:mount_point)
end

# @param mount_path [String]
# @return [Array<String>]
def volumes_with_max_size_fallback(mount_path)
specs = settings.volumes.select { |s| s.max_size_fallback == mount_path }
specs = settings.volumes.select { |s| s.fallback_for_max_size == mount_path }
specs.map(&:mount_point)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ def volumes_conversion(target)
# @param target [Y2Storage::ProposalSettings]
def fallbacks_conversion(target)
target.volumes.each do |spec|
spec.min_size_fallback = find_min_size_fallback(spec.mount_point)
spec.max_size_fallback = find_max_size_fallback(spec.mount_point)
spec.fallback_for_min_size = find_min_size_fallback(spec.mount_point)
spec.fallback_for_max_size = find_max_size_fallback(spec.mount_point)
end
end

Expand All @@ -115,7 +115,7 @@ def find_min_size_fallback(mount_path)

# @param mount_path [String]
def find_max_size_fallback(mount_path)
volume = volumes.find { |v| v.max_size_fallback_for.include?(mount_path) }
volume = settings.volumes.find { |v| v.max_size_fallback_for.include?(mount_path) }
volume&.mount_path
end

Expand All @@ -136,7 +136,7 @@ def candidate_devices
# @return [Array<String>]
def all_devices
devices = candidate_devices
devices += settings.volumes.map(&:device)
devices += settings.volumes.map(&:device).compact

devices.uniq.map { |d| device_or_partitions(d) }.flatten
end
Expand Down
2 changes: 1 addition & 1 deletion service/lib/agama/storage/proposal_settings_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def initialize(config)
# @return [ProposalSettings]
def read
settings = ProposalSettings.new
config.fetch("storage", {}).each do |key, value|
config.data.fetch("storage", {}).each do |key, value|
send(READERS[key], settings, value)
end
end
Expand Down
10 changes: 8 additions & 2 deletions service/lib/agama/storage/volume.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.

require "pathname"
require "forwardable"
require "agama/storage/btrfs_settings"
require "agama/storage/volume_outline"

Expand All @@ -30,6 +30,8 @@ module Storage
# A volume is converted to D-Bus and to Y2Storage formats in order to provide the volume
# information with the expected representation, see {VolumeConversion}.
class Volume
extend Forwardable

# Mount path
#
# @return [String]
Expand All @@ -38,7 +40,7 @@ class Volume
# Outline of the volume
#
# @return [VolumeOutline]
attr_reader :outline
attr_accessor :outline

# Filesystem for the volume
#
Expand Down Expand Up @@ -88,6 +90,10 @@ def initialize(mount_path)
@outline = VolumeOutline.new
end

def_delegators :outline,
:min_size_fallback_for, :min_size_fallback_for=,
:max_size_fallback_for, :max_size_fallback_for=

# Whether it makes sense to have automatic size limits for the volume
#
# @return [Boolean]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def convert # rubocop:disable Metrics/AbcSize
target.device = volume.device
target.separate_vg_name = volume.separate_vg_name
target.mount_point = volume.mount_path
target.mount_options = volume.mount_options
target.mount_options = volume.mount_options.join(",")
target.proposed = true
target.proposed_configurable = !volume.outline.required?
target.fs_types = volume.outline.filesystems
Expand Down
16 changes: 8 additions & 8 deletions service/lib/agama/storage/volume_outline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,27 @@ class VolumeOutline
# this volume or an equivalent one (ie. one with the same mount_path).
#
# @return [Boolean]
attr_reader :required
attr_accessor :required
alias_method :required?, :required

# Possible filesystem types for the volume
#
# @return [Array<Y2Storage::Filesystems::Type>]
attr_reader :filesystems
attr_accessor :filesystems

# Base value to calculate the min size for the volume (if #auto_size is set to true
# for that final volume) or to use as default value (if #auto_size is false)
#
# @return [Y2Storage::DiskSize]
attr_reader :base_min_size
attr_accessor :base_min_size

# Base value to calculate the max size for the volume (if #auto_size is set to true
# for that final volume) or to use as default value (if #auto_size is false)
#
# @return [Y2Storage::DiskSize]
attr_reader :base_max_size
attr_accessor :base_max_size

attr_reader :adjust_by_ram
attr_accessor :adjust_by_ram
alias_method :adjust_by_ram?, :adjust_by_ram

# @return [Array<String>] mount paths of other volumes
Expand All @@ -63,18 +63,18 @@ class VolumeOutline
# Whether snapshots option can be configured
#
# @return [Boolean]
attr_reader :snapshots_configurable
attr_accessor :snapshots_configurable
alias_method :snapshots_configurable?, :snapshots_configurable

# Size required for snapshots
#
# @return [Y2Storage::DiskSize, nil]
attr_reader :snapshots_size
attr_accessor :snapshots_size

# Percentage of space required for snapshots
#
# @return [Integer, nil]
attr_reader :snapshots_percentage
attr_accessor :snapshots_percentage

def initialize
@filesystems = []
Expand Down
18 changes: 14 additions & 4 deletions service/lib/agama/storage/volume_templates_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ def initialize(config_data)
# @param path [String]
# @return [Agama::Storage::Volume]
def for(path)
data = @data[cleanpath(path)] || @data[""]
data = @data[cleanpath(path)] || @data[""] || empty_data

Volume.new(path).tap do |volume|
volume.btrfs = data[:btrfs]
volume.outline = data[:outline]
volume.filesystem = data[:filesystem]
volume.fs_type = data[:filesystem]
volume.mount_options = data[:mount_options]

if data[:auto_size] && volume.auto_size_supported?
Expand All @@ -79,6 +79,16 @@ def key(data)
cleanpath(path)
end

# Temporary method to avoid crashes if there is no default template
def empty_data
{
btrfs: BtrfsSettings.new,
outline: VolumeOutline.new,
mount_options: [],
filesystem: Y2Storage::Filesystems::Type::EXT4
}
end

def values(data) # rubocop:disable Metrics/AbcSize
{}.tap do |values|
values[:btrfs] = btrfs(data)
Expand All @@ -91,7 +101,7 @@ def values(data) # rubocop:disable Metrics/AbcSize
values[:filesystem] ||= values[:outline].filesystems.first
values[:filesystem] ||= Y2Storage::Filesystems::Type::EXT4

size = outline_data.fetch("size", {})
size = data.fetch("size", {})
values[:auto_size] = size.fetch("auto", false)
values[:min_size] = parse_disksize(size["min"])
values[:max_size] = parse_disksize(size["max"])
Expand Down Expand Up @@ -141,7 +151,7 @@ def outline(data) # rubocop:disable Metrics/AbcSize
end

def assign_snapshots_increment(outline, increment)
return if increment.nil
return if increment.nil?

if increment =~ /(\d+)\s*%/
outline.snapshots_percentage = Regexp.last_match(1).to_i
Expand Down
92 changes: 0 additions & 92 deletions service/test/agama/storage/proposal_conversions_test.rb

This file was deleted.

Loading

0 comments on commit 6469521

Please sign in to comment.