Skip to content

Commit

Permalink
grub2bls
Browse files Browse the repository at this point in the history
  • Loading branch information
schubi2 committed Nov 12, 2024
1 parent 03efdc7 commit d959048
Showing 1 changed file with 41 additions and 27 deletions.
68 changes: 41 additions & 27 deletions test/grub2_bls_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,21 @@
describe "#read" do
before do
allow(Yast::Misc).to receive(:CustomSysconfigRead)
.with("ID_LIKE", "openSUSE", "/etc/os-release")
.and_return("openSUSE")
.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")
.with("timeout", "", "/boot/efi/EFI/openSUSE/grubenv")
.and_return("10")
allow(Yast::Misc).to receive(:CustomSysconfigRead)
.with("default", "", "/boot/efi/EFI/openSUSE/grubenv")
.and_return("")
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
expect(subject.grub_default.timeout).to eq "10"
end

it "reads entries from /etc/kernel/cmdline" do
Expand All @@ -51,59 +54,66 @@
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-timeout",
subject.grub_default.timeout,
allowed_exitstatus: [0, 1])
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-timeout",
subject.grub_default.timeout,
allowed_exitstatus: [0, 1])
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", "install")
allow(Yast::Execute).to receive(:on_target!)
.with("/usr/bin/sdbootutil", "--verbose", "add-all-kernels")

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
expect(subject.grub_default.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)
.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)

expect(Yast::Execute).to receive(:on_target)
.with("/usr/bin/sdbootutil", "set-timeout",
subject.grub_default.timeout,
allowed_exitstatus: [0, 1])
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"]
expect(subject.packages).to include("grub2-" + Yast::Arch.architecture + "-efi-bls")
expect(subject.packages).to include("sdbootutil")
expect(subject.packages).to include("grub2")
end
end

Expand All @@ -118,21 +128,25 @@
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)
other.grub_default.timeout = 12
other.grub_default.kernel_params.replace(other_cmdline)

subject.menu_timeout = 10
subject.kernel_params.replace(cmdline_content)
subject.grub_default.timeout = 10
subject.grub_default.kernel_params.replace(cmdline_content)

subject.merge(other)

expect(subject.menu_timeout).to eq 12
expect(subject.grub_default.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"
expect(subject.grub_default.kernel_params.serialize).to include "security=apparmor splash=silent quiet mitigations=auto"
end
end

describe "#propose" do
before do
allow(Yast::BootStorage).to receive(:available_swap_partitions).and_return({})
end

it "proposes timeout to product/role default" do
allow(Yast::ProductFeatures).to receive(:GetIntegerFeature)
.with("globals", "boot_timeout").and_return(2)
Expand Down

0 comments on commit d959048

Please sign in to comment.