Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
joseivanlopez committed Sep 4, 2023
1 parent b4974f9 commit b44d277
Show file tree
Hide file tree
Showing 24 changed files with 636 additions and 504 deletions.
3 changes: 3 additions & 0 deletions service/etc/agama.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ ALP-Dolomite:
patterns: null

storage:
space_policy: delete
encryption:
method: luks2
pbkd_function: pbkdf2
Expand Down Expand Up @@ -150,6 +151,7 @@ Tumbleweed:
patterns: null

storage:
space_policy: delete
volumes:
- "/"
- "swap"
Expand Down Expand Up @@ -274,6 +276,7 @@ Leap16:
patterns: null

storage:
space_policy: delete
encryption:
method: luks2
pbkd_function: pbkdf2
Expand Down
13 changes: 3 additions & 10 deletions service/lib/agama/dbus/storage/manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ def initialize(backend, logger)
register_progress_callbacks
register_service_status_callbacks
register_iscsi_callbacks
register_software_callbacks

add_s390_interfaces if Yast::Arch.s390
end
Expand Down Expand Up @@ -149,7 +148,7 @@ def calculate_proposal(dbus_settings)
logger.info(
"Calculating storage proposal from D-Bus.\n " \
"D-Bus settings: #{dbus_settings}\n" \
"Agama settings: #{settings}"
"Agama settings: #{settings.inspect}"
)

success = proposal.calculate(settings)
Expand All @@ -164,8 +163,8 @@ def calculate_proposal(dbus_settings)

dbus_reader :result, "o"

dbus_method :DefaultVolume, "in mount_path:s , out volume:a{sv}" do |mount_path|
default_volume(mount_path)
dbus_method :DefaultVolume, "in mount_path:s, out volume:a{sv}" do |mount_path|
[default_volume(mount_path)]
end

# result: 0 success; 1 error
Expand Down Expand Up @@ -298,12 +297,6 @@ def register_iscsi_callbacks
end
end

def register_software_callbacks
backend.software.on_product_selected do |_product|
backend.proposal.invalidate
end
end

def storage_properties_changed
properties = interfaces_and_properties[STORAGE_INTERFACE]
dbus_properties_changed(STORAGE_INTERFACE, properties, [])
Expand Down
36 changes: 8 additions & 28 deletions service/lib/agama/storage/proposal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,34 +38,11 @@ def initialize(config, logger: nil)

# Whether the proposal was successfully calculated.
#
# @note: The proposal must not be invalidated.
#
# @return [Boolean]
def success?
calculated? && !proposal.failed?
end

# Whether the proposal was already calculated.
#
# @note: The proposal must not be invalidated.
#
# @return [Boolean]
def calculated?
!invalidated? && !proposal.nil?
end

# Whether the proposal was invalidated.
#
# @return [Boolean]
def invalidated?
!!@invalidated
end

# Invalidates the current proposal.
def invalidate
@invalidated = true
end

# Stores callbacks to be call after calculating a proposal.
def on_calculate(&block)
@on_calculate_callbacks << block
Expand All @@ -91,7 +68,6 @@ def calculate(settings)
calculate_proposal(settings)

@on_calculate_callbacks.each(&:call)
@invalidated = false

success?
end
Expand All @@ -101,8 +77,7 @@ def calculate(settings)
# Note that this settings might differ from the {#original_settings}. For example, the sizes
# of some volumes could be adjusted if auto size is set.
#
# @return [ProposalSettings, nil] nil if no proposal has been calculated yet or the proposal
# was invalidated.
# @return [ProposalSettings, nil] nil if no proposal has been calculated yet.
def settings
return nil unless calculated?

Expand Down Expand Up @@ -154,11 +129,16 @@ def issues

# @return [Y2Storage::MinGuidedProposal, nil]
def proposal
return nil if invalidated?

storage_manager.proposal
end

# Whether the proposal was already calculated.
#
# @return [Boolean]
def calculated?
!proposal.nil?
end

# Instantiates and executes a Y2Storage proposal with the given settings
#
# @param settings [Y2Storage::ProposalSettings]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ def lvm_conversion(target)

target.lvm = lvm
target.separate_vgs = lvm
# Prevent VG reuse
target.lvm_vg_reuse = false
end

# @param target [Y2Storage::ProposalSettings]
Expand Down Expand Up @@ -135,8 +137,12 @@ def missing_volumes
# @param target [Y2Storage::ProposalSettings]
def fallbacks_conversion(target)
target.volumes.each do |spec|
spec.fallback_for_min_size = find_min_size_fallback(spec.mount_point)
spec.fallback_for_max_size = find_max_size_fallback(spec.mount_point)
min_size_fallback = find_min_size_fallback(spec.mount_point)
max_size_fallback = find_max_size_fallback(spec.mount_point)

spec.fallback_for_min_size = min_size_fallback
spec.fallback_for_max_size = max_size_fallback
spec.fallback_for_max_size_lvm = max_size_fallback
end
end

Expand Down
8 changes: 6 additions & 2 deletions service/lib/agama/storage/volume_conversion/to_y2storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,12 @@ def sizes_conversion(target)
# And note that the final range of sizes used by the Y2Storage proposal is calculated by
# Y2Storage according the range configured here and other sizes like fallback sizes or
# the size for snapshots.
target.min_size = auto ? volume.outline.base_min_size : volume.min_size
target.max_size = auto ? volume.outline.base_max_size : volume.max_size
min_size = auto ? volume.outline.base_min_size : volume.min_size
max_size = auto ? volume.outline.base_max_size : volume.max_size

target.min_size = min_size
target.max_size = max_size
target.max_size_lvm = max_size
end

# @param target [Y2Storage::VolumeSpecification]
Expand Down
5 changes: 4 additions & 1 deletion service/lib/agama/storage/volume_templates_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,10 @@ def btrfs(data)
def subvolume(data)
return Y2Storage::SubvolSpecification.new(data) if data.is_a?(String)

attrs = { copy_on_write: fetch(data, :copy_on_write), archs: fetch(data, :archs) }.compact
archs = fetch(data, :archs, "").gsub(/\s+/, "").split(",")
archs = nil if archs.none?

attrs = { copy_on_write: fetch(data, :copy_on_write), archs: archs }.compact
Y2Storage::SubvolSpecification.new(fetch(data, :path), **attrs)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
root_device: "/dev/sda",
lvm: true,
separate_vgs: true,
lvm_vg_reuse: false,
encryption_password: "notsecret",
encryption_method: Y2Storage::EncryptionMethod::LUKS2,
encryption_pbkdf: Y2Storage::PbkdFunction::ARGON2ID,
Expand Down Expand Up @@ -269,24 +270,28 @@

expect(y2storage_settings.volumes).to contain_exactly(
an_object_having_attributes(
mount_point: "/",
fallback_for_min_size: nil,
fallback_for_max_size: nil
mount_point: "/",
fallback_for_min_size: nil,
fallback_for_max_size: nil,
fallback_for_max_size_lvm: nil
),
an_object_having_attributes(
mount_point: "/home",
fallback_for_min_size: "/test",
fallback_for_max_size: nil
mount_point: "/home",
fallback_for_min_size: "/test",
fallback_for_max_size: nil,
fallback_for_max_size_lvm: nil
),
an_object_having_attributes(
mount_point: "swap",
fallback_for_min_size: "/test",
fallback_for_max_size: "/test"
mount_point: "swap",
fallback_for_min_size: "/test",
fallback_for_max_size: "/test",
fallback_for_max_size_lvm: "/test"
),
an_object_having_attributes(
mount_point: "/test",
fallback_for_min_size: nil,
fallback_for_max_size: nil
mount_point: "/test",
fallback_for_min_size: nil,
fallback_for_max_size: nil,
fallback_for_max_size_lvm: nil
)
)
end
Expand Down
47 changes: 0 additions & 47 deletions service/test/agama/storage/proposal_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,6 @@
it "returns true" do
expect(subject.success?).to eq(true)
end

context "but the proposal was invalidated" do
before do
subject.invalidate
end

it "returns false" do
expect(subject.success?).to eq(false)
end
end
end

context "and the proposal failed" do
Expand All @@ -92,18 +82,6 @@
end
end

describe "#invalidated?" do
it "returns false if the proposal has not been invalidated yet" do
expect(subject.invalidated?).to eq(false)
end

it "returns true if the proposal was invalidated" do
subject.invalidate

expect(subject.invalidated?).to eq(true)
end
end

describe "#calculate" do
it "calculates a new proposal with the given settings" do
expect(Y2Storage::StorageManager.instance.proposal).to be_nil
Expand Down Expand Up @@ -150,21 +128,6 @@
)
end
end

context "if the previous proposal was invalidated" do
before do
subject.calculate(achievable_settings)
subject.invalidate
end

it "sets the new proposal as not invalidated" do
expect(subject.invalidated?).to eq(true)

subject.calculate(achievable_settings)

expect(subject.invalidated?).to eq(false)
end
end
end

describe "#settings" do
Expand Down Expand Up @@ -201,16 +164,6 @@
)
)
end

context "and the proposal was invalidated" do
before do
subject.invalidate
end

it "returns nil" do
expect(proposal.settings).to be_nil
end
end
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
ignore_snapshots_sizes: true,
min_size: Y2Storage::DiskSize.GiB(5),
max_size: Y2Storage::DiskSize.GiB(20),
max_size_lvm: Y2Storage::DiskSize.GiB(20),
snapshots: true,
snapshots_configurable?: true,
snapshots_size: Y2Storage::DiskSize.GiB(10),
Expand All @@ -96,7 +97,8 @@
ignore_fallback_sizes: false,
ignore_snapshots_sizes: false,
min_size: Y2Storage::DiskSize.GiB(10),
max_size: Y2Storage::DiskSize.GiB(50)
max_size: Y2Storage::DiskSize.GiB(50),
max_size_lvm: Y2Storage::DiskSize.GiB(50)
)
end
end
Expand Down
38 changes: 32 additions & 6 deletions service/test/agama/storage/volume_templates_builder_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -256,20 +256,46 @@
context "when the list of subvolumes mixes strings and hashes" do
let(:subvolumes) do
[
"root", "home",
{ "path" => "boot", "archs" => "x86_64" },
"root",
"home",
{ "path" => "boot", "archs" => "x86_64, !ppc" },
{ "path" => "var", "copy_on_write" => false },
"srv"
]
end

it "creates the correct list of subvolumes" do
subvols = builder.for("/").btrfs.subvolumes
expect(subvols.size).to eq 5

expect(subvols).to all be_a(Y2Storage::SubvolSpecification)
expect(subvols.map(&:path)).to contain_exactly("home", "root", "srv", "boot", "var")
expect(subvols.map(&:archs)).to contain_exactly(nil, nil, nil, nil, "x86_64")
expect(subvols.map(&:copy_on_write)).to contain_exactly(true, true, true, true, false)

expect(subvols).to contain_exactly(
an_object_having_attributes(
path: "root",
archs: nil,
copy_on_write: true
),
an_object_having_attributes(
path: "home",
archs: nil,
copy_on_write: true
),
an_object_having_attributes(
path: "boot",
archs: ["x86_64", "!ppc"],
copy_on_write: true
),
an_object_having_attributes(
path: "var",
archs: nil,
copy_on_write: false
),
an_object_having_attributes(
path: "srv",
archs: nil,
copy_on_write: true
)
)
end
end
end
Expand Down
Loading

0 comments on commit b44d277

Please sign in to comment.