-
Notifications
You must be signed in to change notification settings - Fork 19
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
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7579aba
Introduce SpaceMakerActions
ancorgs 7483834
Extract SpaceMaker-related settings to a separate class
ancorgs 8a1beab
SpaceMakerActions::BiggerResizeStrategy
ancorgs af0193f
Update copyright date of recently modified files
ancorgs 0a60196
Version and changelog
ancorgs 802b15d
Remove pointless code
ancorgs File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Copyright (c) [2023] SUSE LLC | ||
# | ||
# All Rights Reserved. | ||
# | ||
# This program is free software; you can redistribute it and/or modify it | ||
# under the terms of version 2 of the GNU General Public License as published | ||
# by the Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
# more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along | ||
# with this program; if not, contact SUSE LLC. | ||
# | ||
# To contact SUSE LLC about this file by physical or electronic mail, you may | ||
# find current contact information at www.suse.com. | ||
|
||
module Y2Storage | ||
module Proposal | ||
# Namespace for the classes used to represent the actions performed by SpaceMaker | ||
module SpaceMakerProspects | ||
end | ||
end | ||
end | ||
|
||
require "y2storage/proposal/space_maker_actions/delete" | ||
require "y2storage/proposal/space_maker_actions/wipe" | ||
require "y2storage/proposal/space_maker_actions/shrink" | ||
require "y2storage/proposal/space_maker_actions/list" |
95 changes: 95 additions & 0 deletions
95
src/lib/y2storage/proposal/space_maker_actions/auto_strategy.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# Copyright (c) [2023] SUSE LLC | ||
# | ||
# All Rights Reserved. | ||
# | ||
# This program is free software; you can redistribute it and/or modify it | ||
# under the terms of version 2 of the GNU General Public License as published | ||
# by the Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
# more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along | ||
# with this program; if not, contact SUSE LLC. | ||
# | ||
# To contact SUSE LLC about this file by physical or electronic mail, you may | ||
# find current contact information at www.suse.com. | ||
|
||
require "y2storage/proposal/space_maker_prospects" | ||
|
||
module Y2Storage | ||
module Proposal | ||
module SpaceMakerActions | ||
# Classical YaST strategy for {SpaceMakerActions::List}, used by default and if the strategy | ||
# is configured as :auto. | ||
# | ||
# This is basically a wrapper around {SpaceMakerProspects::List}, since the original logic | ||
# was implemented there. | ||
class AutoStrategy | ||
# Constructor | ||
# | ||
# @param settings [ProposalSpaceSettings] proposal settings | ||
# @param disk_analyzer [DiskAnalyzer] information about existing partitions | ||
def initialize(settings, disk_analyzer) | ||
@settings = settings | ||
@disk_analyzer = disk_analyzer | ||
@prospects = SpaceMakerProspects::List.new(settings, disk_analyzer) | ||
@mandatory = [] | ||
end | ||
|
||
# In the case of the traditional YaST strategy for making space, this corresponds to | ||
# deleting all partitions explicitly marked for removal in the proposal settings, i.e. | ||
# all the partitions belonging to one of the types with delete_mode set to :all. | ||
# | ||
# @see ProposalSettings#windows_delete_mode | ||
# @see ProposalSettings#linux_delete_mode | ||
# @see ProposalSettings#other_delete_mode | ||
# | ||
# @param disk [Disk] see {List} | ||
def add_mandatory_actions(disk) | ||
mandatory.concat(prospects.unwanted_partition_prospects(disk)) | ||
end | ||
|
||
# @param disk [Disk] see {List} | ||
# @param keep [Array<Integer>] see {List} | ||
# @param lvm_helper [Proposal::LvmHelper] see {List} | ||
def add_optional_actions(disk, keep, lvm_helper) | ||
prospects.add_prospects(disk, lvm_helper, keep) | ||
end | ||
|
||
# @return [Action, nil] nil if there are no more actions in the list | ||
def next | ||
next_prospect&.action | ||
end | ||
|
||
# @param deleted_sids [Array<Integer>] see {List} | ||
def done(deleted_sids) | ||
if mandatory.any? | ||
mandatory.shift | ||
return | ||
end | ||
|
||
prospects.next_available_prospect.available = false | ||
prospects.mark_deleted(deleted_sids) | ||
end | ||
|
||
private | ||
|
||
# @return [Array<Action>] list of mandatory actions to be executed | ||
attr_reader :mandatory | ||
|
||
# @return [SpaceMakerProspects::List] optional actions to be executed if needed | ||
attr_reader :prospects | ||
|
||
# @see #next | ||
def next_prospect | ||
return @mandatory.first unless @mandatory.empty? | ||
|
||
prospects.next_available_prospect | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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.