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

yast / yast-bootloader / 5402801408

pending completion
5402801408

push

github

schubi2
adapted suggestions

38 of 38 new or added lines in 4 files covered. (100.0%)

3188 of 3643 relevant lines covered (87.51%)

12.96 hits per line

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

91.53
/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)
1✔
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)
445✔
43
      end
44

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

49
      def clear_cache
1✔
50
        @cached_bootloaders = nil
208✔
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
        ret << SYSTEMDBOOT if Systeminfo.efi_supported? && Yast::ProductFeatures.GetBooleanFeature(
16✔
76
          "globals", "enable_systemd_boot"
77
        )
78
        ret << "none"
16✔
79
        # avoid double entry for selected one
80
        ret.uniq
16✔
81
      end
82

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

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

106
    private
1✔
107

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

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

115
        return "grub2-efi" if Yast::Arch.x86_64 && boot_efi?
1✔
116

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