Skip to content

Commit

Permalink
storage: avoid to generate unsupported actions
Browse files Browse the repository at this point in the history
  • Loading branch information
joseivanlopez committed Jul 8, 2024
1 parent b591623 commit a4a9436
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

require "y2storage"
require "agama/storage/device_settings"
require "agama/storage/device_shrinking"
require "agama/storage/volume_templates_builder"

module Agama
Expand Down Expand Up @@ -134,7 +135,7 @@ def space_policy_conversion(target)
settings.space.actions
end

target.space_settings.actions = actions
target.space_settings.actions = remove_unsupported_actions(actions)
end

# @param target [Y2Storage::ProposalSettings]
Expand Down Expand Up @@ -222,6 +223,25 @@ def partitions(device)
device_object.partitions.map(&:name)
end

# Removes the unsupported actions.
#
# @param actions [Hash]
# @return [Hash]
def remove_unsupported_actions(actions)
actions.reject { |d, a| a == :resize && !support_shrinking?(d) }
end

# Whether the device supports shrinking.
#
# @param device_name [String]
# @return [Boolean]
def support_shrinking?(device_name)
device = devicegraph.find_by_name(device_name)
return false unless device

DeviceShrinking.new(device).supported?
end

# @return [Y2Storage::Devicegraph]
def devicegraph
Y2Storage::StorageManager.instance.probed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,15 +300,13 @@
settings.space.policy = :resize
end

it "generates resize actions for all the partitions at the used devices" do
it "generates resize actions for the partitions that support shrinking" do
y2storage_settings = subject.convert

expect(y2storage_settings.space_settings).to have_attributes(
strategy: :bigger_resize,
actions: {
"/dev/sda1" => :resize,
"/dev/sda2" => :resize,
"/dev/sda3" => :resize
"/dev/sda2" => :resize
}
)
end
Expand Down

0 comments on commit a4a9436

Please sign in to comment.