From 3616df4d3d96851b78d149fee4c3f19f0a08fcd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Iv=C3=A1n=20L=C3=B3pez=20Gonz=C3=A1lez?= Date: Fri, 28 Jun 2024 07:28:33 +0100 Subject: [PATCH] storage: move Y2Storage conversions --- .../lib/agama/storage/proposal_settings.rb | 8 +++ .../storage/proposal_settings_conversion.rb | 50 ------------------- .../storage/proposal_settings_conversions.rb | 2 + .../from_y2storage.rb | 8 +-- .../to_y2storage.rb | 7 ++- .../storage/proposal_strategies/autoyast.rb | 3 +- .../storage/proposal_strategies/guided.rb | 9 ++-- service/lib/agama/storage/volume.rb | 7 +++ .../lib/agama/storage/volume_conversion.rb | 46 ----------------- .../lib/agama/storage/volume_conversions.rb | 2 + .../from_y2storage.rb | 2 +- .../to_y2storage.rb | 2 +- .../from_y2storage_test.rb | 4 +- .../to_y2storage_test.rb | 4 +- .../volume_conversions/from_y2storage_test.rb | 4 +- .../volume_conversions/to_y2storage_test.rb | 4 +- 16 files changed, 42 insertions(+), 120 deletions(-) delete mode 100644 service/lib/agama/storage/proposal_settings_conversion.rb rename service/lib/agama/storage/{proposal_settings_conversion => proposal_settings_conversions}/from_y2storage.rb (93%) rename service/lib/agama/storage/{proposal_settings_conversion => proposal_settings_conversions}/to_y2storage.rb (96%) delete mode 100644 service/lib/agama/storage/volume_conversion.rb rename service/lib/agama/storage/{volume_conversion => volume_conversions}/from_y2storage.rb (99%) rename service/lib/agama/storage/{volume_conversion => volume_conversions}/to_y2storage.rb (99%) diff --git a/service/lib/agama/storage/proposal_settings.rb b/service/lib/agama/storage/proposal_settings.rb index cbf3d297a8..8ec12201ae 100644 --- a/service/lib/agama/storage/proposal_settings.rb +++ b/service/lib/agama/storage/proposal_settings.rb @@ -103,6 +103,14 @@ def to_json_settings Storage::ProposalSettingsConversions::ToJSON.new(self).convert end + # Generates Y2Storage proposal settings. + # + # @param config [Config] + # @return [Y2Storage::ProposalSettings] + def to_y2storage(config:) + Storage::ProposalSettingsConversions::ToY2Storage.new(self, config: config).convert + end + private # Device used for booting. diff --git a/service/lib/agama/storage/proposal_settings_conversion.rb b/service/lib/agama/storage/proposal_settings_conversion.rb deleted file mode 100644 index f8439c7531..0000000000 --- a/service/lib/agama/storage/proposal_settings_conversion.rb +++ /dev/null @@ -1,50 +0,0 @@ -# frozen_string_literal: true - -# Copyright (c) [2023-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/proposal_settings_conversion/from_y2storage" -require "agama/storage/proposal_settings_conversion/to_y2storage" - -module Agama - module Storage - # Conversions for the proposal settings. - module ProposalSettingsConversion - # Performs conversion from Y2Storage. - # - # @param y2storage_settings [Y2Storage::ProposalSettings] - # @param settings [Agama::Storage::ProposalSettings] - # - # @return [Agama::Storage::ProposalSettings] - def self.from_y2storage(y2storage_settings, settings) - FromY2Storage.new(y2storage_settings, settings).convert - end - - # Performs conversion to Y2Storage. - # - # @param settings [Agama::Storage::ProposalSettings] - # @param config [Agama::Config] - # - # @return [Y2Storage::ProposalSettings] - def self.to_y2storage(settings, config:) - ToY2Storage.new(settings, config: config).convert - end - end - end -end diff --git a/service/lib/agama/storage/proposal_settings_conversions.rb b/service/lib/agama/storage/proposal_settings_conversions.rb index 6ad03db45f..11517c4b58 100644 --- a/service/lib/agama/storage/proposal_settings_conversions.rb +++ b/service/lib/agama/storage/proposal_settings_conversions.rb @@ -20,7 +20,9 @@ # find current contact information at www.suse.com. require "agama/storage/proposal_settings_conversions/from_json" +require "agama/storage/proposal_settings_conversions/from_y2storage" require "agama/storage/proposal_settings_conversions/to_json" +require "agama/storage/proposal_settings_conversions/to_y2storage" module Agama module Storage diff --git a/service/lib/agama/storage/proposal_settings_conversion/from_y2storage.rb b/service/lib/agama/storage/proposal_settings_conversions/from_y2storage.rb similarity index 93% rename from service/lib/agama/storage/proposal_settings_conversion/from_y2storage.rb rename to service/lib/agama/storage/proposal_settings_conversions/from_y2storage.rb index 475e53e25c..4a5f26983f 100644 --- a/service/lib/agama/storage/proposal_settings_conversion/from_y2storage.rb +++ b/service/lib/agama/storage/proposal_settings_conversions/from_y2storage.rb @@ -19,11 +19,11 @@ # 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/volume_conversion" +require "agama/storage/volume_conversions/from_y2storage" module Agama module Storage - module ProposalSettingsConversion + module ProposalSettingsConversions # Proposal settings conversion from Y2Storage. # # @note This class does not perform a real conversion from Y2Storage settings. Instead of @@ -60,7 +60,7 @@ def convert # Recovers space actions. # # @note Space actions are generated in the conversion of the settings to Y2Storage format, - # see {ProposalSettingsConversion::ToY2Storage}. + # see {ProposalSettingsConversions::ToY2Storage}. # # @param target [Agama::Storage::ProposalSettings] def space_actions_conversion(target) @@ -77,7 +77,7 @@ def volumes_conversion(target) # @param volume [Agama::Storage::Volume] # @return [Agama::Storage::Volume] def volume_conversion(volume) - VolumeConversion.from_y2storage(volume) + VolumeConversions::FromY2Storage.new(volume).convert end end end diff --git a/service/lib/agama/storage/proposal_settings_conversion/to_y2storage.rb b/service/lib/agama/storage/proposal_settings_conversions/to_y2storage.rb similarity index 96% rename from service/lib/agama/storage/proposal_settings_conversion/to_y2storage.rb rename to service/lib/agama/storage/proposal_settings_conversions/to_y2storage.rb index eacee97742..72572e491a 100644 --- a/service/lib/agama/storage/proposal_settings_conversion/to_y2storage.rb +++ b/service/lib/agama/storage/proposal_settings_conversions/to_y2storage.rb @@ -21,12 +21,11 @@ require "y2storage" require "agama/storage/device_settings" -require "agama/storage/volume_conversion" require "agama/storage/volume_templates_builder" module Agama module Storage - module ProposalSettingsConversion + module ProposalSettingsConversions # Proposal settings conversion to Y2Storage. class ToY2Storage # @param settings [Agama::Storage::ProposalSettings] @@ -142,10 +141,10 @@ def space_policy_conversion(target) def volumes_conversion(target) target.swap_reuse = :none - volumes = settings.volumes.map { |v| VolumeConversion.to_y2storage(v) } + volumes = settings.volumes.map(&:to_y2storage) disabled_volumes = missing_volumes.map do |volume| - VolumeConversion.to_y2storage(volume).tap { |v| v.proposed = false } + volume.to_y2storage.tap { |v| v.proposed = false } end target.volumes = volumes + disabled_volumes diff --git a/service/lib/agama/storage/proposal_strategies/autoyast.rb b/service/lib/agama/storage/proposal_strategies/autoyast.rb index 832e1b1eb2..e076672095 100644 --- a/service/lib/agama/storage/proposal_strategies/autoyast.rb +++ b/service/lib/agama/storage/proposal_strategies/autoyast.rb @@ -22,7 +22,6 @@ require "agama/storage/proposal_strategies/base" require "agama/storage/proposal_settings" require "agama/storage/proposal_settings_reader" -require "agama/storage/proposal_settings_conversion" module Agama module Storage @@ -78,7 +77,7 @@ def issues # @return [Y2Storage::ProposalSettings] def proposal_settings agama_default = ProposalSettingsReader.new(config).read - ProposalSettingsConversion.to_y2storage(agama_default, config: config) + agama_default.to_y2storage(config: config) end # Agama issue equivalent to the given AutoYaST issue diff --git a/service/lib/agama/storage/proposal_strategies/guided.rb b/service/lib/agama/storage/proposal_strategies/guided.rb index 105b86d46d..7318085d97 100644 --- a/service/lib/agama/storage/proposal_strategies/guided.rb +++ b/service/lib/agama/storage/proposal_strategies/guided.rb @@ -21,7 +21,7 @@ require "agama/storage/proposal_strategies/base" require "agama/storage/device_settings" -require "agama/storage/proposal_settings_conversion" +require "agama/storage/proposal_settings_conversions/from_y2storage" module Agama module Storage @@ -43,7 +43,7 @@ def initialize(config, logger, input_settings) # Settings used for calculating the proposal. # # @note Some values are recoverd from Y2Storage, see - # {ProposalSettingsConversion::FromY2Storage} + # {ProposalSettingsConversions::FromY2Storage} # # @return [ProposalSettings] attr_reader :settings @@ -55,7 +55,8 @@ def calculate proposal.propose ensure storage_manager.proposal = proposal - @settings = ProposalSettingsConversion.from_y2storage(proposal.settings, input_settings) + @settings = ProposalSettingsConversions::FromY2Storage + .new(proposal.settings, input_settings) end # @see Base#issues @@ -107,7 +108,7 @@ def missing_target_device?(settings) # @return [Y2Storage::GuidedProposal] def guided_proposal(settings) Y2Storage::MinGuidedProposal.new( - settings: ProposalSettingsConversion.to_y2storage(settings, config: config), + settings: settings.to_y2storage(config: config), devicegraph: probed_devicegraph, disk_analyzer: disk_analyzer ) diff --git a/service/lib/agama/storage/volume.rb b/service/lib/agama/storage/volume.rb index 76b4a39417..b88b0367b5 100644 --- a/service/lib/agama/storage/volume.rb +++ b/service/lib/agama/storage/volume.rb @@ -130,6 +130,13 @@ def self.new_from_json(volume_json, config:) def to_json_settings Storage::VolumeConversions::ToJSON.new(self).convert end + + # Generates a Y2Storage volume. + # + # @return [Y2Storage::VolumeSpecification] + def to_y2storage + Storage::VolumeConversions::ToY2Storage.new(self).convert + end end end end diff --git a/service/lib/agama/storage/volume_conversion.rb b/service/lib/agama/storage/volume_conversion.rb deleted file mode 100644 index 432f39034f..0000000000 --- a/service/lib/agama/storage/volume_conversion.rb +++ /dev/null @@ -1,46 +0,0 @@ -# frozen_string_literal: true - -# Copyright (c) [2023-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/volume_conversion/from_y2storage" -require "agama/storage/volume_conversion/to_y2storage" - -module Agama - module Storage - # Conversions for a volume - module VolumeConversion - # Performs conversion from Y2Storage. - # - # @param volume [Agama::Storage::Volume] - # @return [Agama::Storage::Volume] - def self.from_y2storage(volume) - FromY2Storage.new(volume).convert - end - - # Performs conversion to Y2Storage. - # - # @param volume [Agama::Storage::Volume] - # @return [Y2Storage::VolumeSpecification] - def self.to_y2storage(volume) - ToY2Storage.new(volume).convert - end - end - end -end diff --git a/service/lib/agama/storage/volume_conversions.rb b/service/lib/agama/storage/volume_conversions.rb index 3c37c4d329..e8a2518a78 100644 --- a/service/lib/agama/storage/volume_conversions.rb +++ b/service/lib/agama/storage/volume_conversions.rb @@ -20,7 +20,9 @@ # find current contact information at www.suse.com. require "agama/storage/volume_conversions/from_json" +require "agama/storage/volume_conversions/from_y2storage" require "agama/storage/volume_conversions/to_json" +require "agama/storage/volume_conversions/to_y2storage" module Agama module Storage diff --git a/service/lib/agama/storage/volume_conversion/from_y2storage.rb b/service/lib/agama/storage/volume_conversions/from_y2storage.rb similarity index 99% rename from service/lib/agama/storage/volume_conversion/from_y2storage.rb rename to service/lib/agama/storage/volume_conversions/from_y2storage.rb index 0c493fe707..0ad025eb1b 100644 --- a/service/lib/agama/storage/volume_conversion/from_y2storage.rb +++ b/service/lib/agama/storage/volume_conversions/from_y2storage.rb @@ -23,7 +23,7 @@ module Agama module Storage - module VolumeConversion + module VolumeConversions # Volume conversion from Y2Storage. # # @note This class does not perform a real conversion from Y2Storage. Instead of that, it diff --git a/service/lib/agama/storage/volume_conversion/to_y2storage.rb b/service/lib/agama/storage/volume_conversions/to_y2storage.rb similarity index 99% rename from service/lib/agama/storage/volume_conversion/to_y2storage.rb rename to service/lib/agama/storage/volume_conversions/to_y2storage.rb index dd258c3bce..be7a7d43d5 100644 --- a/service/lib/agama/storage/volume_conversion/to_y2storage.rb +++ b/service/lib/agama/storage/volume_conversions/to_y2storage.rb @@ -24,7 +24,7 @@ module Agama module Storage - module VolumeConversion + module VolumeConversions # Volume conversion to Y2Storage. class ToY2Storage # @param volume [Agama::Storage::Volume] diff --git a/service/test/agama/storage/proposal_settings_conversions/from_y2storage_test.rb b/service/test/agama/storage/proposal_settings_conversions/from_y2storage_test.rb index 93f0f9e519..cb4b4b4dd0 100644 --- a/service/test/agama/storage/proposal_settings_conversions/from_y2storage_test.rb +++ b/service/test/agama/storage/proposal_settings_conversions/from_y2storage_test.rb @@ -22,10 +22,10 @@ require_relative "../../../test_helper" require "agama/config" require "agama/storage/proposal_settings" -require "agama/storage/proposal_settings_conversion/from_y2storage" +require "agama/storage/proposal_settings_conversions/from_y2storage" require "y2storage" -describe Agama::Storage::ProposalSettingsConversion::FromY2Storage do +describe Agama::Storage::ProposalSettingsConversions::FromY2Storage do subject { described_class.new(y2storage_settings, original_settings) } let(:y2storage_settings) do diff --git a/service/test/agama/storage/proposal_settings_conversions/to_y2storage_test.rb b/service/test/agama/storage/proposal_settings_conversions/to_y2storage_test.rb index 48918aa4bb..82b5d6a110 100644 --- a/service/test/agama/storage/proposal_settings_conversions/to_y2storage_test.rb +++ b/service/test/agama/storage/proposal_settings_conversions/to_y2storage_test.rb @@ -24,10 +24,10 @@ require "agama/config" require "agama/storage/device_settings" require "agama/storage/proposal_settings" -require "agama/storage/proposal_settings_conversion/to_y2storage" +require "agama/storage/proposal_settings_conversions/to_y2storage" require "y2storage" -describe Agama::Storage::ProposalSettingsConversion::ToY2Storage do +describe Agama::Storage::ProposalSettingsConversions::ToY2Storage do include Agama::RSpec::StorageHelpers subject { described_class.new(settings, config: config) } diff --git a/service/test/agama/storage/volume_conversions/from_y2storage_test.rb b/service/test/agama/storage/volume_conversions/from_y2storage_test.rb index ceecba866b..7fa66d558b 100644 --- a/service/test/agama/storage/volume_conversions/from_y2storage_test.rb +++ b/service/test/agama/storage/volume_conversions/from_y2storage_test.rb @@ -23,10 +23,10 @@ require_relative "../storage_helpers" require_relative "../../rspec/matchers/storage" require "agama/storage/volume" -require "agama/storage/volume_conversion/from_y2storage" +require "agama/storage/volume_conversions/from_y2storage" require "y2storage" -describe Agama::Storage::VolumeConversion::FromY2Storage do +describe Agama::Storage::VolumeConversions::FromY2Storage do include Agama::RSpec::StorageHelpers before { mock_storage } diff --git a/service/test/agama/storage/volume_conversions/to_y2storage_test.rb b/service/test/agama/storage/volume_conversions/to_y2storage_test.rb index 8b52a1372f..5c7ae44b53 100644 --- a/service/test/agama/storage/volume_conversions/to_y2storage_test.rb +++ b/service/test/agama/storage/volume_conversions/to_y2storage_test.rb @@ -20,10 +20,10 @@ # find current contact information at www.suse.com. require_relative "../../../test_helper" -require "agama/storage/volume_conversion/to_y2storage" +require "agama/storage/volume_conversions/to_y2storage" require "y2storage" -describe Agama::Storage::VolumeConversion::ToY2Storage do +describe Agama::Storage::VolumeConversions::ToY2Storage do subject { described_class.new(volume) } describe "#convert" do