Skip to content

Commit

Permalink
Use class method and no cache
Browse files Browse the repository at this point in the history
  • Loading branch information
teclator committed Nov 19, 2021
1 parent be3b488 commit e76591e
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
13 changes: 7 additions & 6 deletions src/lib/autoinstall/efi_detector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@
Yast.import "Stage"

module Y2Autoinstallation
# This module defines some methods that are used by different classes
# This class is responsible of detecting if the system was booted using EFI or not
class EFIDetector
# 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
# Returns 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?
# During the First Stage of the installation it relies on linuxrc for detecting the boot
# but in the rest of cases it checks if any of the EFI vars directories exist
#
# @return [Boolean] whether the system was booted using UEFI or not
def self.boot_efi?
if Yast::Stage.initial
Yast::Linuxrc.InstallInf("EFI") == "1"
else
Expand Down
2 changes: 1 addition & 1 deletion src/lib/autoinstall/y2erb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class TemplateEnvironment
# @see Y2Autoinstallation::EFIDetector
# @return [Boolean] whether the system is booted using EFI or not
def boot_efi?
(@efi_detector ||= EFIDetector.new).boot_efi?
EFIDetector.boot_efi?
end

def hardware
Expand Down
2 changes: 1 addition & 1 deletion src/modules/AutoInstallRules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,7 @@ def AutoInstallRules
# @see Y2Autoinstallation::EFIDetector
# @return [String] "yes" when the system is booted using EFI or "no" when not
def boot_efi?
(@detector ||= Y2Autoinstallation::EFIDetector.new).boot_efi? ? "yes" : "no"
Y2Autoinstallation::EFIDetector.boot_efi? ? "yes" : "no"
end

# Regexp to extract the IP from the routes table
Expand Down
3 changes: 1 addition & 2 deletions test/AutoInstallRules_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@
expect(Yast::Kernel).to receive(:GetPackages).and_return([])
expect(subject).to receive(:getNetwork).and_return("192.168.1.0")
expect(subject).to receive(:getHostname).and_return("myhost")
expect_any_instance_of(Y2Autoinstallation::EFIDetector)
.to receive(:boot_efi?).and_return(true)
expect(Y2Autoinstallation::EFIDetector).to receive(:boot_efi?).and_return(true)
expect(Yast::SCR).to receive(:Read).with(Yast::Path.new(".etc.install_inf.XServer"))
expect(Yast::Hostname).to receive(:CurrentDomain).and_return("mydomain.lan")

Expand Down
2 changes: 1 addition & 1 deletion test/lib/y2erb_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def hardware_mock_data
let(:efi) { true }

before do
allow_any_instance_of(Y2Autoinstallation::EFIDetector).to receive(:boot_efi?).and_return(efi)
allow(Y2Autoinstallation::EFIDetector).to receive(:boot_efi?).and_return(efi)
end

context "when the system was booted with EFI" do
Expand Down

0 comments on commit e76591e

Please sign in to comment.