Skip to content

Commit

Permalink
Add the bcache backing partition usage
Browse files Browse the repository at this point in the history
  • Loading branch information
dgdavid committed May 18, 2020
1 parent 7ed9ee9 commit 42b9f79
Show file tree
Hide file tree
Showing 8 changed files with 196 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/lib/autoinstall/presenters/partition.rb
Expand Up @@ -49,6 +49,8 @@ def usage
:lvm_pv
elsif filesystem || mounted?
:filesystem
elsif bcache_backing_for
:bcache_backing
else
:none
end
Expand Down Expand Up @@ -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
Expand Down
78 changes: 78 additions & 0 deletions 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<String,Object>]
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
7 changes: 7 additions & 0 deletions src/lib/autoinstall/widgets/storage/partition_usage_tab.rb
Expand Up @@ -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"
Expand Down Expand Up @@ -105,6 +106,7 @@ def relevant_widgets
filesystem_widget,
raid_widget,
lvm_pv_widget,
bcache_backing_widget,
encryption_widget
]
end
Expand All @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions src/lib/autoinstall/widgets/storage/used_as.rb
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions test/lib/presenters/partition_test.rb
Expand Up @@ -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) { {} }

Expand Down
73 changes: 73 additions & 0 deletions 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
18 changes: 18 additions & 0 deletions test/lib/widgets/storage/partition_usage_tab_test.rb
Expand Up @@ -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
{
Expand Down
4 changes: 4 additions & 0 deletions test/lib/widgets/storage/used_as_test.rb
Expand Up @@ -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

0 comments on commit 42b9f79

Please sign in to comment.