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

yast / yast-bootloader / 12048550996

27 Nov 2024 10:37AM UTC coverage: 87.484% (+0.1%) from 87.378%
12048550996

Pull #708

github

schubi2
cleanup
Pull Request #708: Supporting Grub2-BLS

210 of 240 new or added lines in 13 files covered. (87.5%)

88 existing lines in 7 files now uncovered.

3362 of 3843 relevant lines covered (87.48%)

13.0 hits per line

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

82.19
/src/lib/bootloader/bootloader_factory.rb
1
# frozen_string_literal: true
2

3
require "yast"
1✔
4
require "bootloader/sysconfig"
1✔
5
require "bootloader/none_bootloader"
1✔
6
require "bootloader/grub2"
1✔
7
require "bootloader/grub2efi"
1✔
8
require "bootloader/grub2bls"
1✔
9
require "bootloader/systemdboot"
1✔
10
require "bootloader/exceptions"
1✔
11

12
Yast.import "Arch"
1✔
13
Yast.import "Mode"
1✔
14
Yast.import "ProductFeatures"
1✔
15

16
module Bootloader
1✔
17
  # Factory to get instance of bootloader
18
  class BootloaderFactory
1✔
19
    SUPPORTED_BOOTLOADERS = [
1✔
20
      "none", # allows user to manage bootloader itself
21
      "grub2",
22
      "grub2-efi"
23
    ].freeze
24

25
    # Keyword used in autoyast for default bootloader used for given system.
26
    DEFAULT_KEYWORD = "default"
1✔
27
    SYSTEMDBOOT = "systemd-boot"
1✔
28
    GRUB2BLS = "grub2-bls"
1✔
29

30
    class << self
1✔
31
      include Yast::Logger
1✔
32

33
      attr_writer :current
1✔
34

35
      def proposed
1✔
36
        bootloader_by_name(proposed_name)
×
37
      end
38

39
      def system
1✔
40
        sysconfig_name = Sysconfig.from_system.bootloader
21✔
41
        return nil unless sysconfig_name
21✔
42

43
        bootloader_by_name(sysconfig_name)
2✔
44
      end
45

46
      def current
1✔
47
        @current ||= (system || proposed)
460✔
48
      end
49

50
      def current_name=(name)
1✔
51
        @current = bootloader_by_name(name)
252✔
52
      end
53

54
      def clear_cache
1✔
55
        @cached_bootloaders = nil
227✔
56
      end
57

58
      def supported_names
1✔
59
        if Yast::Mode.config
18✔
60
          # default means bootloader use what it think is the best
61
          result = BootloaderFactory::SUPPORTED_BOOTLOADERS.clone
×
NEW
62
          result << GRUB2BLS if use_grub2_bls?
×
63
          result << SYSTEMDBOOT if use_systemd_boot?
×
64
          result << DEFAULT_KEYWORD
×
65
          return result
×
66
        end
67

68
        begin
69
          system_bl = system.name
18✔
70
        # rescue exception if system one is not support
71
        rescue StandardError
72
          system_bl = nil
18✔
73
        end
74
        ret = system_bl ? [system.name] : [] # use current as first
18✔
75
        # grub2 everywhere except aarch64 or riscv64
76
        ret << "grub2" unless Systeminfo.efi_mandatory?
18✔
77
        ret << "grub2-efi" if Systeminfo.efi_supported?
18✔
78
        ret << GRUB2BLS if use_grub2_bls?
18✔
79
        ret << SYSTEMDBOOT if use_systemd_boot?
18✔
80
        ret << "none"
18✔
81
        # avoid double entry for selected one
82
        ret.uniq
18✔
83
      end
84

85
      # rubocop:disable Metrics/CyclomaticComplexity
86
      def bootloader_by_name(name)
1✔
87
        # needed to be able to store settings when moving between bootloaders
88
        @cached_bootloaders ||= {}
272✔
89
        case name
272✔
90
        when "grub2"
91
          @cached_bootloaders["grub2"] ||= Grub2.new
186✔
92
        when "grub2-efi"
93
          @cached_bootloaders["grub2-efi"] ||= Grub2EFI.new
12✔
94
        when "systemd-boot"
95
          @cached_bootloaders["systemd-boot"] ||= SystemdBoot.new
63✔
96
        when "grub2-bls"
97
          @cached_bootloaders["grub2-bls"] ||= Grub2Bls.new
1✔
98
        when "none"
99
          @cached_bootloaders["none"] ||= NoneBootloader.new
8✔
100
        when String
101
          raise UnsupportedBootloader, name
1✔
102
        else
103
          log.error "Factory receive nil name"
1✔
104

105
          nil # in other cases it means that read failed
106
        end
107
      end
108
    # rubocop:enable Metrics/CyclomaticComplexity
109

110
    private
1✔
111

112
      def use_systemd_boot?
1✔
113
        Yast::ProductFeatures.GetBooleanFeature("globals", "enable_systemd_boot") &&
18✔
114
          (Yast::Arch.x86_64 || Yast::Arch.aarch64) # only these architectures are supported.
16✔
115
      end
116

117
      def use_grub2_bls?
1✔
118
        (Yast::Arch.x86_64 || Yast::Arch.aarch64) # only these architectures are supported.
18✔
119
      end
120

121
      def grub2_efi_installable?
1✔
122
        Systeminfo.efi_mandatory? ||
×
123
          ((Yast::Arch.x86_64 || Yast::Arch.i386) && Systeminfo.efi?)
×
124
      end
125

126
      def proposed_name
1✔
127
        prefered_bootloader = Yast::ProductFeatures.GetStringFeature("globals",
×
128
          "prefered_bootloader")
129
        if supported_names.include?(prefered_bootloader) && prefered_bootloader != "grub2-efi"
×
130
          return prefered_bootloader
×
131
        end
132

133
        return "grub2-efi" if grub2_efi_installable?
×
134

135
        "grub2" # grub2 works(c) everywhere
×
136
      end
137
    end
138
  end
139
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

© 2025 Coveralls, Inc