Skip to content

Commit 8ca0d83

Browse files
committed
test(workload-updater): remove obsolete kvvmi checks from firmware tests
Signed-off-by: Daniil Antoshin <daniil.antoshin@flant.com>
1 parent e2198ef commit 8ca0d83

File tree

1 file changed

+7
-50
lines changed
  • images/virtualization-artifact/pkg/controller/workload-updater/internal/handler

1 file changed

+7
-50
lines changed

images/virtualization-artifact/pkg/controller/workload-updater/internal/handler/firmware_test.go

Lines changed: 7 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
appsv1 "k8s.io/api/apps/v1"
2626
corev1 "k8s.io/api/core/v1"
2727
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
28-
virtv1 "kubevirt.io/api/core/v1"
2928
"sigs.k8s.io/controller-runtime/pkg/client"
3029

3130
vmbuilder "github.com/deckhouse/virtualization-controller/pkg/builder/vm"
@@ -80,22 +79,6 @@ var _ = Describe("TestFirmwareHandler", func() {
8079
return newVM(metav1.ConditionTrue)
8180
}
8281

83-
newKVVMI := func(phase virtv1.VirtualMachineInstancePhase) *virtv1.VirtualMachineInstance {
84-
return &virtv1.VirtualMachineInstance{
85-
TypeMeta: metav1.TypeMeta{
86-
APIVersion: virtv1.GroupVersion.String(),
87-
Kind: "VirtualMachineInstance",
88-
},
89-
ObjectMeta: metav1.ObjectMeta{
90-
Name: name,
91-
Namespace: namespace,
92-
},
93-
Status: virtv1.VirtualMachineInstanceStatus{
94-
Phase: phase,
95-
},
96-
}
97-
}
98-
9982
setupFirmwareEnvironment := func(vm *v1alpha2.VirtualMachine, objs ...client.Object) client.Client {
10083
allObjects := []client.Object{vm}
10184
allObjects = append(allObjects, objs...)
@@ -136,12 +119,8 @@ var _ = Describe("TestFirmwareHandler", func() {
136119
}
137120

138121
DescribeTable("FirmwareHandler should return serviceCompleteErr if migration executed",
139-
func(vm *v1alpha2.VirtualMachine, kvvmi *virtv1.VirtualMachineInstance, deploy *appsv1.Deployment, needMigrate bool) {
140-
objs := []client.Object{deploy}
141-
if kvvmi != nil {
142-
objs = append(objs, kvvmi)
143-
}
144-
fakeClient = setupFirmwareEnvironment(vm, objs...)
122+
func(vm *v1alpha2.VirtualMachine, deploy *appsv1.Deployment, needMigrate bool) {
123+
fakeClient = setupFirmwareEnvironment(vm, deploy)
145124

146125
mockMigration := &firmwareMigrationStub{
147126
onceMigrate: func(ctx context.Context, vm *v1alpha2.VirtualMachine, annotationKey, annotationExpectedValue string) (bool, error) {
@@ -159,35 +138,13 @@ var _ = Describe("TestFirmwareHandler", func() {
159138
Expect(err).NotTo(HaveOccurred())
160139
}
161140
},
162-
Entry("Migration should be executed", newVMNeedMigrate(), newKVVMI(virtv1.Running), newVirtController(true, firmwareImage), true),
163-
Entry("Migration should be executed when kvvmi is not found", newVMNeedMigrate(), nil, newVirtController(true, firmwareImage), true),
164-
Entry("Migration not should be executed", newVMUpToDate(), newKVVMI(virtv1.Running), newVirtController(true, firmwareImage), false),
165-
Entry("Migration should be executed even when kvvmi is stopped", newVMNeedMigrate(), newKVVMI(virtv1.Succeeded), newVirtController(true, firmwareImage), true),
166-
Entry("Migration should be executed even when kvvmi is pending", newVMNeedMigrate(), newKVVMI(virtv1.Pending), newVirtController(true, firmwareImage), true),
167-
Entry("Migration not should be executed because virt-controller not ready", newVMNeedMigrate(), newKVVMI(virtv1.Running), newVirtController(false, firmwareImage), false),
168-
Entry("Migration not should be executed because virt-controller ready but has wrong image", newVMNeedMigrate(), newKVVMI(virtv1.Running), newVirtController(true, "wrong-image"), false),
141+
Entry("Migration should be executed", newVMNeedMigrate(), newVirtController(true, firmwareImage), true),
142+
Entry("Migration not should be executed", newVMUpToDate(), newVirtController(true, firmwareImage), false),
143+
Entry("Migration not should be executed because virt-controller not ready", newVMNeedMigrate(), newVirtController(false, firmwareImage), false),
144+
Entry("Migration not should be executed because virt-controller ready but has wrong image", newVMNeedMigrate(), newVirtController(true, "wrong-image"), false),
169145
)
170146

171-
It("should call migration when kvvmi is not running", func() {
172-
vm := newVMNeedMigrate()
173-
kvvmi := newKVVMI(virtv1.Failed)
174-
deploy := newVirtController(true, firmwareImage)
175-
fakeClient = setupFirmwareEnvironment(vm, kvvmi, deploy)
176-
177-
migrationCalled := false
178-
h := NewFirmwareHandler(fakeClient, &firmwareMigrationStub{
179-
onceMigrate: func(ctx context.Context, vm *v1alpha2.VirtualMachine, annotationKey, annotationExpectedValue string) (bool, error) {
180-
migrationCalled = true
181-
return true, nil
182-
},
183-
}, firmwareImage, virtControllerNamespace, virtControllerName)
184-
185-
_, err := h.Handle(ctx, vm)
186-
Expect(err).NotTo(HaveOccurred())
187-
Expect(migrationCalled).To(BeTrue())
188-
})
189-
190-
It("should continue processing when kvvmi is not found", func() {
147+
It("should call migration when update is needed and virt-controller is ready", func() {
191148
vm := newVMNeedMigrate()
192149
deploy := newVirtController(true, firmwareImage)
193150
fakeClient = setupFirmwareEnvironment(vm, deploy)

0 commit comments

Comments
 (0)