Skip to content

Commit

Permalink
rubify code slightly
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed May 2, 2014
1 parent fb86296 commit 5263d27
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 190 deletions.
12 changes: 5 additions & 7 deletions src/clients/inst_reiplauto.rb
Expand Up @@ -47,19 +47,17 @@ def main

@args = GetInstArgs.argmap

if Ops.get_string(@args, "first_run", "yes") != "no"
Ops.set(@args, "first_run", "yes")
end
# first run unless explicitelly mentioned
@args["first_run"] = "yes" if @args["first_run"] != "no"

Wizard.HideAbortButton if Mode.mode == "firstboot"

@rc = true

@configuration = Reipl.ReadState

if @configuration != nil

if Reipl.IPL_from_boot_zipl == false
if !@configuration.nil?
if !Reipl.IPL_from_boot_zipl
Builtins.y2error("Could not modify reipl configuration")
end
else
Expand All @@ -69,7 +67,7 @@ def main
# Finish
Builtins.y2milestone("inst_reiplauto finished ----------------------------------------")

:next
:next

# EOF
end
Expand Down
61 changes: 14 additions & 47 deletions src/clients/reipl_bootloader_finish.rb
Expand Up @@ -29,60 +29,27 @@ def main
if Arch.s390
@oldConfiguration = Reipl.ReadState

if Reipl.IPL_from_boot_zipl == false
if !Reipl.IPL_from_boot_zipl
@newConfiguration = Reipl.ReadState

@oldCcwMap = Ops.get_map(@oldConfiguration, "ccw")
@newCcwMap = Ops.get_map(@newConfiguration, "ccw")
@oldFcpMap = Ops.get_map(@oldConfiguration, "fcp")
@newFcpMap = Ops.get_map(@newConfiguration, "fcp")

@different = Ops.get_string(@oldConfiguration, "method", "a") != Ops.get_string(@newConfiguration, "method", "b") ||
Ops.get_string(@oldCcwMap, "device", "a") != Ops.get_string(@newCcwMap, "device", "b") ||
Ops.get_string(@oldCcwMap, "loadparm", "a") != Ops.get_string(@newCcwMap, "loadparm", "b") ||
Ops.get_string(@oldCcwMap, "parm", "a") != Ops.get_string(@newCcwMap, "parm", "b") ||
Ops.get_string(@oldFcpMap, "device", "a") != Ops.get_string(@newFcpMap, "device", "b") ||
Ops.get_string(@oldFcpMap, "wwpn", "a") != Ops.get_string(@newFcpMap, "wwpn", "b") ||
Ops.get_string(@oldFcpMap, "lun", "a") != Ops.get_string(@newFcpMap, "lun", "b") ||
Ops.get_string(@oldFcpMap, "bootprog", "a") != Ops.get_string(@newFcpMap, "bootprog", "b") ||
Ops.get_string(@oldFcpMap, "br_lba", "a") != Ops.get_string(@newFcpMap, "br_lba", "b")

Builtins.y2milestone(
"(oldConfiguration['method']:'a' != newConfiguration['method']:'b') = %1",
Ops.get_string(@oldConfiguration, "method", "a") != Ops.get_string(@newConfiguration, "method", "b")
)
Builtins.y2milestone(
"(oldCcwMap['device']:'a' != newCcwMap['device']:'b') = %1",
Ops.get_string(@oldCcwMap, "device", "a") != Ops.get_string(@newCcwMap, "device", "b")
)
Builtins.y2milestone(
"(oldCcwMap['loadparm']:'a' != newCcwMap['loadparm']:'b') = %1",
Ops.get_string(@oldCcwMap, "loadparm", "a") != Ops.get_string(@newCcwMap, "loadparm", "b")
)
Builtins.y2milestone(
"(oldCcwMap['parm']:'a' != newCcwMap['parm']:'b') = %1",
Ops.get_string(@oldCcwMap, "parm", "a") != Ops.get_string(@newCcwMap, "parm", "b")
)
Builtins.y2milestone(
"(oldFcpMap['device']:'a' != newFcpMap['device']:'b') = %1",
Ops.get_string(@oldFcpMap, "device", "a") != Ops.get_string(@newFcpMap, "device", "b")
)
Builtins.y2milestone(
"(oldFcpMap['wwpn']:'a' != newFcpMap['wwpn']:'b') = %1",
Ops.get_string(@oldFcpMap, "wwpn", "a") != Ops.get_string(@newFcpMap, "wwpn", "b")
)
Builtins.y2milestone(
"(oldFcpMap['lun']:'a' != newFcpMap['lun']:'b') = %1",
Ops.get_string(@oldFcpMap, "lun", "a") != Ops.get_string(@newFcpMap, "lun", "b")
)
Builtins.y2milestone(
"(oldFcpMap['bootprog']:'a' != newFcpMap['bootprog']:'b') = %1",
Ops.get_string(@oldFcpMap, "bootprog", "a") != Ops.get_string(@newFcpMap, "bootprog", "b")
)
Builtins.y2milestone(
"(oldFcpMap['br_lba']:'a' != newFcpMap['br_lba']:'b') = %1",
Ops.get_string(@oldFcpMap, "br_lba", "a") != Ops.get_string(@newFcpMap, "br_lba", "b")
)
ccw_different = ["device", "loadparm", "parm"].any? do |param|
# TODO: why two nils are different?
res = @oldCcwMap[param].nil? || @newCcwMap[param].nil? || @oldCcwMap[param] != @newCcwMap[param]
Builtins.y2milestone "ccw comparison for '#{param}' is different?: #{res}"
res
end
fcp_different = ["device", "wwpn", "lun", "bootprog", "br_lba"].any? do |param|
# TODO: why two nils are different?
res = @oldFcpMap[param].nil? || @newFcpMap[param].nil? || @oldFcpMap[param] != @newFcpMap[param]
Builtins.y2milestone "fcp comparison for '#{param}' is different?: #{res}"
res
end
@different = ccw_different || fcp_different
Builtins.y2milestone("different = %1", @different)

Builtins.y2milestone("newConfiguration['method'] : %1", Ops.get_string(@newConfiguration, "method", "ERROR"))
Expand Down
63 changes: 16 additions & 47 deletions src/clients/reipl_finish.rb
Expand Up @@ -24,7 +24,8 @@ def main
if Arch.s390
@oldConfiguration = Reipl.ReadState

if Reipl.IPL_from_boot_zipl == false
# FIXME almost same code as reipl_bootloader_finish and this client is not called at all now
if Reipl.IPL_from_boot_zipl

@newConfiguration = Reipl.ReadState

Expand All @@ -33,52 +34,20 @@ def main
@oldFcpMap = Ops.get_map(@oldConfiguration, "fcp")
@newFcpMap = Ops.get_map(@newConfiguration, "fcp")

@different = Ops.get_string(@oldConfiguration, "method", "a") != Ops.get_string(@newConfiguration, "method", "b") ||
Ops.get_string(@oldCcwMap, "device", "a") != Ops.get_string(@newCcwMap, "device", "b") ||
Ops.get_string(@oldCcwMap, "loadparm", "a") != Ops.get_string(@newCcwMap, "loadparm", "b") ||
Ops.get_string(@oldCcwMap, "parm", "a") != Ops.get_string(@newCcwMap, "parm", "b") ||
Ops.get_string(@oldFcpMap, "device", "a") != Ops.get_string(@newFcpMap, "device", "b") ||
Ops.get_string(@oldFcpMap, "wwpn", "a") != Ops.get_string(@newFcpMap, "wwpn", "b") ||
Ops.get_string(@oldFcpMap, "lun", "a") != Ops.get_string(@newFcpMap, "lun", "b") ||
Ops.get_string(@oldFcpMap, "bootprog", "a") != Ops.get_string(@newFcpMap, "bootprog", "b") ||
Ops.get_string(@oldFcpMap, "br_lba", "a") != Ops.get_string(@newFcpMap, "br_lba", "b")

Builtins.y2milestone(
"(oldConfiguration['method']:'a' != newConfiguration['method']:'b') = %1",
Ops.get_string(@oldConfiguration, "method", "a") != Ops.get_string(@newConfiguration, "method", "b")
)
Builtins.y2milestone(
"(oldCcwMap['device']:'a' != newCcwMap['device']:'b') = %1",
Ops.get_string(@oldCcwMap, "device", "a") != Ops.get_string(@newCcwMap, "device", "b")
)
Builtins.y2milestone(
"(oldCcwMap['loadparm']:'a' != newCcwMap['loadparm']:'b') = %1",
Ops.get_string(@oldCcwMap, "loadparm", "a") != Ops.get_string(@newCcwMap, "loadparm", "b")
)
Builtins.y2milestone(
"(oldCcwMap['parm']:'a' != newCcwMap['parm']:'b') = %1",
Ops.get_string(@oldCcwMap, "parm", "a") != Ops.get_string(@newCcwMap, "parm", "b")
)
Builtins.y2milestone(
"(oldFcpMap['device']:'a' != newFcpMap['device']:'b') = %1",
Ops.get_string(@oldFcpMap, "device", "a") != Ops.get_string(@newFcpMap, "device", "b")
)
Builtins.y2milestone(
"(oldFcpMap['wwpn']:'a' != newFcpMap['wwpn']:'b') = %1",
Ops.get_string(@oldFcpMap, "wwpn", "a") != Ops.get_string(@newFcpMap, "wwpn", "b")
)
Builtins.y2milestone(
"(oldFcpMap['lun']:'a' != newFcpMap['lun']:'b') = %1",
Ops.get_string(@oldFcpMap, "lun", "a") != Ops.get_string(@newFcpMap, "lun", "b")
)
Builtins.y2milestone(
"(oldFcpMap['bootprog']:'a' != newFcpMap['bootprog']:'b') = %1",
Ops.get_string(@oldFcpMap, "bootprog", "a") != Ops.get_string(@newFcpMap, "bootprog", "b")
)
Builtins.y2milestone(
"(oldFcpMap['br_lba']:'a' != newFcpMap['br_lba']:'b') = %1",
Ops.get_string(@oldFcpMap, "br_lba", "a") != Ops.get_string(@newFcpMap, "br_lba", "b")
)
ccw_different = ["device", "loadparm", "parm"].any? do |param|
# TODO: why two nils are different?
res = @oldCcwMap[param].nil? || @newCcwMap[param].nil? || @oldCcwMap[param] != @newCcwMap[param]
Builtins.y2milestone "ccw comparison for '#{param}' is different?: #{res}"
res
end
fcp_different = ["device", "wwpn", "lun", "bootprog", "br_lba"].any? do |param|
# TODO: why two nils are different?
res = @oldFcpMap[param].nil? || @newFcpMap[param].nil? || @oldFcpMap[param] != @newFcpMap[param]
Builtins.y2milestone "fcp comparison for '#{param}' is different?: #{res}"
res
end

@different = ccw_different || fcp_different
Builtins.y2milestone("different = %1", @different)
end

Expand Down
22 changes: 4 additions & 18 deletions src/include/reipl/dialogs.rb
Expand Up @@ -42,33 +42,18 @@ def initialize_reipl_dialogs(include_target)
# Configure dialog
# @return dialog result
def ConfigureDialog
ccw_map = Convert.convert(
Ops.get(Reipl.reipl_configuration, "ccw") do
ccw_map = Reipl.reipl_configuration["ccw"] ||
{ "device" => "", "loadparm" => "" }
end,
:from => "any",
:to => "map <string, string>"
)
fcp_map = Convert.convert(
Ops.get(Reipl.reipl_configuration, "fcp") do
fcp_map = Reipl.reipl_configuration["fcp"] ||
{
"device" => "",
"wwpn" => "",
"lun" => "",
"bootprog" => "",
"br_lba" => ""
}
end,
:from => "any",
:to => "map <string, string>"
)
nss_map = Convert.convert(
Ops.get(Reipl.reipl_configuration, "nss") do
nss_map = Reipl.reipl_configuration["nss"] ||
{ "name" => "" }
end,
:from => "any",
:to => "map <string, string>"
)

# Reipl configure dialog caption
caption = _("Reipl Configuration")
Expand Down Expand Up @@ -310,6 +295,7 @@ def ConfigureDialog
elsif ret == :useccw
next
elsif ret == :usenss
next
else
Builtins.y2error("unexpected retcode: %1", ret)
next
Expand Down
108 changes: 37 additions & 71 deletions src/modules/Reipl.rb
Expand Up @@ -76,19 +76,19 @@ def main
# ]
#];

@reipl_directory = Ops.add("/sys", "/firmware/reipl")
@ccw_directory = Ops.add(@reipl_directory, "/ccw")
@fcp_directory = Ops.add(@reipl_directory, "/fcp")
@nss_directory = Ops.add(@reipl_directory, "/nss")
@ccw_exists = FileUtils.IsDirectory(@ccw_directory) != nil
@fcp_exists = FileUtils.IsDirectory(@fcp_directory) != nil
@nss_exists = FileUtils.IsDirectory(@fcp_directory) != nil
@reipl_directory = "/sys/firmware/reipl"
@ccw_directory = @reipl_directory + "/ccw"
@fcp_directory = @reipl_directory + "/fcp"
@nss_directory = @reipl_directory + "/nss"
@ccw_exists = FileUtils.IsDirectory(@ccw_directory)
@fcp_exists = FileUtils.IsDirectory(@fcp_directory)
@nss_exists = FileUtils.IsDirectory(@fcp_directory)
end

# Abort function
# @return [Boolean] return true if abort
def Abort
return @AbortFunction.call == true if @AbortFunction != nil
return @AbortFunction.call if @AbortFunction
false
end

Expand All @@ -114,24 +114,8 @@ def SetModified
# @return a map of the new target configuration.
def IPL_from_boot_zipl
# get target information
# result = Yast::SCR.Execute(path(".target.bash_output"), "lsreipl")
# raise "Calling lsreipl failed with #{result["stderr"]}" unless result["exit"].zero?
#
# lines = result["stdout"].split("\n")
# type = lines[0][/ccw$|fcp$|node$/]
# raise "Ergebnis ist #{type} IHNO"
#
result = Yast::SCR.Execute(path(".target.bash_output"), "chreipl node /mnt/boot/zipl")
if Ops.get(result, "exit") == 0
rc = true
else
rc = false
end

# ipl_from_boot_zipl_lines = result["stdout"].split("\n")
# type = ipl_from_boot_zipl_lines[0][/ccw$|fcp$|node$/]

rc
result = Yast::SCR.Execute(path(".target.bash_output"), "chreipl node /mnt/boot/zipl")
return result["exit"] == 0
end

# Read all reipl settings
Expand All @@ -155,45 +139,31 @@ def ReadState
{ "name" => "", "loadparm" => "", "parm" => "" }
)

# if !SanityCheck()
# Builtins.y2error("Reipl::Read: SanityCheck failed!")
#
# # Popup::Error (_("This machine does not support reipl!"));
# # Don't bother the user, just silently do shutdown in the end.
# # Especially, since this would currently popup three times
# # during installation.
#
# return deep_copy(configuration)
# end

result = Yast::SCR.Execute(path(".target.bash_output"), "lsreipl")
raise "Calling lsreipl failed with #{result["stderr"]}" unless result["exit"].zero?

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 \""))
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 \""))
Ops.set(configuration, "fcp", fcp_map)

# raise "Ergebnis ist #{Ops.get(ccw_map,"device")} #{Ops.get(ccw_map,"loadparm")} #{Ops.get(ccw_map,"parm")} IHNO"
end
# raise "Ergebnis ist #{type} IHNO"

Ops.set(configuration, "method", type)
result = Yast::SCR.Execute(path(".target.bash_output"), "lsreipl")
raise "Calling lsreipl failed with #{result["stderr"]}" unless result["exit"].zero?

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 \""))
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 \""))
Ops.set(configuration, "fcp", fcp_map)

end

configuration["method"] = type

deep_copy(configuration)
end
Expand All @@ -203,7 +173,7 @@ def ReadState
def Read
configuration = ReadState()

@reipl_configuration = deep_copy(configuration) if configuration != nil
@reipl_configuration = deep_copy(configuration) if configuration

return false if Abort()
@modified = false
Expand Down Expand Up @@ -253,7 +223,6 @@ def WriteState(configuration)

device = Ops.get_string(fcp_map, "device") + " " + Ops.get_string(fcp_map, "wwpn") + " " + Ops.get_string(fcp_map, "lun")
loadparm = Ops.get_string(fcp_map, "loadparm", "???")
# loadparm = Ops.add(loadparm, Ops.add(" -b ", Ops.get_string(fcp_map, "bootprog")), "\" > ")

Builtins.y2milestone("FCP Device %1, loadparm %2 %1", device, loadparm)

Expand All @@ -273,7 +242,7 @@ def WriteState(configuration)
# now type, device, loadparm contain all what is needed to call chreipl
chreiplCmd = "chreipl " + type + " " + device
if loadparm != ""
chreiplCmd = chreiplCmd + " -L " + loadparm
chreiplCmd << " -L " + loadparm
end
Builtins.y2milestone("Executing %1", chreiplCmd)
result = Convert.to_map(SCR.Execute(path(".target.bash_output"), chreiplCmd))
Expand Down Expand Up @@ -420,7 +389,6 @@ def AutoPackages
publish :variable => :AbortFunction, :type => "boolean ()"
publish :function => :Abort, :type => "boolean ()"
publish :function => :SetModified, :type => "void ()"
# publish :function => :FindSysfsRoot, :type => "string ()"
publish :variable => :reipl_configuration, :type => "map <string, any>"
publish :variable => :reipl_directory, :type => "string"
publish :variable => :ccw_directory, :type => "string"
Expand All @@ -429,8 +397,6 @@ def AutoPackages
publish :variable => :ccw_exists, :type => "boolean"
publish :variable => :fcp_exists, :type => "boolean"
publish :variable => :nss_exists, :type => "boolean"
# publish :function => :SanityCheck, :type => "boolean ()"
# publish :function => :FindBootPartition, :type => "list <string> ()"
publish :function => :IPL_from_boot_zipl, :type => "boolean ()"
publish :function => :ReadState, :type => "map <string, any> ()"
publish :function => :Read, :type => "boolean ()"
Expand Down

0 comments on commit 5263d27

Please sign in to comment.