New test case "delete file during import" (#1272)

* New test case "delete file during import"

Signed-off-by: Bartosz Rybacki <brybacki@redhat.com>

* Code review fixes (const and cleanup)

Signed-off-by: Bartosz Rybacki <brybacki@redhat.com>

* Use utility WaitPVCDeleted

Signed-off-by: Bartosz Rybacki <brybacki@redhat.com>
This commit is contained in:
Bartosz Rybacki 2020-07-06 20:17:37 +02:00 committed by GitHub
parent ec38c570ef
commit 831fc3df94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 94 additions and 1 deletions

View File

@ -811,6 +811,99 @@ var _ = Describe("[vendor:cnv-qe@redhat.com][level:component]DataVolume tests",
})
})
Describe("[rfe_id:1115][crit:high][vendor:cnv-qe@redhat.com][level:component][test] CDI Import from HTTP/S3", func() {
const (
originalImageName = "cirros-qcow2.img"
testImageName = "cirros-qcow2-1990.img"
)
var (
dataVolume *cdiv1.DataVolume
err error
tinyCoreIsoRateLimitURL = "http://cdi-file-host." + f.CdiInstallNs + ":82/cirros-qcow2-1990.img"
)
BeforeEach(func() {
By("Prepare the file")
fileHostPod, err := utils.FindPodByPrefix(f.K8sClient, f.CdiInstallNs, utils.FileHostName, "name="+utils.FileHostName)
_, _, err = f.ExecCommandInContainerWithFullOutput(fileHostPod.Namespace, fileHostPod.Name, "http",
"/bin/sh",
"-c",
"cp /tmp/shared/images/"+originalImageName+" /tmp/shared/images/"+testImageName)
Expect(err).To(BeNil())
})
AfterEach(func() {
By("Delete DV")
err = utils.DeleteDataVolume(f.CdiClient, f.Namespace.Name, dataVolume.Name)
Expect(err).ToNot(HaveOccurred())
By("Cleanup the file")
fileHostPod, err := utils.FindPodByPrefix(f.K8sClient, f.CdiInstallNs, utils.FileHostName, "name="+utils.FileHostName)
_, _, err = f.ExecCommandInContainerWithFullOutput(fileHostPod.Namespace, fileHostPod.Name, "http",
"/bin/sh",
"-c",
"rm -f /tmp/shared/images/"+testImageName)
Expect(err).To(BeNil())
By("Verifying pvc was deleted")
deleted, err := utils.WaitPVCDeleted(f.K8sClient, dataVolume.Name, dataVolume.Namespace, timeout)
Expect(deleted).To(BeTrue())
Expect(err).ToNot(HaveOccurred())
})
It("[test_id:1990] CDI Data Volume - file is removed from http server while import is in progress", func() {
dvName := "import-file-removed"
By(fmt.Sprintf("Creating new datavolume %s", dvName))
dv := utils.NewDataVolumeWithHTTPImport(dvName, "500Mi", tinyCoreIsoRateLimitURL)
dataVolume, err = utils.CreateDataVolumeFromDefinition(f.CdiClient, f.Namespace.Name, dv)
Expect(err).ToNot(HaveOccurred())
phase := cdiv1.ImportInProgress
By(fmt.Sprintf("Waiting for datavolume to match phase %s", string(phase)))
err = utils.WaitForDataVolumePhase(f.CdiClient, f.Namespace.Name, phase, dataVolume.Name)
Expect(err).ToNot(HaveOccurred())
// here we want to have more than 0, to be sure it started
progressRegExp := regexp.MustCompile("[1-9]\\d{0,2}\\.?\\d{1,2}%")
Eventually(func() bool {
dv, err := f.CdiClient.CdiV1alpha1().DataVolumes(f.Namespace.Name).Get(dataVolume.Name, metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())
progress := dv.Status.Progress
fmt.Fprintf(GinkgoWriter, "INFO: current progress:%v, matches:%v\n", progress, progressRegExp.MatchString(string(progress)))
return progressRegExp.MatchString(string(progress))
}, timeout, pollingInterval).Should(BeTrue())
By("Remove source image file & kill http container to force restart")
fileHostPod, err := utils.FindPodByPrefix(f.K8sClient, f.CdiInstallNs, utils.FileHostName, "name="+utils.FileHostName)
_, _, err = f.ExecCommandInContainerWithFullOutput(fileHostPod.Namespace, fileHostPod.Name, "http",
"/bin/sh",
"-c",
"rm /tmp/shared/images/"+testImageName)
Expect(err).To(BeNil())
By("Verify the number of retries on the datavolume")
Eventually(func() int32 {
dv, err := f.CdiClient.CdiV1alpha1().DataVolumes(f.Namespace.Name).Get(dataVolume.Name, metav1.GetOptions{})
Expect(err).NotTo(HaveOccurred())
restarts := dv.Status.RestartCount
return restarts
}, timeout, pollingInterval).Should(BeNumerically(">=", 1))
By("Restore the file, import should progress")
utils.WaitTimeoutForPodReady(f.K8sClient, fileHostPod.Name, fileHostPod.Namespace, utils.PodWaitForTime)
_, _, err = f.ExecCommandInContainerWithFullOutput(fileHostPod.Namespace, fileHostPod.Name, "http",
"/bin/sh",
"-c",
"cp /tmp/shared/images/"+originalImageName+" /tmp/shared/images/"+testImageName)
Expect(err).To(BeNil())
By("Wait for the eventual success")
err = utils.WaitForDataVolumePhaseWithTimeout(f.CdiClient, f.Namespace.Name, cdiv1.Succeeded, dataVolume.Name, 300*time.Second)
Expect(err).To(BeNil())
})
})
})
func verifyConditions(actualConditions []cdiv1.DataVolumeCondition, startTime time.Time, testConditions ...*cdiv1.DataVolumeCondition) bool {

View File

@ -60,7 +60,7 @@ http {
location / {
autoindex on;
autoindex_format json;
limit_rate 10k;
limit_rate 100k;
}
}
# tls