Skip to content

Commit 95888ab

Browse files
committed
Add e2e tests for various cloud formats
Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me>
1 parent 5f3866d commit 95888ab

File tree

3 files changed

+509
-102
lines changed

3 files changed

+509
-102
lines changed

tests/e2e/e2e_formats_test.go

Lines changed: 356 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,356 @@
1+
package e2e_test
2+
3+
import (
4+
osbuilder "github.com/kairos-io/osbuilder/api/v1alpha2"
5+
. "github.com/onsi/ginkgo/v2"
6+
batchv1 "k8s.io/api/batch/v1"
7+
corev1 "k8s.io/api/core/v1"
8+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
9+
"k8s.io/apimachinery/pkg/labels"
10+
)
11+
12+
var _ = Describe("Artifact Format Tests", func() {
13+
var tc *TestClients
14+
15+
BeforeEach(func() {
16+
tc = SetupTestClients()
17+
})
18+
19+
Describe("CloudImage (Raw Disk)", func() {
20+
var artifactName string
21+
var artifactLabelSelector labels.Selector
22+
23+
BeforeEach(func() {
24+
artifact := &osbuilder.OSArtifact{
25+
TypeMeta: metav1.TypeMeta{
26+
Kind: "OSArtifact",
27+
APIVersion: osbuilder.GroupVersion.String(),
28+
},
29+
ObjectMeta: metav1.ObjectMeta{
30+
GenerateName: "cloudimage-",
31+
},
32+
Spec: osbuilder.OSArtifactSpec{
33+
ImageName: "quay.io/kairos/opensuse:leap-15.6-core-amd64-generic-v3.6.0",
34+
CloudImage: true,
35+
Exporters: []batchv1.JobSpec{
36+
{
37+
Template: corev1.PodTemplateSpec{
38+
Spec: corev1.PodSpec{
39+
RestartPolicy: corev1.RestartPolicyNever,
40+
Containers: []corev1.Container{
41+
{
42+
Name: "verify",
43+
Image: "debian:latest",
44+
Command: []string{"bash"},
45+
Args: []string{
46+
"-xec",
47+
`
48+
set -e
49+
# Check that raw file exists
50+
raw_file=$(ls /artifacts/*.raw 2>/dev/null | head -n1)
51+
if [ -z "$raw_file" ]; then
52+
echo "No .raw file found"
53+
exit 1
54+
fi
55+
# Check that it's a valid disk image (has non-zero size)
56+
if [ ! -s "$raw_file" ]; then
57+
echo "Raw file is empty"
58+
exit 1
59+
fi
60+
# Check file size is reasonable (at least 100MB)
61+
size=$(stat -c%s "$raw_file")
62+
if [ "$size" -lt 104857600 ]; then
63+
echo "Raw file too small: $size bytes"
64+
exit 1
65+
fi
66+
echo "Raw disk verification passed: $raw_file"
67+
`,
68+
},
69+
VolumeMounts: []corev1.VolumeMount{
70+
{
71+
Name: "artifacts",
72+
ReadOnly: true,
73+
MountPath: "/artifacts",
74+
},
75+
},
76+
},
77+
},
78+
},
79+
},
80+
},
81+
},
82+
},
83+
}
84+
85+
artifactName, artifactLabelSelector = tc.CreateArtifact(artifact)
86+
})
87+
88+
It("builds a valid raw disk image", func() {
89+
tc.WaitForBuildCompletion(artifactName, artifactLabelSelector)
90+
tc.WaitForExportCompletion(artifactLabelSelector)
91+
tc.Cleanup(artifactName, artifactLabelSelector)
92+
})
93+
})
94+
95+
Describe("Netboot", func() {
96+
var artifactName string
97+
var artifactLabelSelector labels.Selector
98+
99+
BeforeEach(func() {
100+
artifact := &osbuilder.OSArtifact{
101+
TypeMeta: metav1.TypeMeta{
102+
Kind: "OSArtifact",
103+
APIVersion: osbuilder.GroupVersion.String(),
104+
},
105+
ObjectMeta: metav1.ObjectMeta{
106+
GenerateName: "netboot-",
107+
},
108+
Spec: osbuilder.OSArtifactSpec{
109+
ImageName: "quay.io/kairos/opensuse:leap-15.6-core-amd64-generic-v3.6.0",
110+
ISO: true,
111+
Netboot: true,
112+
NetbootURL: "http://example.com",
113+
Exporters: []batchv1.JobSpec{
114+
{
115+
Template: corev1.PodTemplateSpec{
116+
Spec: corev1.PodSpec{
117+
RestartPolicy: corev1.RestartPolicyNever,
118+
Containers: []corev1.Container{
119+
{
120+
Name: "verify",
121+
Image: "debian:latest",
122+
Command: []string{"bash"},
123+
Args: []string{
124+
"-xec",
125+
`
126+
set -e
127+
# Check for kernel file (pattern: *-kernel)
128+
kernel_file=$(ls /artifacts/*-kernel 2>/dev/null | head -n1)
129+
if [ -z "$kernel_file" ]; then
130+
echo "No kernel file found (pattern: *-kernel)"
131+
ls -la /artifacts/ || true
132+
exit 1
133+
fi
134+
# Check for initrd file (pattern: *-initrd)
135+
initrd_file=$(ls /artifacts/*-initrd 2>/dev/null | head -n1)
136+
if [ -z "$initrd_file" ]; then
137+
echo "No initrd file found (pattern: *-initrd)"
138+
ls -la /artifacts/ || true
139+
exit 1
140+
fi
141+
# Check for squashfs file (pattern: *.squashfs)
142+
squashfs_file=$(ls /artifacts/*.squashfs 2>/dev/null | head -n1)
143+
if [ -z "$squashfs_file" ]; then
144+
echo "No squashfs file found (pattern: *.squashfs)"
145+
ls -la /artifacts/ || true
146+
exit 1
147+
fi
148+
# Verify files are non-empty
149+
for file in "$kernel_file" "$initrd_file" "$squashfs_file"; do
150+
if [ ! -s "$file" ]; then
151+
echo "File is empty: $file"
152+
exit 1
153+
fi
154+
done
155+
echo "Netboot artifacts verification passed"
156+
echo "Kernel: $kernel_file"
157+
echo "Initrd: $initrd_file"
158+
echo "Squashfs: $squashfs_file"
159+
`,
160+
},
161+
VolumeMounts: []corev1.VolumeMount{
162+
{
163+
Name: "artifacts",
164+
ReadOnly: true,
165+
MountPath: "/artifacts",
166+
},
167+
},
168+
},
169+
},
170+
},
171+
},
172+
},
173+
},
174+
},
175+
}
176+
177+
artifactName, artifactLabelSelector = tc.CreateArtifact(artifact)
178+
})
179+
180+
It("builds valid netboot artifacts", func() {
181+
tc.WaitForBuildCompletion(artifactName, artifactLabelSelector)
182+
tc.WaitForExportCompletion(artifactLabelSelector)
183+
tc.Cleanup(artifactName, artifactLabelSelector)
184+
})
185+
})
186+
187+
Describe("AzureImage (VHD)", func() {
188+
var artifactName string
189+
var artifactLabelSelector labels.Selector
190+
191+
BeforeEach(func() {
192+
artifact := &osbuilder.OSArtifact{
193+
TypeMeta: metav1.TypeMeta{
194+
Kind: "OSArtifact",
195+
APIVersion: osbuilder.GroupVersion.String(),
196+
},
197+
ObjectMeta: metav1.ObjectMeta{
198+
GenerateName: "azure-",
199+
},
200+
Spec: osbuilder.OSArtifactSpec{
201+
ImageName: "quay.io/kairos/opensuse:leap-15.6-core-amd64-generic-v3.6.0",
202+
AzureImage: true,
203+
Exporters: []batchv1.JobSpec{
204+
{
205+
Template: corev1.PodTemplateSpec{
206+
Spec: corev1.PodSpec{
207+
RestartPolicy: corev1.RestartPolicyNever,
208+
Containers: []corev1.Container{
209+
{
210+
Name: "verify",
211+
Image: "debian:latest",
212+
Command: []string{"bash"},
213+
Args: []string{
214+
"-xec",
215+
`
216+
set -e
217+
# Check that VHD file exists
218+
vhd_file=$(ls /artifacts/*.vhd 2>/dev/null | head -n1)
219+
if [ -z "$vhd_file" ]; then
220+
echo "No .vhd file found"
221+
exit 1
222+
fi
223+
# Check that it's non-empty
224+
if [ ! -s "$vhd_file" ]; then
225+
echo "VHD file is empty"
226+
exit 1
227+
fi
228+
# Check file size is reasonable (at least 100MB)
229+
size=$(stat -c%s "$vhd_file")
230+
if [ "$size" -lt 104857600 ]; then
231+
echo "VHD file too small: $size bytes"
232+
exit 1
233+
fi
234+
# Check VHD footer (last 512 bytes should contain VHD signature)
235+
# VHD footer starts at offset -512 and contains "conectix" string
236+
tail -c 512 "$vhd_file" | grep -q "conectix" || {
237+
echo "VHD file does not have valid VHD footer"
238+
exit 1
239+
}
240+
echo "VHD verification passed: $vhd_file"
241+
`,
242+
},
243+
VolumeMounts: []corev1.VolumeMount{
244+
{
245+
Name: "artifacts",
246+
ReadOnly: true,
247+
MountPath: "/artifacts",
248+
},
249+
},
250+
},
251+
},
252+
},
253+
},
254+
},
255+
},
256+
},
257+
}
258+
259+
artifactName, artifactLabelSelector = tc.CreateArtifact(artifact)
260+
})
261+
262+
It("builds a valid Azure VHD image", func() {
263+
tc.WaitForBuildCompletion(artifactName, artifactLabelSelector)
264+
tc.WaitForExportCompletion(artifactLabelSelector)
265+
tc.Cleanup(artifactName, artifactLabelSelector)
266+
})
267+
})
268+
269+
Describe("GCEImage", func() {
270+
var artifactName string
271+
var artifactLabelSelector labels.Selector
272+
273+
BeforeEach(func() {
274+
artifact := &osbuilder.OSArtifact{
275+
TypeMeta: metav1.TypeMeta{
276+
Kind: "OSArtifact",
277+
APIVersion: osbuilder.GroupVersion.String(),
278+
},
279+
ObjectMeta: metav1.ObjectMeta{
280+
GenerateName: "gce-",
281+
},
282+
Spec: osbuilder.OSArtifactSpec{
283+
ImageName: "quay.io/kairos/opensuse:leap-15.6-core-amd64-generic-v3.6.0",
284+
GCEImage: true,
285+
Exporters: []batchv1.JobSpec{
286+
{
287+
Template: corev1.PodTemplateSpec{
288+
Spec: corev1.PodSpec{
289+
RestartPolicy: corev1.RestartPolicyNever,
290+
Containers: []corev1.Container{
291+
{
292+
Name: "verify",
293+
Image: "debian:latest",
294+
Command: []string{"bash"},
295+
Args: []string{
296+
"-xec",
297+
`
298+
set -e
299+
# Check that GCE tar.gz file exists
300+
gce_file=$(ls /artifacts/*.gce.tar.gz 2>/dev/null | head -n1)
301+
if [ -z "$gce_file" ]; then
302+
echo "No .gce.tar.gz file found"
303+
exit 1
304+
fi
305+
# Check that it's non-empty
306+
if [ ! -s "$gce_file" ]; then
307+
echo "GCE tar.gz file is empty"
308+
exit 1
309+
fi
310+
# Extract and verify it contains disk.raw
311+
temp_dir=$(mktemp -d)
312+
trap "rm -rf $temp_dir" EXIT
313+
tar -xzf "$gce_file" -C "$temp_dir"
314+
if [ ! -f "$temp_dir/disk.raw" ]; then
315+
echo "GCE archive does not contain disk.raw"
316+
exit 1
317+
fi
318+
# Verify disk.raw is non-empty and reasonable size
319+
if [ ! -s "$temp_dir/disk.raw" ]; then
320+
echo "disk.raw in archive is empty"
321+
exit 1
322+
fi
323+
size=$(stat -c%s "$temp_dir/disk.raw")
324+
if [ "$size" -lt 104857600 ]; then
325+
echo "disk.raw too small: $size bytes"
326+
exit 1
327+
fi
328+
echo "GCE verification passed: $gce_file"
329+
`,
330+
},
331+
VolumeMounts: []corev1.VolumeMount{
332+
{
333+
Name: "artifacts",
334+
ReadOnly: true,
335+
MountPath: "/artifacts",
336+
},
337+
},
338+
},
339+
},
340+
},
341+
},
342+
},
343+
},
344+
},
345+
}
346+
347+
artifactName, artifactLabelSelector = tc.CreateArtifact(artifact)
348+
})
349+
350+
It("builds a valid GCE image", func() {
351+
tc.WaitForBuildCompletion(artifactName, artifactLabelSelector)
352+
tc.WaitForExportCompletion(artifactLabelSelector)
353+
tc.Cleanup(artifactName, artifactLabelSelector)
354+
})
355+
})
356+
})

0 commit comments

Comments
 (0)