Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion openshift-hack/cmd/k8s-tests-ext/k8s-tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ func main() {
framework.RegisterCommonFlags(flag.CommandLine)
framework.RegisterClusterFlags(flag.CommandLine)

if err := initializeCommonTestFramework(); err != nil {
panic(err)
}

// Get version info from kube
kubeVersion := version.Get()
v.GitTreeState = kubeVersion.GitTreeState
Expand Down Expand Up @@ -85,7 +89,7 @@ func main() {

// Initialization for kube ginkgo test framework needs to run before all tests execute
specs.AddBeforeAll(func() {
if err := initializeTestFramework(os.Getenv("TEST_PROVIDER")); err != nil {
if err := updateTestFrameworkForTests(os.Getenv("TEST_PROVIDER")); err != nil {
panic(err)
}
})
Expand Down
87 changes: 48 additions & 39 deletions openshift-hack/cmd/k8s-tests-ext/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,41 @@ import (
_ "k8s.io/kubernetes/test/e2e/lifecycle"
)

// copied directly from github.com/openshift/origin/cmd/openshift-tests/provider.go
// and github.com/openshift/origin/test/extended/util/test.go
func initializeTestFramework(provider string) error {
// Initialize a good enough test context for generating e2e tests,
// so they can be listed and filtered.
func initializeCommonTestFramework() error {
// update testContext with loaded config
testContext := &framework.TestContext
testContext.AllowedNotReadyNodes = -1
testContext.MinStartupPods = -1
testContext.MaxNodesToGather = 0
testContext.KubeConfig = os.Getenv("KUBECONFIG")

if ad := os.Getenv("ARTIFACT_DIR"); len(strings.TrimSpace(ad)) == 0 {
os.Setenv("ARTIFACT_DIR", filepath.Join(os.TempDir(), "artifacts"))
}

testContext.DeleteNamespace = os.Getenv("DELETE_NAMESPACE") != "false"
testContext.VerifyServiceAccount = true
testfiles.AddFileSource(e2etestingmanifests.GetE2ETestingManifestsFS())
testfiles.AddFileSource(testfixtures.GetTestFixturesFS())
testfiles.AddFileSource(conformancetestdata.GetConformanceTestdataFS())
testContext.KubectlPath = "kubectl"
// context.KubeConfig = KubeConfigPath()
testContext.KubeConfig = os.Getenv("KUBECONFIG")

// "debian" is used when not set. At least GlusterFS tests need "custom".
// (There is no option for "rhel" or "centos".)
testContext.NodeOSDistro = "custom"
testContext.MasterOSDistro = "custom"

return nil
}

// Finish test context initialization. This is called before a real test is going to run.
// It parses the cloud provider and file other parameters that are needed for running
// already generated tests.
func updateTestFrameworkForTests(provider string) error {
providerInfo := &ClusterConfiguration{}
if err := json.Unmarshal([]byte(provider), &providerInfo); err != nil {
return fmt.Errorf("provider must be a JSON object with the 'type' key at a minimum: %v", err)
Expand All @@ -58,39 +90,13 @@ func initializeTestFramework(provider string) error {
MultiZone: config.MultiZone,
ConfigFile: config.ConfigFile,
}
testContext.AllowedNotReadyNodes = -1
testContext.MinStartupPods = -1
testContext.MaxNodesToGather = 0
testContext.KubeConfig = os.Getenv("KUBECONFIG")

// allow the CSI tests to access test data, but only briefly
// TODO: ideally CSI would not use any of these test methods
// var err error
// exutil.WithCleanup(func() { err = initCSITests(dryRun) })
// TODO: for now I'm only initializing CSI directly, but we probably need that
// WithCleanup here as well
if err := initCSITests(); err != nil {
return err
}

if ad := os.Getenv("ARTIFACT_DIR"); len(strings.TrimSpace(ad)) == 0 {
os.Setenv("ARTIFACT_DIR", filepath.Join(os.TempDir(), "artifacts"))
// these constants are taken from kube e2e and used by tests
testContext.IPFamily = "ipv4"
if config.HasIPv6 && !config.HasIPv4 {
testContext.IPFamily = "ipv6"
}

testContext.DeleteNamespace = os.Getenv("DELETE_NAMESPACE") != "false"
testContext.VerifyServiceAccount = true
testfiles.AddFileSource(e2etestingmanifests.GetE2ETestingManifestsFS())
testfiles.AddFileSource(testfixtures.GetTestFixturesFS())
testfiles.AddFileSource(conformancetestdata.GetConformanceTestdataFS())
testContext.KubectlPath = "kubectl"
// context.KubeConfig = KubeConfigPath()
testContext.KubeConfig = os.Getenv("KUBECONFIG")

// "debian" is used when not set. At least GlusterFS tests need "custom".
// (There is no option for "rhel" or "centos".)
testContext.NodeOSDistro = "custom"
testContext.MasterOSDistro = "custom"

// load and set the host variable for kubectl
clientConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(&clientcmd.ClientConfigLoadingRules{ExplicitPath: testContext.KubeConfig}, &clientcmd.ConfigOverrides{})
cfg, err := clientConfig.ClientConfig()
Expand All @@ -108,15 +114,18 @@ func initializeTestFramework(provider string) error {

framework.AfterReadingAllFlags(testContext)
testContext.DumpLogsOnFailure = true
testContext.ReportDir = os.Getenv("TEST_JUNIT_DIR")

// these constants are taken from kube e2e and used by tests
testContext.IPFamily = "ipv4"
if config.HasIPv6 && !config.HasIPv4 {
testContext.IPFamily = "ipv6"
// allow the CSI tests to access test data, but only briefly
// TODO: ideally CSI would not use any of these test methods
// var err error
// exutil.WithCleanup(func() { err = initCSITests(dryRun) })
// TODO: for now I'm only initializing CSI directly, but we probably need that
// WithCleanup here as well
if err := initCSITests(); err != nil {
return err
}

testContext.ReportDir = os.Getenv("TEST_JUNIT_DIR")

return nil
}

Expand Down