Skip to content

Commit

Permalink
do not crash if grub.cfg is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Feb 14, 2019
1 parent f6260df commit eeda9cf
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
6 changes: 6 additions & 0 deletions package/yast2-bootloader.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Thu Feb 14 07:56:05 UTC 2019 - jreidinger@suse.com

- Do not crash if generated grub.cfg is missing (bsc#1124064)
- 4.1.17

-------------------------------------------------------------------
Fri Feb 8 08:47:35 UTC 2019 - dgonzalez@suse.com

Expand Down
2 changes: 1 addition & 1 deletion package/yast2-bootloader.spec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


Name: yast2-bootloader
Version: 4.1.16
Version: 4.1.17
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand Down
5 changes: 2 additions & 3 deletions src/lib/bootloader/grub2base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,8 @@ def read
begin
grub_cfg.load
rescue Errno::ENOENT
# raise error only outside of first stage, as there may not need to be
# grub.cfg generated (bnc#976534)
raise unless Yast::Stage.initial
# there may not need to be grub.cfg generated (bnc#976534),(bsc#1124064)
log.info "/boot/grub2/grub.cfg is missing. Defaulting to empty one."
end
@sections = ::Bootloader::Sections.new(grub_cfg)
log.info "grub sections: #{@sections.all}"
Expand Down
8 changes: 8 additions & 0 deletions test/grub2base_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@
subject.read
end

it "use empty file as default if grub.cfg is missing" do
grub_cfg = double(::CFA::Grub2::GrubCfg)
allow(::CFA::Grub2::GrubCfg).to receive(:new).and_return(grub_cfg)
allow(grub_cfg).to receive(:load).and_raise(Errno::ENOENT)

expect{subject.read}.to_not raise_error
end

it "reads trusted boot configuration from sysconfig" do
mocked_sysconfig = ::Bootloader::Sysconfig.new(trusted_boot: true)
allow(::Bootloader::Sysconfig).to receive(:from_system).and_return(mocked_sysconfig)
Expand Down

0 comments on commit eeda9cf

Please sign in to comment.