Skip to content

Commit

Permalink
Add the create_subvolumes filesystem option
Browse files Browse the repository at this point in the history
  • Loading branch information
dgdavid committed May 20, 2020
1 parent 568b19a commit ea87f5c
Show file tree
Hide file tree
Showing 6 changed files with 178 additions and 14 deletions.
41 changes: 41 additions & 0 deletions src/lib/autoinstall/widgets/storage/create_subvolumes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# 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 "autoinstall/widgets/storage/boolean_selector"

module Y2Autoinstallation
module Widgets
module Storage
# Widget to set whether Btrfs subvolumes should be created or not.
class CreateSubvolumes < BooleanSelector
# Constructor
def initialize
textdomain "autoinst"
super
end

# @macro seeAbstractWidget
def label
_("Create Subvolumes")
end
end
end
end
end
6 changes: 6 additions & 0 deletions src/lib/autoinstall/widgets/storage/filesystem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,19 @@ class Filesystem < CWM::ComboBox
# Constructor
def initialize
textdomain "autoinst"
self.widget_id = "filesystem_attr"
end

# @macro seeAbstractWidget
def label
_("Filesystem")
end

# @macro seeAbstractWidget
def opt
[:notify]
end

# @macro seeComboBox
def items
@items ||= [
Expand Down
62 changes: 49 additions & 13 deletions src/lib/autoinstall/widgets/storage/filesystem_attrs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
require "autoinstall/widgets/storage/mountby"
require "autoinstall/widgets/storage/mkfs_options"
require "autoinstall/widgets/storage/fstopt"
require "autoinstall/widgets/storage/create_subvolumes"

module Y2Autoinstallation
module Widgets
Expand All @@ -39,9 +40,10 @@ class FilesystemAttrs < CWM::CustomWidget
#
# @param section [Presenters::Partition] presenter for the partition section
def initialize(section)
super()
textdomain "autoinst"
super()
@section = section
self.handle_all_events = true
end

# @macro seeAbstractWidget
Expand All @@ -60,6 +62,8 @@ def contents
)
),
VSpacing(0.5),
Left(create_subvolumes_widget),
VSpacing(0.5),
Left(
HBox(
HSquash(MinWidth(15, mount_point_widget)),
Expand All @@ -78,33 +82,60 @@ def contents

# @macro seeAbstractWidget
def init
filesystem_widget.value = section.filesystem
label_widget.value = section.label
mount_point_widget.value = section.mount
mountby_widget.value = section.mountby
fstab_options_widget.value = section.fstab_options
mkfs_options_widget.value = section.mkfs_options
filesystem_widget.value = section.filesystem
label_widget.value = section.label
mount_point_widget.value = section.mount
mountby_widget.value = section.mountby
fstab_options_widget.value = section.fstab_options
mkfs_options_widget.value = section.mkfs_options
create_subvolumes_widget.value = section.create_subvolumes

set_btrfs_attrs_status
end

# Returns the widgets values
#
# @return [Hash<String,Object>]
def values
{
"filesystem" => filesystem_widget.value,
"label" => label_widget.value,
"mount" => mount_point_widget.value,
"mountby" => mountby_widget.value,
"fstab_options" => fstab_options_widget.value,
"mkfs_options" => mkfs_options_widget.value
"filesystem" => filesystem_widget.value,
"label" => label_widget.value,
"mount" => mount_point_widget.value,
"mountby" => mountby_widget.value,
"fstab_options" => fstab_options_widget.value,
"mkfs_options" => mkfs_options_widget.value,
"create_subvolumes" => btrfs? ? create_subvolumes_widget.value : nil
}
end

# @macro seeAbstractWidget
def handle(event)
set_btrfs_attrs_status if event["ID"] == filesystem_widget.widget_id

nil
end

private

# @return [Presenters::Partition] presenter for the partition section
attr_reader :section

# Whether selected files ystem is Btrfs
#
# @return [Boolean] true if selected file system is Btrfs; false otherwise
def btrfs?
filesystem_widget.value == :btrfs
end

# Update the Btrfs attrs status according to the value of #filesystem_widget
def set_btrfs_attrs_status
if btrfs?
create_subvolumes_widget.enable
else
create_subvolumes_widget.disable
end
end

# Widget for settings the filesystem type
def filesystem_widget
@filesystem_widget ||= Filesystem.new
Expand Down Expand Up @@ -134,6 +165,11 @@ def fstab_options_widget
def mkfs_options_widget
@mkfs_options_widget ||= MkfsOptions.new
end

# Widget for setting if Btrfs subvolumes should be created or not
def create_subvolumes_widget
@create_subvolumes_widget ||= CreateSubvolumes.new
end
end
end
end
Expand Down
34 changes: 34 additions & 0 deletions test/lib/widgets/storage/create_subvolumes_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# 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_relative "./shared_examples"
require "autoinstall/widgets/storage/create_subvolumes"

describe Y2Autoinstallation::Widgets::Storage::CreateSubvolumes do
subject(:widget) { described_class.new }

include_examples "Y2Autoinstallation::Widgets::Storage::BooleanSelector"

describe "#include_blank?" do
it "returns true" do
expect(subject.include_blank?).to eq(true)
end
end
end
46 changes: 46 additions & 0 deletions test/lib/widgets/storage/filesystem_attrs_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@

include_examples "CWM::CustomWidget"

let(:filesystem_widget) do
instance_double(
Y2Autoinstallation::Widgets::Storage::Filesystem,
widget_id: "filesystem_widget",
value: :ext3
)
end
let(:label_widget) do
instance_double(Y2Autoinstallation::Widgets::Storage::Label, value: "mydata")
end
Expand All @@ -46,8 +53,13 @@
let(:fstopt_widget) do
instance_double(Y2Autoinstallation::Widgets::Storage::Fstopt, value: "ro,noatime,user")
end
let(:create_subvolumes_widget) do
instance_double(Y2Autoinstallation::Widgets::Storage::CreateSubvolumes, value: false)
end

before do
allow(Y2Autoinstallation::Widgets::Storage::Filesystem).to receive(:new)
.and_return(filesystem_widget)
allow(Y2Autoinstallation::Widgets::Storage::Label).to receive(:new)
.and_return(label_widget)
allow(Y2Autoinstallation::Widgets::Storage::Mount).to receive(:new)
Expand All @@ -58,20 +70,54 @@
.and_return(mkfs_options_widget)
allow(Y2Autoinstallation::Widgets::Storage::Fstopt).to receive(:new)
.and_return(fstopt_widget)
allow(Y2Autoinstallation::Widgets::Storage::CreateSubvolumes).to receive(:new)
.and_return(create_subvolumes_widget)
allow(create_subvolumes_widget).to receive(:enable)
allow(create_subvolumes_widget).to receive(:disable)
end

describe "#init" do
it "sets initial values" do
expect(filesystem_widget).to receive(:value=)
expect(label_widget).to receive(:value=)
expect(mount_point_widget).to receive(:value=)
expect(mountby_widget).to receive(:value=)
expect(mkfs_options_widget).to receive(:value=)
expect(fstopt_widget).to receive(:value=)
expect(create_subvolumes_widget).to receive(:value=)

widget.init
end
end

describe "#handle" do
let(:event) { { "ID" => filesystem_widget.widget_id } }

before do
allow(filesystem_widget).to receive(:value).and_return(filesystem)
end

context "when file system is Btrfs" do
let(:filesystem) { :btrfs }

it "enables create_subvolumes attribute" do
expect(create_subvolumes_widget).to receive(:enable)

widget.handle(event)
end
end

context "when file system is not Btrfs" do
let(:filesystem) { :ext3 }

it "disables create_subvolumes attribute" do
expect(create_subvolumes_widget).to receive(:disable)

widget.handle(event)
end
end
end

describe "#values" do
it "includes label" do
expect(widget.values).to include("label" => "mydata")
Expand Down
3 changes: 2 additions & 1 deletion test/lib/widgets/storage/partition_usage_tab_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@
"mount",
"mountby",
"raid_name",
"bcache_backing_for"
"bcache_backing_for",
"create_subvolumes"
)
end
end
Expand Down

0 comments on commit ea87f5c

Please sign in to comment.