-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
152 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "test_helper" | ||
|
||
require "bootloader/grub2bls" | ||
|
||
describe Bootloader::Grub2Bls do | ||
subject do | ||
sub = described_class.new | ||
sub | ||
end | ||
|
||
let(:destdir) { File.expand_path("data/", __dir__) } | ||
let(:cmdline_content) { "splash=silent quiet security=apparmor mitigations=off" } | ||
|
||
before do | ||
allow(Yast::Arch).to receive(:architecture).and_return("x86_64") | ||
end | ||
|
||
describe "#read" do | ||
before do | ||
allow(Yast::Misc).to receive(:CustomSysconfigRead) | ||
.with("ID_LIKE", "openSUSE", "/etc/os-release") | ||
.and_return("openSUSE") | ||
allow(Yast::Misc).to receive(:CustomSysconfigRead) | ||
.with("timeout", "", "/boot/efi/EFI/openSUSE/grubenv") | ||
.and_return("10") | ||
allow(Yast::Installation).to receive(:destdir).and_return(destdir) | ||
end | ||
|
||
it "reads menu timeout" do | ||
subject.read | ||
|
||
expect(subject.grub_default.timeout).to eq 10 | ||
end | ||
|
||
it "reads entries from /etc/kernel/cmdline" do | ||
subject.read | ||
|
||
expect(subject.cpu_mitigations.to_human_string).to eq "Off" | ||
expect(subject.grub_default.kernel_params.serialize).to eq cmdline_content | ||
end | ||
end | ||
|
||
describe "#write" do | ||
before do | ||
allow(Yast::Stage).to receive(:initial).and_return(false) | ||
allow(Yast::Installation).to receive(:destdir).and_return(destdir) | ||
subject.grub_default.kernel_params.replace(cmdline_content) | ||
subject.grub_default.timeout = 10 | ||
end | ||
|
||
it "installs the bootloader" do | ||
allow(Yast::Execute).to receive(:on_target!) | ||
.with("/usr/bin/sdbootutil", "set-timeout", subject.grub_default.timeout) | ||
allow(Yast::Execute).to receive(:on_target!) | ||
.with("/usr/bin/sdbootutil", "set-default", subject.sections.default) | ||
|
||
# install bootloader | ||
expect(Yast::Execute).to receive(:on_target!) | ||
.with("/usr/bin/sdbootutil", "--verbose", "install") | ||
|
||
# create menu entries | ||
expect(Yast::Execute).to receive(:on_target!) | ||
.with("/usr/bin/sdbootutil", "--verbose", "add-all-kernels") | ||
|
||
subject.write | ||
end | ||
|
||
it "writes kernel cmdline" do | ||
allow(Yast::Execute).to receive(:on_target!) | ||
.with("/usr/bin/sdbootutil", "set-timeout", subject.grub_default.timeout) | ||
allow(Yast::Execute).to receive(:on_target!) | ||
.with("/usr/bin/sdbootutil", "set-default", subject.sections.default) | ||
allow(Yast::Execute).to receive(:on_target!) | ||
.with("/usr/bin/sdbootutil", "--verbose", "install") | ||
|
||
subject.write | ||
# Checking written kernel parameters | ||
subject.read | ||
expect(subject.cpu_mitigations.to_human_string).to eq "Off" | ||
expect(subject.kernel_params.serialize).to include cmdline_content | ||
end | ||
|
||
it "saves menu timeout" do | ||
allow(Yast::Execute).to receive(:on_target!) | ||
.with("/usr/bin/sdbootutil", "set-default", subject.sections.default) | ||
allow(Yast::Execute).to receive(:on_target!) | ||
.with("/usr/bin/sdbootutil", "--verbose", "install") | ||
allow(Yast::Execute).to receive(:on_target!) | ||
.with("/usr/bin/sdbootutil", "--verbose", "add-all-kernels") | ||
|
||
# Saving menu timeout | ||
expect(Yast::Execute).to receive(:on_target!) | ||
.with("/usr/bin/sdbootutil", "set-timeout", subject.grub_default.timeout) | ||
|
||
subject.write | ||
end | ||
end | ||
|
||
describe "#packages" do | ||
it "adds grub2* and sdbootutil packages" do | ||
allow(Yast::Arch).to receive(:architecture).and_return("x86_64") | ||
|
||
expect(subject.packages).to ["grub2-" + Yast::Arch.architecture + "-efi-bls", | ||
"sdbootutil", "grub2"] | ||
end | ||
end | ||
|
||
describe "#summary" do | ||
it "returns line with boot loader type specified" do | ||
expect(subject.summary).to include("Boot Loader Type: GRUB2 BLS") | ||
end | ||
|
||
end | ||
|
||
describe "#merge" do | ||
it "overwrite mitigations and menu timeout if specified in merged one" do | ||
other_cmdline = "splash=silent quiet mitigations=auto" | ||
other = described_class.new | ||
other.menu_timeout = 12 | ||
other.kernel_params.replace(other_cmdline) | ||
|
||
subject.menu_timeout = 10 | ||
subject.kernel_params.replace(cmdline_content) | ||
|
||
subject.merge(other) | ||
|
||
expect(subject.menu_timeout).to eq 12 | ||
expect(subject.cpu_mitigations.to_human_string).to eq "Auto" | ||
expect(subject.kernel_params.serialize).to include "security=apparmor splash=silent quiet mitigations=auto" | ||
end | ||
end | ||
|
||
describe "#propose" do | ||
it "proposes timeout to product/role default" do | ||
allow(Yast::ProductFeatures).to receive(:GetIntegerFeature) | ||
.with("globals", "boot_timeout").and_return(2) | ||
subject.propose | ||
|
||
expect(subject.grub_default.timeout).to eq 2 | ||
end | ||
|
||
it "proposes kernel cmdline" do | ||
expect(Yast::BootArch).to receive(:DefaultKernelParams).and_return(cmdline_content) | ||
|
||
subject.propose | ||
expect(subject.grub_default.kernel_params.serialize).to eq cmdline_content | ||
end | ||
end | ||
end |