Skip to content

Commit

Permalink
feat(storage): check boot config
Browse files Browse the repository at this point in the history
  • Loading branch information
joseivanlopez committed Dec 5, 2024
1 parent ee50918 commit 43fed96
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 0 deletions.
9 changes: 9 additions & 0 deletions service/lib/agama/storage/config_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# find current contact information at www.suse.com.

require "agama/config"
require "agama/storage/config_checkers/boot"
require "agama/storage/config_checkers/drive"
require "agama/storage/config_checkers/volume_group"
require "agama/storage/config_checkers/volume_groups"
Expand All @@ -40,6 +41,7 @@ def initialize(storage_config, product_config = nil)
# @return [Array<Issue>]
def issues
[
boot_issues,
drives_issues,
volume_groups_issues
].flatten
Expand All @@ -53,6 +55,13 @@ def issues
# @return [Agama::Config]
attr_reader :product_config

# Issues from boot config.
#
# @return [Array<Issue>]
def boot_issues
ConfigCheckers::Boot.new(storage_config, product_config).issues
end

# Issues from drives.
#
# @return [Array<Issue>]
Expand Down
1 change: 1 addition & 0 deletions service/lib/agama/storage/config_checkers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
# 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/config_checkers/boot"
require "agama/storage/config_checkers/drive"
require "agama/storage/config_checkers/encryption"
require "agama/storage/config_checkers/filesystem"
Expand Down
57 changes: 57 additions & 0 deletions service/lib/agama/storage/config_checkers/boot.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# frozen_string_literal: true

# Copyright (c) [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/config_checkers/base"
require "yast/i18n"

module Agama
module Storage
module ConfigCheckers
# Class for checking the boot config.
class Boot < Base
include Yast::I18n

# Boot config issues.
#
# @return [Array<Issue>]
def issues
[missing_boot_device_issue].compact
end

private

# @return [Configs::Boot]
def boot
storage_config.boot
end

# @return [Issue, nil]
def missing_boot_device_issue
return unless boot.configure? && boot.device
return if storage_config.drives.any? { |d| d.alias == boot.device }

# TRANSLATORS: %s is the replaced by a device alias (e.g., "boot").
error(format(_("There is no boot device with alias '%s'"), boot.device))
end
end
end
end
end
69 changes: 69 additions & 0 deletions service/test/agama/storage/config_checker_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,75 @@

let(:scenario) { "disks.yaml" }

context "if the boot configuration is enabled" do
let(:config_json) do
{
boot: {
configure: true,
device: boot_device
},
drives: [
{
alias: "disk"
}
]
}
end

context "and the given alias does not exist" do
let(:boot_device) { "foo" }

it "includes the expected issue" do
issues = subject.issues
expect(issues.size).to eq(1)

issue = issues.first
expect(issue.error?).to eq(true)
expect(issue.description).to eq("There is no boot device with alias 'foo'")
end
end

context "and the given alias exists" do
let(:boot_device) { "disk" }

it "does not include any issue" do
expect(subject.issues).to be_empty
end
end
end

context "if the boot configuration is not enabled" do
let(:config_json) do
{
boot: {
configure: false,
device: boot_device
},
drives: [
{
alias: "disk"
}
]
}
end

context "and the given alias does not exist" do
let(:boot_device) { "foo" }

it "does not include any issue" do
expect(subject.issues).to be_empty
end
end

context "and the given alias exists" do
let(:boot_device) { "disk" }

it "does not include any issue" do
expect(subject.issues).to be_empty
end
end
end

context "if a drive has not found device" do
let(:config_json) do
{
Expand Down

0 comments on commit 43fed96

Please sign in to comment.