Skip to content

Commit

Permalink
Check missing filesystem when trying to reuse it
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Oct 17, 2018
1 parent 73d669c commit ba09fd2
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 18 deletions.
9 changes: 5 additions & 4 deletions src/lib/y2storage/proposal/autoinst_disk_device_planner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def planned_devices(drive)
def planned_for_disk(disk, drive)
master_partition = drive.master_partition
result = if master_partition
planned_for_full_disk(drive, master_partition)
planned_for_full_disk(disk, drive, master_partition)
else
planned_for_partitions(disk, drive)
end
Expand All @@ -81,12 +81,12 @@ def planned_for_disk(disk, drive)
#
# @note The part argument is used when we emulate the sle12 behavior to
# have partition 0 mean the full disk.
def planned_for_full_disk(drive, part)
def planned_for_full_disk(disk, drive, part)
planned_disk = Y2Storage::Planned::Disk.new
device_config(planned_disk, part, drive)
planned_disk.lvm_volume_group_name = part.lvm_group
planned_disk.raid_name = part.raid_name
add_device_reuse(planned_disk, drive.device, part)
add_device_reuse(planned_disk, disk, part)

[planned_disk]
end
Expand Down Expand Up @@ -134,7 +134,8 @@ def planned_for_stray_devices(drive)
stray.filesystem_type = device_to_use.filesystem_type if device_to_use
end

add_device_reuse(stray, name, section)
device = devicegraph.find_by_name(name)
add_device_reuse(stray, device, section)

result << stray
end
Expand Down
25 changes: 17 additions & 8 deletions src/lib/y2storage/proposal/autoinst_drive_planner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,22 @@ def read_only?(mount_point)
!!spec && spec.btrfs_read_only?
end

# @param device [Planned::Partition,Planned::LvmLV,Planned::Md] Planned device
# @param name [String] Name of the device to reuse
# @param section [AutoinstProfile::PartitionSection] AutoYaST specification
def add_device_reuse(device, name, section)
device.reuse_name = name
device.reformat = !!section.format
device.resize = !!section.resize if device.respond_to?(:resize=)
# @param planned_device [Planned::Partition,Planned::LvmLV,Planned::Md] Planned device
# @param device [Y2Storage::Device] Device to reuse
# @param section [AutoinstProfile::PartitionSection] AutoYaST specification
def add_device_reuse(planned_device, device, section)
planned_device.reuse_name = device.is_a?(LvmVg) ? device.volume_group_name : device.name
planned_device.reformat = !!section.format
planned_device.resize = !!section.resize if planned_device.respond_to?(:resize=)
check_reusable_filesystem(planned_device, device, section) if device.respond_to?(:filesystem)
end

# @param planned_device [Planned::Partition,Planned::LvmLV,Planned::Md] Planned device
# @param device [Y2Storage::Device] Device to reuse
# @param section [AutoinstProfile::PartitionSection] AutoYaST specification
def check_reusable_filesystem(planned_device, device, section)
return if planned_device.reformat || device.filesystem || planned_device.component?
issues_list.add(:missing_reusable_filesystem, section)
end

# Parse the 'size' element
Expand Down Expand Up @@ -206,7 +215,7 @@ def add_partition_reuse(partition, section)
partition_to_reuse = find_partition_to_reuse(partition, section)
return unless partition_to_reuse
partition.filesystem_type ||= partition_to_reuse.filesystem_type
add_device_reuse(partition, partition_to_reuse.name, section)
add_device_reuse(partition, partition_to_reuse, section)
if !partition.reformat && !partition_to_reuse.filesystem && !partition.component?
issues_list.add(:missing_reusable_filesystem, section)
end
Expand Down
12 changes: 6 additions & 6 deletions src/lib/y2storage/proposal/autoinst_vg_planner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def planned_for_lv(drive, planned_vg, section)
if section.used_pool
return nil unless add_to_thin_pool(planned_lv, planned_vg, section)
end
add_lv_reuse(planned_lv, planned_vg.volume_group_name, section) if section.create == false
add_lv_reuse(planned_lv, planned_vg, section) if section.create == false
assign_size_to_lv(planned_vg, planned_lv, section) ? planned_lv : nil
end

Expand All @@ -77,16 +77,16 @@ def planned_for_lv(drive, planned_vg, section)
# This method modifies the first argument setting the values related to
# reusing a logical volume (reuse and format).
#
# @param vg_name [String] Volume group name to search for the logical volume to reuse
# @param planned_lv [Planned::LvmLv] Planned logical volume
# @param planned_vg [Planned::LvmVg] Volume group to search for the logical volume to reuse
# @param section [AutoinstProfile::PartitionSection] AutoYaST specification
def add_lv_reuse(planned_lv, vg_name, section)
lv_to_reuse = find_lv_to_reuse(vg_name, section)
def add_lv_reuse(planned_lv, planned_vg, section)
lv_to_reuse, vg = find_lv_to_reuse(planned_vg.volume_group_name, section)
return unless lv_to_reuse
planned_lv.logical_volume_name ||= lv_to_reuse.lv_name
planned_lv.filesystem_type ||= lv_to_reuse.filesystem_type
add_device_reuse(planned_lv, lv_to_reuse, section)
add_device_reuse(planned_lv.thin_pool, vg_name, section) if planned_lv.thin_pool
add_device_reuse(planned_lv.thin_pool, vg, section) if planned_lv.thin_pool
end

# Set 'reusing' attributes for a volume group
Expand Down Expand Up @@ -135,7 +135,7 @@ def find_lv_to_reuse(vg_name, part_section)
end

issues_list.add(:missing_reusable_device, part_section) unless device
:missing_info == device ? nil : device
:missing_info == device ? nil : [device, parent]
end

# @param vg_name [String] Volume group name to search for the logical volume
Expand Down
21 changes: 21 additions & 0 deletions test/y2storage/proposal/autoinst_disk_device_planner_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,27 @@
)
end
end

context "when trying to reuse a filesystem which does not exist" do
let(:disk_spec) do
{ "device" => "/dev/sda", "disklabel" => "none", "partitions" => [root_spec] }
end
let(:root_spec) do
{ "create" => false, "format" => false, "mount" => "/" }
end

before do
sda = Y2Storage::BlkDevice.find_by_name(fake_devicegraph, "/dev/sda")
sda.remove_descendants
end

it "registers an issue" do
expect(issues_list).to be_empty
planner.planned_devices(drive)
issue = issues_list.find { |i| i.is_a?(Y2Storage::AutoinstIssues::MissingReusableFilesystem) }
expect(issue).to_not be_nil
end
end
end
end
end
14 changes: 14 additions & 0 deletions test/y2storage/proposal/autoinst_vg_planner_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,20 @@
)
)
end

context "when the filesystem does not exist" do
before do
lv = fake_devicegraph.find_by_name("/dev/vg0/lv1")
lv.remove_descendants
end

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

context "when label is specified" do
Expand Down

0 comments on commit ba09fd2

Please sign in to comment.