Skip to content

Commit

Permalink
Adjust tests functions to handle dvs using populators
Browse files Browse the repository at this point in the history
Signed-off-by: Shelly Kagan <skagan@redhat.com>
  • Loading branch information
ShellyKa13 committed May 24, 2023
1 parent 30c0f4c commit 87994ea
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 11 deletions.
14 changes: 13 additions & 1 deletion tests/datavolume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,12 +404,24 @@ var _ = Describe("[vendor:cnv-qe@redhat.com][level:component]DataVolume tests",
utils.WaitForConditions(f, dataVolume.Name, f.Namespace.Name, timeout, pollingInterval, boundCondition, readyCondition)

By("Increase quota")
err = f.UpdateStorageQuota(int64(2), int64(2*1024*1024*1024))
err = f.UpdateStorageQuota(int64(3), int64(4*1024*1024*1024))
Expect(err).ToNot(HaveOccurred())
f.ForceBindPvcIfDvIsWaitForFirstConsumer(dataVolume)

waitForDvPhase(args.phase, dataVolume, f)

// in case of upload if we use populators the pvc will stay pending
// until the upload completes
if args.name == "upload-dv" {
pvc, err := utils.FindPVC(f.K8sClient, dataVolume.Namespace, dataVolume.Name)
Expect(err).ToNot(HaveOccurred())
if pvc.Spec.DataSourceRef != nil {
args.boundCondition.Status = v1.ConditionFalse
args.boundCondition.Message = "PVC upload-dv Pending"
args.boundCondition.Reason = "Pending"
}
}

By("Verifying the DV has the correct conditions and messages for those conditions")
utils.WaitForConditions(f, dataVolume.Name, f.Namespace.Name, timeout, pollingInterval, args.readyCondition, args.runningCondition, args.boundCondition)

Expand Down
15 changes: 12 additions & 3 deletions tests/framework/pvc.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,13 @@ func (f *Framework) ForceBindPvcIfDvIsWaitForFirstConsumer(dv *cdiv1.DataVolume)
pvc, err := utils.WaitForPVC(f.K8sClient, dv.Namespace, dv.Name)
gomega.Expect(err).ToNot(gomega.HaveOccurred(), "PVC should exist")
if f.IsBindingModeWaitForFirstConsumer(pvc.Spec.StorageClassName) {
err = utils.WaitForDataVolumePhase(f, dv.Namespace, cdiv1.WaitForFirstConsumer, dv.Name)
expectedPhase := cdiv1.WaitForFirstConsumer
if pvc.Spec.DataSourceRef != nil {
expectedPhase = cdiv1.PendingPopulation
}
err = utils.WaitForDataVolumePhase(f, dv.Namespace, expectedPhase, dv.Name)
gomega.Expect(err).ToNot(gomega.HaveOccurred())
createConsumerPod(pvc, f)
f.ForceBindIfWaitForFirstConsumer(pvc)
}
}

Expand All @@ -91,7 +95,11 @@ func (f *Framework) WaitPVCDeletedByUID(pvcSpec *k8sv1.PersistentVolumeClaim, ti
// ForceBindIfWaitForFirstConsumer creates a Pod with the passed in PVC mounted under /dev/pvc, which forces the PVC to be scheduled and bound.
func (f *Framework) ForceBindIfWaitForFirstConsumer(targetPvc *k8sv1.PersistentVolumeClaim) {
if targetPvc.Spec.VolumeName == "" && f.IsBindingModeWaitForFirstConsumer(targetPvc.Spec.StorageClassName) {
createConsumerPod(targetPvc, f)
if targetPvc.Spec.DataSourceRef != nil {
createConsumerPodForPopulationPVC(targetPvc, f)
} else {
createConsumerPod(targetPvc, f)
}
}
}

Expand Down Expand Up @@ -299,6 +307,7 @@ func (f *Framework) VerifyFSOverhead(namespace *k8sv1.Namespace, pvc *k8sv1.Pers
}

requestedSize := pvc.Spec.Resources.Requests[k8sv1.ResourceStorage]
fmt.Fprintf(ginkgo.GinkgoWriter, "INFO: VerifyFSOverhead comparison: Virtual: %d, Actual: %d, requestedSize: %d\n", info.VirtualSize, info.ActualSize, requestedSize.Value())
return info.VirtualSize <= info.ActualSize && info.VirtualSize < requestedSize.Value(), nil
}

Expand Down
22 changes: 18 additions & 4 deletions tests/import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1244,9 +1244,17 @@ var _ = Describe("Preallocation", func() {
if dv.Spec.Source.Registry != nil && dv.Spec.Source.Registry.ImageStream != nil {
By("Verify image lookup annotation")
podName := pvc.Annotations[controller.AnnImportPod]
pod, err := f.K8sClient.CoreV1().Pods(f.Namespace.Name).Get(context.TODO(), podName, metav1.GetOptions{})
Expect(err).NotTo(HaveOccurred())
Expect(pod.Annotations[controller.AnnOpenShiftImageLookup]).To(Equal("*"))
if pvc.Spec.DataSourceRef != nil {
Expect(podName).To(BeEmpty())
} else {
// when using populators when the population completes PVC' and
// the importer pod are deleted, so can't check the annotation
// TODO: any suggestions? putting the check before dv completes is
// still racy
pod, err := f.K8sClient.CoreV1().Pods(f.Namespace.Name).Get(context.TODO(), podName, metav1.GetOptions{})
Expect(err).NotTo(HaveOccurred())
Expect(pod.Annotations[controller.AnnOpenShiftImageLookup]).To(Equal("*"))
}
}
},
Entry("HTTP import (ISO image)", true, utils.TinyCoreMD5, utils.DefaultImagePath, func() *cdiv1.DataVolume {
Expand Down Expand Up @@ -1376,7 +1384,13 @@ var _ = Describe("Preallocation", func() {
Expect(err).ToNot(HaveOccurred())
Expect(found).To(BeTrue())

Expect(f.VerifyFSOverhead(f.Namespace, pvc, preallocation)).To(BeTrue())
// incase of using populators the requested size with the fsoverhead
// is put only on the PVC' which at thisd point we can't check
// TODO: any suggestions? getting the requested size from PVC' in earlier
// point in the test seems to be racy
if pvc.Spec.DataSourceRef == nil {
Expect(f.VerifyFSOverhead(f.Namespace, pvc, preallocation)).To(BeTrue())
}

pvc, err = utils.FindPVC(f.K8sClient, dataVolume.Namespace, dataVolume.Name)
Expect(err).ToNot(HaveOccurred())
Expand Down
1 change: 1 addition & 0 deletions tests/utils/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ go_library(
"//pkg/common:go_default_library",
"//pkg/controller/common:go_default_library",
"//pkg/controller/datavolume:go_default_library",
"//pkg/controller/populators:go_default_library",
"//pkg/image:go_default_library",
"//pkg/util:go_default_library",
"//pkg/util/naming:go_default_library",
Expand Down
10 changes: 7 additions & 3 deletions tests/utils/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package utils
import (
"context"

corev1 "k8s.io/api/core/v1"
k8sv1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
Expand All @@ -14,6 +13,7 @@ import (
cdiClientset "kubevirt.io/containerized-data-importer/pkg/client/clientset/versioned"
"kubevirt.io/containerized-data-importer/pkg/common"
cc "kubevirt.io/containerized-data-importer/pkg/controller/common"
"kubevirt.io/containerized-data-importer/pkg/controller/populators"
"kubevirt.io/containerized-data-importer/pkg/util/naming"
)

Expand Down Expand Up @@ -56,7 +56,11 @@ const (

// UploadPodName returns the name of the upload server pod associated with a PVC
func UploadPodName(pvc *k8sv1.PersistentVolumeClaim) string {
return naming.GetResourceName(common.UploadPodName, pvc.Name)
uploadPodNameSuffix := pvc.Name
if pvc.Spec.DataSourceRef != nil {
uploadPodNameSuffix = populators.PVCPrimeName(pvc)
}
return naming.GetResourceName(common.UploadPodName, uploadPodNameSuffix)
}

// UploadPVCDefinition creates a PVC with the upload target annotation
Expand Down Expand Up @@ -91,7 +95,7 @@ func UploadPopulationPVCDefinition() *k8sv1.PersistentVolumeClaim {
func UploadPopulationBlockPVCDefinition(storageClassName string) *k8sv1.PersistentVolumeClaim {
pvcDef := UploadPopulationPVCDefinition()
pvcDef.Spec.StorageClassName = &storageClassName
volumeMode := corev1.PersistentVolumeBlock
volumeMode := k8sv1.PersistentVolumeBlock
pvcDef.Spec.VolumeMode = &volumeMode
return pvcDef
}
Expand Down

0 comments on commit 87994ea

Please sign in to comment.