Skip to content

Commit

Permalink
add readonly flag to test executor pods
Browse files Browse the repository at this point in the history
synchronize get hash calls

Signed-off-by: Michael Henriksen <mhenriks@redhat.com>
  • Loading branch information
mhenriks committed May 19, 2023
1 parent aa2dd2f commit b835445
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
16 changes: 8 additions & 8 deletions tests/clone-populator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ var _ = Describe("Clone Populator tests", func() {
source := createSource(defaultSize, corev1.PersistentVolumeFilesystem)
createDataSource()
target := createTarget(defaultSize, corev1.PersistentVolumeFilesystem)
sourceHash := getHash(source, 0)
target = waitSucceeded(target)
sourceHash := getHash(source, 0)
targetHash := getHash(target, 0)
Expect(targetHash).To(Equal(sourceHash))
})
Expand All @@ -153,8 +153,8 @@ var _ = Describe("Clone Populator tests", func() {
createDataSource()
target := createTarget(defaultSize, corev1.PersistentVolumeFilesystem)
source := createSource(defaultSize, corev1.PersistentVolumeFilesystem)
sourceHash := getHash(source, 0)
target = waitSucceeded(target)
sourceHash := getHash(source, 0)
targetHash := getHash(target, 0)
Expect(targetHash).To(Equal(sourceHash))
})
Expand All @@ -163,8 +163,8 @@ var _ = Describe("Clone Populator tests", func() {
source := createSource(defaultSize, corev1.PersistentVolumeFilesystem)
target := createTarget(defaultSize, corev1.PersistentVolumeFilesystem)
createDataSource()
sourceHash := getHash(source, 0)
target = waitSucceeded(target)
sourceHash := getHash(source, 0)
targetHash := getHash(target, 0)
Expect(targetHash).To(Equal(sourceHash))
})
Expand All @@ -173,10 +173,10 @@ var _ = Describe("Clone Populator tests", func() {
source := createSource(defaultSize, corev1.PersistentVolumeFilesystem)
createDataSource()
target := createTarget(biggerSize, corev1.PersistentVolumeFilesystem)
sourceHash := getHash(source, 0)
target = waitSucceeded(target)
targetSize := target.Status.Capacity[corev1.ResourceStorage]
Expect(targetSize.Cmp(biggerSize)).To(BeNumerically(">=", 0))
sourceHash := getHash(source, 0)
targetHash := getHash(target, 0)
Expect(targetHash).To(Equal(sourceHash))
})
Expand All @@ -188,10 +188,10 @@ var _ = Describe("Clone Populator tests", func() {
source := createSource(defaultSize, corev1.PersistentVolumeBlock)
createDataSource()
target := createTarget(defaultSize, corev1.PersistentVolumeFilesystem)
sourceHash := getHash(source, 0)
target = waitSucceeded(target)
targetSize := target.Status.Capacity[corev1.ResourceStorage]
Expect(targetSize.Cmp(defaultSize)).To(BeNumerically(">", 0))
sourceHash := getHash(source, 0)
targetHash := getHash(target, 0)
Expect(targetHash).To(Equal(sourceHash))
})
Expand All @@ -203,10 +203,10 @@ var _ = Describe("Clone Populator tests", func() {
source := createSource(defaultSize, corev1.PersistentVolumeFilesystem)
createDataSource()
target := createTarget(defaultSize, corev1.PersistentVolumeBlock)
sourceHash := getHash(source, 100000)
target = waitSucceeded(target)
targetSize := target.Status.Capacity[corev1.ResourceStorage]
Expect(targetSize.Cmp(defaultSize)).To(BeNumerically(">=", 0))
sourceHash := getHash(source, 100000)
targetHash := getHash(target, 100000)
Expect(targetHash).To(Equal(sourceHash))
})
Expand All @@ -218,9 +218,9 @@ var _ = Describe("Clone Populator tests", func() {
source := createSource(defaultSize, corev1.PersistentVolumeFilesystem)
createDataSource()
target := createTargetWithStrategy(defaultSize, corev1.PersistentVolumeFilesystem, "csi-clone")
sourceHash := getHash(source, 0)
target = waitSucceeded(target)
Expect(target.Annotations["cdi.kubevirt.io/cloneType"]).To(Equal("csi-clone"))
sourceHash := getHash(source, 0)
targetHash := getHash(target, 0)
Expect(targetHash).To(Equal(sourceHash))
})
Expand All @@ -232,9 +232,9 @@ var _ = Describe("Clone Populator tests", func() {
source := createSource(defaultSize, corev1.PersistentVolumeFilesystem)
createDataSource()
target := createTargetWithStrategy(defaultSize, corev1.PersistentVolumeFilesystem, "snapshot")
sourceHash := getHash(source, 0)
target = waitSucceeded(target)
Expect(target.Annotations["cdi.kubevirt.io/cloneType"]).To(Equal("snapshot"))
sourceHash := getHash(source, 0)
targetHash := getHash(target, 0)
Expect(targetHash).To(Equal(sourceHash))
})
Expand Down
14 changes: 7 additions & 7 deletions tests/framework/pvc.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func (f *Framework) CreateAndPopulateSourcePVC(pvcDef *k8sv1.PersistentVolumeCla

// PopulatePVC populates a PVC using a pod with the provided pod name and command
func (f *Framework) PopulatePVC(pvc *k8sv1.PersistentVolumeClaim, podName string, fillCommand string) {
pod, err := f.CreatePod(f.NewPodWithPVC(podName, fillCommand+"&& sync", pvc))
pod, err := f.CreatePod(f.NewPodWithPVC(podName, fillCommand+"&& sync", pvc, false))
gomega.Expect(err).ToNot(gomega.HaveOccurred())

err = f.WaitTimeoutForPodStatus(pod.Name, k8sv1.PodSucceeded, utils.PodWaitForTime)
Expand Down Expand Up @@ -392,7 +392,7 @@ func (f *Framework) RunCommandAndCaptureOutput(pvc *k8sv1.PersistentVolumeClaim,
}

// NewPodWithPVC creates a new pod that mounts the given PVC
func (f *Framework) NewPodWithPVC(podName, cmd string, pvc *k8sv1.PersistentVolumeClaim) *k8sv1.Pod {
func (f *Framework) NewPodWithPVC(podName, cmd string, pvc *k8sv1.PersistentVolumeClaim, readOnly bool) *k8sv1.Pod {
var importerImage string
volumeName := naming.GetLabelNameFromResourceName(pvc.GetName())
for _, e := range f.ControllerPod.Spec.Containers[0].Env {
Expand Down Expand Up @@ -443,7 +443,7 @@ func (f *Framework) NewPodWithPVC(podName, cmd string, pvc *k8sv1.PersistentVolu
if volumeMode != nil && *volumeMode == k8sv1.PersistentVolumeBlock {
pod.Spec.Containers[0].VolumeDevices = addVolumeDevices(pvc, volumeName)
} else {
pod.Spec.Containers[0].VolumeMounts = addVolumeMounts(pvc, volumeName)
pod.Spec.Containers[0].VolumeMounts = addVolumeMounts(pvc, volumeName, readOnly)
}

controller.SetRestrictedSecurityContext(&pod.Spec)
Expand All @@ -452,7 +452,7 @@ func (f *Framework) NewPodWithPVC(podName, cmd string, pvc *k8sv1.PersistentVolu
}

func (f *Framework) newExecutorPodWithPVC(podName string, pvc *k8sv1.PersistentVolumeClaim) *k8sv1.Pod {
return f.NewPodWithPVC(podName, "while true; do echo hello; sleep 2;done", pvc)
return f.NewPodWithPVC(podName, "while true; do echo hello; sleep 2;done", pvc, true)
}

// CreateExecutorPodWithPVC creates a Pod with the passed in PVC mounted under /dev/pvc. You can then use the executor utilities to
Expand All @@ -473,7 +473,7 @@ func (f *Framework) CreateExecutorPodWithPVCSpecificNode(podName, namespace stri

// CreateNoopPodWithPVC creates a short living pod, that might be used to force bind a pvc
func (f *Framework) CreateNoopPodWithPVC(podName, namespace string, pvc *k8sv1.PersistentVolumeClaim) (*k8sv1.Pod, error) {
return utils.CreatePod(f.K8sClient, namespace, f.NewPodWithPVC(podName, "echo I am vm doppleganger pod;", pvc))
return utils.CreatePod(f.K8sClient, namespace, f.NewPodWithPVC(podName, "echo I am vm doppleganger pod;", pvc, true))
}

// CreateVerifierPodWithPVC creates a Pod called verifier, with the passed in PVC mounted under /dev/pvc. You can then use the executor utilities to
Expand All @@ -493,12 +493,12 @@ func addVolumeDevices(pvc *k8sv1.PersistentVolumeClaim, volumeName string) []k8s
}

// this is being called for pods using PV with filesystem volume mode
func addVolumeMounts(pvc *k8sv1.PersistentVolumeClaim, volumeName string) []k8sv1.VolumeMount {
func addVolumeMounts(pvc *k8sv1.PersistentVolumeClaim, volumeName string, readOnly bool) []k8sv1.VolumeMount {
volumeMounts := []k8sv1.VolumeMount{
{
Name: volumeName,
MountPath: utils.DefaultPvcMountPath,
ReadOnly: true,
ReadOnly: readOnly,
},
}
return volumeMounts
Expand Down

0 comments on commit b835445

Please sign in to comment.