/
grub_install_test.rb
162 lines (120 loc) · 4.37 KB
/
grub_install_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#! /usr/bin/env rspec --format doc
require_relative "./test_helper"
require "bootloader/grub_install"
describe Bootloader::GrubInstall do
describe "#execute" do
def stub_arch(arch)
allow(Yast::Arch).to receive(:architecture).and_return(arch)
end
def stub_efivars(removable: false)
if removable
efivardirs = []
else
efivardirs = ["Boot0000-8be4df61-93ca-11d2-aa0d-00e098032b8c",
"BootCurrent-8be4df61-93ca-11d2-aa0d-00e098032b8c",
"BootOrder-8be4df61-93ca-11d2-aa0d-00e098032b8c"]
end
allow(Dir).to receive(:glob).and_return(efivardirs)
end
def expect_grub2_install(target, device: nil, removable: false)
params = [/grub2-install/, "--target=#{target}", "--force", "--skip-fs-probe"]
params << "--no-nvram" << "--removable" if removable
params << device if device
expect(Yast::Execute).to receive(:on_target)
.with(params)
end
context "initialized with efi: true" do
subject { Bootloader::GrubInstall.new(efi: true) }
it "runs shim-install instead of grub2-install if secure_boot: true passed" do
stub_efivars
expect(Yast::Execute).to receive(:on_target)
.with([/shim-install/, "--config-file=/boot/grub2/grub.cfg"])
subject.execute(secure_boot: true)
end
it "runs with target i386-efi on i386" do
stub_arch("i386")
stub_efivars
expect_grub2_install("i386-efi")
subject.execute
end
it "runs with target x86_64-efi on x86_64" do
stub_arch("x86_64")
stub_efivars
expect_grub2_install("x86_64-efi")
subject.execute
end
it "raise exception on ppc64" do
stub_arch("ppc64")
stub_efivars
expect { subject.execute }.to raise_error(RuntimeError)
end
it "raise exception on s390" do
stub_arch("s390_64")
stub_efivars
expect { subject.execute }.to raise_error(RuntimeError)
end
it "runs with target arm64-efi on aarch64" do
stub_arch("aarch64")
stub_efivars
expect_grub2_install("arm64-efi")
subject.execute
end
it "raise exception for other architectures" do
stub_arch("punks_not_dead")
expect { subject.execute }.to raise_error(RuntimeError)
end
it "creates a removable grub2 install on non-nvram systems" do
stub_arch("aarch64")
stub_efivars(removable: true)
expect_grub2_install("arm64-efi", removable: true)
subject.execute
end
end
context "initialized with efi:false" do
subject { Bootloader::GrubInstall.new(efi: false) }
it "raise exception if secure_boot: true passed" do
expect { subject.execute(secure_boot: true) }.to raise_error(RuntimeError)
end
it "runs for each device passed in devices" do
stub_arch("x86_64")
stub_efivars
expect_grub2_install("i386-pc", device: "/dev/sda")
expect_grub2_install("i386-pc", device: "/dev/sdb")
expect_grub2_install("i386-pc", device: "/dev/sdc")
subject.execute(devices: ["/dev/sda", "/dev/sdb", "/dev/sdc"])
end
it "runs with target i386-pc on i386" do
stub_arch("i386")
stub_efivars
expect_grub2_install("i386-pc", device: "/dev/sda")
subject.execute(devices: ["/dev/sda"])
end
it "runs with target i386-pc on x86_64" do
stub_arch("x86_64")
stub_efivars
expect_grub2_install("i386-pc", device: "/dev/sda")
subject.execute(devices: ["/dev/sda"])
end
it "runs with target powerpc-ieee1275 on ppc64" do
stub_arch("ppc64")
stub_efivars
expect_grub2_install("powerpc-ieee1275", device: "/dev/sda")
subject.execute(devices: ["/dev/sda"])
end
it "runs with target s390x-emu on s390" do
stub_arch("s390_64")
stub_efivars
expect_grub2_install("s390x-emu", device: "/dev/dasda1")
subject.execute(devices: ["/dev/dasda1"])
end
it "raise exception on aarch64" do
stub_arch("aarch64")
expect { subject.execute }.to raise_error(RuntimeError)
end
it "raise exception for other architectures" do
stub_arch("punks_not_dead")
expect { subject.execute }.to raise_error(RuntimeError)
end
end
end
end