Fix clone tests (#386)

* test: fix pvc annotation check

The clone controller uses a slightly different annotation on PVCs.  The
test was using the form used by the import controller.  Quick fix.

Signed-off-by: Adam Litke <alitke@redhat.com>

* tests: Pods must be polled to determine their node

When checking the node on which a pod is scheduled we must use an
Eventually assertion and poll.  Otherwise, tests could flake when pod
scheduling is delayed.

Signed-off-by: Adam Litke <alitke@redhat.com>
This commit is contained in:
Adam Litke 2018-08-29 15:59:28 -04:00 committed by Alexander Wels
parent d394d2de78
commit facfe372b6
2 changed files with 29 additions and 14 deletions

View File

@ -17,15 +17,16 @@ import (
)
const (
testSuiteName = "Cloner Test Suite"
namespacePrefix = "cloner"
sourcePodFillerName = "fill-source"
sourcePVCName = "source-pvc"
fillData = "123456789012345678901234567890123456789012345678901234567890"
testFile = utils.DefaultPvcMountPath + "/source.txt"
fillCommand = "echo \"" + fillData + "\" >> " + testFile
cloneCompleteTimeout = 10 * time.Second
testCompleteTimeout = 300 * time.Second
testSuiteName = "Cloner Test Suite"
namespacePrefix = "cloner"
sourcePodFillerName = "fill-source"
sourcePVCName = "source-pvc"
fillData = "123456789012345678901234567890123456789012345678901234567890"
testFile = utils.DefaultPvcMountPath + "/source.txt"
fillCommand = "echo \"" + fillData + "\" >> " + testFile
assertionPollInterval = 2 * time.Second
cloneCompleteTimeout = 10 * time.Second
testCompleteTimeout = 300 * time.Second
)
var _ = Describe(testSuiteName, func() {
@ -94,10 +95,16 @@ func doCloneTest(f *framework.Framework, targetNs *v1.Namespace) {
targetPod, err := utils.FindPodByPrefix(f.K8sClient, targetNs.Name, common.CLONER_TARGET_PODNAME, common.CDI_LABEL_SELECTOR)
Expect(err).ToNot(HaveOccurred())
By("Source and Target pods have to be on same node")
fmt.Fprintf(GinkgoWriter, "INFO: Source POD host %s\n", sourcePod.Spec.NodeName)
fmt.Fprintf(GinkgoWriter, "INFO: Target POD host %s\n", targetPod.Spec.NodeName)
Expect(sourcePod.Spec.NodeName).To(Equal(targetPod.Spec.NodeName))
By("Verifying that the source and target pods are scheduled on the same node")
Eventually(func() bool {
srcNode, err := utils.PodNode(f.K8sClient, sourcePod.Name, sourcePod.Namespace)
Expect(err).ToNot(HaveOccurred())
tgtNode, err := utils.PodNode(f.K8sClient, targetPod.Name, targetPod.Namespace)
Expect(err).ToNot(HaveOccurred())
fmt.Fprintf(GinkgoWriter, "INFO: Source POD host %s\n", srcNode)
fmt.Fprintf(GinkgoWriter, "INFO: Target POD host %s\n", tgtNode)
return srcNode == tgtNode
}, cloneCompleteTimeout, assertionPollInterval).Should(BeTrue())
err = f.WaitTimeoutForPodStatus(sourcePod.Name, v1.PodSucceeded, cloneCompleteTimeout)
Expect(err).ToNot(HaveOccurred())
@ -110,7 +117,7 @@ func doCloneTest(f *framework.Framework, targetNs *v1.Namespace) {
Expect(cloneAnnotationFound).To(BeTrue())
By("Verify the clone status is success on the target PVC")
status, phaseAnnotation, err := utils.WaitForPVCAnnotation(f.K8sClient, targetNs.Name, targetPvc, controller.AnnPodPhase)
status, phaseAnnotation, err := utils.WaitForPVCAnnotation(f.K8sClient, targetNs.Name, targetPvc, controller.AnnClonePodPhase)
Expect(phaseAnnotation).To(BeTrue())
Expect(status).Should(BeEquivalentTo(v1.PodSucceeded))

View File

@ -136,3 +136,11 @@ func podStatus(clientSet *kubernetes.Clientset, podName, namespace string, statu
return false, nil
}
}
func PodGetNode(clientSet *kubernetes.Clientset, podName, namespace string) (string, error) {
pod, err := clientSet.CoreV1().Pods(namespace).Get(podName, metav1.GetOptions{})
if err != nil {
return "", err
}
return pod.Spec.NodeName, nil
}