Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Oct 31, 2017
1 parent 740114e commit 513dc8b
Show file tree
Hide file tree
Showing 6 changed files with 259 additions and 53 deletions.
2 changes: 2 additions & 0 deletions src/lib/y2storage/autoinst_issues.rb
Expand Up @@ -41,3 +41,5 @@ module AutoinstIssues
require "y2storage/autoinst_issues/missing_root"
require "y2storage/autoinst_issues/exception"
require "y2storage/autoinst_issues/no_disk_space"
require "y2storage/autoinst_issues/missing_reusable_device"
require "y2storage/autoinst_issues/missing_reuse_info"
52 changes: 52 additions & 0 deletions src/lib/y2storage/autoinst_issues/missing_reusable_device.rb
@@ -0,0 +1,52 @@
# encoding: utf-8

# Copyright (c) [2017] 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 "y2storage/autoinst_issues/issue"

module Y2Storage
module AutoinstIssues
# The proposal was successful but there is not root partition (/) defined.
#
# This is a fatal error because the installation is not possible.
class MissingReusableDevice < Issue
# @param section [AutoinstProfile::SectionWithAttributes] Section where it was detected
def initialize(section)
@section = section
end

# Return problem severity
#
# @return [Symbol] :warn
# @see Issue#severity
def severity
:warn
end

# Return the error message to be displayed
#
# @return [String] Error message
# @see Issue#message
def message
_("Reusable device not found")
end
end
end
end
52 changes: 52 additions & 0 deletions src/lib/y2storage/autoinst_issues/missing_reuse_info.rb
@@ -0,0 +1,52 @@
# encoding: utf-8

# Copyright (c) [2017] 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 "y2storage/autoinst_issues/issue"

module Y2Storage
module AutoinstIssues
# The proposal was successful but there is not root partition (/) defined.
#
# This is a fatal error because the installation is not possible.
class MissingReuseInfo < Issue
# @param section [AutoinstProfile::SectionWithAttributes] Section where it was detected
def initialize(section)
@section = section
end

# Return problem severity
#
# @return [Symbol] :warn
# @see Issue#severity
def severity
:warn
end

# Return the error message to be displayed
#
# @return [String] Error message
# @see Issue#message
def message
_("Not enough information to locate a device to reuse")
end
end
end
end
2 changes: 1 addition & 1 deletion src/lib/y2storage/autoinst_profile/partitioning_section.rb
Expand Up @@ -62,7 +62,7 @@ def parent
def self.new_from_hashes(drives_array)
result = new
result.drives = drives_array.each_with_object([]) do |hash, array|
drive = DriveSection.new_from_hashes(hash, self)
drive = DriveSection.new_from_hashes(hash, result)
array << drive if drive
end
result
Expand Down
48 changes: 31 additions & 17 deletions src/lib/y2storage/proposal/autoinst_devices_planner.rb
Expand Up @@ -243,11 +243,9 @@ def add_subvolumes_attrs(device, section)
# @param section [AutoinstProfile::PartitionSection] AutoYaST specification
def add_partition_reuse(partition, section)
partition_to_reuse = find_partition_to_reuse(devicegraph, section)
return unless partition_to_reuse
partition.filesystem_type ||= partition_to_reuse.filesystem_type
add_device_reuse(partition, partition_to_reuse.name, !!section.format)
# TODO: possible errors here
# - missing information about what device to use
# - the specified device was not found
end

# Set 'reusing' attributes for a logical volume
Expand Down Expand Up @@ -283,19 +281,26 @@ def add_vg_reuse(vg, drive)
vg.make_space_policy = drive.keep_unknown_lv ? :keep : :remove

return unless vg.make_space_policy == :keep || vg.lvs.any?(&:reuse?)
vg_to_reuse = find_vg_to_reuse(devicegraph, vg)
vg_to_reuse = find_vg_to_reuse(devicegraph, vg, drive)
vg.reuse = vg_to_reuse.vg_name if vg_to_reuse
end

# @param devicegraph [Devicegraph] Devicegraph to search for the partition to reuse
# @param part_section [AutoinstProfile::PartitionSection] Partition specification
# from AutoYaST
def find_partition_to_reuse(devicegraph, part_section)
if part_section.partition_nr
devicegraph.partitions.find { |i| i.number == part_section.partition_nr }
elsif part_section.label
devicegraph.partitions.find { |i| i.filesystem_label == part_section.label }
end
device =
if part_section.partition_nr
devicegraph.partitions.find { |i| i.number == part_section.partition_nr }
elsif part_section.label
devicegraph.partitions.find { |i| i.filesystem_label == part_section.label }
else
issues_list.add(:missing_reuse_info, part_section)
nil
end

issues_list.add(:missing_reusable_device, part_section) unless device
device
end

# @param devicegraph [Devicegraph] Devicegraph to search for the logical volume to reuse
Expand All @@ -304,18 +309,28 @@ def find_partition_to_reuse(devicegraph, part_section)
def find_lv_to_reuse(devicegraph, vg_name, part_section)
vg = devicegraph.lvm_vgs.find { |v| v.vg_name == vg_name }
return unless vg
if part_section.lv_name
vg.lvm_lvs.find { |v| v.lv_name == part_section.lv_name }
elsif part_section.label
vg.lvm_lvs.find { |v| v.filesystem_label == part_section.label }
end
device =
if part_section.lv_name
vg.lvm_lvs.find { |v| v.lv_name == part_section.lv_name }
elsif part_section.label
vg.lvm_lvs.find { |v| v.filesystem_label == part_section.label }
else
issues_list.add(:missing_reuse_info, part_section)
nil
end

issues_list.add(:missing_reusable_device, part_section) unless device
device
end

# @param devicegraph [Devicegraph] Devicegraph to search for the volume group to reuse
# @param vg [Planned::LvmVg] Planned volume group
def find_vg_to_reuse(devicegraph, vg)
# @param drive [AutoinstProfile::DriveSection] drive section describing
def find_vg_to_reuse(devicegraph, vg, drive)
return nil unless vg.volume_group_name
devicegraph.lvm_vgs.find { |v| v.vg_name == vg.volume_group_name }
device = devicegraph.lvm_vgs.find { |v| v.vg_name == vg.volume_group_name }
issues_list.add(:missing_reusable_device, drive) unless device
device
end

# @return [DiskSize] Minimal partition size
Expand Down Expand Up @@ -420,7 +435,6 @@ def root?(devices)
return true if devices.any? { |d| d.respond_to?(:mount_point) && d.mount_point == "/" }
issues_list.add(:missing_root)
end

end
end
end
156 changes: 121 additions & 35 deletions test/y2storage/proposal/autoinst_devices_planner_test.rb
Expand Up @@ -89,7 +89,7 @@

context "when a partition label is specified" do
let(:root_spec) do
{ "create" => false, "mount" => "/", "filesystem" => "ext4", "label" => "root" }
{ "create" => false, "mount" => "/", "filesystem" => :ext4, "label" => "root" }
end

it "reuses the partition with that label" do
Expand All @@ -98,6 +98,42 @@
expect(root.reuse).to eq("/dev/sda3")
end
end

context "when the partition to reuse does not exist" do
let(:root_spec) do
{ "create" => false, "mount" => "/", "filesystem" => :ext4, "partition_nr" => 99 }
end

it "adds a new partition" do
devices = planner.planned_devices(drives_map)
root = devices.find { |d| d.mount_point == "/" }
expect(root.reuse).to be_nil
end

it "registers an issue" do
planner.planned_devices(drives_map)
issue = issues_list.find { |i| i.is_a?(Y2Storage::AutoinstIssues::MissingReusableDevice) }
expect(issue).to_not be_nil
end
end

context "when no partition number or label is specified" do
let(:root_spec) do
{ "create" => false, "mount" => "/", "filesystem" => :ext4 }
end

it "adds a new partition" do
devices = planner.planned_devices(drives_map)
root = devices.find { |d| d.mount_point == "/" }
expect(root.reuse).to be_nil
end

it "registers an issue" do
planner.planned_devices(drives_map)
issue = issues_list.find { |i| i.is_a?(Y2Storage::AutoinstIssues::MissingReuseInfo) }
expect(issue).to_not be_nil
end
end
end

context "specifying size" do
Expand Down Expand Up @@ -503,50 +539,100 @@
context "reusing logical volumes" do
let(:scenario) { "lvm-two-vgs" }

let(:root_spec) do
{
"create" => false, "mount" => "/", "filesystem" => "ext4", "lv_name" => "lv1",
"size" => "20G", "label" => "rootfs"
}
end
context "when volume name is specified" do
let(:root_spec) do
{
"create" => false, "mount" => "/", "filesystem" => "ext4", "lv_name" => "lv1",
"size" => "20G"
}
end

it "sets the reuse attribute of the volume group" do
_pv, vg = planner.planned_devices(drives_map)
expect(vg.reuse).to eq(lvm_group)
expect(vg.make_space_policy).to eq(:remove)
it "sets the reuse attribute of the volume group" do
_pv, vg = planner.planned_devices(drives_map)
expect(vg.reuse).to eq(lvm_group)
expect(vg.make_space_policy).to eq(:remove)
end

it "sets the reuse attribute of logical volumes" do
_pv, vg = planner.planned_devices(drives_map)
expect(vg.reuse).to eq(lvm_group)
expect(vg.lvs).to contain_exactly(
an_object_having_attributes(
"logical_volume_name" => "lv1",
"reuse" => "/dev/vg0/lv1"
)
)
end
end

it "sets the reuse attribute of logical volumes" do
_pv, vg = planner.planned_devices(drives_map)
expect(vg.reuse).to eq(lvm_group)
expect(vg.lvs).to contain_exactly(
an_object_having_attributes(
"logical_volume_name" => "lv1",
"reuse" => "/dev/vg0/lv1"
context "when label is specified" do
let(:root_spec) do
{
"create" => false, "mount" => "/", "filesystem" => "ext4",
"size" => "20G", "label" => "rootfs"
}
end

it "sets the reuse attribute of logical volumes" do
_pv, vg = planner.planned_devices(drives_map)
expect(vg.reuse).to eq(lvm_group)
expect(vg.lvs).to contain_exactly(
an_object_having_attributes(
"logical_volume_name" => "lv2",
"reuse" => "/dev/vg0/lv2"
)
)
)
end
end
end

context "reusing logical volumes by label" do
let(:scenario) { "lvm-two-vgs" }
context "when the logical volume to be reused does not exist" do
let(:root_spec) do
{
"create" => false, "mount" => "/", "filesystem" => "ext4", "lv_name" => "new_lv",
"size" => "20G"
}
end

let(:root_spec) do
{
"create" => false, "mount" => "/", "filesystem" => "ext4",
"size" => "20G", "label" => "rootfs"
}
it "adds a new logical volume" do
_pv, vg = planner.planned_devices(drives_map)
expect(vg.reuse).to be_nil
expect(vg.lvs).to contain_exactly(
an_object_having_attributes(
"logical_volume_name" => "new_lv",
"reuse" => nil
)
)
end

it "registers an issue" do
planner.planned_devices(drives_map)
issue = issues_list.find { |i| i.is_a?(Y2Storage::AutoinstIssues::MissingReusableDevice) }
expect(issue).to_not be_nil
end
end

it "sets the reuse attribute of logical volumes" do
_pv, vg = planner.planned_devices(drives_map)
expect(vg.reuse).to eq(lvm_group)
expect(vg.lvs).to contain_exactly(
an_object_having_attributes(
"logical_volume_name" => "lv2",
"reuse" => "/dev/vg0/lv2"
context "when no volume name or label is specified" do
let(:root_spec) do
{
"create" => false, "mount" => "/", "filesystem" => "ext4", "size" => "20G"
}
end

it "adds a new logical volume" do
_pv, vg = planner.planned_devices(drives_map)
expect(vg.reuse).to be_nil
expect(vg.lvs).to contain_exactly(
an_object_having_attributes(
"reuse" => nil
)
)
)
end

it "registers an issue" do
planner.planned_devices(drives_map)
issue = issues_list.find { |i| i.is_a?(Y2Storage::AutoinstIssues::MissingReusableDevice) }
expect(issue).to_not be_nil
end
end
end

Expand Down

0 comments on commit 513dc8b

Please sign in to comment.