From 42b9f791ca148e3349fb61d479abcc010241893d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20D=C3=ADaz=20Gonz=C3=A1lez?= Date: Sun, 17 May 2020 15:17:48 +0100 Subject: [PATCH] Add the bcache backing partition usage --- src/lib/autoinstall/presenters/partition.rb | 5 ++ .../widgets/storage/bcache_backing_attrs.rb | 78 +++++++++++++++++++ .../widgets/storage/partition_usage_tab.rb | 7 ++ .../autoinstall/widgets/storage/used_as.rb | 5 +- test/lib/presenters/partition_test.rb | 8 ++ .../storage/bcache_backing_attrs_test.rb | 73 +++++++++++++++++ .../storage/partition_usage_tab_test.rb | 18 +++++ test/lib/widgets/storage/used_as_test.rb | 4 + 8 files changed, 196 insertions(+), 2 deletions(-) create mode 100644 src/lib/autoinstall/widgets/storage/bcache_backing_attrs.rb create mode 100644 test/lib/widgets/storage/bcache_backing_attrs_test.rb diff --git a/src/lib/autoinstall/presenters/partition.rb b/src/lib/autoinstall/presenters/partition.rb index 2fbcbe459..8646ee2e7 100644 --- a/src/lib/autoinstall/presenters/partition.rb +++ b/src/lib/autoinstall/presenters/partition.rb @@ -49,6 +49,8 @@ def usage :lvm_pv elsif filesystem || mounted? :filesystem + elsif bcache_backing_for + :bcache_backing else :none end @@ -161,6 +163,9 @@ def usage_label when :lvm_pv # TRANSLATORS: %s is a placeholder for the name of a RAID Kernel.format(_("Part of %s"), lvm_group) + when :bcache_backing + # TRANSLATORS: %s is a placeholder for the name of a bcache device + Kernel.format(_("Backing for %s"), bcache_backing_for) when :none _("Not used") end diff --git a/src/lib/autoinstall/widgets/storage/bcache_backing_attrs.rb b/src/lib/autoinstall/widgets/storage/bcache_backing_attrs.rb new file mode 100644 index 000000000..3d3e28b97 --- /dev/null +++ b/src/lib/autoinstall/widgets/storage/bcache_backing_attrs.rb @@ -0,0 +1,78 @@ +# Copyright (c) [2020] SUSE LLC +# +# All Rights Reserved. +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of version 2 of the GNU General Public License as published +# by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, contact SUSE LLC. +# +# To contact SUSE LLC about this file by physical or electronic mail, you may +# find current contact information at www.suse.com. + +require "yast" +require "cwm/custom_widget" +require "autoinstall/widgets/storage/bcache_backing_for" + +module Y2Autoinstallation + module Widgets + module Storage + # Bcache backing device attributes + # + # It groups those attributes that are specific for a partition being used as a bcache backing + # device. + # + # @see PartitionUsageTab + class BcacheBackingAttrs < CWM::CustomWidget + # Constructor + # + # @param section [Presenters::Partition] presenter for the partition section + def initialize(section) + textdomain "autoinst" + super() + @section = section + end + + # @macro seeAbstractWidget + def label + "" + end + + # @macro seeCustomWidget + def contents + Left(HSquash(MinWidth(15, backing_for_widget))) + end + + # @macro seeAbstractWidget + def init + backing_for_widget.items = section.available_bcaches + backing_for_widget.value = section.bcache_backing_for + end + + # Returns the widgets values + # + # @return [Hash] + def values + { "bcache_backing_for" => backing_for_widget.value } + end + + private + + # @return [Presenters::Partition] presenter for the partition section + attr_reader :section + + # Widget for setting the bcache backing device + def backing_for_widget + @backing_for_widget ||= BcacheBackingFor.new + end + end + end + end +end diff --git a/src/lib/autoinstall/widgets/storage/partition_usage_tab.rb b/src/lib/autoinstall/widgets/storage/partition_usage_tab.rb index 93f584388..9bbb9595e 100644 --- a/src/lib/autoinstall/widgets/storage/partition_usage_tab.rb +++ b/src/lib/autoinstall/widgets/storage/partition_usage_tab.rb @@ -24,6 +24,7 @@ require "autoinstall/widgets/storage/filesystem_attrs" require "autoinstall/widgets/storage/raid_attrs" require "autoinstall/widgets/storage/lvm_pv_attrs" +require "autoinstall/widgets/storage/bcache_backing_attrs" require "autoinstall/widgets/storage/lvm_partition_attrs" require "autoinstall/widgets/storage/encryption_attrs" require "autoinstall/widgets/storage/size_selector" @@ -105,6 +106,7 @@ def relevant_widgets filesystem_widget, raid_widget, lvm_pv_widget, + bcache_backing_widget, encryption_widget ] end @@ -124,6 +126,11 @@ def lvm_pv_widget @lvm_pv_widget ||= LvmPvAttrs.new(partition) end + # Widget grouping attributes related to a bcache backing device + def bcache_backing_widget + @bcache_backing_widget ||= BcacheBackingAttrs.new(partition) + end + # Widget for setting encryption related attributes def encryption_widget @encryption_widget ||= EncryptionAttrs.new(partition) diff --git a/src/lib/autoinstall/widgets/storage/used_as.rb b/src/lib/autoinstall/widgets/storage/used_as.rb index e0f1c6aa0..f3ea19722 100644 --- a/src/lib/autoinstall/widgets/storage/used_as.rb +++ b/src/lib/autoinstall/widgets/storage/used_as.rb @@ -54,9 +54,10 @@ def items # TRANSLATORS: option for setting the partition as a RAID member [:raid, _("RAID member")], # TRANSLATORS: option for setting the partition as an LVM physical volume - [:lvm_pv, _("LVM physical volume")] + [:lvm_pv, _("LVM physical volume")], + # TRANSLATORS: option for setting the partition as a bcache backing device + [:bcache_backing, _("Bcache backing device")] # ["bcache_caching", _("Bcache caching device")], - # ["bcache_backing", _("Bcache backing device")], # ["btrfs_member", _("Btrfs multi-device member")] ] end diff --git a/test/lib/presenters/partition_test.rb b/test/lib/presenters/partition_test.rb index b53c68a0d..0aa263e75 100644 --- a/test/lib/presenters/partition_test.rb +++ b/test/lib/presenters/partition_test.rb @@ -87,6 +87,14 @@ end end + context "when the section refers to a bcache backing device" do + let(:attrs) { { bcache_backing_for: "/dev/bcache0" } } + + it "returns :bcache_backing" do + expect(subject.usage).to eq(:bcache_backing) + end + end + context "when the section does not refer an specific usage" do let(:attrs) { {} } diff --git a/test/lib/widgets/storage/bcache_backing_attrs_test.rb b/test/lib/widgets/storage/bcache_backing_attrs_test.rb new file mode 100644 index 000000000..bf436915b --- /dev/null +++ b/test/lib/widgets/storage/bcache_backing_attrs_test.rb @@ -0,0 +1,73 @@ +# Copyright (c) [2020] SUSE LLC +# +# All Rights Reserved. +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of version 2 of the GNU General Public License as published +# by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, contact SUSE LLC. +# +# To contact SUSE LLC about this file by physical or electronic mail, you may +# find current contact information at www.suse.com. + +require_relative "../../../test_helper" +require "y2storage" +require "autoinstall/presenters" +require "autoinstall/widgets/storage/bcache_backing_attrs" +require "cwm/rspec" + +describe Y2Autoinstallation::Widgets::Storage::BcacheBackingAttrs do + subject(:widget) { described_class.new(section) } + + include_examples "CWM::CustomWidget" + + let(:drive) { Y2Autoinstallation::Presenters::Drive.new(partitioning.drives.first) } + let(:section) { drive.partitions.first } + + let(:partitioning) do + Y2Storage::AutoinstProfile::PartitioningSection.new_from_hashes( + [ + { "type" => :CT_DISK, "partitions" => [{}] }, + { "type" => :CT_BCACHE, "device" => "/dev/bcache0" }, + { "type" => :CT_BCACHE, "device" => "/dev/bcache1" } + ] + ) + end + + let(:backing_for_widget) do + instance_double(Y2Autoinstallation::Widgets::Storage::BcacheBackingFor, value: "/dev/bcache") + end + + before do + allow(backing_for_widget).to receive(:items=) + allow(backing_for_widget).to receive(:value=) + allow(Y2Autoinstallation::Widgets::Storage::BcacheBackingFor) + .to receive(:new) + .and_return(backing_for_widget) + end + + describe "#init" do + it "sets the available bcache devices" do + expect(backing_for_widget).to receive(:items=).with(["/dev/bcache0", "/dev/bcache1"]) + widget.init + end + + it "sets the backing device initial valaue" do + expect(backing_for_widget).to receive(:value=) + widget.init + end + end + + describe "#values" do + it "includes bcache_backing_for" do + expect(widget.values).to include("bcache_backing_for" => "/dev/bcache") + end + end +end diff --git a/test/lib/widgets/storage/partition_usage_tab_test.rb b/test/lib/widgets/storage/partition_usage_tab_test.rb index 5881ccafc..fe7f144f1 100644 --- a/test/lib/widgets/storage/partition_usage_tab_test.rb +++ b/test/lib/widgets/storage/partition_usage_tab_test.rb @@ -165,6 +165,24 @@ end end + describe "#values" do + it "contains all section attributes related to its usage" do + expect(subject.values.keys).to contain_exactly( + "crypt_key", + "crypt_method", + "filesystem", + "fstab_options", + "label", + "lvm_group", + "mkfs_options", + "mount", + "mountby", + "raid_name", + "bcache_backing_for" + ) + end + end + describe "#store" do let(:filesystem_attrs) do { diff --git a/test/lib/widgets/storage/used_as_test.rb b/test/lib/widgets/storage/used_as_test.rb index 5d7065813..249b2a6dc 100644 --- a/test/lib/widgets/storage/used_as_test.rb +++ b/test/lib/widgets/storage/used_as_test.rb @@ -44,5 +44,9 @@ it "includes :lvm_pv" do expect(items).to include(:lvm_pv) end + + it "includes :bcache_backing" do + expect(items).to include(:bcache_backing) + end end end