Skip to content

Commit

Permalink
Some changes based on CR
Browse files Browse the repository at this point in the history
  • Loading branch information
teclator committed Nov 19, 2021
1 parent 19a2907 commit 412a89b
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 19 deletions.
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions 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
Expand All @@ -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"))
Expand Down
14 changes: 10 additions & 4 deletions src/modules/AutoInstallRules.rb
Expand Up @@ -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"
Expand Down Expand Up @@ -292,7 +291,7 @@ def ProbeRules

#
# EFI Boot
#
@efi = boot_efi?
@ATTR["efi"] = @efi

#
Expand Down Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions test/AutoInstallRules_test.rb
Expand Up @@ -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")

Expand All @@ -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

Expand Down
14 changes: 2 additions & 12 deletions test/lib/common_helpers_test.rb → 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 }

Expand Down
22 changes: 22 additions & 0 deletions test/lib/y2erb_test.rb
Expand Up @@ -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)
Expand Down

0 comments on commit 412a89b

Please sign in to comment.