Update framework imports and its functions.

Signed-off-by: Cedric Hauber <hauber.c@gmail.com>
This commit is contained in:
Humble Chirammal 2020-01-16 14:56:51 +05:30 committed by mergify[bot]
parent 7c96c5c567
commit 2d0ed298e3
5 changed files with 31 additions and 6 deletions

View File

@ -93,7 +93,7 @@ var _ = Describe("cephfs", func() {
var err error var err error
sts := deployProvAsSTS(f.ClientSet) sts := deployProvAsSTS(f.ClientSet)
if sts { if sts {
err = framework.WaitForStatefulSetReplicasReady(cephfsDeploymentName, namespace, f.ClientSet, 1*time.Second, timeout) err = waitForStatefulSetReplicasReady(cephfsDeploymentName, namespace, f.ClientSet, 1*time.Second, timeout)
} else { } else {
err = waitForDeploymentComplete(cephfsDeploymentName, namespace, f.ClientSet, deployTimeout) err = waitForDeploymentComplete(cephfsDeploymentName, namespace, f.ClientSet, deployTimeout)
} }

View File

@ -25,7 +25,7 @@ func init() {
setDefaultKubeconfig() setDefaultKubeconfig()
// Register framework flags, then handle flags // Register framework flags, then handle flags
framework.HandleFlags() handleFlags()
framework.AfterReadingAllFlags(&framework.TestContext) framework.AfterReadingAllFlags(&framework.TestContext)
fmt.Println("timeout for deploytimeout ", deployTimeout) fmt.Println("timeout for deploytimeout ", deployTimeout)

View File

@ -20,8 +20,8 @@ import (
v1 "k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clientset "k8s.io/client-go/kubernetes" clientset "k8s.io/client-go/kubernetes"
"k8s.io/kubernetes/test/e2e/framework"
e2elog "k8s.io/kubernetes/test/e2e/framework/log" e2elog "k8s.io/kubernetes/test/e2e/framework/log"
frameworkPod "k8s.io/kubernetes/test/e2e/framework/pod"
) )
func logsCSIPods(label string, c clientset.Interface) { func logsCSIPods(label string, c clientset.Interface) {
@ -44,7 +44,7 @@ func logsCSIPods(label string, c clientset.Interface) {
func kubectlLogPod(c clientset.Interface, pod *v1.Pod) { func kubectlLogPod(c clientset.Interface, pod *v1.Pod) {
container := pod.Spec.Containers container := pod.Spec.Containers
for i := range container { for i := range container {
logs, err := framework.GetPodLogs(c, pod.Namespace, pod.Name, container[i].Name) logs, err := frameworkPod.GetPodLogs(c, pod.Namespace, pod.Name, container[i].Name)
if err != nil { if err != nil {
logs, err = getPreviousPodLogs(c, pod.Namespace, pod.Name, container[i].Name) logs, err = getPreviousPodLogs(c, pod.Namespace, pod.Name, container[i].Name)
if err != nil { if err != nil {

View File

@ -103,7 +103,7 @@ var _ = Describe("RBD", func() {
var err error var err error
sts := deployProvAsSTS(f.ClientSet) sts := deployProvAsSTS(f.ClientSet)
if sts { if sts {
err = framework.WaitForStatefulSetReplicasReady(rbdDeploymentName, namespace, f.ClientSet, 1*time.Second, timeout) err = waitForStatefulSetReplicasReady(rbdDeploymentName, namespace, f.ClientSet, 1*time.Second, timeout)
} else { } else {
err = waitForDeploymentComplete(rbdDeploymentName, namespace, f.ClientSet, deployTimeout) err = waitForDeploymentComplete(rbdDeploymentName, namespace, f.ClientSet, deployTimeout)
} }

View File

@ -28,6 +28,7 @@ import (
"k8s.io/kubernetes/pkg/client/conditions" "k8s.io/kubernetes/pkg/client/conditions"
"k8s.io/kubernetes/test/e2e/framework" "k8s.io/kubernetes/test/e2e/framework"
e2elog "k8s.io/kubernetes/test/e2e/framework/log" e2elog "k8s.io/kubernetes/test/e2e/framework/log"
e2epv "k8s.io/kubernetes/test/e2e/framework/pv"
testutils "k8s.io/kubernetes/test/utils" testutils "k8s.io/kubernetes/test/utils"
) )
@ -134,6 +135,23 @@ func waitForDeploymentComplete(name, ns string, c clientset.Interface, t int) er
return nil return nil
} }
func waitForStatefulSetReplicasReady(statefulSetName, ns string, c clientset.Interface, Poll, timeout time.Duration) error {
framework.Logf("Waiting up to %v for StatefulSet %s to have all replicas ready", timeout, statefulSetName)
for start := time.Now(); time.Since(start) < timeout; time.Sleep(Poll) {
sts, err := c.AppsV1().StatefulSets(ns).Get(statefulSetName, metav1.GetOptions{})
if err != nil {
framework.Logf("Get StatefulSet %s failed, ignoring for %v: %v", statefulSetName, Poll, err)
continue
}
if sts.Status.ReadyReplicas == *sts.Spec.Replicas {
framework.Logf("All %d replicas of StatefulSet %s are ready. (%v)", sts.Status.ReadyReplicas, statefulSetName, time.Since(start))
return nil
}
framework.Logf("StatefulSet %s found but there are %d ready replicas and %d total replicas.", statefulSetName, sts.Status.ReadyReplicas, *sts.Spec.Replicas)
}
return fmt.Errorf("StatefulSet %s still has unready pods within %v", statefulSetName, timeout)
}
func execCommandInPod(f *framework.Framework, c, ns string, opt *metav1.ListOptions) (string, string) { func execCommandInPod(f *framework.Framework, c, ns string, opt *metav1.ListOptions) (string, string) {
cmd := []string{"/bin/sh", "-c", c} cmd := []string{"/bin/sh", "-c", c}
podList, err := f.PodClientNS(ns).List(*opt) podList, err := f.PodClientNS(ns).List(*opt)
@ -393,7 +411,7 @@ func createPVCAndvalidatePV(c kubernetes.Interface, pvc *v1.PersistentVolumeClai
if apierrs.IsNotFound(err) { if apierrs.IsNotFound(err) {
return false, nil return false, nil
} }
err = framework.WaitOnPVandPVC(c, pvc.Namespace, pv, pvc) err = e2epv.WaitOnPVandPVC(c, pvc.Namespace, pv, pvc)
if err != nil { if err != nil {
return false, nil return false, nil
} }
@ -877,3 +895,10 @@ func checkDataPersist(pvcPath, appPath string, f *framework.Framework) error {
err = deletePVCAndApp("", f, pvc, app) err = deletePVCAndApp("", f, pvc, app)
return err return err
} }
func handleFlags() {
config.CopyFlags(config.Flags, flag.CommandLine)
framework.RegisterCommonFlags(flag.CommandLine)
framework.RegisterClusterFlags(flag.CommandLine)
flag.Parse()
}