From 8ae951f8640ee48acfdcfea8f5062bffa6941692 Mon Sep 17 00:00:00 2001 From: Ancor Gonzalez Sosa Date: Fri, 22 Mar 2024 09:59:41 +0100 Subject: [PATCH 1/4] [Service] Non-auto sizes for volumes with adjust_by_ram --- .../volume_conversion/from_y2storage.rb | 12 ++- .../storage/volume_conversion/to_y2storage.rb | 1 + .../agama/storage/proposal_volumes_test.rb | 75 ++++++++++++++++++- .../volume_conversion/to_y2storage_test.rb | 2 + 4 files changed, 86 insertions(+), 4 deletions(-) diff --git a/service/lib/agama/storage/volume_conversion/from_y2storage.rb b/service/lib/agama/storage/volume_conversion/from_y2storage.rb index ee4dd9651d..e881a0f26a 100644 --- a/service/lib/agama/storage/volume_conversion/from_y2storage.rb +++ b/service/lib/agama/storage/volume_conversion/from_y2storage.rb @@ -60,7 +60,7 @@ def convert # @param target [Agama::Storage::Volume] def sizes_conversion(target) - target.auto_size = !spec.ignore_fallback_sizes? || !spec.ignore_snapshots_sizes? + target.auto_size = auto_size? # The volume specification contains the min and max sizes for the volume. But the final # range of sizes used by the Y2Storage proposal depends on the fallback sizes (if this @@ -74,6 +74,16 @@ def sizes_conversion(target) target.max_size = planned&.max || spec.max_size end + # @see #sizes_conversion + # + # @return [Boolean] + def auto_size? + # The three ignore_xxx attributes (ignore_snapshots_sizes, ignore_fallback_sizes and + # ignore_adjust_by_ram) are always in sync and always initialized to the inverse of + # #auto_size + !spec.ignore_fallback_sizes? + end + # @param target [Agama::Storage::Volume] def btrfs_conversion(target) target.btrfs.snapshots = spec.snapshots? diff --git a/service/lib/agama/storage/volume_conversion/to_y2storage.rb b/service/lib/agama/storage/volume_conversion/to_y2storage.rb index 0e62261f3c..9c00bcd1e0 100644 --- a/service/lib/agama/storage/volume_conversion/to_y2storage.rb +++ b/service/lib/agama/storage/volume_conversion/to_y2storage.rb @@ -63,6 +63,7 @@ def sizes_conversion(target) target.ignore_fallback_sizes = !auto target.ignore_snapshots_sizes = !auto + target.ignore_adjust_by_ram = !auto # The range of sizes is defined by the volume outline in case of auto size (mix and max # sizes cannot be configured if auto size is set). diff --git a/service/test/agama/storage/proposal_volumes_test.rb b/service/test/agama/storage/proposal_volumes_test.rb index 7a722ea5f0..e571321799 100644 --- a/service/test/agama/storage/proposal_volumes_test.rb +++ b/service/test/agama/storage/proposal_volumes_test.rb @@ -29,7 +29,13 @@ describe Agama::Storage::Proposal do include Agama::RSpec::StorageHelpers - before { mock_storage } + before do + allow(Yast::SCR).to receive(:Read).and_call_original + allow(Yast::SCR).to receive(:Read).with(path(".proc.meminfo")) + .and_return("memtotal" => 8388608) + + mock_storage + end subject(:proposal) { described_class.new(config, logger: logger) } @@ -42,7 +48,7 @@ let(:cfg_volumes) { ["/", "swap"] } - let(:cfg_templates) { [root_template, other_template] } + let(:cfg_templates) { [root_template, swap_template, other_template] } let(:root_template) do { "mount_path" => "/", "filesystem" => "btrfs", "size" => { "auto" => true }, @@ -55,6 +61,14 @@ } } end + let(:swap_template) do + { + "mount_path" => "swap", "filesystem" => "swap", "size" => { "auto" => true }, + "outline" => { + "auto_size" => { "base_min" => "1 GiB", "base_max" => "2 GiB", "adjust_by_ram" => true } + } + } + end let(:other_template) do { "mount_path" => "/two", "filesystem" => "xfs", @@ -126,6 +140,7 @@ def expect_proposal_with_expects(*specs) ignore_fallback_sizes: false, ignore_snapshots_sizes: false, min_size: Y2Storage::DiskSize.GiB(10) }, + { mount_point: "swap", proposed: false }, { mount_point: "/two", proposed: false, fallback_for_min_size: "/" } ) proposal.calculate(settings) @@ -163,6 +178,7 @@ def expect_proposal_with_expects(*specs) ignore_fallback_sizes: false, ignore_snapshots_sizes: false, min_size: Y2Storage::DiskSize.GiB(10) }, + { mount_point: "swap", proposed: false }, { mount_point: "/two", proposed: true, fallback_for_min_size: "/" } ) proposal.calculate(settings) @@ -201,6 +217,7 @@ def expect_proposal_with_expects(*specs) ignore_fallback_sizes: false, ignore_snapshots_sizes: false, min_size: Y2Storage::DiskSize.GiB(10) }, + { mount_point: "swap", proposed: false }, { mount_point: "/two", proposed: false, fallback_for_min_size: "/" } ) proposal.calculate(settings) @@ -224,8 +241,50 @@ def expect_proposal_with_expects(*specs) end end + context "when auto size is used and it is affected by RAM size" do + let(:volumes) { [test_vol("/"), test_vol("swap")] } + + describe "#calculate" do + before do + allow(Y2Storage::StorageManager.instance).to receive(:proposal=) + end + + it "runs the Y2Storage proposal with the correct set of VolumeSpecification" do + expect_proposal_with_expects( + { mount_point: "/", proposed: true }, + { mount_point: "/two", proposed: false }, + { + mount_point: "swap", proposed: true, ignore_adjust_by_ram: false, + min_size: Y2Storage::DiskSize.GiB(1) + } + ) + proposal.calculate(settings) + end + end + + describe "#settings" do + it "returns settings with a set of volumes with adjusted sizes" do + proposal.calculate(settings) + + expect(proposal.settings.volumes).to contain_exactly( + an_object_having_attributes(mount_path: "/", auto_size: true), + an_object_having_attributes( + mount_path: "swap", + auto_size?: true, + min_size: Y2Storage::DiskSize.GiB(8) + ) + ) + end + end + end + context "when fixed sizes are enforced" do - let(:volumes) { [test_vol("/", auto_size: false, min_size: "6 GiB")] } + let(:volumes) do + [ + test_vol("/", auto_size: false, min_size: "6 GiB"), + test_vol("swap", auto_size: false, min_size: "1 GiB") + ] + end describe "#calculate" do before do @@ -239,6 +298,10 @@ def expect_proposal_with_expects(*specs) ignore_fallback_sizes: true, ignore_snapshots_sizes: true, min_size: Y2Storage::DiskSize.GiB(6) }, + { + mount_point: "swap", proposed: true, ignore_adjust_by_ram: true, + min_size: Y2Storage::DiskSize.GiB(1) + }, { mount_point: "/two", proposed: false, fallback_for_min_size: "/" } ) proposal.calculate(settings) @@ -256,6 +319,12 @@ def expect_proposal_with_expects(*specs) auto_size?: false, min_size: Y2Storage::DiskSize.GiB(6), outline: an_object_having_attributes(min_size_fallback_for: ["/two"]) + ), + an_object_having_attributes( + mount_path: "swap", + auto_size?: false, + min_size: Y2Storage::DiskSize.GiB(1), + outline: an_object_having_attributes(adjust_by_ram: true) ) ) end diff --git a/service/test/agama/storage/volume_conversion/to_y2storage_test.rb b/service/test/agama/storage/volume_conversion/to_y2storage_test.rb index a08ce862eb..792ee31eec 100644 --- a/service/test/agama/storage/volume_conversion/to_y2storage_test.rb +++ b/service/test/agama/storage/volume_conversion/to_y2storage_test.rb @@ -70,6 +70,7 @@ adjust_by_ram?: false, ignore_fallback_sizes: true, ignore_snapshots_sizes: true, + ignore_adjust_by_ram: true, min_size: Y2Storage::DiskSize.GiB(5), max_size: Y2Storage::DiskSize.GiB(20), max_size_lvm: Y2Storage::DiskSize.GiB(20), @@ -96,6 +97,7 @@ expect(spec).to have_attributes( ignore_fallback_sizes: false, ignore_snapshots_sizes: false, + ignore_adjust_by_ram: false, min_size: Y2Storage::DiskSize.GiB(10), max_size: Y2Storage::DiskSize.GiB(50), max_size_lvm: Y2Storage::DiskSize.GiB(50) From 4d41cb06bf9467eeb87f499fd6ec5f887f27fb7d Mon Sep 17 00:00:00 2001 From: Ancor Gonzalez Sosa Date: Fri, 22 Mar 2024 10:09:31 +0100 Subject: [PATCH 2/4] Tumbleweed configuration: enable adjust_by_ram for swap --- products.d/tumbleweed.yaml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/products.d/tumbleweed.yaml b/products.d/tumbleweed.yaml index cebe4f493e..a4d5a11d71 100644 --- a/products.d/tumbleweed.yaml +++ b/products.d/tumbleweed.yaml @@ -165,10 +165,12 @@ storage: - mount_path: "swap" filesystem: swap size: - auto: false - min: 1 GiB - max: 2 GiB + auto: true outline: + auto_size: + base_min: 1 GiB + base_max: 2 GiB + adjust_by_ram: true required: false filesystems: - swap From 107d6008194286a96b3fbbb582cfb42c2442f8ac Mon Sep 17 00:00:00 2001 From: Ancor Gonzalez Sosa Date: Fri, 22 Mar 2024 10:11:19 +0100 Subject: [PATCH 3/4] Update dependency on yast2-storage-ng (ignore_adjust_by_ram) --- service/package/gem2rpm.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/package/gem2rpm.yml b/service/package/gem2rpm.yml index 9a886072bd..7b8e9bd8ce 100644 --- a/service/package/gem2rpm.yml +++ b/service/package/gem2rpm.yml @@ -38,7 +38,7 @@ Requires: yast2-iscsi-client >= 4.5.7 Requires: yast2-network Requires: yast2-proxy - Requires: yast2-storage-ng >= 5.0.8 + Requires: yast2-storage-ng >= 5.0.10 Requires: yast2-users %ifarch s390 s390x Requires: yast2-s390 >= 4.6.4 From 7fd7f757a2bd3614bc4f04f3de92bf8faa239b3a Mon Sep 17 00:00:00 2001 From: Ancor Gonzalez Sosa Date: Fri, 22 Mar 2024 10:19:24 +0100 Subject: [PATCH 4/4] Changelog --- service/package/rubygem-agama-yast.changes | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/service/package/rubygem-agama-yast.changes b/service/package/rubygem-agama-yast.changes index f5473aaae0..2168eafe66 100644 --- a/service/package/rubygem-agama-yast.changes +++ b/service/package/rubygem-agama-yast.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Fri Mar 22 09:18:20 UTC 2024 - Ancor Gonzalez Sosa + +- Make it possible to use non-auto sizes for volumes with + adjust_by_ram (gh#openSUSE/agama#1111). + ------------------------------------------------------------------- Thu Mar 21 10:35:09 UTC 2024 - Ancor Gonzalez Sosa