Skip to content

Commit

Permalink
storage: move Y2Storage conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
joseivanlopez committed Jun 28, 2024
1 parent ad6106d commit c2afbe5
Show file tree
Hide file tree
Showing 20 changed files with 64 additions and 214 deletions.
8 changes: 8 additions & 0 deletions service/lib/agama/storage/proposal_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
50 changes: 0 additions & 50 deletions service/lib/agama/storage/proposal_settings_conversion.rb

This file was deleted.

2 changes: 2 additions & 0 deletions service/lib/agama/storage/proposal_settings_conversions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions service/lib/agama/storage/proposal_strategies/autoyast.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions service/lib/agama/storage/proposal_strategies/guided.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
)
Expand Down
7 changes: 7 additions & 0 deletions service/lib/agama/storage/volume.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
46 changes: 0 additions & 46 deletions service/lib/agama/storage/volume_conversion.rb

This file was deleted.

2 changes: 2 additions & 0 deletions service/lib/agama/storage/volume_conversions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

module Agama
module Storage
module VolumeConversion
module VolumeConversions
# Volume conversion to Y2Storage.
class ToY2Storage
# @param volume [Agama::Storage::Volume]
Expand Down
49 changes: 0 additions & 49 deletions service/test/agama/storage/proposal_settings_conversion_test.rb

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down
12 changes: 12 additions & 0 deletions service/test/agama/storage/proposal_settings_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
require "agama/storage/device_settings"
require "agama/storage/proposal_settings"
require "agama/storage/volume"
require "y2storage/proposal_settings"

describe Agama::Storage::ProposalSettings do
describe "#default_boot_device" do
Expand Down Expand Up @@ -197,4 +198,15 @@
expect(result).to be_a(Hash)
end
end

describe "#to_y2storage" do
let(:config) { Agama::Config.new }

let(:settings) { Agama::Storage::ProposalSettings.new }

it "generates Y2Storage settings from proposal settings" do
result = subject.to_y2storage(config: config)
expect(result).to be_a(Y2Storage::ProposalSettings)
end
end
end
Loading

0 comments on commit c2afbe5

Please sign in to comment.