Skip to content

Commit

Permalink
feat: integrate actions with space policy (#1354)
Browse files Browse the repository at this point in the history
The [new user interface](#1202)
made us to see an small improvement for easing the understanding of the
kind of complex storage/Proposal page. It basically consist on making
more explicit the relation between the space policy and the actions that
installer will take on the storage level. To see more, read
#1327
  • Loading branch information
dgdavid authored Jun 25, 2024
2 parents 4a52076 + e817e2a commit 29b4ffd
Show file tree
Hide file tree
Showing 40 changed files with 1,285 additions and 1,197 deletions.
2 changes: 2 additions & 0 deletions rust/agama-lib/src/storage/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ pub struct Action {
text: String,
subvol: bool,
delete: bool,
resize: bool,
}

impl TryFrom<HashMap<String, OwnedValue>> for Action {
Expand All @@ -316,6 +317,7 @@ impl TryFrom<HashMap<String, OwnedValue>> for Action {
text: get_property(&hash, "Text")?,
subvol: get_property(&hash, "Subvol")?,
delete: get_property(&hash, "Delete")?,
resize: get_property(&hash, "Resize")?,
};

Ok(res)
Expand Down
5 changes: 5 additions & 0 deletions rust/package/agama.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
-------------------------------------------------------------------
Tue Jun 25 15:04:20 UTC 2024 - David Diaz <[email protected]>

- Add resize actions to storage model (gh#openSUSE/agama#1354).

-------------------------------------------------------------------
Mon Jun 24 20:35:00 UTC 2024 - Lubos Kocman <[email protected]>

Expand Down
10 changes: 6 additions & 4 deletions service/lib/agama/dbus/storage/manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,15 @@ def deprecated_system
# * "Text" [String]
# * "Subvol" [Boolean]
# * "Delete" [Boolean]
# * "Resize" [Boolean]
def read_actions
backend.actions.map do |action|
{
"Device" => action.target_device.sid,
"Text" => action.sentence,
"Subvol" => action.device_is?(:btrfs_subvolume),
"Delete" => action.delete?
"Device" => action.device.sid,
"Text" => action.text,
"Subvol" => action.on_btrfs_subvolume?,
"Delete" => action.delete?,
"Resize" => action.resize?
}
end
end
Expand Down
10 changes: 6 additions & 4 deletions service/lib/agama/dbus/storage/proposal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,14 @@ def actions
# * "Text" [String]
# * "Subvol" [Boolean]
# * "Delete" [Boolean]
# * "Resize" [Boolean]
def to_dbus_action(action)
{
"Device" => action.target_device.sid,
"Text" => action.sentence,
"Subvol" => action.device_is?(:btrfs_subvolume),
"Delete" => action.delete?
"Device" => action.device.sid,
"Text" => action.text,
"Subvol" => action.on_btrfs_subvolume?,
"Delete" => action.delete?,
"Resize" => action.resize?
}
end
end
Expand Down
4 changes: 2 additions & 2 deletions service/lib/agama/storage.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# Copyright (c) [2022] SUSE LLC
# Copyright (c) [2022-2024] SUSE LLC
#
# All Rights Reserved.
#
Expand All @@ -27,4 +27,4 @@ module Storage

require "agama/storage/manager"
require "agama/storage/proposal"
require "agama/storage/actions"
require "agama/storage/actions_generator"
80 changes: 80 additions & 0 deletions service/lib/agama/storage/action.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# frozen_string_literal: true

# Copyright (c) [2024] 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 Agama
module Storage
# Represents an action to perform in the storage devices.
class Action
# @param action [Y2Storage::CompoundAction]
# @param system_graph [Y2Storage::Devicegraph]
def initialize(action, system_graph)
@action = action
@system_graph = system_graph
end

# Affected device
#
# @return [Y2Storage::Device]
def device
action.target_device
end

# Text describing the action.
#
# @return [String]
def text
action.sentence
end

# Whether the action affects to a Btrfs subvolume.
#
# @return [Boolean]
def on_btrfs_subvolume?
action.device_is?(:btrfs_subvolume)
end

# Whether the action deletes the device.
#
# @return [Boolean]
def delete?
action.delete?
end

# Whether the action resizes the device.
#
# @return [Boolean]
def resize?
return false unless device.exists_in_devicegraph?(system_graph)
return false unless device.respond_to?(:size)

system_graph.find_device(device.sid).size != device.size
end

private

# @return [Y2Storage::CompoundAction]
attr_reader :action

# @return [Y2Storage::Devicegraph]
attr_reader :system_graph
end
end
end
91 changes: 0 additions & 91 deletions service/lib/agama/storage/actions.rb

This file was deleted.

85 changes: 85 additions & 0 deletions service/lib/agama/storage/actions_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# frozen_string_literal: true

# Copyright (c) [2024] 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 "agama/storage/action"

module Agama
module Storage
# Generates the list of actions to perform over the storage devices.
class ActionsGenerator
# param system_graph [Y2Storage::Devicegraph]
# param target_graph [Y2Storage::Devicegraph]
def initialize(system_graph, target_graph)
@system_graph = system_graph
@target_graph = target_graph
end

# All actions properly sorted.
#
# @return [Array<Action>]
def generate
main_actions + subvolume_actions
end

private

# @return [Y2Storage::Devicegraph]
attr_reader :system_graph

# @return [Y2Storage::Devicegraph]
attr_reader :target_graph

# Sorted main actions (everything except subvolume actions).
#
# @return [Array<Action>]
def main_actions
actions = self.actions.reject(&:on_btrfs_subvolume?)
sort_actions(actions)
end

# Sorted subvolume actions.
#
# @return [Array<Action>]
def subvolume_actions
actions = self.actions.select(&:on_btrfs_subvolume?)
sort_actions(actions)
end

# All actions, without sorting.
#
# @return [Array<Action>]
def actions
@actions ||= target_graph.actiongraph.compound_actions.map do |action|
Action.new(action, system_graph)
end
end

# Sorts actions, placing destructive actions at the end.
#
# @param actions [Array<Action>]
# @return [Array<Action>]
def sort_actions(actions)
delete, other = actions.partition(&:delete?)
delete.concat(other)
end
end
end
end
5 changes: 3 additions & 2 deletions service/lib/agama/storage/manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
require "bootloader/proposal_client"
require "y2storage/storage_manager"
require "y2storage/clients/inst_prepdisk"
require "agama/storage/actions"
require "agama/storage/actions_generator"
require "agama/storage/proposal"
require "agama/storage/proposal_settings"
require "agama/storage/callbacks"
Expand Down Expand Up @@ -167,8 +167,9 @@ def software
def actions
return [] unless Y2Storage::StorageManager.instance.probed?

probed = Y2Storage::StorageManager.instance.probed
staging = Y2Storage::StorageManager.instance.staging
Actions.new(logger, staging.actiongraph).all
ActionsGenerator.new(probed, staging).generate
end

private
Expand Down
7 changes: 5 additions & 2 deletions service/lib/agama/storage/proposal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# find current contact information at www.suse.com.

require "agama/issue"
require "agama/storage/actions"
require "agama/storage/actions_generator"
require "agama/storage/proposal_strategies"
require "yast"
require "y2storage"
Expand Down Expand Up @@ -109,7 +109,10 @@ def calculate_autoyast(partitioning)
def actions
return [] unless proposal&.devices

Actions.new(logger, proposal.devices.actiongraph).all
probed = storage_manager.probed
target = proposal.devices

ActionsGenerator.new(probed, target).generate
end

# Whether the current proposal was calculated the given strategy (:autoyast or :guided).
Expand Down
6 changes: 6 additions & 0 deletions service/package/rubygem-agama-yast.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Tue Jun 25 15:03:05 UTC 2024 - David Diaz <[email protected]>

- Add support for retrieving the storage resize actions
(gh#openSUSE/agama#1354).

-------------------------------------------------------------------
Thu Jun 20 05:25:49 UTC 2024 - Imobach Gonzalez Sosa <[email protected]>

Expand Down
Loading

0 comments on commit 29b4ffd

Please sign in to comment.