From 412a89b791b4019aa9b47b002abb8f77b7cc4fc8 Mon Sep 17 00:00:00 2001 From: Knut Anderssen Date: Fri, 19 Nov 2021 09:57:36 +0000 Subject: [PATCH] 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)