Skip to content

Commit

Permalink
Fix AutoInstallRules#ProbeRules to not crash when .content.DISTRO is nil
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Apr 7, 2015
1 parent 57d5d44 commit 1b9c344
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
34 changes: 11 additions & 23 deletions src/modules/AutoInstallRules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand All @@ -50,19 +58,12 @@ def main
@ATTR = {}

@installed_product = ""

@installed_product_version = ""

@hostname = ""

@hostaddress = ""

@network = ""

@domain = ""

@arch = ""

@karch = ""

# Taken from smbios
Expand All @@ -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
Expand Down Expand Up @@ -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"] || ""
Expand Down
15 changes: 15 additions & 0 deletions test/AutoInstallRules_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.