From bee29b59d281725f5718a26437454c6f7c612c8f Mon Sep 17 00:00:00 2001 From: Wojciech Tyczynski Date: Mon, 4 Jul 2016 15:16:13 +0200 Subject: [PATCH] Cleanup integration RunAMaster --- test/integration/client_test.go | 16 ++++++++-------- test/integration/configmap_test.go | 2 +- test/integration/dynamic_client_test.go | 2 +- test/integration/extender_test.go | 2 +- test/integration/framework/master_utils.go | 19 +++++-------------- test/integration/master_test.go | 10 +++++----- test/integration/metrics_test.go | 4 ++-- test/integration/persistent_volumes_test.go | 18 +++++++++--------- test/integration/pods_test.go | 4 ++-- test/integration/scheduler_test.go | 6 +++--- test/integration/secret_test.go | 2 +- 11 files changed, 38 insertions(+), 47 deletions(-) diff --git a/test/integration/client_test.go b/test/integration/client_test.go index 112c261aa9..ba5c4b5b9b 100644 --- a/test/integration/client_test.go +++ b/test/integration/client_test.go @@ -44,7 +44,7 @@ import ( ) func TestClient(t *testing.T) { - _, s := framework.RunAMaster(t) + _, s := framework.RunAMaster(nil) defer s.Close() client := client.NewOrDie(&restclient.Config{Host: s.URL, ContentConfig: restclient.ContentConfig{GroupVersion: testapi.Default.GroupVersion()}}) @@ -116,7 +116,7 @@ func TestClient(t *testing.T) { } func TestAtomicPut(t *testing.T) { - _, s := framework.RunAMaster(t) + _, s := framework.RunAMaster(nil) defer s.Close() c := client.NewOrDie(&restclient.Config{Host: s.URL, ContentConfig: restclient.ContentConfig{GroupVersion: testapi.Default.GroupVersion()}}) @@ -208,7 +208,7 @@ func TestAtomicPut(t *testing.T) { } func TestPatch(t *testing.T) { - _, s := framework.RunAMaster(t) + _, s := framework.RunAMaster(nil) defer s.Close() c := client.NewOrDie(&restclient.Config{Host: s.URL, ContentConfig: restclient.ContentConfig{GroupVersion: testapi.Default.GroupVersion()}}) @@ -317,7 +317,7 @@ func TestPatch(t *testing.T) { } func TestPatchWithCreateOnUpdate(t *testing.T) { - _, s := framework.RunAMaster(t) + _, s := framework.RunAMaster(nil) defer s.Close() c := client.NewOrDie(&restclient.Config{Host: s.URL, ContentConfig: restclient.ContentConfig{GroupVersion: testapi.Default.GroupVersion()}}) @@ -428,7 +428,7 @@ func TestPatchWithCreateOnUpdate(t *testing.T) { } func TestAPIVersions(t *testing.T) { - _, s := framework.RunAMaster(t) + _, s := framework.RunAMaster(nil) defer s.Close() c := client.NewOrDie(&restclient.Config{Host: s.URL, ContentConfig: restclient.ContentConfig{GroupVersion: testapi.Default.GroupVersion()}}) @@ -450,7 +450,7 @@ func TestAPIVersions(t *testing.T) { } func TestSingleWatch(t *testing.T) { - _, s := framework.RunAMaster(t) + _, s := framework.RunAMaster(nil) defer s.Close() ns := framework.CreateTestingNamespace("single-watch", s, t) @@ -535,7 +535,7 @@ func TestMultiWatch(t *testing.T) { const watcherCount = 50 rt.GOMAXPROCS(watcherCount) - _, s := framework.RunAMaster(t) + _, s := framework.RunAMaster(nil) defer s.Close() ns := framework.CreateTestingNamespace("multi-watch", s, t) @@ -794,7 +794,7 @@ func TestSelfLinkOnNamespace(t *testing.T) { // TODO: Limit the test to a single non-default namespace and clean this up at the end. framework.DeleteAllEtcdKeys() - _, s := framework.RunAMaster(t) + _, s := framework.RunAMaster(nil) defer s.Close() c := client.NewOrDie(&restclient.Config{Host: s.URL, ContentConfig: restclient.ContentConfig{GroupVersion: testapi.Default.GroupVersion()}}) diff --git a/test/integration/configmap_test.go b/test/integration/configmap_test.go index bc54670a9b..7e0433eb42 100644 --- a/test/integration/configmap_test.go +++ b/test/integration/configmap_test.go @@ -32,7 +32,7 @@ import ( // TestConfigMap tests apiserver-side behavior of creation of ConfigMaps and pods that consume them. func TestConfigMap(t *testing.T) { - _, s := framework.RunAMaster(t) + _, s := framework.RunAMaster(nil) defer s.Close() client := client.NewOrDie(&restclient.Config{Host: s.URL, ContentConfig: restclient.ContentConfig{GroupVersion: testapi.Default.GroupVersion()}}) diff --git a/test/integration/dynamic_client_test.go b/test/integration/dynamic_client_test.go index 8eaa5a2d6a..2628c7a110 100644 --- a/test/integration/dynamic_client_test.go +++ b/test/integration/dynamic_client_test.go @@ -37,7 +37,7 @@ func TestDynamicClient(t *testing.T) { // TODO: Limit the test to a single non-default namespace and clean this up at the end. framework.DeleteAllEtcdKeys() - _, s := framework.RunAMaster(t) + _, s := framework.RunAMaster(nil) defer s.Close() gv := testapi.Default.GroupVersion() diff --git a/test/integration/extender_test.go b/test/integration/extender_test.go index 5ce8cd6aa9..b2acaeb30b 100644 --- a/test/integration/extender_test.go +++ b/test/integration/extender_test.go @@ -188,7 +188,7 @@ func TestSchedulerExtender(t *testing.T) { // TODO: Limit the test to a single non-default namespace and clean this up at the end. framework.DeleteAllEtcdKeys() - _, s := framework.RunAMaster(t) + _, s := framework.RunAMaster(nil) defer s.Close() restClient := client.NewOrDie(&restclient.Config{Host: s.URL, ContentConfig: restclient.ContentConfig{GroupVersion: testapi.Default.GroupVersion()}}) diff --git a/test/integration/framework/master_utils.go b/test/integration/framework/master_utils.go index b48b462fd6..8af24d81d3 100644 --- a/test/integration/framework/master_utils.go +++ b/test/integration/framework/master_utils.go @@ -347,21 +347,12 @@ func StartPods(numPods int, host string, restClient *client.Client) error { } } -// TODO: Merge this into startMasterOrDie. -func RunAMaster(t *testing.T) (*master.Master, *httptest.Server) { - masterConfig := NewMasterConfig() - masterConfig.EnableProfiling = true - m, err := master.New(masterConfig) - if err != nil { - // TODO: Return error. - glog.Fatalf("error in bringing up the master: %v", err) +func RunAMaster(masterConfig *master.Config) (*master.Master, *httptest.Server) { + if masterConfig == nil { + masterConfig = NewMasterConfig() + masterConfig.EnableProfiling = true } - - s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { - m.Handler.ServeHTTP(w, req) - })) - - return m, s + return startMasterOrDie(masterConfig) } // Task is a function passed to worker goroutines by RunParallel. diff --git a/test/integration/master_test.go b/test/integration/master_test.go index 6931ff45d9..eaa13db3a1 100644 --- a/test/integration/master_test.go +++ b/test/integration/master_test.go @@ -42,7 +42,7 @@ import ( ) func testPrefix(t *testing.T, prefix string) { - _, s := framework.RunAMaster(t) + _, s := framework.RunAMaster(nil) defer s.Close() resp, err := http.Get(s.URL + prefix) @@ -71,7 +71,7 @@ func TestExtensionsPrefix(t *testing.T) { } func TestWatchSucceedsWithoutArgs(t *testing.T) { - _, s := framework.RunAMaster(t) + _, s := framework.RunAMaster(nil) defer s.Close() resp, err := http.Get(s.URL + "/api/v1/namespaces?watch=1") @@ -118,7 +118,7 @@ func extensionsPath(resource, namespace, name string) string { } func TestAutoscalingGroupBackwardCompatibility(t *testing.T) { - _, s := framework.RunAMaster(t) + _, s := framework.RunAMaster(nil) defer s.Close() transport := http.DefaultTransport @@ -261,7 +261,7 @@ func TestBatchGroupBackwardCompatibility(t *testing.T) { if *testapi.Batch.GroupVersion() == v2alpha1.SchemeGroupVersion { t.Skip("Shared job storage is not required for batch/v2alpha1.") } - _, s := framework.RunAMaster(t) + _, s := framework.RunAMaster(nil) defer s.Close() transport := http.DefaultTransport @@ -314,7 +314,7 @@ func TestBatchGroupBackwardCompatibility(t *testing.T) { } func TestAccept(t *testing.T) { - _, s := framework.RunAMaster(t) + _, s := framework.RunAMaster(nil) defer s.Close() resp, err := http.Get(s.URL + "/api/") diff --git a/test/integration/metrics_test.go b/test/integration/metrics_test.go index 2529c25486..6f43035e23 100644 --- a/test/integration/metrics_test.go +++ b/test/integration/metrics_test.go @@ -86,7 +86,7 @@ func checkForExpectedMetrics(t *testing.T, metrics []*prometheuspb.MetricFamily, } func TestMasterProcessMetrics(t *testing.T) { - _, s := framework.RunAMaster(t) + _, s := framework.RunAMaster(nil) defer s.Close() metrics, err := scrapeMetrics(s) @@ -103,7 +103,7 @@ func TestMasterProcessMetrics(t *testing.T) { } func TestApiserverMetrics(t *testing.T) { - _, s := framework.RunAMaster(t) + _, s := framework.RunAMaster(nil) defer s.Close() // Make a request to the apiserver to ensure there's at least one data point diff --git a/test/integration/persistent_volumes_test.go b/test/integration/persistent_volumes_test.go index 01c2b7e437..43edc3be36 100644 --- a/test/integration/persistent_volumes_test.go +++ b/test/integration/persistent_volumes_test.go @@ -108,7 +108,7 @@ func TestPersistentVolumeRecycler(t *testing.T) { framework.DeleteAllEtcdKeys() glog.V(2).Infof("TestPersistentVolumeRecycler started") - _, s := framework.RunAMaster(t) + _, s := framework.RunAMaster(nil) defer s.Close() testClient, ctrl, watchPV, watchPVC := createClients(t, s) @@ -158,7 +158,7 @@ func TestPersistentVolumeDeleter(t *testing.T) { framework.DeleteAllEtcdKeys() glog.V(2).Infof("TestPersistentVolumeDeleter started") - _, s := framework.RunAMaster(t) + _, s := framework.RunAMaster(nil) defer s.Close() testClient, ctrl, watchPV, watchPVC := createClients(t, s) @@ -212,7 +212,7 @@ func TestPersistentVolumeBindRace(t *testing.T) { // Test a race binding many claims to a PV that is pre-bound to a specific // PVC. Only this specific PVC should get bound. glog.V(2).Infof("TestPersistentVolumeBindRace started") - _, s := framework.RunAMaster(t) + _, s := framework.RunAMaster(nil) defer s.Close() testClient, ctrl, watchPV, watchPVC := createClients(t, s) @@ -279,7 +279,7 @@ func TestPersistentVolumeClaimLabelSelector(t *testing.T) { // TODO: Limit the test to a single non-default namespace and clean this up at the end. framework.DeleteAllEtcdKeys() - _, s := framework.RunAMaster(t) + _, s := framework.RunAMaster(nil) defer s.Close() testClient, controller, watchPV, watchPVC := createClients(t, s) @@ -354,7 +354,7 @@ func TestPersistentVolumeClaimLabelSelectorMatchExpressions(t *testing.T) { // TODO: Limit the test to a single non-default namespace and clean this up at the end. framework.DeleteAllEtcdKeys() - _, s := framework.RunAMaster(t) + _, s := framework.RunAMaster(nil) defer s.Close() testClient, controller, watchPV, watchPVC := createClients(t, s) @@ -448,7 +448,7 @@ func TestPersistentVolumeMultiPVs(t *testing.T) { // TODO: Limit the test to a single non-default namespace and clean this up at the end. framework.DeleteAllEtcdKeys() - _, s := framework.RunAMaster(t) + _, s := framework.RunAMaster(nil) defer s.Close() testClient, controller, watchPV, watchPVC := createClients(t, s) @@ -532,7 +532,7 @@ func TestPersistentVolumeMultiPVsPVCs(t *testing.T) { // TODO: Limit the test to a single non-default namespace and clean this up at the end. framework.DeleteAllEtcdKeys() - _, s := framework.RunAMaster(t) + _, s := framework.RunAMaster(nil) defer s.Close() testClient, binder, watchPV, watchPVC := createClients(t, s) @@ -613,7 +613,7 @@ func TestPersistentVolumeProvisionMultiPVCs(t *testing.T) { // TODO: Limit the test to a single non-default namespace and clean this up at the end. framework.DeleteAllEtcdKeys() - _, s := framework.RunAMaster(t) + _, s := framework.RunAMaster(nil) defer s.Close() testClient, binder, watchPV, watchPVC := createClients(t, s) @@ -692,7 +692,7 @@ func TestPersistentVolumeMultiPVsDiffAccessModes(t *testing.T) { // TODO: Limit the test to a single non-default namespace and clean this up at the end. framework.DeleteAllEtcdKeys() - _, s := framework.RunAMaster(t) + _, s := framework.RunAMaster(nil) defer s.Close() testClient, controller, watchPV, watchPVC := createClients(t, s) diff --git a/test/integration/pods_test.go b/test/integration/pods_test.go index 9628149935..2d69a2a46b 100644 --- a/test/integration/pods_test.go +++ b/test/integration/pods_test.go @@ -30,7 +30,7 @@ import ( ) func TestPodUpdateActiveDeadlineSeconds(t *testing.T) { - _, s := framework.RunAMaster(t) + _, s := framework.RunAMaster(nil) defer s.Close() ns := framework.CreateTestingNamespace("pod-activedeadline-update", s, t) @@ -147,7 +147,7 @@ func TestPodUpdateActiveDeadlineSeconds(t *testing.T) { } func TestPodReadOnlyFilesystem(t *testing.T) { - _, s := framework.RunAMaster(t) + _, s := framework.RunAMaster(nil) defer s.Close() isReadOnly := true diff --git a/test/integration/scheduler_test.go b/test/integration/scheduler_test.go index 1cd1425fab..08239e82c4 100644 --- a/test/integration/scheduler_test.go +++ b/test/integration/scheduler_test.go @@ -53,7 +53,7 @@ func TestUnschedulableNodes(t *testing.T) { // TODO: Limit the test to a single non-default namespace and clean this up at the end. framework.DeleteAllEtcdKeys() - _, s := framework.RunAMaster(t) + _, s := framework.RunAMaster(nil) defer s.Close() restClient := client.NewOrDie(&restclient.Config{Host: s.URL, ContentConfig: restclient.ContentConfig{GroupVersion: testapi.Default.GroupVersion()}}) @@ -292,7 +292,7 @@ func TestMultiScheduler(t *testing.T) { // TODO: Limit the test to a single non-default namespace and clean this up at the end. framework.DeleteAllEtcdKeys() - _, s := framework.RunAMaster(t) + _, s := framework.RunAMaster(nil) // TODO: Uncomment when fix #19254 // This seems to be a different issue - it still doesn't work. // defer s.Close() @@ -473,7 +473,7 @@ func createPod(client *client.Client, name string, annotation map[string]string) func TestAllocatable(t *testing.T) { framework.DeleteAllEtcdKeys() - _, s := framework.RunAMaster(t) + _, s := framework.RunAMaster(nil) defer s.Close() // 1. create and start default-scheduler diff --git a/test/integration/secret_test.go b/test/integration/secret_test.go index 26692adf76..e90e4858ff 100644 --- a/test/integration/secret_test.go +++ b/test/integration/secret_test.go @@ -38,7 +38,7 @@ func deleteSecretOrErrorf(t *testing.T, c *client.Client, ns, name string) { // TestSecrets tests apiserver-side behavior of creation of secret objects and their use by pods. func TestSecrets(t *testing.T) { - _, s := framework.RunAMaster(t) + _, s := framework.RunAMaster(nil) defer s.Close() client := client.NewOrDie(&restclient.Config{Host: s.URL, ContentConfig: restclient.ContentConfig{GroupVersion: testapi.Default.GroupVersion()}})