/
cio_ignore_test.rb
executable file
·288 lines (226 loc) · 9.3 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
#! /usr/bin/env rspec
require_relative "./test_helper"
require "installation/cio_ignore"
describe ::Installation::CIOIgnore do
describe "cio_ignore enable/disable" do
it "take AutoYaST cio_ignore setting" do
allow(Yast::Mode).to receive(:autoinst).and_return(true)
allow(Yast::AutoinstConfig).to receive(:cio_ignore).and_return(false)
::Installation::CIOIgnore.instance.reset
expect(::Installation::CIOIgnore.instance.cio_enabled).to eq(false)
end
it "take default cio_ignore entry if it is in the normal workflow" do
allow(Yast::Mode).to receive(:autoinst).and_return(false)
expect(Yast::AutoinstConfig).not_to receive(:cio_ignore)
expect(File).to receive(:exist?).with("/proc/sysinfo").exactly(2).times.and_return(false)
::Installation::CIOIgnore.instance.reset
expect(::Installation::CIOIgnore.instance.cio_enabled).to eq(true)
end
end
end
describe ::Installation::CIOIgnoreProposal do
subject { ::Installation::CIOIgnoreProposal.new }
before(:each) do
::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\" passed with non-existing chosen_id in second param hash" 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
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::SCR).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::SCR).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::SCR).to receive(:Execute)
.with(
::Installation::CIOIgnoreFinish::YAST_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::SCR).to receive(:Execute)
.with(
::Installation::CIOIgnoreFinish::YAST_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
it "adds kernel parameters IPLDEV and CONDEV to the bootloader" do
expect(Yast::Bootloader).to receive(:modify_kernel_params)
.with("cio_ignore" => "all,!ipldev,!condev").once
.and_return(true)
subject.run("Write")
end
it "writes list of active devices to zipl so it is not blocked" do
test_output = <<-EOL
Devices that are not ignored:
=============================
0.0.0160
0.0.01c0
0.0.0700-0.0.0702
0.0.fc00
EOL
expect(Yast::SCR).to receive(:Execute)
.with(
::Installation::CIOIgnoreFinish::YAST_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::SCR).to receive(:Execute)
.with(
::Installation::CIOIgnoreFinish::YAST_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