Skip to content

Commit

Permalink
Add the partition size option
Browse files Browse the repository at this point in the history
  • Loading branch information
dgdavid committed Apr 27, 2020
1 parent 149304a commit 1f54d4d
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/lib/autoinstall/widgets/storage/partition_page.rb
Expand Up @@ -25,6 +25,7 @@
require "autoinstall/widgets/storage/filesystem_attrs"
require "autoinstall/widgets/storage/raid_attrs"
require "autoinstall/widgets/storage/lvm_pv_attrs"
require "autoinstall/widgets/storage/size"
require "autoinstall/widgets/storage/lvm_partition_attrs"
require "autoinstall/widgets/storage/used_as"

Expand Down Expand Up @@ -63,6 +64,10 @@ def contents
VBox(
Left(Heading(_("Partition"))),
VBox(
HBox(
HWeight(1, size_widget),
HWeight(2, HStretch())
),
Left(drive_dependent_attrs_widget),
Left(used_as_widget),
Left(replace_point),
Expand All @@ -77,6 +82,7 @@ def contents

# @macro seeAbstractWidget
def init
size_widget.value = section.size
used_as_widget.value = controller.partition_usage(section).to_s
update_replace_point
end
Expand All @@ -90,6 +96,7 @@ def handle(event)
# @macro seeAbstractWidget
def store
values = selected_widget.values
values["size"] = size_widget.value

if drive_dependent_attrs_widget.respond_to?(:values)
values.merge!(drive_dependent_attrs_widget.values)
Expand All @@ -110,6 +117,10 @@ def store
# @return [Y2Storage::AutoinstProfile::PartitionSection]
attr_reader :section

def size_widget
@size_widget ||= Size.new
end

def used_as_widget
@used_as_widget ||= UsedAs.new
end
Expand Down
82 changes: 82 additions & 0 deletions src/lib/autoinstall/widgets/storage/size.rb
@@ -0,0 +1,82 @@
# 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 "y2storage"
require "cwm/common_widgets"

module Y2Autoinstallation
module Widgets
module Storage
# Determines the size of a section
class Size < CWM::ComboBox
ITEMS = [
"",
"auto",
"max"
].freeze
private_constant :ITEMS

# Constructor
def initialize
textdomain "autoinst"
super
end

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

# @macro seeComboBox
def items
@items ||= ITEMS.map { |i| [i, i] }
end

# Returns selected size
#
# @return [String] a human readable disk size
def value
formatted_size(super)
end

# @macro seeComboBox
def value=(size)
super(formatted_size(size))
end

# @macro seeAbstractWidget
def opt
[:editable]
end

private

# Format given size, when possible
#
# @return [String] a human readable disk size or given value when cannot perform the format
def formatted_size(size)
Y2Storage::DiskSize.from_s(size.to_s).to_human_string
rescue TypeError
size
end
end
end
end
end
10 changes: 9 additions & 1 deletion test/lib/widgets/storage/partition_page_test.rb
Expand Up @@ -76,10 +76,18 @@
end

describe "#contents" do
it "constains a widget to fill the size" do
widget = subject.contents.nested_find do |w|
w.is_a?(Y2Autoinstallation::Widgets::Storage::Size)
end

expect(widget).to_not be_nil
end

context "when the partition belongs to an LVM" do
let(:type) { :CT_LVM }

it "includes LVM partition attributes" do
it "contains LVM partition attributes" do
widget = subject.contents.nested_find do |w|
w.is_a?(Y2Autoinstallation::Widgets::Storage::LvmPartitionAttrs)
end
Expand Down
52 changes: 52 additions & 0 deletions test/lib/widgets/storage/size_test.rb
@@ -0,0 +1,52 @@
# 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 "autoinstall/widgets/storage/size"
require "cwm/rspec"

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

include_examples "CWM::ComboBox"

describe "#value" do
before do
allow(Yast::UI).to receive(:QueryWidget)
.with(Id(widget.widget_id), :Value)
.and_return(size)
end

context "when size is a valid DiskSize" do
let(:size) { "10737418240" }

it "returns the human readable DiskSize" do
expect(widget.value).to eq("10.00 GiB")
end
end

context "when size is a not valid DiskSize" do
let(:size) { "max" }

it "returns the value as it is" do
expect(widget.value).to eq("max")
end
end
end
end

0 comments on commit 1f54d4d

Please sign in to comment.