Skip to content

Commit

Permalink
clean TODOs and implement back some Bootloader API calls
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Apr 13, 2016
1 parent e77dcc8 commit 6ae9676
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 199 deletions.
24 changes: 3 additions & 21 deletions src/lib/bootloader/auto_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,10 @@ def run
end

def import(data)
Yast::BootStorage.detect_disks

imported_configuration = AutoyastConverter.import(data)
BootloaderFactory.clear_cache

proposed_configuration = BootloaderFactory.bootloader_by_name(imported_configuration.name)
proposed_configuration.propose

proposed_configuration.merge(imported_configuration)
BootloaderFactory.current = proposed_configuration
Yast::Bootloader.Import(data)

Yast::PackagesProposal.AddResolvables("yast2-bootloader",
:package, proposed_configuration.packages)
:package, BootloaderFactory.current..packages)

true
end
Expand Down Expand Up @@ -75,16 +66,7 @@ def change
#
# return map or list
def export
# it is needed to have information about storage configuration to understand current config
Yast::BootStorage.detect_disks

config = BootloaderFactory.current
config.read if !config.read? && !config.proposed?
result = AutoyastConverter.export(config)

log.info "autoyast map for bootloader: #{result.inspect}"

result
Yast::Bootloader.Export
end

def write
Expand Down
2 changes: 2 additions & 0 deletions src/lib/bootloader/autoyast_converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class << self
include Yast::Logger

def import(data)
log.info "import data #{data.inspect}"

bootloader = bootloader_from_data(data)
return bootloader if bootloader.name == "none"
# let it be empty if not defined to keep code simplier as effect is same
Expand Down
1 change: 0 additions & 1 deletion src/lib/bootloader/grub2_widgets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,6 @@ def initialize
end

def contents
# TODO: simplify a bit content or split it
VBox(
graphical_console_frame,
serial_console_frame
Expand Down
12 changes: 8 additions & 4 deletions src/lib/bootloader/grub2base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,17 +153,21 @@ def merge_password(other)
@password = other.password
end

KERNEL_FLAVORS_METHODS = [:kernel_params, :xen_hypervisor_params, :xen_kernel_params]

def merge_grub_default(other)
default = grub_default
other = other.grub_default

log.info "before merge default #{default.inspect}"
log.info "before merge other #{other.inspect}"

# TODO: other kernel flavors probably will be also needed
unless other.kernel_params.serialize.empty?
new_kernel_params = default.kernel_params.serialize + " " + other.kernel_params.serialize
default.kernel_params.replace(new_kernel_params)
KERNEL_FLAVORS_METHODS.each do |method|
unless other.public_send(method).empty?
new_kernel_params = default.public_send(method).serialize +
" " + other.public_send(method).serialize
default.public_send(method).replace(new_kernel_params)
end
end

merge_attributes(default, other)
Expand Down
15 changes: 0 additions & 15 deletions src/lib/bootloader/udev_mapping.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,10 @@ class UdevMapping
class << self
extend Forwardable
def_delegators :instance,
:to_hash,
:to_kernel_device,
:to_mountby_device
end

# Returns hash where keys are udev links for disks and partitions and value
# their kernel devices.
# TODO: remove when remove pbl support
# @example of output
# {
# "/dev/disk/by-id/abcd" => "/dev/sda",
# "/dev/disk/by-id/abcde" => "/dev/sda",
# "/dev/disk/by-label/label1" => "/dev/sda1",
# "/dev/disk/by-uuid/aaaa-bbbb-cccc-dddd" => "/dev/sda",
# }
def to_hash
all_devices
end

# Converts full udev name to kernel device ( disk or partition )
# @param dev [String] device udev, mdadm or kernel name like /dev/disk/by-id/blabla
# @raise when device have udev format but do not exists
Expand Down
201 changes: 54 additions & 147 deletions src/modules/Bootloader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,25 @@
require "bootloader/bootloader_factory"
require "cfa/matcher"

Yast.import "UI"
Yast.import "Arch"
Yast.import "BootStorage"
Yast.import "Initrd"
Yast.import "Mode"
Yast.import "Progress"
Yast.import "Stage"
Yast.import "Storage"
Yast.import "StorageDevices"

module Yast
class BootloaderClass < Module
include Yast::Logger

BOOLEAN_MAPPING = { true => :present, false => :missing }

def main
Yast.import "UI"

textdomain "bootloader"

Yast.import "Arch"
Yast.import "BootStorage"
Yast.import "Installation"
Yast.import "Initrd"
Yast.import "Kernel"
Yast.import "Mode"
Yast.import "Progress"
Yast.import "Stage"
Yast.import "Storage"
Yast.import "StorageDevices"
Yast.import "Directory"

# fate 303395
Yast.import "ProductFeatures"
# Write is repeating again
# Because of progress bar during inst_finish
@repeating_write = false

# installation proposal help variables

# Configuration was changed during inst. proposal if true
Expand Down Expand Up @@ -84,57 +74,34 @@ def checkUsedStorage
# Export bootloader settings to a map
# @return bootloader settings
def Export
ReadOrProposeIfNeeded()
# TODO: implement it using new way
# out = {
# "loader_type" => getLoaderType,
# "initrd" => Initrd.Export,
# "specific" => blExport,
# "write_settings" => BootCommon.write_settings,
# "loader_device" => BootCommon.loader_device,
# "loader_location" => BootCommon.selected_location
# }
# log.info "Exporting settings: #{out}"
# out
{}
Yast::BootStorage.detect_disks

config = Bootloader::BootloaderFactory.current
config.read if !config.read? && !config.proposed?
result = Bootloader::AutoyastConverter.export(config)

log.info "autoyast map for bootloader: #{result.inspect}"

result
end

# Import settings from a map
# @param [Hash] settings map of bootloader settings
# @param [Hash] data map of bootloader settings
# @return [Boolean] true on success
def Import(settings)
settings = deep_copy(settings)
log.info "Importing settings: #{settings}"
# TODO: implement it using new way
# Reset()
#
# BootCommon.was_read = true
# BootCommon.was_proposed = true
# BootCommon.changed = true
# BootCommon.location_changed = true
#
# settings["loader_type"] = nil if settings["loader_type"] == ""
# # if bootloader is not set, then propose it
# loader_type = settings["loader_type"] || BootCommon.getLoaderType(true)
# # Explitelly set it to ensure it is installed
# BootCommon.setLoaderType(loader_type)
#
# # import loader_device and selected_location only for bootloaders
# # that have not phased them out yet
# BootCommon.loader_device = settings["loader_device"] || ""
# BootCommon.selected_location = settings["loader_location"] || "custom"
#
# # FIXME: obsolete for grub (but inactive through the outer "if" now anyway):
# # for grub, always correct the bootloader device according to
# # selected_location (or fall back to value of loader_device)
# if Arch.i386 || Arch.x86_64
# BootCommon.loader_device = BootCommon.GetBootloaderDevice
# end
#
# Initrd.Import(settings["initrd"] || {})
# ret = blImport(settings["specific"] || {})
# BootCommon.write_settings = settings["write_settings"] || {}
# ret
def Import(data)
Yast::BootStorage.detect_disks

imported_configuration = Bootloader::AutoyastConverter.import(data)
Bootloader::BootloaderFactory.clear_cache

proposed_configuration = Bootloader::BootloaderFactory
.bootloader_by_name(imported_configuration.name)
proposed_configuration.propose

proposed_configuration.merge(imported_configuration)
Bootloader::BootloaderFactory.current = proposed_configuration

true
end

# Read settings from disk
Expand Down Expand Up @@ -201,9 +168,16 @@ def Read
def Reset
return if Mode.autoinst
log.info "Reseting configuration"
# TODO: consider what to actually do in reset

nil
::Bootloader::BootloaderFactory.clear_cache
if Stage.initial
config = ::Bootloader::BootloaderFactory.proposed
config.propose
else
config = ::Bootloader::BootloaderFactory.system
config.read
end
::Bootloader::BootloaderFactory.current = config
end

# Propose bootloader settings
Expand Down Expand Up @@ -274,72 +248,26 @@ def Write
Progress.Title(titles[0])
end

params_to_save = {}
ret = write_initrd(params_to_save)
ret = write_initrd

log.error "Error occurred while creating initrd" unless ret

if Mode.normal
Progress.NextStage
else
Progress.NextStep if !@repeating_write
Progress.Title(titles[1])
end
Progress.NextStep
Progress.Title(titles[1]) unless Mode.normal

::Bootloader::BootloaderFactory.current.write

true
end

# Write bootloader settings during installation
# @return [Boolean] true on success
def WriteInstallation
log.info "Writing bootloader configuration during installation"

mark_as_changed

params_to_save = {}
ret = write_initrd(params_to_save)

log.error "Error occurred while creating initrd" unless ret

write_sysconfig
write_proposed_params(params_to_save)

return ret if getLoaderType == "none"

# F#300779 - Install diskless client (NFS-root)
# kokso: bootloader will not be installed
if BootStorage.disk_with_boot_partition == "/dev/nfs"
log.info "Bootloader::Write() -> Boot partition is nfs type, bootloader will not be installed."
return ret
end

# F#300779 -end

# save bootloader settings
reinit = !(Mode.update || Mode.normal)
log.info "Reinitialize bootloader library before saving: #{reinit}"

ret = blSave(true, reinit, true) && ret

log.eror "Error before configuration files saving finished" unless ret

# call bootloader executable
log.info "Calling bootloader executable"
ret &&= blWrite
ret = handle_failed_write unless ret

ret
end

# return default section label
# @return [String] default section label
def getDefaultSection
ReadOrProposeIfNeeded()

""
# FIXME: use bootloader factory to get it
bootloader = Bootloader::BootloaderFactory.current
return "" unless bootloader.respond_to?(:sections)
bootloader.sections.default
end

FLAVOR_KERNEL_LINE_MAP = {
Expand Down Expand Up @@ -422,9 +350,8 @@ def modify_kernel_params(*args)
grub_default = current_bl.grub_default

values = args.pop
if !values.is_a? Hash
raise ArgumentError, "Missing parameters to modify #{args.inspect}"
end
raise ArgumentError, "Missing parameters to modify #{args.inspect}" if !values.is_a? Hash

args = [:common] if args.empty? # by default change common kernels only
args = args.first if args.first.is_a? Array # support array like syntax

Expand Down Expand Up @@ -506,36 +433,16 @@ def mark_as_changed
Initrd.changed = true if Arch.s390 && Stage.initial
end

def handle_failed_write
log.error "Installing bootloader failed"
if writeErrorPopup
@repeating_write = true
res = WFM.call("bootloader_proposal", ["AskUser", { "has_next" => false }])
return Write() if res["workflow_sequence"] == :next
end

false
end

NONSPLASH_VGA_VALUES = ["", "false", "ask"]

# store new vgamode if needed and regenerate initrd in such case
# @param params_to_save used to store predefined vgamode value
# @return boolean if succeed
def write_initrd(_params_to_save)
ret = true
# TODO: detect VGA change
# new_vga = BootCommon.globals["vgamode"]
# if (new_vga != @old_vga && !NONSPLASH_VGA_VALUES.include?(new_vga)) ||
# !Mode.normal
# Initrd.setSplash(new_vga)
# params_to_save["vgamode"] = new_vga if Stage.initial
# end
def write_initrd
return true unless Initrd.changed

# save initrd
ret = Initrd.Write if Initrd.changed

ret
Initrd.Write
end

publish :function => :Export, :type => "map ()"
Expand Down
Loading

0 comments on commit 6ae9676

Please sign in to comment.