Skip to content
Merged
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
8 changes: 4 additions & 4 deletions cmd/openshift-tests/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ func isStandardEarlyOrLateTest(name string) bool {
// suiteWithInitializedProviderPreSuite loads the provider info, but does not
// exclude any tests specific to that provider.
func suiteWithInitializedProviderPreSuite(opt *runOptions) error {
config, err := decodeProvider(opt.Provider, opt.DryRun, true)
config, err := decodeProvider(opt.Provider, opt.DryRun, true, nil)
if err != nil {
return err
}
Expand All @@ -401,13 +401,13 @@ func suiteWithInitializedProviderPreSuite(opt *runOptions) error {
}

// suiteWithProviderPreSuite ensures that the suite filters out tests from providers
// that aren't relevant (see getProviderMatchFn) by loading the provider info from the
// cluster or flags.
// that aren't relevant (see exutilcluster.ClusterConfig.MatchFn) by loading the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This refactor is fine, you could also pull this out into its own PR to reduce churn in this one

// provider info from the cluster or flags.
func suiteWithProviderPreSuite(opt *runOptions) error {
if err := suiteWithInitializedProviderPreSuite(opt); err != nil {
return err
}
opt.MatchFn = getProviderMatchFn(opt.config)
opt.MatchFn = opt.config.MatchFn()
return nil
}

Expand Down
6 changes: 3 additions & 3 deletions cmd/openshift-tests/openshift-tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
testginkgo "github.com/openshift/origin/pkg/test/ginkgo"
"github.com/openshift/origin/pkg/version"
exutil "github.com/openshift/origin/test/extended/util"
"github.com/openshift/origin/test/extended/util/cloud"
"github.com/openshift/origin/test/extended/util/cluster"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This rename is fine, you could also pull this out into its own PR to reduce churn in this one

)

func main() {
Expand Down Expand Up @@ -204,7 +204,7 @@ type runOptions struct {
TestOptions []string

// Shared by initialization code
config *cloud.ClusterConfiguration
config *cluster.ClusterConfiguration
}

func (opt *runOptions) AsEnv() []string {
Expand Down Expand Up @@ -406,7 +406,7 @@ func newRunTestCommand() *cobra.Command {
ginkgo.GlobalSuite().ClearBeforeSuiteNode()
ginkgo.GlobalSuite().ClearAfterSuiteNode()

config, err := decodeProvider(os.Getenv("TEST_PROVIDER"), testOpt.DryRun, false)
config, err := decodeProvider(os.Getenv("TEST_PROVIDER"), testOpt.DryRun, false, nil)
if err != nil {
return err
}
Expand Down
107 changes: 30 additions & 77 deletions cmd/openshift-tests/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"os"
"strings"

"github.com/onsi/ginkgo"
"github.com/onsi/gomega"
Expand All @@ -13,7 +12,7 @@ import (
e2e "k8s.io/kubernetes/test/e2e/framework"

exutil "github.com/openshift/origin/test/extended/util"
exutilcloud "github.com/openshift/origin/test/extended/util/cloud"
exutilcluster "github.com/openshift/origin/test/extended/util/cluster"

// Initialize baremetal as a provider
_ "github.com/openshift/origin/test/extended/util/baremetal"
Expand All @@ -29,9 +28,7 @@ import (
_ "k8s.io/kubernetes/test/e2e/lifecycle"
)

type TestNameMatchesFunc func(name string) bool

func initializeTestFramework(context *e2e.TestContextType, config *exutilcloud.ClusterConfiguration, dryRun bool) error {
func initializeTestFramework(context *e2e.TestContextType, config *exutilcluster.ClusterConfiguration, dryRun bool) error {
// update context with loaded config
context.Provider = config.ProviderName
context.CloudConfig = e2e.CloudConfig{
Expand Down Expand Up @@ -67,51 +64,34 @@ func initializeTestFramework(context *e2e.TestContextType, config *exutilcloud.C
return nil
}

func getProviderMatchFn(config *exutilcloud.ClusterConfiguration) TestNameMatchesFunc {
// given the configuration we have loaded, skip tests that our provider, disconnected status,
// or our network plugin should exclude
var skips []string
skips = append(skips, fmt.Sprintf("[Skipped:%s]", config.ProviderName))
for _, id := range config.NetworkPluginIDs {
skips = append(skips, fmt.Sprintf("[Skipped:Network/%s]", id))
}
if config.Disconnected {
skips = append(skips, "[Skipped:Disconnected]")
}

matchFn := func(name string) bool {
for _, skip := range skips {
if strings.Contains(name, skip) {
return false
}
}
return true
}
return matchFn
}

func decodeProvider(provider string, dryRun, discover bool) (*exutilcloud.ClusterConfiguration, error) {
func decodeProvider(provider string, dryRun, discover bool, clusterState *exutilcluster.ClusterState) (*exutilcluster.ClusterConfiguration, error) {
switch provider {
case "none":
return &exutilcloud.ClusterConfiguration{ProviderName: "skeleton"}, nil
return &exutilcluster.ClusterConfiguration{ProviderName: "skeleton"}, nil

case "":
if _, ok := os.LookupEnv("KUBE_SSH_USER"); ok {
if _, ok := os.LookupEnv("LOCAL_SSH_KEY"); ok {
return &exutilcloud.ClusterConfiguration{ProviderName: "local"}, nil
return &exutilcluster.ClusterConfiguration{ProviderName: "local"}, nil
}
}
if dryRun {
return &exutilcloud.ClusterConfiguration{ProviderName: "skeleton"}, nil
return &exutilcluster.ClusterConfiguration{ProviderName: "skeleton"}, nil
}
fallthrough

case "azure", "aws", "baremetal", "gce", "vsphere":
clientConfig, err := e2e.LoadConfig(true)
if err != nil {
return nil, err
if clusterState == nil {
clientConfig, err := e2e.LoadConfig(true)
if err != nil {
return nil, err
}
clusterState, err = exutilcluster.DiscoverClusterState(clientConfig)
if err != nil {
return nil, err
}
}
config, err := exutilcloud.LoadConfig(clientConfig)
config, err := exutilcluster.LoadConfig(clusterState)
if err != nil {
return nil, err
}
Expand All @@ -122,58 +102,31 @@ func decodeProvider(provider string, dryRun, discover bool) (*exutilcloud.Cluste

default:
var providerInfo struct {
Type string
Disconnected bool
e2e.CloudConfig `json:",inline"`
Type string
}
if err := json.Unmarshal([]byte(provider), &providerInfo); err != nil {
return nil, fmt.Errorf("provider must be a JSON object with the 'type' key at a minimum, and decode into a cloud config object: %v", err)
return nil, fmt.Errorf("provider must be a JSON object with the 'type' key at a minimum: %v", err)
}
if len(providerInfo.Type) == 0 {
return nil, fmt.Errorf("provider must be a JSON object with the 'type' key")
}
// attempt to load the default config, then overwrite with any values from the passed
// object that can be overridden
var config *exutilcloud.ClusterConfiguration
var config *exutilcluster.ClusterConfiguration
if discover {
if clientConfig, err := e2e.LoadConfig(true); err == nil {
config, _ = exutilcloud.LoadConfig(clientConfig)
if clusterState == nil {
if clientConfig, err := e2e.LoadConfig(true); err == nil {
clusterState, _ = exutilcluster.DiscoverClusterState(clientConfig)
}
}
}
if config == nil {
config = &exutilcloud.ClusterConfiguration{
ProviderName: providerInfo.Type,
ProjectID: providerInfo.ProjectID,
Region: providerInfo.Region,
Zone: providerInfo.Zone,
Zones: providerInfo.Zones,
NumNodes: providerInfo.NumNodes,
MultiMaster: providerInfo.MultiMaster,
MultiZone: providerInfo.MultiZone,
ConfigFile: providerInfo.ConfigFile,
if clusterState != nil {
config, _ = exutilcluster.LoadConfig(clusterState)
}
} else {
config.ProviderName = providerInfo.Type
if len(providerInfo.ProjectID) > 0 {
config.ProjectID = providerInfo.ProjectID
}
if len(providerInfo.Region) > 0 {
config.Region = providerInfo.Region
}
if len(providerInfo.Zone) > 0 {
config.Zone = providerInfo.Zone
}
if len(providerInfo.Zones) > 0 {
config.Zones = providerInfo.Zones
}
if len(providerInfo.ConfigFile) > 0 {
config.ConfigFile = providerInfo.ConfigFile
}
if providerInfo.NumNodes > 0 {
config.NumNodes = providerInfo.NumNodes
}
config = &exutilcluster.ClusterConfiguration{}
}

if err := json.Unmarshal([]byte(provider), config); err != nil {
return nil, fmt.Errorf("provider must decode into the ClusterConfig object: %v", err)
}
config.Disconnected = providerInfo.Disconnected
return config, nil
}
}
Loading