forked from cobbler/cobbler
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbuildiso_test.py
More file actions
306 lines (262 loc) · 9.45 KB
/
buildiso_test.py
File metadata and controls
306 lines (262 loc) · 9.45 KB
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
import os
import pytest
from cobbler import enums
from cobbler.actions import buildiso
from cobbler.actions.buildiso import LoaderCfgsParts
from cobbler.actions.buildiso.netboot import NetbootBuildiso
from cobbler.actions.buildiso.standalone import StandaloneBuildiso
from tests.conftest import does_not_raise
@pytest.mark.parametrize(
"input_arch,result_binary_name,expected_exception",
[
(enums.Archs.X86_64, ["grubx64.efi", "grubx86.efi"], does_not_raise()),
(enums.Archs.PPC, ["grub.ppc64le"], does_not_raise()),
(enums.Archs.PPC64, ["grub.ppc64le"], does_not_raise()),
(enums.Archs.PPC64EL, ["grub.ppc64le"], does_not_raise()),
(enums.Archs.PPC64LE, ["grub.ppc64le"], does_not_raise()),
(enums.Archs.AARCH64, ["grubaa64.efi"], does_not_raise()),
(enums.Archs.ARM, ["bootarm.efi"], does_not_raise()),
(enums.Archs.I386, ["bootia32.efi"], does_not_raise()),
(enums.Archs.IA64, ["bootia64.efi"], does_not_raise()),
],
)
def test_calculate_grub_name(
input_arch,
result_binary_name,
expected_exception,
cobbler_api,
):
# Arrange
test_builder = buildiso.BuildIso(cobbler_api)
# Act
with expected_exception:
result = test_builder.calculate_grub_name(input_arch)
# Assert
assert result in result_binary_name
@pytest.mark.parametrize(
"input_kopts_dict,exepcted_output",
[
({}, ""),
({"test": 1}, " test=1"),
({"test": None}, " test"),
({"test": '"test"'}, ' test="test"'),
({"test": "test test test"}, ' test="test test test"'),
({"test": 'test "test" test'}, ' test="test "test" test"'),
({"test": ['"test"']}, ' test="test"'),
({"test": ['"test"', "test"]}, ' test="test" test=test'),
],
)
def test_add_remaining_kopts(input_kopts_dict, exepcted_output):
# Arrange (missing)
# Act
output = buildiso.add_remaining_kopts(input_kopts_dict)
# Assert
assert output == exepcted_output
def test_make_shorter(cobbler_api):
# Arrange
build_iso = NetbootBuildiso(cobbler_api)
distroname = "Testdistro"
# Act
result = build_iso.make_shorter(distroname)
# Assert
assert type(result) == str
assert distroname in build_iso.distmap
assert result == "1"
def test_copy_boot_files(cobbler_api, create_distro, tmpdir):
# Arrange
target_folder = tmpdir.mkdir("target")
build_iso = buildiso.BuildIso(cobbler_api)
testdistro = create_distro()
# Act
build_iso._copy_boot_files(testdistro.kernel, testdistro.initrd, target_folder)
# Assert
assert len(os.listdir(target_folder)) == 2
def test_netboot_generate_boot_loader_configs(
cobbler_api, create_distro, create_profile, create_system
):
test_distro = create_distro()
test_distro.kernel_options = 'test_distro_option=distro'
test_profile = create_profile(test_distro.name)
test_profile.kernel_options = 'test_profile_option=profile'
test_system = create_system(test_profile.name)
test_system.kernel_options = 'test_system_option=system'
build_iso = NetbootBuildiso(cobbler_api)
# Act
result = build_iso._generate_boot_loader_configs(
[test_profile], [test_system], True
)
matching_isolinux_kernel = [
part for part in result.isolinux if "KERNEL /1.krn" in part
]
matching_isolinux_initrd = [
part for part in result.isolinux if "initrd=/1.img" in part
]
matching_grub_kernel = [part for part in result.grub if "linux /1.krn" in part]
matching_grub_initrd = [part for part in result.grub if "initrd /1.img" in part]
matching_grub_distro_kopts = [
part for part in result.grub if "test_distro_option=distro" in part
]
matching_grub_profile_kopts = [
part for part in result.grub if "test_profile_option=profile" in part
]
matching_grub_system_kopts = [
part for part in result.grub if "test_system_option=system" in part
]
matching_isolinux_distro_kopts = [
part for part in result.isolinux if "test_distro_option=distro" in part
]
matching_isolinux_profile_kopts = [
part for part in result.isolinux if "test_profile_option=profile" in part
]
matching_isolinux_system_kopts = [
part for part in result.isolinux if "test_system_option=system" in part
]
# Assert
assert isinstance(result, LoaderCfgsParts)
for iterable_to_check in [
matching_isolinux_kernel,
matching_isolinux_initrd,
matching_grub_kernel,
matching_grub_initrd,
result.bootfiles_copysets,
matching_grub_distro_kopts,
matching_grub_profile_kopts,
matching_isolinux_distro_kopts,
matching_isolinux_profile_kopts
]:
print(iterable_to_check)
# one entry for the profile, one for the system
assert len(iterable_to_check) == 2
# only system entries have system kernel opts
assert len(matching_grub_system_kopts) == 1
assert len(matching_isolinux_system_kopts) == 1
def test_netboot_generate_boot_loader_config_for_profile_only(
cobbler_api, create_distro, create_profile, create_system
):
test_distro = create_distro()
test_distro.kernel_options = 'test_distro_option=distro'
test_profile = create_profile(test_distro.name)
test_profile.kernel_options = 'test_profile_option=profile'
test_system = create_system(test_profile.name)
test_system.kernel_options = 'test_system_option=system'
build_iso = NetbootBuildiso(cobbler_api)
# Act
result = build_iso._generate_boot_loader_configs(
[test_profile], [], True
)
matching_isolinux_kernel = [
part for part in result.isolinux if "KERNEL /1.krn" in part
]
matching_isolinux_initrd = [
part for part in result.isolinux if "initrd=/1.img" in part
]
matching_grub_kernel = [part for part in result.grub if "linux /1.krn" in part]
matching_grub_initrd = [part for part in result.grub if "initrd /1.img" in part]
matching_grub_distro_kopts = [
part for part in result.grub if "test_distro_option=distro" in part
]
matching_grub_profile_kopts = [
part for part in result.grub if "test_profile_option=profile" in part
]
matching_grub_system_kopts = [
part for part in result.grub if "test_system_option=system" in part
]
matching_isolinux_distro_kopts = [
part for part in result.isolinux if "test_distro_option=distro" in part
]
matching_isolinux_profile_kopts = [
part for part in result.isolinux if "test_profile_option=profile" in part
]
matching_isolinux_system_kopts = [
part for part in result.isolinux if "test_system_option=system" in part
]
# Assert
assert isinstance(result, LoaderCfgsParts)
for iterable_to_check in [
matching_isolinux_kernel,
matching_isolinux_initrd,
matching_grub_kernel,
matching_grub_initrd,
result.bootfiles_copysets,
matching_grub_distro_kopts,
matching_grub_profile_kopts,
matching_isolinux_distro_kopts,
matching_isolinux_profile_kopts
]:
print(iterable_to_check)
# one entry for the profile, and none for the system
assert len(iterable_to_check) == 1
# there are no system entries
assert len(matching_grub_system_kopts) == 0
assert len(matching_isolinux_system_kopts) == 0
def test_filter_system(cobbler_api, create_distro, create_profile, create_system):
# Arrange
test_distro = create_distro()
test_profile = create_profile(test_distro.name)
test_system = create_system(profile_name=test_profile.name)
itemlist = [test_system.name]
build_iso = NetbootBuildiso(cobbler_api)
expected_result = [test_system]
# Act
result = build_iso.filter_systems(itemlist)
# Assert
assert expected_result == result
def test_filter_profile(cobbler_api, create_distro, create_profile):
# Arrange
test_distro = create_distro()
test_profile = create_profile(test_distro.name)
itemlist = [test_profile.name]
build_iso = buildiso.BuildIso(cobbler_api)
expected_result = [test_profile]
# Act
result = build_iso.filter_profiles(itemlist)
# Assert
assert expected_result == result
def test_netboot_run(
cobbler_api,
create_distro,
create_loaders,
tmpdir,
):
# Arrange
test_distro = create_distro()
build_iso = NetbootBuildiso(cobbler_api)
iso_location = tmpdir.join("autoinst.iso")
# Act
build_iso.run(iso=str(iso_location), distro_name=test_distro.name)
# Assert
assert iso_location.exists()
def test_netboot_run_nodistro(
cobbler_api,
create_distro,
create_profile,
create_loaders,
tmpdir,
):
# Arrange
test_distro = create_distro()
test_profile = create_profile(test_distro.name)
build_iso = NetbootBuildiso(cobbler_api)
iso_location = tmpdir.join("autoinst.iso")
# Act
build_iso.run(iso=str(iso_location))
# Assert
assert iso_location.exists()
def test_standalone_run(
cobbler_api,
create_distro,
create_loaders,
tmpdir_factory,
):
# Arrange
iso_directory = tmpdir_factory.mktemp("isodir")
iso_source = tmpdir_factory.mktemp("isosource")
iso_location = iso_directory.join("autoinst.iso")
test_distro = create_distro()
build_iso = StandaloneBuildiso(cobbler_api)
# Act
build_iso.run(
iso=str(iso_location), distro_name=test_distro.name, source=str(iso_source)
)
# Assert
assert iso_location.exists()