Skip to content

Commit

Permalink
Merge pull request #366 from yast/restore_broken_config
Browse files Browse the repository at this point in the history
Restore broken config
  • Loading branch information
jreidinger committed Oct 6, 2016
2 parents cf19b9c + 05381df commit 4731889
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 14 deletions.
7 changes: 7 additions & 0 deletions package/yast2-bootloader.changes
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Thu Oct 6 08:24:51 UTC 2016 - jreidinger@suse.com

- allow user to repropose configuration if unknown udev link found
(bnc#931291)
- 3.2.2

-------------------------------------------------------------------
Tue Oct 4 12:51:04 UTC 2016 - ancor@suse.com

Expand Down
2 changes: 1 addition & 1 deletion package/yast2-bootloader.spec
Expand Up @@ -17,7 +17,7 @@


Name: yast2-bootloader
Version: 3.2.1
Version: 3.2.2
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand Down
20 changes: 20 additions & 0 deletions src/lib/bootloader/config_dialog.rb
Expand Up @@ -18,6 +18,26 @@ class ConfigDialog
include Yast::UIShortcuts

def run
guarded_run
rescue ::Bootloader::BrokenConfiguration => e
ret = Yast::Report.AnyQuestion(_("Broken Configuration"),
# TRANSLATORS: %s stands for readon why yast cannot process it
_("YaST cannot process current bootloader configuration (%s). " \
"Propose new configuration from scratch?") % e.reason,
_("Propose"),
_("Quit"),
:yes) # focus proposing new one
return :abort unless ret

::Bootloader::BootloaderFactory.current = ::Bootloader::BootloaderFactory.proposed
::Bootloader::BootloaderFactory.current.propose

retry
end

private

def guarded_run
textdomain "bootloader"

log.info "Running Main Dialog"
Expand Down
18 changes: 18 additions & 0 deletions src/lib/bootloader/exceptions.rb
@@ -1,3 +1,5 @@
require "yast"

module Bootloader
# Represents error when during read it found bootloader name that is not supported.
class UnsupportedBootloader < RuntimeError
Expand All @@ -7,4 +9,20 @@ def initialize(bootloader_name)
@bootloader_name = bootloader_name
end
end

# universal exception when unrecoverable error found during parsing configuration
# holds in {#reason} translated message what exactly is broken.
class BrokenConfiguration < RuntimeError
include Yast::I18n
attr_reader :reason

def initialize(msg)
@reason = msg
textdomain "bootloader"

# TRANSLATORS: %s is translated description of error
super _("Error reading the bootloader configuration files. " \
"Please use YaST2 bootloader to fix it. Details: %s") % msg
end
end
end
39 changes: 28 additions & 11 deletions src/lib/bootloader/udev_mapping.rb
@@ -1,6 +1,8 @@
require "yast"
require "singleton"

require "bootloader/exceptions"

Yast.import "Storage"
Yast.import "Mode"
Yast.import "Arch"
Expand All @@ -10,6 +12,7 @@ module Bootloader
class UdevMapping
include Singleton
include Yast::Logger
include Yast::I18n

# make more comfortable to work with singleton
class << self
Expand All @@ -24,23 +27,15 @@ class << self
# @raise when device have udev format but do not exists
# @return [String,nil] kernel device or nil when running AutoYaST configuration.
def to_kernel_device(dev)
textdomain "bootloader"
log.info "call to_kernel_device for #{dev}"
raise "invalid device nil" unless dev

# for non-udev devices try to see specific raid names (bnc#944041)
if dev =~ /^\/dev\/disk\/by-/
# in mode config if not found, then return itself
all_devices[dev] or Yast::Mode.config ? dev : raise("Unknown udev device #{dev}")
udev_to_kernel(dev)
else
param = Yast::ArgRef.new({})
result = Yast::Storage.GetContVolInfo(dev, param)
return dev unless result # not raid with funny name

info = param.value
return info["vdevice"] unless info["vdevice"].empty?
return info["cdevice"] unless info["cdevice"].empty?

raise "unknown value for raid device '#{info.inspect}'"
alternative_raid_to_kernel(dev)
end
end

Expand Down Expand Up @@ -79,6 +74,28 @@ def to_mountby_device(dev)

private

def udev_to_kernel(dev)
return all_devices[dev] if all_devices[dev]

# in mode config if not found, then return itself
return dev if Yast::Mode.config

# TRANSLATORS: error message, %s stands for problematic device.
raise(Bootloader::BrokenConfiguration, _("Unknown udev device '%s'") % dev)
end

def alternative_raid_to_kernel(dev)
param = Yast::ArgRef.new({})
result = Yast::Storage.GetContVolInfo(dev, param)
return dev unless result # not raid with funny name

info = param.value
return info["vdevice"] unless info["vdevice"].empty?
return info["cdevice"] unless info["cdevice"].empty?

raise "unknown value for raid device '#{info.inspect}'"
end

def storage_data_for(kernel_dev)
# we do not know if it is partition or disk, but target map help us
target_map = Yast::Storage.GetTargetMap
Expand Down
16 changes: 14 additions & 2 deletions src/modules/Bootloader.rb
Expand Up @@ -156,9 +156,21 @@ def Read
::Bootloader::BootloaderFactory.current.read
rescue ::Bootloader::UnsupportedBootloader => e
ret = Yast::Report.AnyQuestion(_("Unsupported Bootloader"),
_("Unsupported bootloader '%s' detected. Show proposal of supported configuration?") %
_("Unsupported bootloader '%s' detected. Use proposal of supported configuration instead?") %
e.bootloader_name,
_("Show"),
_("Use"),
_("Quit"),
:yes) # focus proposing new one
return false unless ret

::Bootloader::BootloaderFactory.current = ::Bootloader::BootloaderFactory.proposed
::Bootloader::BootloaderFactory.current.propose
rescue ::Bootloader::BrokenConfiguration => e
ret = Yast::Report.AnyQuestion(_("Broken Configuration"),
# TRANSLATORS: %s stands for readon why yast cannot process it
_("YaST cannot process current bootloader configuration (%s). " \
"Propose new configuration from scratch?") % e.reason,
_("Propose"),
_("Quit"),
:yes) # focus proposing new one
return false unless ret
Expand Down

0 comments on commit 4731889

Please sign in to comment.