Skip to content

Commit

Permalink
storage: generate LVM config issues
Browse files Browse the repository at this point in the history
  • Loading branch information
joseivanlopez committed Sep 17, 2024
1 parent 63b3bea commit 6c0d094
Show file tree
Hide file tree
Showing 3 changed files with 173 additions and 8 deletions.
62 changes: 57 additions & 5 deletions service/lib/agama/storage/config_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

module Agama
module Storage
# Class for checking a config.
# Class for checking a storage config.
class ConfigChecker
include Yast::I18n

Expand Down Expand Up @@ -72,15 +72,64 @@ def partition_issues(config)
# @param config [Configs::VolumeGroup]
# @return [Array<Issue>]
def volume_group_issues(config)
config.logical_volumes.flat_map { |v| logical_volume_issues(v) }
lvs_issues = config.logical_volumes.flat_map { |v| logical_volume_issues(v, config) }
pvs_issues = config.physical_volumes.map { |v| missing_physical_volume_issue(v) }.compact

lvs_issues + pvs_issues
end

# Issues from a logical volume config.
#
# @param config [Configs::LogicalVolume]
# @param lv_config [Configs::LogicalVolume]
# @param vg_config [Configs::VolumeGroup]
#
# @return [Array<Issue>]
def logical_volume_issues(config)
encryption_issues(config)
def logical_volume_issues(lv_config, vg_config)
[
encryption_issues(lv_config),
missing_thin_pool_issue(lv_config, vg_config)
].compact.flatten
end

# @see #logical_volume_issues
#
# @param lv_config [Configs::LogicalVolume]
# @param vg_config [Configs::VolumeGroup]
#
# @return [Issue, nil]
def missing_thin_pool_issue(lv_config, vg_config)
return unless lv_config.thin_volume?

pool = vg_config.logical_volumes
.select(&:pool?)
.find { |p| p.alias == lv_config.used_pool }

return if pool

error(
format(
# TRANSLATORS: %s is the replaced by a device alias (e.g., "pv1").
_("There is no LVM thin pool volume with alias %s"),
lv_config.used_pool
)
)
end

# @see #logical_volume_issues
#
# @param pv_alias [String]
# @return [Issue, nil]
def missing_physical_volume_issue(pv_alias)
configs = config.drives + config.drives.flat_map(&:partitions)
return if configs.any? { |c| c.alias == pv_alias }

error(
format(
# TRANSLATORS: %s is the replaced by a device alias (e.g., "pv1").
_("There is no LVM physical volume with alias %s"),
pv_alias
)
)
end

# Issues related to encryption.
Expand All @@ -98,6 +147,7 @@ def encryption_issues(config)
end

# @see #encryption_issues
#
# @param config [Configs::Drive, Configs::Partition, Configs::LogicalVolume]
# @return [Issue, nil]
def missing_encryption_password_issue(config)
Expand All @@ -114,6 +164,7 @@ def missing_encryption_password_issue(config)
end

# @see #encryption_issues
#
# @param config [Configs::Drive, Configs::Partition, Configs::LogicalVolume]
# @return [Issue, nil]
def available_encryption_method_issue(config)
Expand All @@ -131,6 +182,7 @@ def available_encryption_method_issue(config)
end

# @see #encryption_issues
#
# @param config [Configs::Drive, Configs::Partition, Configs::LogicalVolume]
# @return [Issue, nil]
def wrong_encryption_method_issue(config)
Expand Down
3 changes: 0 additions & 3 deletions service/lib/y2storage/proposal/agama_vg_planner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ def planned_vg(config)
# automatically generated if missing?
#
# @see AgamaDevicePlanner#configure_pv

# TODO: Generate issue if the config has an unknown physical volume alias.
# TODO: Generate issue if a thin lv config has an unknown pool alias.
Y2Storage::Planned::LvmVg.new(volume_group_name: config.name).tap do |planned|
planned.extent_size = config.extent_size
planned.lvs = planned_lvs(config)
Expand Down
116 changes: 116 additions & 0 deletions service/test/y2storage/agama_proposal_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -916,5 +916,121 @@ def partition_config(name: nil, filesystem: nil, size: nil)
)
end
end

context "when a LVM physical volume is not found" do
let(:initial_config) do
Agama::Storage::ConfigConversions::FromJSON
.new(config_json, product_config: product_config)
.convert
end

let(:product_config) { Agama::Config.new }

let(:config_json) do
{
drives: [
{
partitions: [
{
size: "40 GiB"
},
{
alias: "pv1",
size: "5 GiB"
}
]
}
],
volumeGroups: [
{
name: "system",
extentSize: "2 MiB",
physicalVolumes: ["pv1", "pv2"],
logicalVolumes: [
{
name: "root",
filesystem: {
path: "/"
}
}
]
}
]
}
end

it "aborts the proposal process" do
proposal.propose
expect(proposal.failed?).to eq true
end

it "reports the corresponding error" do
proposal.propose
expect(proposal.issues_list).to include an_object_having_attributes(
description: /no LVM physical volume with alias pv2/,
severity: Agama::Issue::Severity::ERROR
)
end
end

context "when a LVM thin pool volume is not found" do
let(:initial_config) do
Agama::Storage::ConfigConversions::FromJSON
.new(config_json, product_config: product_config)
.convert
end

let(:product_config) { Agama::Config.new }

let(:config_json) do
{
drives: [
{
partitions: [
{
size: "40 GiB"
},
{
alias: "pv1",
size: "5 GiB"
}
]
}
],
volumeGroups: [
{
name: "system",
extentSize: "2 MiB",
physicalVolumes: ["pv1"],
logicalVolumes: [
{
pool: true
},
{
name: "root",
filesystem: {
path: "/"
},
usedPool: "pool"
}
]
}
]
}
end

it "aborts the proposal process" do
proposal.propose
expect(proposal.failed?).to eq true
end

it "reports the corresponding error" do
proposal.propose
expect(proposal.issues_list).to include an_object_having_attributes(
description: /no LVM thin pool volume with alias pool/,
severity: Agama::Issue::Severity::ERROR
)
end
end
end
end

0 comments on commit 6c0d094

Please sign in to comment.