From f326dda4f8605b2a519360c26bef2f83aa3c999e Mon Sep 17 00:00:00 2001 From: Knut Anderssen Date: Thu, 18 Nov 2021 11:09:54 +0000 Subject: [PATCH 1/8] Add support for detecting EFI boot --- src/autoyast-rnc/rules.rnc | 2 ++ src/lib/autoinstall/y2erb.rb | 7 +++++++ src/modules/AutoInstallRules.rb | 17 ++++++++++++++++- test/lib/y2erb_test.rb | 22 ++++++++++++++++++++++ 4 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/autoyast-rnc/rules.rnc b/src/autoyast-rnc/rules.rnc index ff62e55e8..dcf4b8286 100644 --- a/src/autoyast-rnc/rules.rnc +++ b/src/autoyast-rnc/rules.rnc @@ -49,6 +49,7 @@ y2_match_to = | hostname | hostaddress | hostid + | efi | karch | linux | installed_product @@ -72,6 +73,7 @@ custom4 = element custom4 { MAP, (match_text custom5 = element custom5 { MAP, (match_text & match_type? & script) } disksize = element disksize { MAP, (match_text & match_type?) } domain = element domain { MAP, (match_text & match_type?) } +efi = element efi { MAP, (match_text & match_type?) } hostname = element hostname { MAP, (match_text & match_type?) } hostaddress = element hostaddress { MAP, (match_text & match_type?) } hostid = element hostid { MAP, (match_text & match_type?) } diff --git a/src/lib/autoinstall/y2erb.rb b/src/lib/autoinstall/y2erb.rb index 7a2deecbf..8dd49619e 100644 --- a/src/lib/autoinstall/y2erb.rb +++ b/src/lib/autoinstall/y2erb.rb @@ -12,6 +12,13 @@ def self.render(path) class TemplateEnvironment include Yast::Logger + # @return [Boolean] whether the system was booted using UEFI or not according to linuxrc + def efi? + Yast.import "Linuxrc" + + Yast::Linuxrc.InstallInf("EFI") == "1" + end + def hardware @hardware ||= Yast::SCR.Read(Yast::Path.new(".probe")) end diff --git a/src/modules/AutoInstallRules.rb b/src/modules/AutoInstallRules.rb index 2955d5110..5b168661a 100644 --- a/src/modules/AutoInstallRules.rb +++ b/src/modules/AutoInstallRules.rb @@ -24,6 +24,7 @@ def main Yast.import "XML" Yast.import "Kernel" Yast.import "Mode" + Yast.import "Linuxrc" Yast.import "Profile" Yast.import "Label" Yast.import "Report" @@ -84,6 +85,7 @@ def reset @totaldisk = 0 @hostid = "" @mac = "" + @efi = false @linux = 0 @others = 0 @xserver = "" @@ -139,6 +141,13 @@ def StdErrLog(stderr) nil end + # Returns whether the system was booted using UEFI or not + # + # @return [Boolean] true when the system is booted using EFI + def boot_efi? + Yast::Linuxrc.InstallInf("EFI") == "1" + end + # getMAC() # Return MAC address of active device # @return [String] mac address @@ -286,6 +295,11 @@ def ProbeRules # Ops.set(@ATTR, "mac", @mac) + # + # EFI Boot + # + @ATTR["efi"] = @efi + # # Network # @@ -1072,7 +1086,8 @@ def CreateFile(filename) def AutoInstallRules @mac = getMAC @hostid = getHostid - Builtins.y2milestone("init mac:%1 hostid:%2", @mac, @hostid) + @efi = boot_efi? + log.info "init mac:#{@mac} hostid: #{@hostid} efi: #{@efi}" nil end diff --git a/test/lib/y2erb_test.rb b/test/lib/y2erb_test.rb index 55cb48006..f9c0cd748 100644 --- a/test/lib/y2erb_test.rb +++ b/test/lib/y2erb_test.rb @@ -232,4 +232,26 @@ def hardware_mock_data expect(subject.os_release).to be_a(Hash) end end + + describe "#efi?" do + let(:efi) { "0" } + + before do + allow(Yast::Linuxrc).to receive(:InstallInf).with("EFI").and_return(efi) + end + + context "when the system is boot using efi" do + let(:efi) { "1" } + + it "returns true" do + expect(subject.efi?).to eq(true) + end + end + + context "when the system is boot without UEFI" do + it "returns false" do + expect(subject.efi?).to eq(false) + end + end + end end From edfd5e0bb8a77b11de38d3335bb46c04936ea309 Mon Sep 17 00:00:00 2001 From: Knut Anderssen Date: Thu, 18 Nov 2021 11:17:16 +0000 Subject: [PATCH 2/8] Bump version & changelog --- package/autoyast2.changes | 7 +++++++ package/autoyast2.spec | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/package/autoyast2.changes b/package/autoyast2.changes index 2d5691299..7507ce4e7 100644 --- a/package/autoyast2.changes +++ b/package/autoyast2.changes @@ -1,3 +1,10 @@ +------------------------------------------------------------------- +Thu Nov 18 11:10:28 UTC 2021 - Knut Anderssen + +- Add support for detecting EFI boot during autoinstallation + (jsc#SLE-18819) +- 4.4.21 + ------------------------------------------------------------------- Fri Nov 12 13:21:54 UTC 2021 - Imobach Gonzalez Sosa diff --git a/package/autoyast2.spec b/package/autoyast2.spec index 3a13a9e36..3674ab4ae 100644 --- a/package/autoyast2.spec +++ b/package/autoyast2.spec @@ -22,7 +22,7 @@ %endif Name: autoyast2 -Version: 4.4.20 +Version: 4.4.21 Release: 0 Summary: YaST2 - Automated Installation License: GPL-2.0-only From ffa1786d572a008a684b5d43f1b0c54eb48f1aa2 Mon Sep 17 00:00:00 2001 From: Knut Anderssen Date: Thu, 18 Nov 2021 14:42:56 +0000 Subject: [PATCH 3/8] Use 'yes' and 'no' for matching efi values --- src/lib/autoinstall/clients/ayast_probe.rb | 1 + src/modules/AutoInstallRules.rb | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/lib/autoinstall/clients/ayast_probe.rb b/src/lib/autoinstall/clients/ayast_probe.rb index bc9e01af1..4d1e5b919 100644 --- a/src/lib/autoinstall/clients/ayast_probe.rb +++ b/src/lib/autoinstall/clients/ayast_probe.rb @@ -75,6 +75,7 @@ def table(rows) :hostaddress, :network, :domain, + :efi, :arch, :karch, :product, diff --git a/src/modules/AutoInstallRules.rb b/src/modules/AutoInstallRules.rb index 5b168661a..942baca11 100644 --- a/src/modules/AutoInstallRules.rb +++ b/src/modules/AutoInstallRules.rb @@ -85,7 +85,7 @@ def reset @totaldisk = 0 @hostid = "" @mac = "" - @efi = false + @efi = "no" @linux = 0 @others = 0 @xserver = "" @@ -484,6 +484,7 @@ def Read "installed_product_version", "installed_product", "domain", + "efi", "network", "mac", "karch", @@ -1086,7 +1087,7 @@ def CreateFile(filename) def AutoInstallRules @mac = getMAC @hostid = getHostid - @efi = boot_efi? + @efi = boot_efi? ? "yes" : "no" log.info "init mac:#{@mac} hostid: #{@hostid} efi: #{@efi}" nil end From 19a2907033dd1beafc776e0e1ae502401f813885 Mon Sep 17 00:00:00 2001 From: Knut Anderssen Date: Fri, 19 Nov 2021 08:26:09 +0000 Subject: [PATCH 4/8] Moved efi detection to a module for sharing code --- src/lib/autoinstall/common_helpers.rb | 22 ++++++++++ src/lib/autoinstall/y2erb.rb | 9 +--- src/modules/AutoInstallRules.rb | 10 ++--- test/lib/common_helpers_test.rb | 59 +++++++++++++++++++++++++++ test/lib/y2erb_test.rb | 22 ---------- 5 files changed, 86 insertions(+), 36 deletions(-) create mode 100644 src/lib/autoinstall/common_helpers.rb create mode 100644 test/lib/common_helpers_test.rb diff --git a/src/lib/autoinstall/common_helpers.rb b/src/lib/autoinstall/common_helpers.rb new file mode 100644 index 000000000..932e04ca9 --- /dev/null +++ b/src/lib/autoinstall/common_helpers.rb @@ -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 diff --git a/src/lib/autoinstall/y2erb.rb b/src/lib/autoinstall/y2erb.rb index 8dd49619e..90e369bd6 100644 --- a/src/lib/autoinstall/y2erb.rb +++ b/src/lib/autoinstall/y2erb.rb @@ -1,5 +1,6 @@ require "yast" require "erb" +require "autoinstall/common_helpers" module Y2Autoinstallation class Y2ERB @@ -11,13 +12,7 @@ def self.render(path) class TemplateEnvironment include Yast::Logger - - # @return [Boolean] whether the system was booted using UEFI or not according to linuxrc - def efi? - Yast.import "Linuxrc" - - Yast::Linuxrc.InstallInf("EFI") == "1" - end + include Y2Autoinstallation::CommonHelpers def hardware @hardware ||= Yast::SCR.Read(Yast::Path.new(".probe")) diff --git a/src/modules/AutoInstallRules.rb b/src/modules/AutoInstallRules.rb index 942baca11..21a3dc23e 100644 --- a/src/modules/AutoInstallRules.rb +++ b/src/modules/AutoInstallRules.rb @@ -6,12 +6,14 @@ # $Id$ require "yast" require "autoinstall/xml_checks" +require "autoinstall/common_helpers" require "yast2/popup" require "y2storage" module Yast class AutoInstallRulesClass < Module include Yast::Logger + include Y2Autoinstallation::CommonHelpers def main Yast.import "UI" @@ -141,13 +143,6 @@ def StdErrLog(stderr) nil end - # Returns whether the system was booted using UEFI or not - # - # @return [Boolean] true when the system is booted using EFI - def boot_efi? - Yast::Linuxrc.InstallInf("EFI") == "1" - end - # getMAC() # Return MAC address of active device # @return [String] mac address @@ -1134,6 +1129,7 @@ def hostaddress publish variable: :mac, type: "string" publish variable: :linux, type: "integer" publish variable: :others, type: "integer" + publish variable: :efi, type: "string" publish variable: :xserver, type: "string" publish variable: :NonLinuxPartitions, type: "list" publish variable: :LinuxPartitions, type: "list" diff --git a/test/lib/common_helpers_test.rb b/test/lib/common_helpers_test.rb new file mode 100644 index 000000000..e7d9879d9 --- /dev/null +++ b/test/lib/common_helpers_test.rb @@ -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 diff --git a/test/lib/y2erb_test.rb b/test/lib/y2erb_test.rb index f9c0cd748..55cb48006 100644 --- a/test/lib/y2erb_test.rb +++ b/test/lib/y2erb_test.rb @@ -232,26 +232,4 @@ def hardware_mock_data expect(subject.os_release).to be_a(Hash) end end - - describe "#efi?" do - let(:efi) { "0" } - - before do - allow(Yast::Linuxrc).to receive(:InstallInf).with("EFI").and_return(efi) - end - - context "when the system is boot using efi" do - let(:efi) { "1" } - - it "returns true" do - expect(subject.efi?).to eq(true) - end - end - - context "when the system is boot without UEFI" do - it "returns false" do - expect(subject.efi?).to eq(false) - end - end - end end From 412a89b791b4019aa9b47b002abb8f77b7cc4fc8 Mon Sep 17 00:00:00 2001 From: Knut Anderssen Date: Fri, 19 Nov 2021 09:57:36 +0000 Subject: [PATCH 5/8] Some changes based on CR --- .../{common_helpers.rb => efi_detector.rb} | 2 +- src/lib/autoinstall/y2erb.rb | 9 ++++++-- src/modules/AutoInstallRules.rb | 14 ++++++++---- test/AutoInstallRules_test.rb | 3 +++ ...n_helpers_test.rb => efi_detector_test.rb} | 14 ++---------- test/lib/y2erb_test.rb | 22 +++++++++++++++++++ 6 files changed, 45 insertions(+), 19 deletions(-) rename src/lib/autoinstall/{common_helpers.rb => efi_detector.rb} (96%) rename test/lib/{common_helpers_test.rb => efi_detector_test.rb} (84%) diff --git a/src/lib/autoinstall/common_helpers.rb b/src/lib/autoinstall/efi_detector.rb similarity index 96% rename from src/lib/autoinstall/common_helpers.rb rename to src/lib/autoinstall/efi_detector.rb index 932e04ca9..06778feaf 100644 --- a/src/lib/autoinstall/common_helpers.rb +++ b/src/lib/autoinstall/efi_detector.rb @@ -3,7 +3,7 @@ module Y2Autoinstallation # This module defines some methods that are used by different classes - module CommonHelpers + 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 diff --git a/src/lib/autoinstall/y2erb.rb b/src/lib/autoinstall/y2erb.rb index 90e369bd6..252d7535b 100644 --- a/src/lib/autoinstall/y2erb.rb +++ b/src/lib/autoinstall/y2erb.rb @@ -1,6 +1,6 @@ require "yast" require "erb" -require "autoinstall/common_helpers" +require "autoinstall/efi_detector" module Y2Autoinstallation class Y2ERB @@ -12,7 +12,12 @@ def self.render(path) class TemplateEnvironment include Yast::Logger - include Y2Autoinstallation::CommonHelpers + + # @see {EFIDetector} + # @return [Boolean] whether the system is booted using EFI or not + def boot_efi? + (@efi_detector ||= EFIDetector.new).boot_efi? + end def hardware @hardware ||= Yast::SCR.Read(Yast::Path.new(".probe")) diff --git a/src/modules/AutoInstallRules.rb b/src/modules/AutoInstallRules.rb index 21a3dc23e..9783951ca 100644 --- a/src/modules/AutoInstallRules.rb +++ b/src/modules/AutoInstallRules.rb @@ -6,14 +6,13 @@ # $Id$ require "yast" require "autoinstall/xml_checks" -require "autoinstall/common_helpers" +require "autoinstall/efi_detector" require "yast2/popup" require "y2storage" module Yast class AutoInstallRulesClass < Module include Yast::Logger - include Y2Autoinstallation::CommonHelpers def main Yast.import "UI" @@ -292,7 +291,7 @@ def ProbeRules # # EFI Boot - # + @efi = boot_efi? @ATTR["efi"] = @efi # @@ -1082,11 +1081,18 @@ def CreateFile(filename) def AutoInstallRules @mac = getMAC @hostid = getHostid - @efi = boot_efi? ? "yes" : "no" + @efi = boot_efi? log.info "init mac:#{@mac} hostid: #{@hostid} efi: #{@efi}" nil end + # @see {Y2Autoinstallation::EFIDetector} + # @return [String] "yes" when the system is booted using EFI or "no" when not according to the + # {Y2Autoinstallation::EFIDetector} + def boot_efi? + (@detector ||= Y2Autoinstallation::EFIDetector.new).boot_efi? ? "yes" : "no" + end + # Regexp to extract the IP from the routes table HOSTADDRESS_REGEXP = /src ([\w.]+) /.freeze diff --git a/test/AutoInstallRules_test.rb b/test/AutoInstallRules_test.rb index a62b7d5e2..54c86ce6e 100755 --- a/test/AutoInstallRules_test.rb +++ b/test/AutoInstallRules_test.rb @@ -43,6 +43,8 @@ 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(Yast::SCR).to receive(:Read).with(Yast::Path.new(".etc.install_inf.XServer")) expect(Yast::Hostname).to receive(:CurrentDomain).and_return("mydomain.lan") @@ -55,6 +57,7 @@ expect(Yast::AutoInstallRules.installed_product).to eq("SUSE Linux Enterprise Server 12") expect(Yast::AutoInstallRules.installed_product_version).to eq("12") + expect(Yast::AutoInstallRules.efi).to eq("yes") end end diff --git a/test/lib/common_helpers_test.rb b/test/lib/efi_detector_test.rb similarity index 84% rename from test/lib/common_helpers_test.rb rename to test/lib/efi_detector_test.rb index e7d9879d9..e02c44ec0 100644 --- a/test/lib/common_helpers_test.rb +++ b/test/lib/efi_detector_test.rb @@ -1,17 +1,7 @@ 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 } +require "autoinstall/efi_detector" +describe Y2Autoinstallation::EFIDetector do describe "#boot_efi?" do let(:efi) { true } diff --git a/test/lib/y2erb_test.rb b/test/lib/y2erb_test.rb index 55cb48006..37c19465e 100644 --- a/test/lib/y2erb_test.rb +++ b/test/lib/y2erb_test.rb @@ -212,6 +212,28 @@ def hardware_mock_data allow(Yast::SCR).to receive(:Read).and_return(hardware_mock_data) end + describe "#boot_efi?" do + let(:efi) { true } + + before do + allow_any_instance_of(Y2Autoinstallation::EFIDetector).to receive(:boot_efi?).and_return(efi) + end + + context "when the system was booted with EFI" do + it "returns true" do + expect(subject.boot_efi?).to eq(true) + end + end + + context "when the system was not booted with EFI" do + let(:efi) { false } + + it "returns false" do + expect(subject.boot_efi?).to eq(false) + end + end + end + describe "#network_cards" do it "returns list of map" do expect(subject.network_cards).to be_a(Array) From be3b488edaf2c353f275bb56a9b070adb4e1338c Mon Sep 17 00:00:00 2001 From: Knut Anderssen Date: Fri, 19 Nov 2021 10:04:57 +0000 Subject: [PATCH 6/8] Fixed documentation --- src/lib/autoinstall/y2erb.rb | 2 +- src/modules/AutoInstallRules.rb | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/lib/autoinstall/y2erb.rb b/src/lib/autoinstall/y2erb.rb index 252d7535b..58ea9d59c 100644 --- a/src/lib/autoinstall/y2erb.rb +++ b/src/lib/autoinstall/y2erb.rb @@ -13,7 +13,7 @@ def self.render(path) class TemplateEnvironment include Yast::Logger - # @see {EFIDetector} + # @see Y2Autoinstallation::EFIDetector # @return [Boolean] whether the system is booted using EFI or not def boot_efi? (@efi_detector ||= EFIDetector.new).boot_efi? diff --git a/src/modules/AutoInstallRules.rb b/src/modules/AutoInstallRules.rb index 9783951ca..c96db9ecc 100644 --- a/src/modules/AutoInstallRules.rb +++ b/src/modules/AutoInstallRules.rb @@ -1086,9 +1086,8 @@ def AutoInstallRules nil end - # @see {Y2Autoinstallation::EFIDetector} - # @return [String] "yes" when the system is booted using EFI or "no" when not according to the - # {Y2Autoinstallation::EFIDetector} + # @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" end From e76591ed13e34f4bb7bb4df3494378d49a7c8b34 Mon Sep 17 00:00:00 2001 From: Knut Anderssen Date: Fri, 19 Nov 2021 10:15:06 +0000 Subject: [PATCH 7/8] Use class method and no cache --- src/lib/autoinstall/efi_detector.rb | 13 +++++++------ src/lib/autoinstall/y2erb.rb | 2 +- src/modules/AutoInstallRules.rb | 2 +- test/AutoInstallRules_test.rb | 3 +-- test/lib/y2erb_test.rb | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/lib/autoinstall/efi_detector.rb b/src/lib/autoinstall/efi_detector.rb index 06778feaf..714503d9e 100644 --- a/src/lib/autoinstall/efi_detector.rb +++ b/src/lib/autoinstall/efi_detector.rb @@ -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 diff --git a/src/lib/autoinstall/y2erb.rb b/src/lib/autoinstall/y2erb.rb index 58ea9d59c..e108dac01 100644 --- a/src/lib/autoinstall/y2erb.rb +++ b/src/lib/autoinstall/y2erb.rb @@ -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 diff --git a/src/modules/AutoInstallRules.rb b/src/modules/AutoInstallRules.rb index c96db9ecc..03a850b02 100644 --- a/src/modules/AutoInstallRules.rb +++ b/src/modules/AutoInstallRules.rb @@ -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 diff --git a/test/AutoInstallRules_test.rb b/test/AutoInstallRules_test.rb index 54c86ce6e..bd72526a5 100755 --- a/test/AutoInstallRules_test.rb +++ b/test/AutoInstallRules_test.rb @@ -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") diff --git a/test/lib/y2erb_test.rb b/test/lib/y2erb_test.rb index 37c19465e..30ed1a1b7 100644 --- a/test/lib/y2erb_test.rb +++ b/test/lib/y2erb_test.rb @@ -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 From f3008e048504c3b5157ce3688722a6f8ab4e35d0 Mon Sep 17 00:00:00 2001 From: Knut Anderssen Date: Fri, 19 Nov 2021 10:18:53 +0000 Subject: [PATCH 8/8] Fixed EFIDetector test --- test/lib/efi_detector_test.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/lib/efi_detector_test.rb b/test/lib/efi_detector_test.rb index e02c44ec0..f843a1b06 100644 --- a/test/lib/efi_detector_test.rb +++ b/test/lib/efi_detector_test.rb @@ -2,7 +2,7 @@ require "autoinstall/efi_detector" describe Y2Autoinstallation::EFIDetector do - describe "#boot_efi?" do + describe ".boot_efi?" do let(:efi) { true } context "when called in the initial Stage" do @@ -12,7 +12,7 @@ context "and EFI is read as '1' from the Install.inf file" do it "returns true" do - expect(subject.boot_efi?) + expect(described_class.boot_efi?) end end @@ -20,7 +20,7 @@ let(:efi) { false } it "returns false" do - expect(subject.boot_efi?) + expect(described_class.boot_efi?) end end end @@ -33,7 +33,7 @@ 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) + expect(described_class.boot_efi?).to eq(true) end end @@ -42,7 +42,7 @@ allow(Dir).to receive(:exist?).with(dir).and_return(false) end - expect(subject.boot_efi?).to eq(false) + expect(described_class.boot_efi?).to eq(false) end end end