Skip to content

Commit

Permalink
AgamaProposal: fix bug when partitions are searched but not managed
Browse files Browse the repository at this point in the history
  • Loading branch information
ancorgs committed Nov 14, 2024
1 parent 1e7c3b2 commit 809770a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
23 changes: 16 additions & 7 deletions service/lib/y2storage/proposal/agama_space_maker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,22 @@ def delete_actions(config)
# @return [Array<Y2Storage::SpaceActions::Resize>]
def resize_actions(config)
partition_configs = partitions(config).select(&:found_device).select(&:size)
partition_configs.map do |part|
# Resize actions contain information that is potentially useful for the SpaceMaker even
# when they are only about growing and not shrinking
min = current_size?(part, :min) ? nil : part.size.min
max = current_size?(part, :max) ? nil : part.size.max
Y2Storage::SpaceActions::Resize.new(part.found_device.name, min_size: min, max_size: max)
end.compact
# Resize actions contain information that is potentially useful for the SpaceMaker even
# when they are only about growing and not shrinking
partition_configs.map { |p| resize_action(p) }.compact
end

# @see #resize_actions
#
# @param part [Agama::Storage::Configs::Partition]
# @return [Y2Storage::SpaceActions::Resize, nil]
def resize_action(part)
min = current_size?(part, :min) ? nil : part.size.min
max = current_size?(part, :max) ? nil : part.size.max
# If both min and max are equal to the current device size, there is nothing to do
return unless min || max

Y2Storage::SpaceActions::Resize.new(part.found_device.name, min_size: min, max_size: max)
end

# @see #resize_actions
Expand Down
25 changes: 25 additions & 0 deletions service/test/y2storage/agama_proposal_search_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,5 +214,30 @@
end
end
end

context "when searching existing partitions but not specifying any action on them" do
let(:config_json) do
{
boot: { configure: false },
drives: [
{
search: "/dev/vda",
partitions: [
{ search: "*" },
{ size: "20 GiB", filesystem: { path: "/" } }
]
}
]
}
end

# Regression test. In the past the proposal tried to resize some partitions due to the
# search "*" without actions.
it "no partitions are deleted or resized" do
expect_any_instance_of(Y2Storage::Partition).to_not receive(:detect_resize_info)
# There is no way to make 20 GiB fit without resizing or deleting
expect { proposal.propose }.to raise_error(Y2Storage::NoDiskSpaceError)
end
end
end
end

0 comments on commit 809770a

Please sign in to comment.