Remove e2e/common package usage in volumemode testsuite

Change 04300826fd has introduced
"e2e/common" package dependency on volumemode testusuite. This results in
pulling all tests defined in common package while running storage e2e tests,
which are not necessary.

The only interested part from common package is the WaitTimeoutForEvent().
This commit is contained in:
Amarnath Valluri
2019-10-03 16:27:00 +03:00
parent cb177dc6a1
commit 3333806734
2 changed files with 34 additions and 5 deletions

View File

@@ -44,7 +44,6 @@ go_library(
"//staging/src/k8s.io/client-go/kubernetes:go_default_library",
"//staging/src/k8s.io/csi-translation-lib:go_default_library",
"//staging/src/k8s.io/csi-translation-lib/plugins:go_default_library",
"//test/e2e/common:go_default_library",
"//test/e2e/framework:go_default_library",
"//test/e2e/framework/log:go_default_library",
"//test/e2e/framework/metrics:go_default_library",

View File

@@ -20,6 +20,7 @@ import (
"fmt"
"path/filepath"
"strings"
"time"
"github.com/onsi/ginkgo"
"github.com/onsi/gomega"
@@ -28,10 +29,10 @@ import (
storagev1 "k8s.io/api/storage/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/util/wait"
clientset "k8s.io/client-go/kubernetes"
volevents "k8s.io/kubernetes/pkg/controller/volume/events"
"k8s.io/kubernetes/pkg/kubelet/events"
"k8s.io/kubernetes/test/e2e/common"
"k8s.io/kubernetes/test/e2e/framework"
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
e2epv "k8s.io/kubernetes/test/e2e/framework/pv"
@@ -222,7 +223,7 @@ func (t *volumeModeTestSuite) defineTests(driver TestDriver, pattern testpattern
}.AsSelector().String()
msg := "Unable to attach or mount volumes"
err = common.WaitTimeoutForEvent(l.cs, l.ns.Name, eventSelector, msg, framework.PodStartTimeout)
err = waitTimeoutForEvent(l.cs, l.ns.Name, eventSelector, msg, framework.PodStartTimeout)
// Events are unreliable, don't depend on the event. It's used only to speed up the test.
if err != nil {
framework.Logf("Warning: did not get event about FailedMountVolume")
@@ -259,7 +260,7 @@ func (t *volumeModeTestSuite) defineTests(driver TestDriver, pattern testpattern
}.AsSelector().String()
msg := "does not support block volume provisioning"
err = common.WaitTimeoutForEvent(l.cs, l.ns.Name, eventSelector, msg, framework.ClaimProvisionTimeout)
err = waitTimeoutForEvent(l.cs, l.ns.Name, eventSelector, msg, framework.ClaimProvisionTimeout)
// Events are unreliable, don't depend on the event. It's used only to speed up the test.
if err != nil {
framework.Logf("Warning: did not get event about provisioing failed")
@@ -309,7 +310,7 @@ func (t *volumeModeTestSuite) defineTests(driver TestDriver, pattern testpattern
} else {
msg = "has volumeMode Filesystem, but is specified in volumeDevices"
}
err = common.WaitTimeoutForEvent(l.cs, l.ns.Name, eventSelector, msg, framework.PodStartTimeout)
err = waitTimeoutForEvent(l.cs, l.ns.Name, eventSelector, msg, framework.PodStartTimeout)
// Events are unreliable, don't depend on them. They're used only to speed up the test.
if err != nil {
framework.Logf("Warning: did not get event about mismatched volume use")
@@ -470,3 +471,32 @@ func listPodDirectory(h utils.HostExec, path string, node *v1.Node) ([]string, e
}
return strings.Split(out, "\n"), nil
}
// NOTE(avalluri): The below code is intentionally copied from e2e/common package.
// Testsuites depending on common package is not desirable as that pulls quite
// many tests which are not interested by storage suites.
//
// waitTimeoutForEvent waits the given timeout duration for an event to occur.
func waitTimeoutForEvent(c clientset.Interface, namespace, eventSelector, msg string, timeout time.Duration) error {
interval := 2 * time.Second
return wait.PollImmediate(interval, timeout, eventOccurred(c, namespace, eventSelector, msg))
}
// NOTE(avalluri): The below code is intentionally copied from e2e/common package.
// Testsuites depending on common package is not desirable as that pulls quite
// many tests which are not interested by storage suites.
func eventOccurred(c clientset.Interface, namespace, eventSelector, msg string) wait.ConditionFunc {
options := metav1.ListOptions{FieldSelector: eventSelector}
return func() (bool, error) {
events, err := c.CoreV1().Events(namespace).List(options)
if err != nil {
return false, fmt.Errorf("got error while getting events: %v", err)
}
for _, event := range events.Items {
if strings.Contains(event.Message, msg) {
return true, nil
}
}
return false, nil
}
}