diff --git a/pkg/controller/datavolume-controller.go b/pkg/controller/datavolume-controller.go index 0b833644fb..d4dda87a3d 100644 --- a/pkg/controller/datavolume-controller.go +++ b/pkg/controller/datavolume-controller.go @@ -66,7 +66,7 @@ const ( // ImportFailed provides a const to indicate import has failed ImportFailed = "ImportFailed" // ImportSucceeded provides a const to indicate import has succeeded - ImportSucceeded = "ImportSucceded" + ImportSucceeded = "ImportSucceeded" // CloneScheduled provides a const to indicate clone is scheduled CloneScheduled = "CloneScheduled" // CloneInProgress provides a const to indicate clone is in progress diff --git a/tests/datavolume_test.go b/tests/datavolume_test.go index 1857195eba..fa9dd13a85 100644 --- a/tests/datavolume_test.go +++ b/tests/datavolume_test.go @@ -46,7 +46,7 @@ var _ = Describe("DataVolume tests", func() { }) Describe("Verify DataVolume", func() { - table.DescribeTable("with http import source should", func(url string, phase cdiv1.DataVolumePhase, dataVolumeName string, eventReasons []string) { + table.DescribeTable("with http import source should", func(url string, phase cdiv1.DataVolumePhase, dataVolumeName string, eventReason string) { dataVolume := utils.NewDataVolumeWithHTTPImport(dataVolumeName, "1Gi", url) By(fmt.Sprintf("creating new datavolume %s", dataVolume.Name)) @@ -61,22 +61,25 @@ var _ = Describe("DataVolume tests", func() { _, err = f.K8sClient.CoreV1().PersistentVolumeClaims(dataVolume.Namespace).Get(dataVolume.Name, metav1.GetOptions{}) Expect(err).ToNot(HaveOccurred()) - By(fmt.Sprint("Verifying events occurred")) - for _, eventReason := range eventReasons { - Eventually(func() bool { - events, err := tests.RunKubectlCommand(f, "get", "events", "-n", dataVolume.Namespace) - Expect(err).NotTo(HaveOccurred()) + By(fmt.Sprint("Verifying event occurred")) + Eventually(func() bool { + events, err := tests.RunKubectlCommand(f, "get", "events", "-n", dataVolume.Namespace) + if err == nil { + fmt.Fprintf(GinkgoWriter, "%s", events) return strings.Contains(events, eventReason) - }, timeout, pollingInterval).Should(BeTrue()) - } + } else { + fmt.Fprintf(GinkgoWriter, "ERROR: %s\n", err.Error()) + return false + } + }, timeout, pollingInterval).Should(BeTrue()) err = utils.DeleteDataVolume(f.CdiClient, f.Namespace.Name, dataVolume.Name) Expect(err).ToNot(HaveOccurred()) }, - table.Entry("succeed when given valid url", utils.TinyCoreIsoURL, cdiv1.Succeeded, "dv-phase-test-1", []string{controller.ImportScheduled, controller.ImportSucceeded}), - table.Entry("fail due to invalid DNS entry", "http://i-made-this-up.kube-system/tinyCore.iso", cdiv1.Failed, "dv-phase-test-2", []string{controller.ImportScheduled}), - table.Entry("fail due to file not found", utils.TinyCoreIsoURL+"not.real.file", cdiv1.Failed, "dv-phase-test-3", []string{controller.ImportScheduled}), + table.Entry("succeed when given valid url", utils.TinyCoreIsoURL, cdiv1.Succeeded, "dv-phase-test-1", controller.ImportSucceeded), + table.Entry("fail due to invalid DNS entry", "http://i-made-this-up.kube-system/tinyCore.iso", cdiv1.Failed, "dv-phase-test-2", controller.ImportFailed), + table.Entry("fail due to file not found", utils.TinyCoreIsoURL+"not.real.file", cdiv1.Failed, "dv-phase-test-3", controller.ImportFailed), ) table.DescribeTable("with clone source should", func(command string, phase cdiv1.DataVolumePhase, dataVolumeName string) { diff --git a/tests/upload_test.go b/tests/upload_test.go index 82da9435f7..8367814495 100644 --- a/tests/upload_test.go +++ b/tests/upload_test.go @@ -6,6 +6,8 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "k8s.io/api/core/v1" + "kubevirt.io/containerized-data-importer/tests/framework" "kubevirt.io/containerized-data-importer/tests/utils" ) @@ -44,6 +46,9 @@ var _ = Describe("Upload tests", func() { err = utils.UploadImageFromNode(f.K8sClient, f.GoCLIPath, token) Expect(err).ToNot(HaveOccurred()) + err = f.WaitForPersistentVolumeClaimPhase(v1.ClaimBound, pvc.Name) + Expect(err).ToNot(HaveOccurred()) + By("Verify content") same := f.VerifyTargetPVCContentMD5(f.Namespace, pvc, testFile, utils.UploadFileMD5) Expect(same).To(BeTrue()) diff --git a/tests/utils/pod.go b/tests/utils/pod.go index e84cc5d57b..e6836d358e 100644 --- a/tests/utils/pod.go +++ b/tests/utils/pod.go @@ -116,7 +116,7 @@ func FindPodByPrefix(clientSet *kubernetes.Clientset, namespace, prefix, labelSe } func newExecutorPodWithPVC(podName string, pvc *k8sv1.PersistentVolumeClaim) *k8sv1.Pod { - return NewPodWithPVC(podName, "sleep 15; echo I am an executor pod;", pvc) + return NewPodWithPVC(podName, "sleep 30; echo I am an executor pod;", pvc) } // WaitTimeoutForPodReady waits for the given pod to be created and ready diff --git a/tests/utils/pvc.go b/tests/utils/pvc.go index b8c7e91979..8a98fab855 100644 --- a/tests/utils/pvc.go +++ b/tests/utils/pvc.go @@ -5,6 +5,7 @@ import ( "fmt" + "github.com/onsi/ginkgo" k8sv1 "k8s.io/api/core/v1" apierrs "k8s.io/apimachinery/pkg/api/errors" k8serrors "k8s.io/apimachinery/pkg/api/errors" @@ -130,6 +131,7 @@ func NewPVCDefinition(pvcName string, size string, annotations, labels map[strin func WaitForPersistentVolumeClaimPhase(clientSet *kubernetes.Clientset, namespace string, phase k8sv1.PersistentVolumeClaimPhase, pvcName string) error { err := wait.PollImmediate(pvcPollInterval, pvcPhaseTime, func() (bool, error) { pvc, err := clientSet.CoreV1().PersistentVolumeClaims(namespace).Get(pvcName, metav1.GetOptions{}) + fmt.Fprintf(ginkgo.GinkgoWriter, "INFO: Checking PVC phase: %s\n", string(pvc.Status.Phase)) if err != nil || pvc.Status.Phase != phase { return false, err } diff --git a/tools/cdi-func-test-file-host-init/main.go b/tools/cdi-func-test-file-host-init/main.go index 8fcd0a4263..641f2a6ae6 100644 --- a/tools/cdi-func-test-file-host-init/main.go +++ b/tools/cdi-func-test-file-host-init/main.go @@ -21,7 +21,6 @@ import ( "os" "path/filepath" "strings" - "sync" ) func main() { @@ -52,7 +51,7 @@ func main() { type formatTable [][]string func (ft formatTable) initializeTestFiles(inFile, outDir string) error { - var wg sync.WaitGroup + sem := make(chan bool, 3) errChan := make(chan error, len(ft)) reportError := func(err error, msg string, format ...interface{}) { @@ -63,10 +62,10 @@ func (ft formatTable) initializeTestFiles(inFile, outDir string) error { } for _, fList := range ft { - wg.Add(1) + sem <- true go func(i, o string, f []string) { - defer wg.Done() + defer func() { <-sem }() glog.Infof("Generating file %s\n", f) ext := strings.Join(f, "") @@ -98,7 +97,9 @@ func (ft formatTable) initializeTestFiles(inFile, outDir string) error { glog.Infof("Generated file %q\n", p) }(inFile, outDir, fList) } - wg.Wait() + for i := 0; i < cap(sem); i++ { + sem <- true + } close(errChan) if len(errChan) > 0 {