Skip to content

Commit

Permalink
fix(storage): do not set the partition to delete if used
Browse files Browse the repository at this point in the history
  • Loading branch information
joseivanlopez committed Jan 29, 2025
1 parent 29756d4 commit b6db50c
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ def conversions
filesystem: convert_filesystem,
size: convert_size,
id: convert_id,
delete: partition_model[:delete],
delete_if_needed: partition_model[:deleteIfNeeded]
delete: convert_delete,
delete_if_needed: convert_delete_if_needed
}
end

Expand All @@ -67,6 +67,24 @@ def convert_id

Y2Storage::PartitionId.find(value)
end

# TODO: do not delete if the partition is used by other device (VG, RAID, etc).
# @return [Boolean]
def convert_delete
# Do not mark to delete if the partition is used.
return false if partition_model[:mountPath]

partition_model[:delete]
end

# TODO: do not delete if the partition is used by other device (VG, RAID, etc).
# @return [Boolean]
def convert_delete_if_needed
# Do not mark to delete if the partition is used.
return false if partition_model[:mountPath]

partition_model[:deleteIfNeeded]
end
end
end
end
Expand Down
6 changes: 4 additions & 2 deletions service/lib/agama/storage/config_solvers/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ def filter_by_disk_analyzer(devices)
# Finds the partitions matching the given search config, if any
#
# @param search_config [Agama::Storage::Configs::Search]
# @return [Y2Storage::Device, nil]
# @param device [#partitions]
#
# @return [Array<Y2Storage::Partition>]
def find_partitions(search_config, device)
candidates = candidate_devices(search_config, default: device.partitions)
candidates.select! { |d| d.is?(:partition) }
Expand Down Expand Up @@ -175,7 +177,7 @@ def find_device(search_config)
#
# @param devices [Array<Y2Storage::Device>]
# @param search [Config::Search]
# @return [Y2Storage::Device, nil]
# @return [Array<Y2Storage::Device>]
def next_unassigned_devices(devices, search)
devices
.reject { |d| sids.include?(d.sid) }
Expand Down
28 changes: 26 additions & 2 deletions service/test/agama/storage/config_conversions/from_model_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -808,23 +808,47 @@
end

context "if a partition specifies 'delete'" do
let(:partitions) { [{ delete: true }] }
let(:partitions) { [{ delete: true, mountPath: mount_path }] }

let(:mount_path) { nil }

it "sets #delete to true" do
config = config_proc.call(subject.convert)
partition = config.partitions.first
expect(partition.delete?).to eq(true)
end

context "and the partition has a mount path" do
let(:mount_path) { "/test" }

it "sets #delete to false" do
config = config_proc.call(subject.convert)
partition = config.partitions.first
expect(partition.delete?).to eq(false)
end
end
end

context "if a partition specifies 'deleteIfNeeded'" do
let(:partitions) { [{ deleteIfNeeded: true }] }
let(:partitions) { [{ deleteIfNeeded: true, mountPath: mount_path }] }

let(:mount_path) { nil }

it "sets #delete_if_needed to true" do
config = config_proc.call(subject.convert)
partition = config.partitions.first
expect(partition.delete_if_needed?).to eq(true)
end

context "and the partition has a mount path" do
let(:mount_path) { "/test" }

it "sets #delete_if_needed to false" do
config = config_proc.call(subject.convert)
partition = config.partitions.first
expect(partition.delete_if_needed?).to eq(false)
end
end
end
end
end
Expand Down

0 comments on commit b6db50c

Please sign in to comment.