Skip to content

Commit

Permalink
Merge pull request openshift#15554 from smarterclayton/integration_fi…
Browse files Browse the repository at this point in the history
…xes_2

Automatic merge from submit-queue

Cleanup integration tests for use with etcd3 and parallelism

A set of cleanup to the integration tests that will allow them to be run in parallel. Also moves to etcd3 (we were still testing only the etcd2 code path).

@deads2k

The parallelism changes depend on these
  • Loading branch information
openshift-merge-robot authored Aug 2, 2017
2 parents 55058fa + 083d51e commit 42e3e3c
Show file tree
Hide file tree
Showing 81 changed files with 646 additions and 598 deletions.
12 changes: 9 additions & 3 deletions pkg/cmd/flagtypes/addr.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

// urlPrefixes is the list of string prefix values that may indicate a URL
// is present.
var urlPrefixes = []string{"http://", "https://", "tcp://"}
var urlPrefixes = []string{"http://", "https://", "tcp://", "unix://"}

// Addr is a flag type that attempts to load a host, IP, host:port, or
// URL value from a string argument. It tracks whether the value was set
Expand Down Expand Up @@ -77,7 +77,7 @@ func (a *Addr) Set(value string) error {
parsed.RawQuery = ""
parsed.Fragment = ""

if strings.Contains(parsed.Host, ":") {
if parsed.Scheme != "unix" && strings.Contains(parsed.Host, ":") {
host, port, err := net.SplitHostPort(parsed.Host)
if err != nil {
return fmt.Errorf("not a valid host:port: %v", err)
Expand All @@ -96,6 +96,8 @@ func (a *Addr) Set(value string) error {
port = 80
case "https":
port = 443
case "unix":
port = 0
default:
return fmt.Errorf("no port specified")
}
Expand Down Expand Up @@ -135,7 +137,11 @@ func (a *Addr) Set(value string) error {
a.Host = value
a.Port = port
}
addr.Host = net.JoinHostPort(a.Host, strconv.FormatInt(int64(a.Port), 10))
if a.Port > 0 {
addr.Host = net.JoinHostPort(a.Host, strconv.FormatInt(int64(a.Port), 10))
} else {
addr.Host = a.Host
}

if value != a.Value {
a.Provided = true
Expand Down
45 changes: 21 additions & 24 deletions pkg/cmd/server/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"time"

etcdclient "github.com/coreos/etcd/client"
clientv3 "github.com/coreos/etcd/clientv3"
"github.com/coreos/etcd/clientv3"
"golang.org/x/net/context"

knet "k8s.io/apimachinery/pkg/util/net"
Expand All @@ -17,18 +17,29 @@ import (
configapi "github.com/openshift/origin/pkg/cmd/server/api"
)

// GetAndTestEtcdClient creates an etcd client based on the provided config. It will attempt to
// TestEtcdConnectionInfo creates an etcd client based on the provided config and attempts to
// connect to the etcd server and block until the server responds at least once, or return an
// error if the server never responded.
func GetAndTestEtcdClient(etcdClientInfo configapi.EtcdConnectionInfo) (etcdclient.Client, error) {
etcdClient, err := MakeEtcdClient(etcdClientInfo)
func TestEtcdConnectionInfo(etcdClientInfo configapi.EtcdConnectionInfo) error {
tlsConfig, err := restclient.TLSConfigFor(&restclient.Config{
TLSClientConfig: restclient.TLSClientConfig{
CertFile: etcdClientInfo.ClientCert.CertFile,
KeyFile: etcdClientInfo.ClientCert.KeyFile,
CAFile: etcdClientInfo.CA,
},
})
if err != nil {
return nil, err
return err
}
if err := TestEtcdClient(etcdClient); err != nil {
return nil, err
client, err := clientv3.New(clientv3.Config{
Endpoints: etcdClientInfo.URLs,
TLS: tlsConfig,
})
if err != nil {
return err
}
return etcdClient, nil
ctx, _ := context.WithDeadline(context.Background(), time.Now().Add(5*time.Second))
return client.Sync(ctx)
}

// MakeEtcdClient creates an etcd client based on the provided config.
Expand Down Expand Up @@ -74,27 +85,13 @@ func TestEtcdClient(etcdClient etcdclient.Client) error {
break
}
if i > 100 {
return fmt.Errorf("could not reach etcd: %v", err)
return fmt.Errorf("could not reach etcd(v2): %v", err)
}
time.Sleep(50 * time.Millisecond)
}
return nil
}

// GetAndTestEtcdClientV3 creates an etcd client based on the provided config. It will attempt to
// connect to the etcd server and block until the server responds at least once, or return an
// error if the server never responded.
func GetAndTestEtcdClientV3(etcdClientInfo configapi.EtcdConnectionInfo) (*clientv3.Client, error) {
etcdClient, err := MakeEtcdClientV3(etcdClientInfo)
if err != nil {
return nil, err
}
if err := TestEtcdClientV3(etcdClient); err != nil {
return nil, err
}
return etcdClient, nil
}

// MakeEtcdClientV3Config creates client configuration based on the configapi.
func MakeEtcdClientV3Config(etcdClientInfo configapi.EtcdConnectionInfo) (*clientv3.Config, error) {
tlsConfig, err := restclient.TLSConfigFor(&restclient.Config{
Expand Down Expand Up @@ -134,7 +131,7 @@ func TestEtcdClientV3(etcdClient *clientv3.Client) error {
break
}
if i > 100 {
return fmt.Errorf("could not reach etcd: %v", err)
return fmt.Errorf("could not reach etcd(v3): %v", err)
}
time.Sleep(50 * time.Millisecond)
}
Expand Down
12 changes: 10 additions & 2 deletions pkg/cmd/server/start/start_master.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,11 +550,19 @@ func StartAPI(oc *origin.MasterConfig, kc *kubernetes.MasterConfig, informers *i

// verify we can connect to etcd with the provided config
if len(kc.Options.APIServerArguments) > 0 && len(kc.Options.APIServerArguments["storage-backend"]) > 0 && kc.Options.APIServerArguments["storage-backend"][0] == "etcd3" {
if _, err := etcd.GetAndTestEtcdClientV3(oc.Options.EtcdClientInfo); err != nil {
etcdClient, err := etcd.MakeEtcdClientV3(oc.Options.EtcdClientInfo)
if err != nil {
return err
}
if err := etcd.TestEtcdClientV3(etcdClient); err != nil {
return err
}
} else {
if _, err := etcd.GetAndTestEtcdClient(oc.Options.EtcdClientInfo); err != nil {
etcdClient, err := etcd.MakeEtcdClient(oc.Options.EtcdClientInfo)
if err != nil {
return err
}
if err := etcd.TestEtcdClient(etcdClient); err != nil {
return err
}
}
Expand Down
41 changes: 19 additions & 22 deletions test/integration/admissionconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ type TestPluginConfig struct {

func (obj *TestPluginConfig) GetObjectKind() schema.ObjectKind { return &obj.TypeMeta }

func setupAdmissionTest(t *testing.T, setupConfig func(*configapi.MasterConfig)) (kclientset.Interface, *client.Client) {
testutil.RequireEtcd(t)
func setupAdmissionTest(t *testing.T, setupConfig func(*configapi.MasterConfig)) (kclientset.Interface, *client.Client, func()) {
masterConfig, err := testserver.DefaultMasterOptions()
if err != nil {
t.Fatalf("error creating config: %v", err)
Expand All @@ -52,7 +51,9 @@ func setupAdmissionTest(t *testing.T, setupConfig func(*configapi.MasterConfig))
if err != nil {
t.Fatalf("error getting openshift client: %v", err)
}
return kubeClient, openshiftClient
return kubeClient, openshiftClient, func() {
testserver.CleanupMasterEtcd(t, masterConfig)
}
}

// testAdmissionPlugin sets a label with its name on the object getting admitted
Expand Down Expand Up @@ -191,11 +192,11 @@ func setupAdmissionPluginTestConfig(t *testing.T, value string) string {
}

func TestKubernetesAdmissionPluginOrderOverride(t *testing.T) {
defer testutil.DumpEtcdOnFailure(t)
registerAdmissionPlugins(t, "plugin1", "plugin2", "plugin3")
kubeClient, _ := setupAdmissionTest(t, func(config *configapi.MasterConfig) {
kubeClient, _, fn := setupAdmissionTest(t, func(config *configapi.MasterConfig) {
config.KubernetesMasterConfig.AdmissionConfig.PluginOrderOverride = []string{"plugin1", "plugin2"}
})
defer fn()

createdPod, err := kubeClient.Core().Pods(metav1.NamespaceDefault).Create(admissionTestPod())
if err != nil {
Expand All @@ -207,29 +208,28 @@ func TestKubernetesAdmissionPluginOrderOverride(t *testing.T) {
}

func TestKubernetesAdmissionPluginConfigFile(t *testing.T) {
defer testutil.DumpEtcdOnFailure(t)
registerAdmissionPluginTestConfigType()
configFile := setupAdmissionPluginTestConfig(t, "plugin1configvalue")
registerAdmissionPlugins(t, "plugin1", "plugin2")
kubeClient, _ := setupAdmissionTest(t, func(config *configapi.MasterConfig) {
kubeClient, _, fn := setupAdmissionTest(t, func(config *configapi.MasterConfig) {
config.KubernetesMasterConfig.AdmissionConfig.PluginOrderOverride = []string{"plugin1", "plugin2"}
config.KubernetesMasterConfig.AdmissionConfig.PluginConfig = map[string]configapi.AdmissionPluginConfig{
"plugin1": {
Location: configFile,
},
}
})
defer fn()
createdPod, err := kubeClient.Core().Pods(metav1.NamespaceDefault).Create(admissionTestPod())
if err = checkAdmissionObjectLabelValues(createdPod.Labels, map[string]string{"plugin1": "plugin1configvalue", "plugin2": "default"}); err != nil {
t.Errorf("Error: %v", err)
}
}

func TestKubernetesAdmissionPluginEmbeddedConfig(t *testing.T) {
defer testutil.DumpEtcdOnFailure(t)
registerAdmissionPluginTestConfigType()
registerAdmissionPlugins(t, "plugin1", "plugin2")
kubeClient, _ := setupAdmissionTest(t, func(config *configapi.MasterConfig) {
kubeClient, _, fn := setupAdmissionTest(t, func(config *configapi.MasterConfig) {
config.KubernetesMasterConfig.AdmissionConfig.PluginOrderOverride = []string{"plugin1", "plugin2"}
config.KubernetesMasterConfig.AdmissionConfig.PluginConfig = map[string]configapi.AdmissionPluginConfig{
"plugin1": {
Expand All @@ -239,18 +239,19 @@ func TestKubernetesAdmissionPluginEmbeddedConfig(t *testing.T) {
},
}
})
defer fn()
createdPod, err := kubeClient.Core().Pods(metav1.NamespaceDefault).Create(admissionTestPod())
if err = checkAdmissionObjectLabelValues(createdPod.Labels, map[string]string{"plugin1": "embeddedvalue1", "plugin2": "default"}); err != nil {
t.Errorf("Error: %v", err)
}
}

func TestOpenshiftAdmissionPluginOrderOverride(t *testing.T) {
defer testutil.DumpEtcdOnFailure(t)
registerAdmissionPlugins(t, "plugin1", "plugin2", "plugin3")
_, openshiftClient := setupAdmissionTest(t, func(config *configapi.MasterConfig) {
_, openshiftClient, fn := setupAdmissionTest(t, func(config *configapi.MasterConfig) {
config.AdmissionConfig.PluginOrderOverride = []string{"plugin1", "plugin2"}
})
defer fn()

createdBuild, err := openshiftClient.Builds(metav1.NamespaceDefault).Create(admissionTestBuild())
if err != nil {
Expand All @@ -262,29 +263,28 @@ func TestOpenshiftAdmissionPluginOrderOverride(t *testing.T) {
}

func TestOpenshiftAdmissionPluginConfigFile(t *testing.T) {
defer testutil.DumpEtcdOnFailure(t)
registerAdmissionPluginTestConfigType()
configFile := setupAdmissionPluginTestConfig(t, "plugin2configvalue")
registerAdmissionPlugins(t, "plugin1", "plugin2")
_, openshiftClient := setupAdmissionTest(t, func(config *configapi.MasterConfig) {
_, openshiftClient, fn := setupAdmissionTest(t, func(config *configapi.MasterConfig) {
config.AdmissionConfig.PluginOrderOverride = []string{"plugin1", "plugin2"}
config.AdmissionConfig.PluginConfig = map[string]configapi.AdmissionPluginConfig{
"plugin2": {
Location: configFile,
},
}
})
defer fn()
createdBuild, err := openshiftClient.Builds(metav1.NamespaceDefault).Create(admissionTestBuild())
if err = checkAdmissionObjectLabelValues(createdBuild.Labels, map[string]string{"plugin1": "default", "plugin2": "plugin2configvalue"}); err != nil {
t.Errorf("Error: %v", err)
}
}

func TestOpenshiftAdmissionPluginEmbeddedConfig(t *testing.T) {
defer testutil.DumpEtcdOnFailure(t)
registerAdmissionPluginTestConfigType()
registerAdmissionPlugins(t, "plugin1", "plugin2")
_, openshiftClient := setupAdmissionTest(t, func(config *configapi.MasterConfig) {
_, openshiftClient, fn := setupAdmissionTest(t, func(config *configapi.MasterConfig) {
config.AdmissionConfig.PluginOrderOverride = []string{"plugin1", "plugin2"}
config.AdmissionConfig.PluginConfig = map[string]configapi.AdmissionPluginConfig{
"plugin2": {
Expand All @@ -294,20 +294,19 @@ func TestOpenshiftAdmissionPluginEmbeddedConfig(t *testing.T) {
},
}
})
defer fn()
createdBuild, err := openshiftClient.Builds(metav1.NamespaceDefault).Create(admissionTestBuild())
if err = checkAdmissionObjectLabelValues(createdBuild.Labels, map[string]string{"plugin1": "default", "plugin2": "embeddedvalue2"}); err != nil {
t.Errorf("Error: %v", err)
}
}

func TestAlwaysPullImagesOn(t *testing.T) {
testutil.RequireEtcd(t)
defer testutil.DumpEtcdOnFailure(t)

masterConfig, err := testserver.DefaultMasterOptions()
if err != nil {
t.Fatalf("error creating config: %v", err)
}
defer testserver.CleanupMasterEtcd(t, masterConfig)
masterConfig.KubernetesMasterConfig.AdmissionConfig.PluginConfig = map[string]configapi.AdmissionPluginConfig{
"AlwaysPullImages": {
Configuration: &configapi.DefaultAdmissionConfig{},
Expand Down Expand Up @@ -352,13 +351,11 @@ func TestAlwaysPullImagesOn(t *testing.T) {
}

func TestAlwaysPullImagesOff(t *testing.T) {
testutil.RequireEtcd(t)
defer testutil.DumpEtcdOnFailure(t)

_, kubeConfigFile, err := testserver.StartTestMaster()
masterConfig, kubeConfigFile, err := testserver.StartTestMaster()
if err != nil {
t.Fatalf("error starting server: %v", err)
}
defer testserver.CleanupMasterEtcd(t, masterConfig)
kubeClientset, err := testutil.GetClusterAdminKubeClient(kubeConfigFile)
if err != nil {
t.Fatalf("error getting client: %v", err)
Expand Down
4 changes: 1 addition & 3 deletions test/integration/aggregator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ import (
)

func TestAggregator(t *testing.T) {
testutil.RequireEtcd(t)
defer testutil.DumpEtcdOnFailure(t)

masterConfig, err := testserver.DefaultMasterOptions()
if err != nil {
t.Fatal(err)
}
defer testserver.CleanupMasterEtcd(t, masterConfig)

// Set up the aggregator ca and proxy cert
caDir, err := ioutil.TempDir("", "aggregator-ca")
Expand Down
4 changes: 1 addition & 3 deletions test/integration/api_paths_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ import (
)

func TestRootAPIPaths(t *testing.T) {
testutil.RequireEtcd(t)
defer testutil.DumpEtcdOnFailure(t)

masterConfig, adminConfigFile, err := testserver.StartTestMaster()
if err != nil {
t.Fatalf("unexpected error starting test master: %v", err)
}
defer testserver.CleanupMasterEtcd(t, masterConfig)

clientConfig, err := testutil.GetClusterAdminClientConfig(adminConfigFile)
if err != nil {
Expand Down
12 changes: 6 additions & 6 deletions test/integration/audit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import (
testserver "github.com/openshift/origin/test/util/server"
)

func setupAuditTest(t *testing.T) (kclientset.Interface, *client.Client) {
testutil.RequireEtcd(t)
func setupAuditTest(t *testing.T) (kclientset.Interface, *client.Client, func()) {
masterConfig, err := testserver.DefaultMasterOptions()
if err != nil {
t.Fatalf("error creating config: %v", err)
Expand All @@ -30,13 +29,14 @@ func setupAuditTest(t *testing.T) (kclientset.Interface, *client.Client) {
if err != nil {
t.Fatalf("error getting openshift client: %v", err)
}
return kubeClient, openshiftClient

return kubeClient, openshiftClient, func() {
testserver.CleanupMasterEtcd(t, masterConfig)
}
}

func TestBasicFunctionalityWithAudit(t *testing.T) {
kubeClient, _ := setupAuditTest(t)
defer testutil.DumpEtcdOnFailure(t)
kubeClient, _, fn := setupAuditTest(t)
defer fn()

if _, err := kubeClient.Core().Pods(metav1.NamespaceDefault).Watch(metav1.ListOptions{}); err != nil {
t.Errorf("Unexpected error watching pods: %v", err)
Expand Down
4 changes: 1 addition & 3 deletions test/integration/auth_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,11 @@ func TestAuthProxyOnAuthorize(t *testing.T) {
idp.Provider = &configapi.RequestHeaderIdentityProvider{Headers: []string{"X-Remote-User"}}
idp.MappingMethod = "claim"

testutil.RequireEtcd(t)
defer testutil.DumpEtcdOnFailure(t)

masterConfig, err := testserver.DefaultMasterOptions()
if err != nil {
t.Fatal(err)
}
defer testserver.CleanupMasterEtcd(t, masterConfig)
masterConfig.OAuthConfig.IdentityProviders = []configapi.IdentityProvider{idp}

clusterAdminKubeConfig, err := testserver.StartConfiguredMasterAPI(masterConfig)
Expand Down
Loading

0 comments on commit 42e3e3c

Please sign in to comment.