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

yast / yast-bootloader / 5544350558

pending completion
5544350558

Pull #686

github

web-flow
Merge 008f4a349 into e4f3f8b02
Pull Request #686: Systemd boot feature

735 of 735 new or added lines in 15 files covered. (100.0%)

3162 of 3609 relevant lines covered (87.61%)

12.88 hits per line

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

83.33
/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/systemdboot"
1✔
9
require "bootloader/exceptions"
1✔
10

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

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

24
    # Keyword used in autoyast for default bootloader used for given system.
25
    DEFAULT_KEYWORD = "default"
1✔
26
    SYSTEMDBOOT = "systemd-boot"
1✔
27

28
    class << self
1✔
29
      include Yast::Logger
1✔
30

31
      attr_writer :current
1✔
32

33
      def proposed
1✔
34
        bootloader_by_name(proposed_name)
×
35
      end
36

37
      def system
1✔
38
        bootloader_by_name(Sysconfig.from_system.bootloader)
19✔
39
      end
40

41
      def current
1✔
42
        @current ||= (system || proposed)
446✔
43
      end
44

45
      def current_name=(name)
1✔
46
        @current = bootloader_by_name(name)
229✔
47
      end
48

49
      def clear_cache
1✔
50
        @cached_bootloaders = nil
206✔
51
      end
52

53
      def supported_names
1✔
54
        if Yast::Mode.config
16✔
55
          # default means bootloader use what it think is the best
56
          result = BootloaderFactory::SUPPORTED_BOOTLOADERS.clone
×
57
          if Yast::ProductFeatures.GetBooleanFeature("globals", "enable_systemd_boot") &&
×
58
              Yast::Arch.x86_64 # only x86_64 is supported
59
            result << SYSTEMDBOOT
×
60
          end
61
          result << DEFAULT_KEYWORD
×
62
          return result
×
63
        end
64

65
        begin
66
          system_bl = system.name
16✔
67
        # rescue exception if system one is not support
68
        rescue StandardError
69
          system_bl = nil
16✔
70
        end
71
        ret = system_bl ? [system.name] : [] # use current as first
16✔
72
        # grub2 everywhere except aarch64 or riscv64
73
        ret << "grub2" unless Systeminfo.efi_mandatory?
16✔
74
        ret << "grub2-efi" if Systeminfo.efi_supported?
16✔
75
        if Yast::ProductFeatures.GetBooleanFeature("globals", "enable_systemd_boot") &&
16✔
76
            Yast::Arch.x86_64 # only x86_64 is supported
77
          ret << SYSTEMDBOOT
9✔
78
        end
79
        ret << "none"
16✔
80
        # avoid double entry for selected one
81
        ret.uniq
16✔
82
      end
83

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

102
          nil # in other cases it means that read failed
103
        end
104
      end
105
    # rubocop:enable Metrics/CyclomaticComplexity
106

107
    private
1✔
108

109
      def boot_efi?
1✔
110
        Systeminfo.efi?
×
111
      end
112

113
      def proposed_name
1✔
114
        return "grub2-efi" if Systeminfo.efi_mandatory?
×
115

116
        return "grub2-efi" if Yast::Arch.x86_64 && boot_efi?
×
117

118
        "grub2" # grub2 works(c) everywhere
×
119
      end
120
    end
121
  end
122
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