-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved efi detection to a module for sharing code
- Loading branch information
Showing
5 changed files
with
86 additions
and
36 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Yast.import "Linuxrc" | ||
Yast.import "Stage" | ||
|
||
module Y2Autoinstallation | ||
# This module defines some methods that are used by different classes | ||
module CommonHelpers | ||
# Use same approach than linuxrc for detecting the EFI boot in a running system but use | ||
# install.inf in case of initial Stage. | ||
EFI_VARS_DIRS = ["/sys/firmware/efi/efivars", "/sys/firmware/efi/vars/"].freeze | ||
|
||
# Whether the system was booted using UEFI or not | ||
# | ||
# @return [Boolean] whether the system was booted using UEFI or not according to linuxrc | ||
def boot_efi? | ||
if Yast::Stage.initial | ||
Yast::Linuxrc.InstallInf("EFI") == "1" | ||
else | ||
EFI_VARS_DIRS.any? { |d| Dir.exist?(d) } | ||
end | ||
end | ||
end | ||
end |
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
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,59 @@ | ||
require_relative "../test_helper" | ||
require "autoinstall/common_helpers" | ||
|
||
describe Y2Autoinstallation::CommonHelpers do | ||
class Dummy | ||
include Y2Autoinstallation::CommonHelpers | ||
|
||
def initialize | ||
@name = "Dummy class" | ||
end | ||
end | ||
|
||
subject { Dummy.new } | ||
|
||
describe "#boot_efi?" do | ||
let(:efi) { true } | ||
|
||
context "when called in the initial Stage" do | ||
before do | ||
allow(Yast::Linuxrc).to receive(:InstallInf).with("EFI").and_return(efi) | ||
end | ||
|
||
context "and EFI is read as '1' from the Install.inf file" do | ||
it "returns true" do | ||
expect(subject.boot_efi?) | ||
end | ||
end | ||
|
||
context "and EFI is not read as '1' from the Install.inf file" do | ||
let(:efi) { false } | ||
|
||
it "returns false" do | ||
expect(subject.boot_efi?) | ||
end | ||
end | ||
end | ||
|
||
context "when called in normal Mode" do | ||
before do | ||
allow(Dir).to receive(:exist?) | ||
end | ||
|
||
described_class.const_get("EFI_VARS_DIRS").each do |dir| | ||
it "returns true if '#{dir}' exists" do | ||
expect(Dir).to receive(:exist?).with(dir).and_return(true) | ||
expect(subject.boot_efi?).to eq(true) | ||
end | ||
end | ||
|
||
it "returns false otherwise" do | ||
described_class.const_get("EFI_VARS_DIRS").each do |dir| | ||
allow(Dir).to receive(:exist?).with(dir).and_return(false) | ||
end | ||
|
||
expect(subject.boot_efi?).to eq(false) | ||
end | ||
end | ||
end | ||
end |
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