-
Notifications
You must be signed in to change notification settings - Fork 20
/
inst_autosetup_test.rb
255 lines (213 loc) · 7.81 KB
/
inst_autosetup_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
# Copyright (c) [2020] SUSE LLC
#
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of version 2 of the GNU General Public License as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, contact SUSE LLC.
#
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.
require_relative "../../test_helper"
require "autoinstall/clients/inst_autosetup"
describe Y2Autoinstallation::Clients::InstAutosetup do
describe "#main" do
let(:product) do
Y2Packager::Product.new(name: "SLES")
end
let(:cmdline) { "" }
let(:s390_arch) { false }
let(:profile) do
{
"bootloader" => { "boot" => "/dev/sda" },
"software" => { "packages" => ["yast2"] }
}
end
before do
allow(Yast::AutoinstGeneral).to receive(:Write)
allow(Yast::AutoinstStorage).to receive(:Write)
allow(Yast::AutoinstFunctions).to receive(:selected_product).and_return(product)
allow(Yast::Progress).to receive(:Title)
allow(Yast::AutoinstStorage).to receive(:Import).and_return(true)
allow(Yast::AutoinstStorage).to receive(:Write).and_return(true)
allow(Yast::Profile).to receive(:current).and_return(profile)
allow(Yast::WFM).to receive(:CallFunction).with(/_auto/, Array).and_return(true)
allow(Yast::Popup).to receive(:ConfirmAbort).and_return(true)
allow(Yast::SCR).to receive(:Read)
.with(Yast::Path.new(".target.string"), "/proc/cmdline")
.and_return(cmdline)
allow(Yast::SCR).to receive(:Read).and_call_original
allow(Yast::Arch).to receive(:s390).and_return(:s390_arch)
allow(subject).to receive(:autosetup_network)
allow(subject).to receive(:autosetup_country)
allow(subject).to receive(:autosetup_security)
allow(subject).to receive(:autosetup_users)
allow(subject).to receive(:probe_storage)
allow(Yast::AutoinstSoftware).to receive(:Write).and_return(true)
allow(Yast::ServicesManager).to receive(:import)
end
it "sets up the network" do
expect(subject).to receive(:autosetup_network)
subject.main
end
it "sets up additional configuration files" do
expect(subject).to receive(:autosetup_files)
subject.main
end
it "sets up the country configuration" do
expect(subject).to receive(:autosetup_country)
subject.main
end
it "sets up the security settings" do
expect(subject).to receive(:autosetup_security)
subject.main
end
it "sets up the firewall configuration" do
expect(subject).to receive(:autosetup_firewall)
subject.main
end
it "sets up the partitioning schema" do
expect(Yast::AutoinstStorage).to receive(:Import).and_return(true)
expect(Yast::AutoinstStorage).to receive(:Write).and_return(true)
subject.main
end
context "when partitioning fails" do
before do
allow(Yast::AutoinstStorage).to receive(:Write).and_return(false)
end
it "reports an error" do
expect(Yast::Report).to receive(:Error).with(/configuring partitions/)
subject.main
end
end
it "sets up the bootloader configuration" do
expect(Yast::WFM).to receive(:CallFunction)
.with("bootloader_auto", ["Import", profile["bootloader"]])
subject.main
end
context "when importing the bootloader configuration fails" do
before do
expect(Yast::WFM).to receive(:CallFunction)
.with("bootloader_auto", Array).and_return(false)
end
it "returns :abort" do
expect(subject.main).to eq(:abort)
end
end
context "when configuration management settings are present in the profile" do
let(:profile) do
{ "configuration_management" => { "master" => "salt.localdomain" } }
end
let(:import_result) { true }
before do
allow(Yast::WFM).to receive(:CallFunction).with("configuration_management_auto", Array)
.and_return(import_result)
end
it "sets up the configuration management module" do
expect(Yast::WFM).to receive(:CallFunction)
.with("configuration_management_auto", ["Import", profile["configuration_management"]])
.and_return(true)
subject.main
end
it "removes the 'configuration_management' section from the profile" do
expect(Yast::Profile).to receive(:remove_sections)
.with("configuration_management")
subject.main
end
context "when importing the settings fails" do
let(:import_result) { false }
it "returns :abort" do
expect(subject.main).to eq(:abort)
end
end
end
context "when kdump settings are present in the profile" do
let(:profile) do
{ "kdump" => { "enabled" => true } }
end
it "sets up the kdump module" do
expect(Yast::WFM).to receive(:CallFunction)
.with("kdump_auto", ["Import", Hash])
.and_return(true)
subject.main
end
it "removes the 'kdump' section from the profile" do
expect(Yast::Profile).to receive(:remove_sections)
.with("kdump")
subject.main
end
end
it "sets up the software" do
expect(Yast::AutoinstSoftware).to receive(:Import).with(profile["software"])
expect(Yast::AutoinstSoftware).to receive(:Write).and_return(true)
subject.main
end
context "when processing the software configuration fails" do
before do
allow(Yast::AutoinstSoftware).to receive(:Write).and_return(false)
end
it "reports and error and returns :abort" do
expect(Yast::Report).to receive(:Error).with(/software/)
expect(subject.main).to eq(:abort)
end
end
it "sets up the users" do
expect(subject).to receive(:autosetup_users)
subject.main
end
context "when ssh import settings are present in the profile" do
let(:profile) do
{ "ssh_import" => { "import" => true } }
end
let(:import_result) { true }
before do
allow(Yast::WFM).to receive(:CallFunction).with("ssh_import", Array)
.and_return(import_result)
end
it "sets up the ssh import behavior" do
expect(Yast::WFM).to receive(:CallFunction)
.with("ssh_import_auto", ["Import", profile["ssh_import"]])
.and_return(true)
subject.main
end
it "removes the 'ssh_import' section from the profile" do
expect(Yast::Profile).to receive(:remove_sections)
.with("ssh_import")
subject.main
end
context "when importing the settings fails" do
let(:import_result) { false }
it "returns :abort" do
expect(subject.main).to eq(:abort)
end
end
end
context "when the user has to accept the base product license" do
let(:profile) do
{ "general" => { "mode" => { "confirm_base_product_license" => true } } }
end
it "asks the user to accept the license" do
expect(Yast::WFM).to receive(:CallFunction).with("inst_product_license", Array)
.and_return(:next)
subject.main
end
context "and does not accept the license" do
before do
allow(Yast::WFM).to receive(:CallFunction).with("inst_product_license", Array)
.and_return(:abort)
end
it "returns :abort" do
expect(subject.main).to eq(:abort)
end
end
end
end
end