• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

yast / yast-bootloader / 18099610444

29 Sep 2025 02:00PM UTC coverage: 87.094% (-0.2%) from 87.325%
18099610444

Pull #724

github

schubi2
description changed
Pull Request #724: Update: Reports error if the bootloader is changed to grub2-bls

5 of 17 new or added lines in 2 files covered. (29.41%)

5 existing lines in 2 files now uncovered.

3489 of 4006 relevant lines covered (87.09%)

12.85 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.7
/src/lib/bootloader/bls_sections.rb
1
# frozen_string_literal: true
2

3
require "json"
1✔
4
require "yast"
1✔
5
require "yast2/execute"
1✔
6
require "bootloader/bls"
1✔
7

8
Yast.import "Misc"
1✔
9
Yast.import "Mode"
1✔
10
Yast.import "Stage"
1✔
11

12
module Bootloader
1✔
13
  # Represents available sections and handling of default BLS boot entry
14
  class BlsSections
1✔
15
    include Yast::Logger
1✔
16
    include Yast::I18n
1✔
17

18
    # @return [Array<String>] list of all available boot titles
19
    # or an empty array
20
    attr_reader :all
1✔
21

22
    # @return [String] title of default boot section.
23
    attr_reader :default
1✔
24

25
    def initialize
1✔
26
      textdomain "bootloader"
87✔
27

28
      @all = []
87✔
29
      @default = ""
87✔
30
    end
31

32
    # Sets default section internally.
33
    # @param [String] value of new boot title to boot
34
    # @note to write it to system use #write later
35
    def default=(value)
1✔
36
      log.info "set new default to '#{value.inspect}'"
5✔
37

38
      # empty value mean no default specified
39
      if !all.empty? && !all.include?(value) && !value.empty?
5✔
40
        log.warn "Invalid value #{value} trying to set as default. Fallback to default"
1✔
41
        value = ""
1✔
42
      end
43

44
      @default = value
5✔
45
    end
46

47
    # writes default to system making it persistent
48
    def write
1✔
49
      return if @default.empty?
11✔
50

51
      set = @data.find { |d| d["title"] == @default }
3✔
52
      Bls.write_default_menu(set["id"]) if set
1✔
53
    end
54

55
    def read
1✔
56
      @data = read_entries
14✔
57
      @all = @data.map { |e| e["title"] if e["type"] == "type1" }.compact
42✔
58
      file = Bls.default_menu.strip
14✔
59
      set = @data.find { |d| d["id"] == file }
42✔
60
      set ||= @data.first
14✔
61
      @default = set["title"] if set
14✔
62
    end
63

64
  private
1✔
65

66
    # @return [Array] return array of entries or []
67
    def read_entries
1✔
68
      begin
69
        output = Yast::Execute.on_target!(
14✔
70
          "/usr/bin/bootctl", "--json=short", "list", stdout: :capture
71
        )
72
      rescue Cheetah::ExecutionFailed => e
NEW
73
        error_message = format(_(
×
74
                                 "Cannot read boot menu entry:\n" \
75
                                 "Command `%{command}`.\n" \
76
                                 "Error output: %{stderr}"
77
                               ), command: e.commands.inspect, stderr: e.stderr)
NEW
78
        if Yast::Stage.initial && Yast::Mode.update
×
NEW
79
          Yast::Report.Warning(error_message)
×
80
        else
NEW
81
          Yast::Report.Error(error_message)
×
82
        end
83
      end
84
      return [] if output.nil?
14✔
85

86
      JSON.parse(output)
14✔
87
    end
88
  end
89
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc