-
Notifications
You must be signed in to change notification settings - Fork 44
/
cio_ignore_test.rb
executable file
·373 lines (295 loc) · 11.8 KB
/
cio_ignore_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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
#! /usr/bin/env rspec
require_relative "./test_helper"
require "installation/cio_ignore"
Yast.import "Bootloader"
describe ::Installation::CIOIgnore do
let(:param) { :missing }
let(:zvm) { false }
let(:kvm) { false }
let(:auto) { false }
before do
arch_mock = double("Yast::Arch", s390: false, is_zkvm: kvm, is_zvm: zvm)
stub_const("Yast::Arch", arch_mock)
allow(Yast::Bootloader).to receive(:kernel_param).with(:common, "rd.zdev")
allow(Yast::Bootloader).to receive(:kernel_param).with(:common, "cio_ignore").and_return(param)
allow(Yast::Mode).to receive(:autoinst).and_return(auto)
end
describe "cio_ignore enable/disable" do
context "in autoinstallation" do
let(:auto) { true }
it "takes AutoYaST cio_ignore setting" do
allow(Yast::AutoinstConfig).to receive(:cio_ignore).and_return(false)
::Installation::CIOIgnore.instance.reset
expect(::Installation::CIOIgnore.instance.cio_enabled).to eq(false)
end
end
context "in other modes" do
it "takes the default cio_ignore entry" do
expect(Yast::AutoinstConfig).not_to receive(:cio_ignore)
::Installation::CIOIgnore.instance.reset
expect(::Installation::CIOIgnore.instance.cio_enabled).to eq(true)
end
end
end
describe "cio_ignore default value" do
before(:each) do
::Installation::CIOIgnore.instance.reset
end
context "when the cio_kernel argument is given" do
let(:param) { "all,!ipdev,!condev" }
it "returns true" do
expect(::Installation::CIOIgnore.instance.cio_enabled).to eq(true)
end
end
context "when the cio_kernel argument is not given" do
context "in zVM" do
let(:zvm) { true }
it "returns true" do
expect(::Installation::CIOIgnore.instance.cio_enabled).to eq(false)
end
end
context "in KVM" do
let(:kvm) { true }
it "returns true" do
expect(::Installation::CIOIgnore.instance.cio_enabled).to eq(false)
end
end
context "in LPAR and others" do
it "returns false" do
expect(::Installation::CIOIgnore.instance.cio_enabled).to eq(true)
end
end
end
end
end
describe ::Installation::CIOIgnoreProposal do
subject { ::Installation::CIOIgnoreProposal.new }
before(:each) do
allow(Yast::Bootloader).to receive(:kernel_param).with(:common, "rd.zdev")
allow(Yast::Bootloader).to receive(:kernel_param).with(:common, "cio_ignore")
::Installation::CIOIgnore.instance.reset
end
describe "#run" do
describe "first parameter \"MakeProposal\"" do
it "returns proposal entry hash containing \"links\", \"help\" and " \
"\"preformatted_proposal\"" do
result = subject.run("MakeProposal")
expect(result).to have_key("links")
expect(result).to have_key("help")
expect(result).to have_key("preformatted_proposal")
end
it "the proposal text is correct if cio_ignore is disabled" do
::Installation::CIOIgnore.instance.cio_enabled = false
result = subject.run("MakeProposal")
expect(result).to have_key("links")
expect(result).to have_key("help")
expect(result["preformatted_proposal"]).to match(/Blacklist devices: disabled/)
end
it "the proposal text is correct if cio_ignore is enabled" do
::Installation::CIOIgnore.instance.cio_enabled = true
result = subject.run("MakeProposal")
expect(result).to have_key("links")
expect(result).to have_key("help")
expect(result["preformatted_proposal"]).to match(/Blacklist devices: enabled/)
end
it "the proposal text is correct if device autoconf is disabled" do
::Installation::CIOIgnore.instance.autoconf_enabled = false
result = subject.run("MakeProposal")
expect(result).to have_key("links")
expect(result).to have_key("help")
expect(result["preformatted_proposal"]).to match(/auto-configuration: disabled/)
end
it "the proposal text is correct if device autoconf is enabled" do
::Installation::CIOIgnore.instance.autoconf_enabled = true
result = subject.run("MakeProposal")
expect(result).to have_key("links")
expect(result).to have_key("help")
expect(result["preformatted_proposal"]).to match(/auto-configuration: enabled/)
end
end
describe "first parameter \"Description\"" do
it "returns proposal metadata hash containing \"rich_text_title\", " \
"\"id\" and \"menu_title\"" do
result = subject.run("Description")
expect(result).to have_key("rich_text_title")
expect(result).to have_key("menu_title")
expect(result).to have_key("id")
end
end
describe "first parameter \"AskUser\"" do
it "changes proposal if passed with chosen_id in second param hash" do
params = [
"AskUser",
{ "chosen_id" => ::Installation::CIOIgnoreProposal::CIO_DISABLE_LINK }
]
result = subject.run(*params)
expect(result["workflow_sequence"]).to eq :next
expect(::Installation::CIOIgnore.instance.cio_enabled).to be false
end
it "raises RuntimeError if passed without chosen_id in second param hash" do
expect { subject.run("AskUser") }.to(
raise_error(RuntimeError)
)
end
it "raises RuntimeError if \"AskUser\" is called with non-existing chosen_id" do
params = [
"AskUser",
{ "chosen_id" => "non_existing" }
]
expect { subject.run(*params) }.to raise_error(RuntimeError)
end
end
it "raises RuntimeError if unknown action passed as first parameter" do
expect { subject.run("non_existing_action") }.to(
raise_error(RuntimeError)
)
end
end
end
describe ::Installation::CIOIgnoreFinish do
subject { ::Installation::CIOIgnoreFinish.new }
describe "#run" do
describe "first paramater \"Info\"" do
it "returns info entry hash with empty \"when\" key for non s390x architectures" do
arch_mock = double("Yast::Arch", s390: false)
stub_const("Yast::Arch", arch_mock)
result = subject.run("Info")
expect(result["when"]).to be_empty
end
it "returns info entry hash with scenarios in \"when\" key for s390x architectures" do
arch_mock = double("Yast::Arch", s390: true)
stub_const("Yast::Arch", arch_mock)
result = subject.run("Info")
expect(result["when"]).to_not be_empty
end
end
describe "first parameter \"Write\"" do
let(:param) { "all,!ipldev,!condev" }
before(:each) do
stub_const("Yast::Installation", double(destdir: "/mnt"))
stub_const("Yast::Bootloader", double)
allow(Yast::Bootloader).to receive(:Write) { true }
allow(Yast::Bootloader).to receive(:Read) { true }
allow(Yast::Bootloader).to receive(:modify_kernel_params) { true }
allow(Yast::Bootloader).to receive(:kernel_param)
.with(:common, "cio_ignore").and_return(param)
allow(Yast::WFM).to receive(:Execute)
.and_return("exit" => 0, "stdout" => "", "stderr" => "")
allow(File).to receive(:write)
end
describe "Device blacklisting is disabled" do
it "does nothing" do
::Installation::CIOIgnore.instance.cio_enabled = false
expect(Yast::WFM).to_not receive(:Execute)
expect(Yast::Bootloader).to_not receive(:Read)
subject.run("Write")
end
end
describe "Device blacklisting is enabled" do
it "calls `cio_ignore --unused --purge`" do
::Installation::CIOIgnore.instance.cio_enabled = true
expect(Yast::WFM).to receive(:Execute)
.with(
::Installation::CIOIgnoreFinish::YAST_LOCAL_BASH_PATH,
"/sbin/cio_ignore --unused --purge"
)
.once
.and_return("exit" => 0, "stdout" => "", "stderr" => "")
subject.run("Write")
end
it "raises RuntimeError if cio_ignore call failed" do
::Installation::CIOIgnore.instance.cio_enabled = true
stderr = "HORRIBLE ERROR!!!"
expect(Yast::WFM).to receive(:Execute)
.with(
::Installation::CIOIgnoreFinish::YAST_LOCAL_BASH_PATH,
"/sbin/cio_ignore --unused --purge"
)
.once
.and_return("exit" => 1, "stdout" => "", "stderr" => stderr)
expect { subject.run("Write") }.to raise_error(RuntimeError, /stderr/)
end
context "when the cio_ignore kernel argument is already given" do
it "does not touch the kernel parameters" do
expect(Yast::Bootloader).to_not receive(:modify_kernel_params)
.with("cio_ignore" => anything)
subject.run("Write")
end
end
context "when the cio_ignore kernel argument is not given" do
let(:param) { :missing }
let(:cio_k_output) { "all,!0009,!0160,!0800-0802" }
it "adds the parameter using the 'cio_ignore -k' output to the bootloader" do
expect(Yast::WFM).to receive(:Execute)
.with(
Installation::CIOIgnoreFinish::YAST_LOCAL_BASH_PATH,
"/sbin/cio_ignore -k"
)
.once
.and_return("exit" => 0, "stdout" => cio_k_output, "stderr" => "")
expect(Yast::Bootloader).to receive(:modify_kernel_params)
.with("cio_ignore" => cio_k_output).once
.and_return(true)
subject.run("Write")
end
end
it "writes list of active devices to zipl so it is not blocked" do
test_output = <<~CIO_IGNORE
Devices that are not ignored:
=============================
0.0.0160
0.0.01c0
0.0.0700-0.0.0702
0.0.fc00
CIO_IGNORE
expect(Yast::WFM).to receive(:Execute)
.with(
::Installation::CIOIgnoreFinish::YAST_LOCAL_BASH_PATH,
"/sbin/cio_ignore -L"
)
.once
.and_return("exit" => 0, "stdout" => test_output, "stderr" => "")
expect(File).to receive(:write).once do |file, content|
expect(file).to eq("/mnt/boot/zipl/active_devices.txt")
expect(content).to match(/0.0.0700-0.0.0702/)
expect(content).to end_with("\n")
end
subject.run("Write")
end
it "raises an exception if cio_ignore -L failed" do
expect(Yast::WFM).to receive(:Execute)
.with(
::Installation::CIOIgnoreFinish::YAST_LOCAL_BASH_PATH,
"/sbin/cio_ignore -L"
)
.once
.and_return("exit" => 1, "stdout" => "", "stderr" => "FAIL")
expect { subject.run("Write") }.to raise_error(RuntimeError, /cio_ignore -L failed/)
end
end
describe "I/O device autoconf is disabled" do
it "adds kernel parameter rd.zdev=no-auto" do
::Installation::CIOIgnore.instance.autoconf_enabled = false
expect(Yast::Bootloader).to receive(:modify_kernel_params)
.with("rd.zdev" => "no-auto").once
.and_return(true)
subject.run("Write")
end
end
describe "I/O device autoconf is enabled" do
it "removes kernel parameter rd.zdev" do
::Installation::CIOIgnore.instance.autoconf_enabled = true
expect(Yast::Bootloader).to receive(:modify_kernel_params)
.with("rd.zdev" => :missing).once
.and_return(true)
subject.run("Write")
end
end
end
it "raises RuntimeError if unknown action passed as first parameter" do
expect { subject.run("non_existing_action") }.to(
raise_error(RuntimeError)
)
end
end
end