Skip to content

Commit

Permalink
Merge pull request #21622 from pwittrock/nodee2essh
Browse files Browse the repository at this point in the history
Auto commit by PR queue bot
  • Loading branch information
k8s-merge-robot committed Feb 24, 2016
2 parents a8c0ac8 + a3623c0 commit 067998e
Show file tree
Hide file tree
Showing 13 changed files with 623 additions and 370 deletions.
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@ test_e2e:
go run hack/e2e.go -v --build --up --test --down
.PHONY: test_e2e

# Build and run node end-to-end tests.
#
# Example:
# make test_e2e_node
test_e2e_node:
hack/e2e-node-test.sh
.PHONY: test_e2e_node


# Remove all build artifacts.
#
# Example:
Expand Down
21 changes: 21 additions & 0 deletions hack/e2e-node-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

# Copyright 2016 The Kubernetes Authors All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Provided for backwards compatibility
sudo -v
ginkgo "$(dirname $0)/../test/e2e_node/" -- --alsologtostderr --v 2 --node-name $(hostname) --build-services=true --start-services=true --stop-services=true

exit $?
1 change: 1 addition & 0 deletions hack/lib/golang.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ kube::golang::test_targets() {
examples/k8petstore/web-server/src
github.com/onsi/ginkgo/ginkgo
test/e2e/e2e.test
test/e2e_node/e2e_node.test
)
if [ -n "${KUBERNETES_CONTRIB:-}" ]; then
for contrib in "${KUBERNETES_CONTRIB}"; do
Expand Down
7 changes: 7 additions & 0 deletions hack/verify-flags/known-flags.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ bench-workers
bind-address
bind-pods-burst
bind-pods-qps
build-services
cadvisor-port
cert-dir
certificate-authority
Expand Down Expand Up @@ -162,6 +163,7 @@ ir-hawkular
jenkins-host
jenkins-jobs
k8s-build-output
k8s-bin-dir
keep-gogoproto
km-path
kube-api-burst
Expand Down Expand Up @@ -323,6 +325,7 @@ scheduler-name
schema-cache-dir
secure-port
serialize-image-pulls
server-start-timeout
service-account-key-file
service-account-lookup
service-account-private-key-file
Expand All @@ -344,10 +347,14 @@ skip-generated-rewrite
skip-munges
sort-by
source-file
ssh-env
ssh-keyfile
ssh-options
ssh-user
start-services
static-pods-config
stats-port
stop-services
storage-version
storage-versions
streaming-connection-idle-timeout
Expand Down
2 changes: 2 additions & 0 deletions test/e2e_node/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// e2e_node contains e2e tests specific to the node
// TODO: rename this package e2e-node
package e2e_node
131 changes: 131 additions & 0 deletions test/e2e_node/e2e_build.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/*
Copyright 2016 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package e2e_node

import (
"flag"
"fmt"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"

"github.com/golang/glog"
)

var k8sBinDir = flag.String("k8s-bin-dir", "", "Directory containing k8s kubelet and kube-apiserver binaries.")

func buildGo() {
glog.Infof("Building k8s binaries...")
k8sRoot, err := getK8sRootDir()
if err != nil {
glog.Fatalf("Failed to locate kubernetes root directory %v.", err)
}
out, err := exec.Command(filepath.Join(k8sRoot, "hack/build-go.sh")).CombinedOutput()
if err != nil {
glog.Fatalf("Failed to build go packages %v. Output:\n%s", err, out)
}
}

func getK8sBin(bin string) (string, error) {
// Use commandline specified path
if *k8sBinDir != "" {
absPath, err := filepath.Abs(*k8sBinDir)
if err != nil {
return "", err
}
if _, err := os.Stat(filepath.Join(*k8sBinDir, bin)); err != nil {
return "", fmt.Errorf("Could not find kube-apiserver under directory %s.", absPath)
}
return filepath.Join(absPath, bin), nil
}

path, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
return "", fmt.Errorf("Could not find absolute path of directory containing the tests %s.", filepath.Dir(os.Args[0]))
}
if _, err := os.Stat(filepath.Join(path, bin)); err == nil {
return filepath.Join(path, bin), nil
}

buildOutputDir, err := getK8sBuildOutputDir()
if err != nil {
return "", err
}
if _, err := os.Stat(filepath.Join(buildOutputDir, bin)); err == nil {
return filepath.Join(buildOutputDir, bin), nil
}

// Give up with error
return "", fmt.Errorf("Unable to locate %s. Can be defined using --k8s-path.", bin)
}

// TODO: Dedup / merge this with comparable utilities in e2e/util.go
func getK8sRootDir() (string, error) {
// Get the directory of the current executable
_, testExec, _, _ := runtime.Caller(0)
path := filepath.Dir(testExec)

// Look for the kubernetes source root directory
if strings.Contains(path, "k8s.io/kubernetes") {
splitPath := strings.Split(path, "k8s.io/kubernetes")
return filepath.Join(splitPath[0], "k8s.io/kubernetes/"), nil
}

return "", fmt.Errorf("Could not find kubernetes source root directory.")
}

func getK8sBuildOutputDir() (string, error) {
k8sRoot, err := getK8sRootDir()
if err != nil {
return "", err
}
buildOutputDir := filepath.Join(k8sRoot, "_output/local/go/bin")
if _, err := os.Stat(buildOutputDir); err != nil {
return "", err
}
return buildOutputDir, nil
}

func getK8sNodeTestDir() (string, error) {
k8sRoot, err := getK8sRootDir()
if err != nil {
return "", err
}
buildOutputDir := filepath.Join(k8sRoot, "test/e2e_node")
if _, err := os.Stat(buildOutputDir); err != nil {
return "", err
}
return buildOutputDir, nil
}

func getKubeletServerBin() string {
bin, err := getK8sBin("kubelet")
if err != nil {
panic(fmt.Sprintf("Could not locate kubelet binary."))
}
return bin
}

func getApiServerBin() string {
bin, err := getK8sBin("kube-apiserver")
if err != nil {
panic(fmt.Sprintf("Could not locate kube-apiserver binary."))
}
return bin
}
56 changes: 50 additions & 6 deletions test/e2e_node/e2e_node_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,31 @@ limitations under the License.
*/

// To run tests in this suite
// Local: `$ ginkgo -- --logtostderr -v 2`
// Remote: `$ ginkgo -- --node-name <hostname> --api-server-address=<hostname:api_port> --kubelet-address=<hostname=kubelet_port> --logtostderr -v 2`
// NOTE: This test suite requires sudo capabilities to run the kubelet and kube-apiserver.
// $ sudo -v && ginkgo test/e2e_node/ -- --logtostderr --v 2 --node-name `hostname` --start-services
package e2e_node

import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

"bytes"
"flag"
"fmt"
"os/exec"
"strings"
"testing"

"github.com/golang/glog"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

var kubeletAddress = flag.String("kubelet-address", "http://127.0.0.1:10255", "Host and port of the kubelet")
var apiServerAddress = flag.String("api-server-address", "http://127.0.0.1:8080", "Host and port of the api server")
var nodeName = flag.String("node-name", "127.0.0.1", "Name of the node")
var nodeName = flag.String("node-name", "", "Name of the node")
var buildServices = flag.Bool("build-services", true, "If true, build local executables")
var startServices = flag.Bool("start-services", true, "If true, start local node services")
var stopServices = flag.Bool("stop-services", true, "If true, stop local node services after running tets")

var e2es *e2eService

func TestE2eNode(t *testing.T) {
flag.Parse()
Expand All @@ -39,8 +49,42 @@ func TestE2eNode(t *testing.T) {

// Setup the kubelet on the node
var _ = BeforeSuite(func() {
if *buildServices {
buildGo()
}
if *nodeName == "" {
output, err := exec.Command("hostname").CombinedOutput()
if err != nil {
glog.Fatal("Could not get node name from hostname %v. Output:\n%s", err, output)
}
*nodeName = strings.TrimSpace(fmt.Sprintf("%s", output))
}

if *startServices {
e2es = newE2eService()
if err := e2es.start(); err != nil {
Fail(fmt.Sprintf("Unable to start node services.\n%v", err))
}
glog.Infof("Node services started. Running tests...")
} else {
glog.Infof("Running tests without starting services.")
}
})

// Tear down the kubelet on the node
var _ = AfterSuite(func() {
if e2es != nil && *startServices && *stopServices {
glog.Infof("Stopping node services...")
e2es.stop()
b := &bytes.Buffer{}
b.WriteString("-------------------------------------------------------------\n")
b.WriteString(fmt.Sprintf("kubelet output:\n%s\n", e2es.kubeletCombinedOut.String()))
b.WriteString("-------------------------------------------------------------\n")
b.WriteString(fmt.Sprintf("apiserver output:\n%s", e2es.apiServerCombinedOut.String()))
b.WriteString("-------------------------------------------------------------\n")
b.WriteString(fmt.Sprintf("etcd output:\n%s", e2es.etcdCombinedOut.String()))
b.WriteString("-------------------------------------------------------------\n")
glog.V(2).Infof(b.String())

}
})
Loading

0 comments on commit 067998e

Please sign in to comment.