From 4af4b9c3d766c95402acee1b61e38c567a6528c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Iv=C3=A1n=20L=C3=B3pez=20Gonz=C3=A1lez?= Date: Wed, 19 Jun 2024 09:27:19 +0100 Subject: [PATCH] service: only set calculated sizes if size is auto --- .../volume_conversion/from_y2storage.rb | 20 ++++--- .../volume_conversion/from_y2storage_test.rb | 52 ++++++++++++++----- 2 files changed, 52 insertions(+), 20 deletions(-) diff --git a/service/lib/agama/storage/volume_conversion/from_y2storage.rb b/service/lib/agama/storage/volume_conversion/from_y2storage.rb index 01415a4135..0c493fe707 100644 --- a/service/lib/agama/storage/volume_conversion/from_y2storage.rb +++ b/service/lib/agama/storage/volume_conversion/from_y2storage.rb @@ -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 diff --git a/service/test/agama/storage/volume_conversion/from_y2storage_test.rb b/service/test/agama/storage/volume_conversion/from_y2storage_test.rb index 55da4f8edb..ceecba866b 100644 --- a/service/test/agama/storage/volume_conversion/from_y2storage_test.rb +++ b/service/test/agama/storage/volume_conversion/from_y2storage_test.rb @@ -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))