forked from kubevirt/kubevirt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvmi_kernel_boot_test.go
191 lines (159 loc) · 7.21 KB
/
vmi_kernel_boot_test.go
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
/*
* This file is part of the kubevirt project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Copyright 2021 Red Hat, Inc.
*
*/
package tests_test
import (
"context"
"fmt"
"time"
"kubevirt.io/kubevirt/tests/decorators"
k8sv1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"k8s.io/apimachinery/pkg/api/errors"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
kubevirtv1 "kubevirt.io/api/core/v1"
cd "kubevirt.io/kubevirt/tests/containerdisk"
"kubevirt.io/kubevirt/tests/framework/kubevirt"
"kubevirt.io/kubevirt/tests/libvmi"
"kubevirt.io/kubevirt/tests/libwait"
"kubevirt.io/kubevirt/tests/testsuite"
"kubevirt.io/client-go/kubecli"
"kubevirt.io/kubevirt/tests"
"kubevirt.io/kubevirt/tools/vms-generator/utils"
)
var _ = Describe("[sig-compute]VMI with external kernel boot", decorators.SigCompute, func() {
var virtClient kubecli.KubevirtClient
var err error
BeforeEach(func() {
virtClient = kubevirt.Client()
})
Context("with external alpine-based kernel & initrd images", func() {
It("[test_id:7748]ensure successful boot", func() {
vmi := utils.GetVMIKernelBoot()
obj, err := virtClient.VirtualMachineInstance(testsuite.GetTestNamespace(vmi)).Create(context.Background(), vmi)
Expect(err).ToNot(HaveOccurred())
libwait.WaitForSuccessfulVMIStart(obj)
})
It("ensure successful boot and deletion when VMI has a disk defined", func() {
By("Creating VMI with disk and kernel boot")
vmi := tests.NewRandomVMIWithEphemeralDisk(cd.ContainerDiskFor(cd.ContainerDiskAlpine))
vmi.Spec.Domain.Resources.Requests[k8sv1.ResourceMemory] = resource.MustParse("1Gi")
utils.AddKernelBootToVMI(vmi)
Expect(vmi.Spec.Volumes).ToNot(BeEmpty())
Expect(vmi.Spec.Domain.Devices.Disks).ToNot(BeEmpty())
By("Ensuring VMI can boot")
vmi, err = virtClient.VirtualMachineInstance(testsuite.GetTestNamespace(vmi)).Create(context.Background(), vmi)
Expect(err).ToNot(HaveOccurred())
libwait.WaitForSuccessfulVMIStart(vmi)
By("Fetching virt-launcher pod")
virtLauncherPod := tests.GetRunningPodByVirtualMachineInstance(vmi, vmi.Namespace)
By("Ensuring VMI is deleted")
err = virtClient.VirtualMachineInstance(testsuite.GetTestNamespace(vmi)).Delete(context.Background(), vmi.Name, &v1.DeleteOptions{})
Expect(err).ToNot(HaveOccurred())
Eventually(func() (isVmiDeleted bool) {
vmi, err = virtClient.VirtualMachineInstance(testsuite.GetTestNamespace(vmi)).Get(context.Background(), vmi.Name, &v1.GetOptions{})
if errors.IsNotFound(err) {
return true
}
Expect(err).ToNot(HaveOccurred())
return false
}, 60*time.Second, 3*time.Second).Should(BeTrue(), "VMI Should be successfully deleted")
By("Ensuring virt-launcher is deleted")
Eventually(func() (isVmiDeleted bool) {
_, err = virtClient.CoreV1().Pods(virtLauncherPod.Namespace).Get(context.Background(), virtLauncherPod.Name, v1.GetOptions{})
if errors.IsNotFound(err) {
return true
}
Expect(err).ToNot(HaveOccurred())
return false
}, 60*time.Second, 3*time.Second).Should(BeTrue(), fmt.Sprintf("virt-launcher pod (%s) Should be successfully deleted", virtLauncherPod.Name))
})
})
Context("with illegal definition ensure rejection of", func() {
It("[test_id:7750]VMI defined without an image", func() {
vmi := utils.GetVMIKernelBoot()
kernelBoot := vmi.Spec.Domain.Firmware.KernelBoot
kernelBoot.Container.Image = ""
_, err := virtClient.VirtualMachineInstance(testsuite.GetTestNamespace(vmi)).Create(context.Background(), vmi)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("denied the request: spec.domain.firmware.kernelBoot.container must be defined with an image"))
})
It("[test_id:7751]VMI defined with image but without initrd & kernel paths", func() {
vmi := utils.GetVMIKernelBoot()
kernelBoot := vmi.Spec.Domain.Firmware.KernelBoot
kernelBoot.Container.KernelPath = ""
kernelBoot.Container.InitrdPath = ""
_, err := virtClient.VirtualMachineInstance(testsuite.GetTestNamespace(vmi)).Create(context.Background(), vmi)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("denied the request: spec.domain.firmware.kernelBoot.container must be defined with at least one of the following: kernelPath, initrdPath"))
})
})
Context("with external alpine-based kernel only (without initrd)", func() {
getVMIKernelBoot := func() *kubevirtv1.VirtualMachineInstance {
vmi := utils.GetVMIKernelBoot()
// Remove initrd path from vmi spec
kernelBoot := vmi.Spec.Domain.Firmware.KernelBoot
kernelBoot.Container.InitrdPath = ""
return vmi
}
It("ensure successful boot", func() {
vmi := getVMIKernelBoot()
obj, err := virtClient.VirtualMachineInstance(testsuite.GetTestNamespace(vmi)).Create(context.Background(), vmi)
Expect(err).ToNot(HaveOccurred())
libwait.WaitForSuccessfulVMIStart(obj)
})
It("ensure successful boot and deletion when VMI has a disk defined", func() {
By("Creating VMI with disk and kernel boot")
vmi := libvmi.NewAlpine(libvmi.WithResourceMemory("1Gi"))
utils.AddKernelBootToVMI(vmi)
// Remove initrd path from vmi spec
kernelBoot := vmi.Spec.Domain.Firmware.KernelBoot
kernelBoot.Container.InitrdPath = ""
Expect(vmi.Spec.Volumes).ToNot(BeEmpty())
Expect(vmi.Spec.Domain.Devices.Disks).ToNot(BeEmpty())
By("Ensuring VMI can boot")
vmi, err = virtClient.VirtualMachineInstance(testsuite.GetTestNamespace(vmi)).Create(context.Background(), vmi)
Expect(err).ToNot(HaveOccurred())
libwait.WaitForSuccessfulVMIStart(vmi)
By("Fetching virt-launcher pod")
virtLauncherPod := tests.GetRunningPodByVirtualMachineInstance(vmi, vmi.Namespace)
By("Ensuring VMI is deleted")
err = virtClient.VirtualMachineInstance(testsuite.GetTestNamespace(vmi)).Delete(context.Background(), vmi.Name, &v1.DeleteOptions{})
Expect(err).ToNot(HaveOccurred())
Eventually(func() (isVmiDeleted bool) {
vmi, err = virtClient.VirtualMachineInstance(testsuite.GetTestNamespace(vmi)).Get(context.Background(), vmi.Name, &v1.GetOptions{})
if errors.IsNotFound(err) {
return true
}
Expect(err).ToNot(HaveOccurred())
return false
}, 60*time.Second, 3*time.Second).Should(BeTrue(), "VMI Should be successfully deleted")
By("Ensuring virt-launcher is deleted")
Eventually(func() (isVmiDeleted bool) {
_, err = virtClient.CoreV1().Pods(virtLauncherPod.Namespace).Get(context.Background(), virtLauncherPod.Name, v1.GetOptions{})
if errors.IsNotFound(err) {
return true
}
Expect(err).ToNot(HaveOccurred())
return false
}, 60*time.Second, 3*time.Second).Should(BeTrue(), fmt.Sprintf("virt-launcher pod (%s) Should be successfully deleted", virtLauncherPod.Name))
})
})
})