Skip to content

Commit f7ab560

Browse files
committed
Avoid planning for skipped or deleted devices
- Do not plan MD RAID, volume group or logical volume if the config is skipped (device not found) or the config represents a delete action.
1 parent 5ad2d34 commit f7ab560

File tree

3 files changed

+65
-5
lines changed

3 files changed

+65
-5
lines changed

service/lib/y2storage/proposal/agama_md_planner.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ class AgamaMdPlanner < AgamaDevicePlanner
3232
# @param config [Agama::Storage::Config]
3333
# @return [Array<Planned::Device>]
3434
def planned_devices(md_config, config)
35+
return [] if md_config.search&.skip_device?
36+
3537
md = planned_md(md_config, config)
3638
register_partitionable(md, md_config)
3739
[md]

service/lib/y2storage/proposal/agama_vg_planner.rb

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ class AgamaVgPlanner < AgamaDevicePlanner
2929
# @param vg_config [Agama::Storage::Configs::VolumeGroup]
3030
# @return [Array<Planned::Device>]
3131
def planned_devices(vg_config)
32+
return [] if vg_config.search&.skip_device?
33+
3234
[planned_vg(vg_config)]
3335
end
3436

@@ -95,15 +97,18 @@ def planned_lvs(config)
9597
# @param config [Agama::Storage::Configs::VolumeGroup]
9698
# @return [Array<Planned::LvmLv>]
9799
def planned_normal_lvs(config)
98-
configs = config.logical_volumes.reject(&:pool?).reject(&:thin_volume?)
99-
configs.map { |c| planned_lv(c, LvType::NORMAL) }
100+
valid_lv_configs(config)
101+
.reject(&:pool?)
102+
.reject(&:thin_volume?)
103+
.map { |c| planned_lv(c, LvType::NORMAL) }
100104
end
101105

102106
# @param config [Agama::Storage::Configs::VolumeGroup]
103107
# @return [Array<Planned::LvmLv>]
104108
def planned_thin_pool_lvs(config)
105-
pool_configs = config.logical_volumes.select(&:pool?)
106-
pool_configs.map { |c| planned_thin_pool_lv(c, config) }
109+
valid_lv_configs(config)
110+
.select(&:pool?)
111+
.map { |c| planned_thin_pool_lv(c, config) }
107112
end
108113

109114
# Plan a thin pool logical volume and its thin volumes.
@@ -147,6 +152,17 @@ def planned_lv(config, type)
147152
configure_reuse(planned, config)
148153
end
149154
end
155+
156+
# Valid logical volume configs to plan for.
157+
#
158+
# @param config [Agama::Storage::Configs::VolumeGroup]
159+
# @return [Array<Agama::Storage::Configs::LogicalVolume>]
160+
def valid_lv_configs(config)
161+
config.logical_volumes
162+
.reject(&:delete?)
163+
.reject(&:delete_if_needed?)
164+
.reject { |c| c.search&.skip_device? }
165+
end
150166
end
151167
end
152168
end

service/test/y2storage/agama_proposal_lvm_test.rb

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
# Copyright (c) [2024-2025] SUSE LLC
3+
# Copyright (c) [2024-2026] SUSE LLC
44
#
55
# All Rights Reserved.
66
#
@@ -784,5 +784,47 @@
784784
expect(lv.size).to be > Y2Storage::DiskSize.GiB(50)
785785
end
786786
end
787+
788+
context "when deleting volumes in a new volume group" do
789+
let(:config_json) do
790+
{
791+
boot: { configure: false },
792+
drives: [
793+
{
794+
partitions: [
795+
{
796+
alias: "system-pv",
797+
size: "40 GiB"
798+
}
799+
]
800+
}
801+
],
802+
volumeGroups: [
803+
{
804+
name: "system",
805+
physicalVolumes: ["system-pv"],
806+
logicalVolumes: [
807+
{ search: "*", delete: true },
808+
{
809+
name: "root",
810+
size: "5 GiB",
811+
filesystem: {
812+
path: "/",
813+
type: "btrfs"
814+
}
815+
}
816+
]
817+
}
818+
]
819+
}
820+
end
821+
822+
it "proposes the expected devices" do
823+
devicegraph = proposal.propose
824+
825+
vg = devicegraph.find_by_name("/dev/system")
826+
expect(vg.lvm_lvs.map { |lv| lv.mount_point.path }).to contain_exactly("/")
827+
end
828+
end
787829
end
788830
end

0 commit comments

Comments
 (0)