Skip to content

Commit

Permalink
fixed parsing of lsreipl output
Browse files Browse the repository at this point in the history
  • Loading branch information
schubi2 committed Nov 6, 2014
1 parent d65568c commit 7e0c55d
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/modules/Reipl.rb
Expand Up @@ -133,20 +133,20 @@ def ReadState
lsreipl_lines = result["stdout"].split("\n")
type = lsreipl_lines[0][/ccw$|fcp$|node$/]
if type == "ccw"
ccw_map = Ops.get_map(configuration, "ccw")
Ops.set(ccw_map, "device", Builtins.deletechars(Convert.to_string(lsreipl_lines[1][/[0-3]\.[0-3]\.[\h.]*$/]), "\n "))
Ops.set(ccw_map, "loadparm", Builtins.deletechars(Convert.to_string(lsreipl_lines[2][/".*"$/]), "\n \""))
Ops.set(ccw_map, "parm", Builtins.deletechars(Convert.to_string(lsreipl_lines[3][/".*"$/]), "\n \""))
ccw_map = configuration["ccw"]
ccw_map["device"] = Builtins.deletechars(Convert.to_string(lsreipl_lines[1][/[0-3]\.[0-3]\.[\h.]*$/]), "\n ") if lsreipl_lines[1]
ccw_map["loadparm"] = Builtins.deletechars(Convert.to_string(lsreipl_lines[2][/".*"$/]), "\n \"") if lsreipl_lines[2]
ccw_map["parm"] = Builtins.deletechars(Convert.to_string(lsreipl_lines[3][/".*"$/]), "\n \"") if lsreipl_lines[3]
Ops.set(configuration, "ccw", ccw_map)
end
if type == "fcp"
fcp_map = Ops.get_map(configuration, "fcp")
Ops.set(ccw_map, "wwpm", Builtins.deletechars(Convert.to_string(lsreipl_lines[1][/[x\h]*$/]), "\n "))
Ops.set(ccw_map, "lun", Builtins.deletechars(Convert.to_string(lsreipl_lines[2][/[x\h]*$/]), "\n "))
Ops.set(ccw_map, "device", Builtins.deletechars(Convert.to_string(lsreipl_lines[3][/[0-3]\.[0-3]\.[\h.]*$/]), "\n "))
Ops.set(ccw_map, "bootprog", Builtins.deletechars(Convert.to_string(lsreipl_lines[4][/[0-9]*$/]), "\n "))
Ops.set(ccw_map, "br_lbr", Builtins.deletechars(Convert.to_string(lsreipl_lines[5][/[0-9]*$/]), "\n "))
Ops.set(ccw_map, "bootparms", Builtins.deletechars(Convert.to_string(lsreipl_lines[6][/".*"*$/]), "\n \""))
fcp_map = configuration["fcp"]
ccw_map["wwpm"] = Builtins.deletechars(Convert.to_string(lsreipl_lines[1][/[x\h]*$/]), "\n ") if lsreipl_lines[1]
ccw_map["lun"] = Builtins.deletechars(Convert.to_string(lsreipl_lines[2][/[x\h]*$/]), "\n ") if lsreipl_lines[2]
ccw_map["device"] = Builtins.deletechars(Convert.to_string(lsreipl_lines[3][/[0-3]\.[0-3]\.[\h.]*$/]), "\n ") if lsreipl_lines[3]
ccw_map["bootprog"] = Builtins.deletechars(Convert.to_string(lsreipl_lines[4][/[0-9]*$/]), "\n ") if lsreipl_lines[4]
ccw_map["br_lbr"] = Builtins.deletechars(Convert.to_string(lsreipl_lines[5][/[0-9]*$/]), "\n ") if lsreipl_lines[5]
ccw_map["bootparms"] = Builtins.deletechars(Convert.to_string(lsreipl_lines[6][/".*"*$/]), "\n \"") if lsreipl_lines[6]
Ops.set(configuration, "fcp", fcp_map)
end

Expand Down
11 changes: 11 additions & 0 deletions test/Makefile.am
@@ -0,0 +1,11 @@
#
# Makefile.am for reipl/test
#

TESTS = Reipl_test.rb

TEST_EXTENSIONS = .rb
RB_LOG_COMPILER = rspec
VERBOSE = 1
EXTRA_DIST = $(TESTS)

28 changes: 28 additions & 0 deletions test/Reipl_test.rb
@@ -0,0 +1,28 @@
#!/usr/bin/rspec

ENV["Y2DIR"] = File.expand_path("../../src", __FILE__)

require "yast"
Yast.import "Reipl"

describe "Reipl#ReadState" do
it "returns map of lsreipl call" do
lsreipl_output = "Re-IPL type: ccw
Device: 0.0.7e64
Loadparm: \"\""

lsreipl_map = {
"ccw" => {"device"=>"0.0.7e64", "loadparm"=>"", "parm"=>""},
"fcp" => {"device"=>"", "wwpn"=>"", "lun"=>"",
"bootprog"=>"", "br_lba"=>"", "bootparms"=>""},
"method" => "ccw",
"nss" => {"name"=>"", "loadparm"=>"", "parm"=>""}
}

expect(Yast::SCR).to receive(:Execute).with(anything(), /lsreipl/).and_return({ "exit" => 0, "stderr" => "", "stdout" => lsreipl_output })


expect(Yast::Reipl.ReadState()).to eq( lsreipl_map )
end

end

0 comments on commit 7e0c55d

Please sign in to comment.