Skip to content

Commit

Permalink
test, utils: Move NotDeleted() and NotDeletedVMs()
Browse files Browse the repository at this point in the history
Signed-off-by: assafad <aadmi@redhat.com>
  • Loading branch information
assafad committed May 5, 2024
1 parent a723532 commit b6851d2
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 25 deletions.
1 change: 1 addition & 0 deletions tests/libreplicaset/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ go_library(
importpath = "kubevirt.io/kubevirt/tests/libreplicaset",
visibility = ["//visibility:public"],
deps = [
"//staging/src/kubevirt.io/api/core/v1:go_default_library",
"//staging/src/kubevirt.io/client-go/kubecli:go_default_library",
"//tests:go_default_library",
"//tests/testsuite:go_default_library",
Expand Down
12 changes: 11 additions & 1 deletion tests/libreplicaset/replicaset.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
autov1 "k8s.io/api/autoscaling/v1"
v12 "k8s.io/apimachinery/pkg/apis/meta/v1"

v1 "kubevirt.io/api/core/v1"
"kubevirt.io/client-go/kubecli"

"kubevirt.io/kubevirt/tests"
Expand Down Expand Up @@ -39,5 +40,14 @@ func DoScaleWithScaleSubresource(virtClient kubecli.KubevirtClient, name string,

vmis, err := virtClient.VirtualMachineInstance(testsuite.GetTestNamespace(nil)).List(context.Background(), v12.ListOptions{})
ExpectWithOffset(1, err).ToNot(HaveOccurred())
ExpectWithOffset(1, tests.NotDeleted(vmis)).To(HaveLen(int(scale)))
ExpectWithOffset(1, NotDeleted(vmis)).To(HaveLen(int(scale)))
}

func NotDeleted(vmis *v1.VirtualMachineInstanceList) (notDeleted []v1.VirtualMachineInstance) {
for _, vmi := range vmis.Items {
if vmi.DeletionTimestamp == nil {
notDeleted = append(notDeleted, vmi)
}
}
return
}
16 changes: 12 additions & 4 deletions tests/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ import (
poolv1 "kubevirt.io/api/pool/v1alpha1"
"kubevirt.io/client-go/kubecli"

"kubevirt.io/kubevirt/tests"
cd "kubevirt.io/kubevirt/tests/containerdisk"
)

Expand Down Expand Up @@ -109,7 +108,7 @@ var _ = Describe("[sig-compute]VirtualMachinePool", decorators.SigCompute, func(

vms, err := virtClient.VirtualMachine(util.NamespaceTestDefault).List(context.Background(), v12.ListOptions{})
Expect(err).ToNot(HaveOccurred())
Expect(notDeletedVMs(pool.Name, vms)).To(HaveLen(int(scale)))
Expect(poolNotDeletedVMs(pool.Name, vms)).To(HaveLen(int(scale)))
}
createVirtualMachinePool := func(pool *poolv1.VirtualMachinePool) *poolv1.VirtualMachinePool {
pool, err = virtClient.VirtualMachinePool(util.NamespaceTestDefault).Create(context.Background(), pool, metav1.CreateOptions{})
Expand Down Expand Up @@ -623,8 +622,8 @@ func newPoolFromVMI(vmi *v1.VirtualMachineInstance) *poolv1.VirtualMachinePool {
return pool
}

func notDeletedVMs(poolName string, vms *v1.VirtualMachineList) (notDeleted []v1.VirtualMachine) {
nonDeletedVms := tests.NotDeletedVMs(vms)
func poolNotDeletedVMs(poolName string, vms *v1.VirtualMachineList) (notDeleted []v1.VirtualMachine) {
nonDeletedVms := notDeletedVMs(vms)
for _, vm := range nonDeletedVms {
for _, ref := range vm.OwnerReferences {
if ref.Name == poolName {
Expand All @@ -634,3 +633,12 @@ func notDeletedVMs(poolName string, vms *v1.VirtualMachineList) (notDeleted []v1
}
return
}

func notDeletedVMs(vms *v1.VirtualMachineList) (notDeleted []v1.VirtualMachine) {
for _, vm := range vms.Items {
if vm.DeletionTimestamp == nil {
notDeleted = append(notDeleted, vm)
}
}
return
}
4 changes: 2 additions & 2 deletions tests/replicaset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ var _ = Describe("[rfe_id:588][crit:medium][vendor:cnv-qe@redhat.com][level:comp

vmis, err := virtClient.VirtualMachineInstance(testsuite.GetTestNamespace(rs)).List(context.Background(), v12.ListOptions{})
Expect(err).ToNot(HaveOccurred())
Expect(tests.NotDeleted(vmis)).To(HaveLen(int(scale)))
Expect(libreplicaset.NotDeleted(vmis)).To(HaveLen(int(scale)))
}

doScaleWithHPA := func(name string, min int32, max int32, expected int32) {
Expand Down Expand Up @@ -114,7 +114,7 @@ var _ = Describe("[rfe_id:588][crit:medium][vendor:cnv-qe@redhat.com][level:comp

vmis, err := virtClient.VirtualMachineInstance(testsuite.GetTestNamespace(nil)).List(context.Background(), v12.ListOptions{})
ExpectWithOffset(1, err).ToNot(HaveOccurred())
ExpectWithOffset(1, tests.NotDeleted(vmis)).To(HaveLen(int(min)))
ExpectWithOffset(1, libreplicaset.NotDeleted(vmis)).To(HaveLen(int(min)))
err = virtClient.AutoscalingV1().HorizontalPodAutoscalers(testsuite.GetTestNamespace(nil)).Delete(context.Background(), name, v12.DeleteOptions{})
ExpectWithOffset(1, err).ToNot(HaveOccurred())
}
Expand Down
18 changes: 0 additions & 18 deletions tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,24 +519,6 @@ func GenerateVMJson(vm *v1.VirtualMachine, generateDirectory string) (string, er
return jsonFile, nil
}

func NotDeleted(vmis *v1.VirtualMachineInstanceList) (notDeleted []v1.VirtualMachineInstance) {
for _, vmi := range vmis.Items {
if vmi.DeletionTimestamp == nil {
notDeleted = append(notDeleted, vmi)
}
}
return
}

func NotDeletedVMs(vms *v1.VirtualMachineList) (notDeleted []v1.VirtualMachine) {
for _, vm := range vms.Items {
if vm.DeletionTimestamp == nil {
notDeleted = append(notDeleted, vm)
}
}
return
}

func UnfinishedVMIPodSelector(vmi *v1.VirtualMachineInstance) metav1.ListOptions {
virtClient := kubevirt.Client()

Expand Down

0 comments on commit b6851d2

Please sign in to comment.