Skip to content
Permalink
Browse files

Fix AutoInstallRules#ProbeRules to not crash when .content.DISTRO is nil

  • Loading branch information...
imobachgs committed Apr 7, 2015
1 parent 57d5d44 commit 1b9c344c86ab04d23b38c1dbacb074b547fcdb48
Showing with 26 additions and 23 deletions.
  1. +11 −23 src/modules/AutoInstallRules.rb
  2. +15 −0 test/AutoInstallRules_test.rb
@@ -36,6 +36,14 @@ def main

Yast.include self, "autoinstall/io.rb"

reset
AutoInstallRules()
end

# Reset the module's state
#
# @return nil
def reset
@userrules = false
@dontmergeIsDefault = true
@dontmergeBackup = []
@@ -50,19 +58,12 @@ def main
@ATTR = {}

@installed_product = ""

@installed_product_version = ""

@hostname = ""

@hostaddress = ""

@network = ""

@domain = ""

@arch = ""

@karch = ""

# Taken from smbios
@@ -78,41 +79,28 @@ def main
@board = ""

@memsize = 0

@disksize = []

@totaldisk = 0

@hostid = ""

@mac = ""

@linux = 0

@others = 0

@xserver = ""

@haspcmcia = "0"

#///////////////////////////////////////////
#///////////////////////////////////////////

@NonLinuxPartitions = []

@LinuxPartitions = []


@UserRules = {}

# Local Variables
@shell = ""
@env = {}

@tomerge = []

@element2file = {}
AutoInstallRules()
nil
end

# Cleanup XML file from namespaces put by xslt
@@ -322,8 +310,8 @@ def ProbeRules
distro_str = SCR.Read(path(".content.DISTRO"))
log.info "DISTRO: #{distro_str}"

distro = distro_map(distro_str)
cpe = distro ? cpeid_map(distro["cpeid"]) : {}
distro = distro_map(distro_str) || {}
cpe = cpeid_map(distro["cpeid"]) || {}

@installed_product = distro["name"] || ""
@installed_product_version = cpe["version"] || ""
@@ -96,6 +96,21 @@
expect(Yast::AutoInstallRules.installed_product).to eq("SUSE Linux Enterprise Server 12")
expect(Yast::AutoInstallRules.installed_product_version).to eq("12")
end

context "when .content.DISTRO is not found" do
before(:each) do
subject.reset
allow(Yast::SCR).to receive(:Read).with(any_args)
end

it 'set installed_product and installed_product_version to blank string' do
expect(Yast::SCR).to receive(:Read).with(Yast::Path.new(".content.DISTRO")).
and_return(nil)
subject.ProbeRules
expect(Yast::AutoInstallRules.installed_product).to eq('')
expect(Yast::AutoInstallRules.installed_product_version).to eq('')
end
end
end

end

0 comments on commit 1b9c344

Please sign in to comment.
You can’t perform that action at this time.