Skip to content

Commit

Permalink
Merge branch 'master' into specify_image_size
Browse files Browse the repository at this point in the history
  • Loading branch information
j-griffith authored Nov 20, 2018
2 parents 3675191 + 273df99 commit cad870d
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 18 deletions.
2 changes: 1 addition & 1 deletion pkg/controller/datavolume-controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 14 additions & 11 deletions tests/datavolume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions tests/upload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/utils/pvc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
11 changes: 6 additions & 5 deletions tools/cdi-func-test-file-host-init/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"os"
"path/filepath"
"strings"
"sync"
)

func main() {
Expand Down Expand Up @@ -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{}) {
Expand All @@ -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, "")
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit cad870d

Please sign in to comment.