Skip to content

Commit

Permalink
service: only set calculated sizes if size is auto
Browse files Browse the repository at this point in the history
  • Loading branch information
joseivanlopez committed Jun 19, 2024
1 parent b4819ac commit 4af4b9c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 20 deletions.
20 changes: 14 additions & 6 deletions service/lib/agama/storage/volume_conversion/from_y2storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,22 @@ def convert
# @return [Agama::Storage::ProposalSettings]
attr_reader :volume

# Recovers the range of sizes used by the Y2Storage proposal, if needed.
#
# If the volume is configured to use auto sizes, then the final range of sizes used by the
# Y2Storage proposal depends on the fallback sizes (if this volume is fallback for other
# volume) and the size for snapshots (if snapshots is active). The planned device contains
# the real range of sizes used by the Y2Storage proposal.
#
# FIXME: Recovering the sizes from the planned device is done to know the range of sizes
# assigned to the volume and to present that information in the UI. But such information
# should be provided in a different way, for example as part of the proposal result
# reported on D-Bus: { success:, settings:, strategy:, computed_sizes: }.
#
# @param target [Agama::Storage::Volume]
def sizes_conversion(target)
# The final range of sizes used by the Y2Storage proposal depends on the fallback sizes
# (if this volume is fallback for other volume) and the size for snapshots (if snapshots
# is active). The planned device contains the real range of sizes used by the proposal.
#
# From Agama point of view, this is the way of recovering the range of sizes used by
# Y2Storage when a volume is set to have auto size.
return unless target.auto_size?

planned = planned_device_for(target.mount_path)
return unless planned

Expand Down
52 changes: 38 additions & 14 deletions service/test/agama/storage/volume_conversion/from_y2storage_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,35 +89,59 @@
instance_double(Y2Storage::MinGuidedProposal, planned_devices: planned_devices)
end

context "if there is a planned device for the volume" do
let(:planned_devices) { [planned_volume] }
let(:planned_devices) { [planned_volume] }

let(:planned_volume) do
Y2Storage::Planned::LvmLv.new("/").tap do |planned|
planned.min = Y2Storage::DiskSize.GiB(10)
planned.max = Y2Storage::DiskSize.GiB(40)
context "if the volume is configured with auto size" do
before do
volume.auto_size = true
end

context "if there is a planned device for the volume" do
let(:planned_volume) do
Y2Storage::Planned::LvmLv.new("/").tap do |planned|
planned.min = Y2Storage::DiskSize.GiB(10)
planned.max = Y2Storage::DiskSize.GiB(40)
end
end

it "sets the min and max sizes according to the planned device" do
result = subject.convert

expect(result.min_size).to eq(Y2Storage::DiskSize.GiB(10))
expect(result.max_size).to eq(Y2Storage::DiskSize.GiB(40))
end
end

it "sets the min and max sizes according to the planned device" do
result = subject.convert
context "if there is no planned device for the volume" do
let(:planned_volume) do
Y2Storage::Planned::LvmLv.new("/home").tap do |planned|
planned.min = Y2Storage::DiskSize.GiB(10)
planned.max = Y2Storage::DiskSize.GiB(40)
end
end

it "keeps the sizes of the given volume" do
result = subject.convert

expect(result.min_size).to eq(Y2Storage::DiskSize.GiB(10))
expect(result.max_size).to eq(Y2Storage::DiskSize.GiB(40))
expect(result.min_size).to eq(Y2Storage::DiskSize.GiB(5))
expect(result.max_size).to eq(Y2Storage::DiskSize.GiB(20))
end
end
end

context "if there is no planned device for the volume" do
let(:planned_devices) { [planned_volume] }
context "if the volume is not configured with auto size" do
before do
volume.auto_size = false
end

let(:planned_volume) do
Y2Storage::Planned::LvmLv.new("/home").tap do |planned|
Y2Storage::Planned::LvmLv.new("/").tap do |planned|
planned.min = Y2Storage::DiskSize.GiB(10)
planned.max = Y2Storage::DiskSize.GiB(40)
end
end

it "sets the sizes of the given volume" do
it "keeps the sizes of the given volume" do
result = subject.convert

expect(result.min_size).to eq(Y2Storage::DiskSize.GiB(5))
Expand Down

0 comments on commit 4af4b9c

Please sign in to comment.