Skip to content

Commit

Permalink
AgamaProposal: consider mandatory shrink actions
Browse files Browse the repository at this point in the history
  • Loading branch information
ancorgs committed Sep 20, 2024
1 parent dac9900 commit 71f58bb
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 12 deletions.
7 changes: 0 additions & 7 deletions service/lib/y2storage/agama_proposal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ def calculate_initial_planned(devicegraph)
# @param devicegraph [Devicegraph] the graph gets modified
def clean_graph(devicegraph)
remove_empty_partition_tables(devicegraph)
protect_sids
# {Proposal::SpaceMaker#prepare_devicegraph} returns a copy of the given devicegraph.
space_maker.prepare_devicegraph(devicegraph, partitions_for_clean)
end
Expand Down Expand Up @@ -234,18 +233,12 @@ def partitions_for_clean
planned_devices.partitions
end

# Configures SpaceMaker#protected_sids according to the given list of planned devices
def protect_sids
space_maker.protected_sids = planned_devices.all.select(&:reuse?).map(&:reuse_sid)
end

# Creates the planned devices on a given devicegraph
#
# @param devicegraph [Devicegraph] the graph gets modified
def create_devices(devicegraph)
devices_creator = Proposal::AgamaDevicesCreator.new(devicegraph, issues_list)
names = config.drives.map(&:found_device).compact.map(&:name)
protect_sids
result = devices_creator.populated_devicegraph(planned_devices, names, space_maker)
end

Expand Down
27 changes: 23 additions & 4 deletions service/lib/y2storage/proposal/agama_space_maker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,9 @@ def guided_settings(config)
# @param config [Agama::Storage::Config]
# @return [Hash]
def space_actions(config)
force_delete_actions = force_delete_actions(config)
delete_actions = delete_actions(config)

force_delete_actions.merge(delete_actions)
actions = force_delete_actions(config)
actions.concat(delete_actions(config))
actions.concat(resize_actions(config))
end

# Space actions for devices that must be deleted.
Expand All @@ -87,6 +86,26 @@ def delete_actions(config)
partition_names.map { |p| Y2Storage::SpaceActions::Delete.new(p) }
end

# Space actions for devices that might be resized
#
# @param config [Agama::Storage::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
end

# @see #resize_actions
def current_size?(part, attr)
part.found_device.size == part.size.public_send(attr)
end

# All partition configs from the given config.
#
# @param config [Agama::Storage::Config]
Expand Down
5 changes: 5 additions & 0 deletions service/test/agama/dbus/storage/manager_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -608,8 +608,13 @@ def serialize(value)
d.filesystem = filesystem
end

boot = Agama::Storage::Configs::Boot.new.tap do |b|
b.configure = false
end

Agama::Storage::Config.new.tap do |config|
config.drives = [drive]
config.boot = boot
end
end

Expand Down
3 changes: 2 additions & 1 deletion service/test/agama/storage/proposal_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ def drive(partitions)
type: "btrfs"
}
}
]
],
boot: { configure: false }
}
}
end
Expand Down

0 comments on commit 71f58bb

Please sign in to comment.