From 43485a4eeffb56111b2155b5cde7a1a547240c1b Mon Sep 17 00:00:00 2001 From: Wojciech Tyczynski Date: Fri, 10 Jun 2016 10:20:05 +0200 Subject: [PATCH 1/2] Move APIVersions test --- cmd/integration/integration.go | 96 --------------------------------- test/integration/client_test.go | 24 +++++++++ 2 files changed, 24 insertions(+), 96 deletions(-) diff --git a/cmd/integration/integration.go b/cmd/integration/integration.go index d210306a6a..06bc53eaec 100644 --- a/cmd/integration/integration.go +++ b/cmd/integration/integration.go @@ -19,8 +19,6 @@ limitations under the License. package main import ( - "fmt" - "io/ioutil" "net" "net/http" "net/http/httptest" @@ -282,67 +280,6 @@ func startComponents(firstManifestURL, secondManifestURL string) (string, string return apiServer.URL, configFilePath } -func makeTempDirOrDie(prefix string, baseDir string) string { - if baseDir == "" { - baseDir = "/tmp" - } - tempDir, err := ioutil.TempDir(baseDir, prefix) - if err != nil { - glog.Fatalf("Can't make a temp rootdir: %v", err) - } - if err = os.MkdirAll(tempDir, 0750); err != nil { - glog.Fatalf("Can't mkdir(%q): %v", tempDir, err) - } - return tempDir -} - -// podsOnNodes returns true when all of the selected pods exist on a node. -func podsOnNodes(c *client.Client, podNamespace string, labelSelector labels.Selector) wait.ConditionFunc { - // Wait until all pods are running on the node. - return func() (bool, error) { - options := api.ListOptions{LabelSelector: labelSelector} - pods, err := c.Pods(podNamespace).List(options) - if err != nil { - glog.Infof("Unable to get pods to list: %v", err) - return false, nil - } - for i := range pods.Items { - pod := pods.Items[i] - podString := fmt.Sprintf("%s/%s", pod.Namespace, pod.Name) - glog.Infof("Check whether pod %q exists on node %q", podString, pod.Spec.NodeName) - if len(pod.Spec.NodeName) == 0 { - glog.Infof("Pod %q is not bound to a host yet", podString) - return false, nil - } - if pod.Status.Phase != api.PodRunning { - glog.Infof("Pod %q is not running, status: %v", podString, pod.Status.Phase) - return false, nil - } - } - return true, nil - } -} - -func endpointsSet(c *client.Client, serviceNamespace, serviceID string, endpointCount int) wait.ConditionFunc { - return func() (bool, error) { - endpoints, err := c.Endpoints(serviceNamespace).Get(serviceID) - if err != nil { - glog.Infof("Error getting endpoints: %v", err) - return false, nil - } - count := 0 - for _, ss := range endpoints.Subsets { - for _, addr := range ss.Addresses { - for _, port := range ss.Ports { - count++ - glog.Infof("%s/%s endpoint: %s:%d %#v", serviceNamespace, serviceID, addr.IP, port.Port, addr.TargetRef) - } - } - } - return count == endpointCount, nil - } -} - func countEndpoints(eps *api.Endpoints) int { count := 0 for i := range eps.Subsets { @@ -351,20 +288,6 @@ func countEndpoints(eps *api.Endpoints) int { return count } -func podExists(c *client.Client, podNamespace string, podName string) wait.ConditionFunc { - return func() (bool, error) { - _, err := c.Pods(podNamespace).Get(podName) - return err == nil, nil - } -} - -func podNotFound(c *client.Client, podNamespace string, podName string) wait.ConditionFunc { - return func() (bool, error) { - _, err := c.Pods(podNamespace).Get(podName) - return apierrors.IsNotFound(err), nil - } -} - func podRunning(c *client.Client, podNamespace string, podName string) wait.ConditionFunc { return func() (bool, error) { pod, err := c.Pods(podNamespace).Get(podName) @@ -385,24 +308,6 @@ func podRunning(c *client.Client, podNamespace string, podName string) wait.Cond } } -func runAPIVersionsTest(c *client.Client) { - g, err := c.ServerGroups() - clientVersion := c.APIVersion().String() - if err != nil { - glog.Fatalf("Failed to get api versions: %v", err) - } - versions := unversioned.ExtractGroupVersions(g) - - // Verify that the server supports the API version used by the client. - for _, version := range versions { - if version == clientVersion { - glog.Infof("Version test passed") - return - } - } - glog.Fatalf("Server does not support APIVersion used by client. Server supported APIVersions: '%v', client APIVersion: '%v'", versions, clientVersion) -} - func runSelfLinkTestOnNamespace(c *client.Client, namespace string) { svcBody := api.Service{ ObjectMeta: api.ObjectMeta{ @@ -897,7 +802,6 @@ func main() { testFuncs := []testFunc{ runAtomicPutTest, runPatchTest, - runAPIVersionsTest, runMasterServiceTest, func(c *client.Client) { runSelfLinkTestOnNamespace(c, api.NamespaceDefault) diff --git a/test/integration/client_test.go b/test/integration/client_test.go index 58c1bfed19..cfa4f5941f 100644 --- a/test/integration/client_test.go +++ b/test/integration/client_test.go @@ -29,6 +29,7 @@ import ( "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api/testapi" + "k8s.io/kubernetes/pkg/api/unversioned" "k8s.io/kubernetes/pkg/client/restclient" client "k8s.io/kubernetes/pkg/client/unversioned" "k8s.io/kubernetes/pkg/labels" @@ -109,6 +110,29 @@ func TestClient(t *testing.T) { } } +func TestAPIVersions(t *testing.T) { + _, s := framework.RunAMaster(t) + defer s.Close() + + framework.DeleteAllEtcdKeys() + c := client.NewOrDie(&restclient.Config{Host: s.URL, ContentConfig: restclient.ContentConfig{GroupVersion: testapi.Default.GroupVersion()}}) + + clientVersion := c.APIVersion().String() + g, err := c.ServerGroups() + if err != nil { + t.Fatalf("Failed to get api versions: %v", err) + } + versions := unversioned.ExtractGroupVersions(g) + + // Verify that the server supports the API version used by the client. + for _, version := range versions { + if version == clientVersion { + return + } + } + t.Errorf("Server does not support APIVersion used by client. Server supported APIVersions: '%v', client APIVersion: '%v'", versions, clientVersion) +} + func TestSingleWatch(t *testing.T) { _, s := framework.RunAMaster(t) defer s.Close() From 67ddac041fde072afbb10d9bda44b16fd769adb0 Mon Sep 17 00:00:00 2001 From: Wojciech Tyczynski Date: Fri, 10 Jun 2016 14:13:09 +0200 Subject: [PATCH 2/2] Move SelfLink test --- cmd/integration/integration.go | 66 --------------------------------- test/integration/client_test.go | 61 ++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 66 deletions(-) diff --git a/cmd/integration/integration.go b/cmd/integration/integration.go index 06bc53eaec..8d8c821e26 100644 --- a/cmd/integration/integration.go +++ b/cmd/integration/integration.go @@ -308,68 +308,6 @@ func podRunning(c *client.Client, podNamespace string, podName string) wait.Cond } } -func runSelfLinkTestOnNamespace(c *client.Client, namespace string) { - svcBody := api.Service{ - ObjectMeta: api.ObjectMeta{ - Name: "selflinktest", - Namespace: namespace, - Labels: map[string]string{ - "name": "selflinktest", - }, - }, - Spec: api.ServiceSpec{ - // This is here because validation requires it. - Selector: map[string]string{ - "foo": "bar", - }, - Ports: []api.ServicePort{{ - Port: 12345, - Protocol: "TCP", - }}, - SessionAffinity: "None", - }, - } - services := c.Services(namespace) - svc, err := services.Create(&svcBody) - if err != nil { - glog.Fatalf("Failed creating selflinktest service: %v", err) - } - err = c.Get().RequestURI(svc.SelfLink).Do().Into(svc) - if err != nil { - glog.Fatalf("Failed listing service with supplied self link '%v': %v", svc.SelfLink, err) - } - - svcList, err := services.List(api.ListOptions{}) - if err != nil { - glog.Fatalf("Failed listing services: %v", err) - } - - err = c.Get().RequestURI(svcList.SelfLink).Do().Into(svcList) - if err != nil { - glog.Fatalf("Failed listing services with supplied self link '%v': %v", svcList.SelfLink, err) - } - - found := false - for i := range svcList.Items { - item := &svcList.Items[i] - if item.Name != "selflinktest" { - continue - } - found = true - err = c.Get().RequestURI(item.SelfLink).Do().Into(svc) - if err != nil { - glog.Fatalf("Failed listing service with supplied self link '%v': %v", item.SelfLink, err) - } - break - } - if !found { - glog.Fatalf("never found selflinktest service in namespace %s", namespace) - } - glog.Infof("Self link test passed in namespace %s", namespace) - - // TODO: Should test PUT at some point, too. -} - func runAtomicPutTest(c *client.Client) { svcBody := api.Service{ TypeMeta: unversioned.TypeMeta{ @@ -803,10 +741,6 @@ func main() { runAtomicPutTest, runPatchTest, runMasterServiceTest, - func(c *client.Client) { - runSelfLinkTestOnNamespace(c, api.NamespaceDefault) - runSelfLinkTestOnNamespace(c, "other") - }, } // Only run at most maxConcurrency tests in parallel. diff --git a/test/integration/client_test.go b/test/integration/client_test.go index cfa4f5941f..baa0f7a864 100644 --- a/test/integration/client_test.go +++ b/test/integration/client_test.go @@ -421,3 +421,64 @@ func TestMultiWatch(t *testing.T) { log.Printf("all watches ended") t.Errorf("durations: %v", dur) } + +func runSelfLinkTestOnNamespace(t *testing.T, c *client.Client, namespace string) { + podBody := api.Pod{ + ObjectMeta: api.ObjectMeta{ + Name: "selflinktest", + Namespace: namespace, + Labels: map[string]string{ + "name": "selflinktest", + }, + }, + Spec: api.PodSpec{ + Containers: []api.Container{ + {Name: "name", Image: "image"}, + }, + }, + } + pod, err := c.Pods(namespace).Create(&podBody) + if err != nil { + t.Fatalf("Failed creating selflinktest pod: %v", err) + } + if err = c.Get().RequestURI(pod.SelfLink).Do().Into(pod); err != nil { + t.Errorf("Failed listing pod with supplied self link '%v': %v", pod.SelfLink, err) + } + + podList, err := c.Pods(namespace).List(api.ListOptions{}) + if err != nil { + t.Errorf("Failed listing pods: %v", err) + } + + if err = c.Get().RequestURI(podList.SelfLink).Do().Into(podList); err != nil { + t.Errorf("Failed listing pods with supplied self link '%v': %v", podList.SelfLink, err) + } + + found := false + for i := range podList.Items { + item := &podList.Items[i] + if item.Name != "selflinktest" { + continue + } + found = true + err = c.Get().RequestURI(item.SelfLink).Do().Into(pod) + if err != nil { + t.Errorf("Failed listing pod with supplied self link '%v': %v", item.SelfLink, err) + } + break + } + if !found { + t.Errorf("never found selflinktest pod in namespace %s", namespace) + } +} + +func TestSelfLinkOnNamespace(t *testing.T) { + _, s := framework.RunAMaster(t) + defer s.Close() + + framework.DeleteAllEtcdKeys() + c := client.NewOrDie(&restclient.Config{Host: s.URL, ContentConfig: restclient.ContentConfig{GroupVersion: testapi.Default.GroupVersion()}}) + + runSelfLinkTestOnNamespace(t, c, api.NamespaceDefault) + runSelfLinkTestOnNamespace(t, c, "other-namespace") +}