Skip to content

Commit

Permalink
Several fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
joseivanlopez committed Aug 22, 2023
1 parent 9ede962 commit 9c3b6cb
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 38 deletions.
15 changes: 1 addition & 14 deletions service/lib/agama/storage/manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,24 +191,11 @@ def probe_devices
#
# It reuses the settings from the previous proposal, if any.
def calculate_proposal
settings = proposal.settings || default_proposal_settings
settings = proposal.settings || read_proposal_settings

proposal.calculate(settings)
end

# Default proposal settings from the config file.
#
# The first device is selected as boot device.
#
# @return [ProposalSettings]
def default_proposal_settings
settings = read_proposal_settings
device = proposal.available_devices.first&.name
settings.boot_device = device if device

settings
end

# Reads the default proposal settings from the config file.
#
# @return [ProposalSettings]
Expand Down
17 changes: 12 additions & 5 deletions service/lib/agama/storage/proposal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ def available_devices
# @param settings [ProposalSettings] settings to calculate the proposal.
# @return [Boolean] whether the proposal was correctly calculated.
def calculate(settings)
# Use the first available device if no boot device is indicated.
settings.boot_device ||= available_devices.first&.name

@original_settings = settings

calculate_proposal(settings)
Expand All @@ -102,11 +105,15 @@ def calculate(settings)
def settings
return nil unless calculated?

settings = ProposalSettingsConversion.from_y2storage(proposal.settings, config: config)

# FIXME: Currently, the conversion from Y2Storage cannot infer the space policy. Copying
# space settings from the original settings.
settings.space = original_settings.space.dup
ProposalSettingsConversion.from_y2storage(
proposal.settings,
config: config
).tap do |settings|
# FIXME: Currently, the conversion from Y2Storage cannot infer the space policy. Copying
# space settings from the original settings.
settings.space.policy = original_settings.space.policy
settings.space.actions = original_settings.space.actions
end
end

# Storage actions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def candidate_devices_conversion(target)
candidate_devices = settings.lvm.system_vg_devices if settings.lvm.enabled?
candidate_devices = [settings.boot_device] if candidate_devices.none?

target.candidate_devices = candidate_devices
target.candidate_devices = candidate_devices.compact
end

# @param target [Y2Storage::ProposalSettings]
Expand Down
4 changes: 3 additions & 1 deletion service/lib/agama/storage/volume_templates_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
# find current contact information at www.suse.com.

require "pathname"
require "yast"
require "y2storage"
require "agama/storage/volume"
require "agama/storage/volume_outline"
require "agama/storage/btrfs_settings"

module Agama
module Storage
Expand Down
7 changes: 3 additions & 4 deletions service/test/agama/storage/manager_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -261,14 +261,13 @@
let(:new_settings) { Agama::Storage::ProposalSettings.new }

before do
allow(Agama::Storage::ProposalSettings).to receive(:new).and_return(new_settings)
allow_any_instance_of(Agama::Storage::ProposalSettingsReader).to receive(:read)
.and_return(new_settings)
end

it "calculates a proposal using new settings and the first available disk" do
it "calculates a proposal using default settings from the config file" do
expect(proposal).to receive(:calculate).with(new_settings)
expect(new_settings.boot_device).to be_nil
storage.probe
expect(new_settings.boot_device).to eq disk1.name
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,32 @@
settings.lvm.system_vg_devices = ["/dev/sdb"]
end

it "uses the boot device as candidate device" do
y2storage_settings = subject.convert
context "and there is a boot device" do
before do
settings.boot_device = "/dev/sda"
end

it "uses the boot device as candidate device" do
y2storage_settings = subject.convert

expect(y2storage_settings).to have_attributes(
candidate_devices: contain_exactly("/dev/sda")
)
end
end

expect(y2storage_settings).to have_attributes(
candidate_devices: contain_exactly("/dev/sda")
)
context "and there is no boot device" do
before do
settings.boot_device = nil
end

it "does not set candidate devices" do
y2storage_settings = subject.convert

expect(y2storage_settings).to have_attributes(
candidate_devices: be_empty
)
end
end
end

Expand All @@ -91,12 +111,32 @@
settings.lvm.system_vg_devices = []
end

it "uses the boot device as candidate device" do
y2storage_settings = subject.convert
context "and there is a boot device" do
before do
settings.boot_device = "/dev/sda"
end

expect(y2storage_settings).to have_attributes(
candidate_devices: contain_exactly("/dev/sda")
)
it "uses the boot device as candidate device" do
y2storage_settings = subject.convert

expect(y2storage_settings).to have_attributes(
candidate_devices: contain_exactly("/dev/sda")
)
end
end

context "and there is no boot device" do
before do
settings.boot_device = nil
end

it "does not set candidate device" do
y2storage_settings = subject.convert

expect(y2storage_settings).to have_attributes(
candidate_devices: be_empty
)
end
end
end

Expand Down
5 changes: 2 additions & 3 deletions service/test/agama/storage/proposal_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@
before do
allow(Y2Storage::StorageManager.instance).to receive(:proposal=)

# This is needed. Not filled by default.
settings.boot_device = "/dev/sda"
settings.space.policy = policy
end

Expand Down Expand Up @@ -248,11 +246,12 @@ def expect_space_actions(actions)

context "when there was already a proposal attempt" do
before do
allow_any_instance_of(Y2Storage::DiskAnalyzer).to receive(:candidate_disks).and_return([])

settings.boot_device = boot_device
proposal.calculate(settings)
end

let(:sda) { instance_double(Y2Storage::Disk, name: "/dev/sda") }
let(:boot_device) { nil }

context "but no boot device was selected" do
Expand Down

0 comments on commit 9c3b6cb

Please sign in to comment.