Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New strategy for SpaceMaker #1337

Merged
merged 6 commits into from May 17, 2023
Merged

Conversation

ancorgs
Copy link
Contributor

@ancorgs ancorgs commented May 16, 2023

Problem

The traditional behavior of Y2Storage::Proposal::SpaceMaker is coupled to the options offered by YaST in that regard. Somehow summarized in this screenshot.

auto

But for Agama we want to offer other options.

First of all, we want to stop making a difference for partitions of type Windows/Linux/other. The criteria for classifying a partition in one group or the other is not so clear.

On the other hand, we want to make it possible for Agama to specify any of the four modes described at storage_ui.md. That is:

  • Delete everything in the disk(s).
  • Resize existing partition(s).
  • Do not modify existing partition(s).
  • Custom, with the user specifying what to do with every individual partition in the affected disks: resize it, delete it or keep it as it is.

Solution

This adds to the ProposalSetting the concept of different strategies for making space.

The default strategy is the classic one, now called auto and based on the known settings resize_windows, windows_delete_mode, linux_delete_mode and other_delete_mode.

A new strategy called bigger_resize is added. This strategy ignores the settings previously mentioned and works with a explicit list of actions specified in the proposal settings. Thus, the caller is responsible for deciding what to do with each partition or disk (:force_delete, :delete or :resize). Omitted devices are kept without modification. The only decision taken by SpaceMaker itself is the order in which those actions must be applied while looking for valid layout. As the name of the strategy suggests, it first executes all the :force_delete actions, then the :resize ones (sorted by "recoverable size") and finally the :delete ones.

With this solution, all the mentioned Agama modes can be easily implemented.

  • Delete everything in the disk(s). Settings with :force_delete for all partitions in the affected disks.
  • Resize existing partition(s). Settings with :resize for all partitions in the affected disks.
  • Do not modify existing partition(s). Settings with an empty list of actions.
  • Custom. Settings describing the exact actions decided by the user.

Implementation

The pull request is divided into several commits because the code was refactored into small steps before implementing the strategy support at SpaceMaker. Our comprehensive battery of unit tests survived all those reorganizations.

Testing

Added new unit tests.

@coveralls
Copy link

coveralls commented May 16, 2023

Coverage Status

Coverage: 97.755% (+0.005%) from 97.75% when pulling 802b15d on ancorgs:space_maker_actions into 1a37459 on yast:master.

@ancorgs ancorgs force-pushed the space_maker_actions branch 2 times, most recently from c474623 to 1c2ac96 Compare May 16, 2023 10:53
@ancorgs ancorgs marked this pull request as ready for review May 16, 2023 14:01
execute_shrink(action, graph, planned_partitions, disk_name)
when SpaceMakerActions::Delete
execute_delete(action, graph)
else
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NP: I would explicitly check by SpaceMakerActions::Shrink, and loging/raising an exception in else.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fear that would only lead to a line of code not covered by tests. This is quite internal, not something receiving direct input from the caller. I wouldn't expect a SpaceMakerActions::List to return an action from an unknown type.

def shrink_partition(partition)
target = shrink_size.unlimited? ? DiskSize.zero : partition.size - shrink_size
# Explicitly avoid alignment to keep current behavior (to be reconsidered)
partition.resize(target, align_type: nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it prevent to resize beyond the available free space?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it does. As you can see here for example, we sometimes use the size of the partition as shrink_size (so target becomes partition.size - partition.size).

Even if those cases, everything works as expected. So this is already proven by the existing tests.

# Class to encapsulate all the GuidedProposal settings related to the process of making space
# to allocate the new operating system
class ProposalSpaceSettings
include EqualByInstanceVariables
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just as note, we have the Equatable mixin for custom comparison: https://github.com/yast/yast-yast2/blob/master/library/general/src/lib/yast2/equatable.rb

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, EqualByInstanceVariables is used for ProposalSettings. And this class is basically a subset of those settings extracted to a separate object for clarity. So it makes sense to be consistent with the container class and use the same mechanism.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, only mentioning to promote it for other cases :)

Copy link
Contributor

@joseivanlopez joseivanlopez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Version bump and changelog?

Copy link
Contributor

@joseivanlopez joseivanlopez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ancorgs ancorgs merged commit 0ae8656 into yast:master May 17, 2023
9 checks passed
@yast-bot
Copy link

❌ Public Jenkins job #464 failed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants