Convert private.sh test to Go and remove basic.sh and private.sh

This commit is contained in:
Satnam Singh 2015-01-15 15:24:58 -08:00
parent 732255706c
commit 33e00320bf
8 changed files with 73 additions and 145 deletions

View File

@ -1,5 +1,5 @@
/*
Copyright 2014 Google Inc. All rights reserved.
Copyright 2015 Google Inc. 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.
@ -22,6 +22,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/test/e2e"
"github.com/golang/glog"
flag "github.com/spf13/pflag"
)
@ -30,6 +31,7 @@ var (
certDir = flag.String("cert_dir", "", "Path to the directory containing the certs. Default is empty, which doesn't use certs.")
host = flag.String("host", "", "The host to connect to")
repoRoot = flag.String("repo_root", "./", "Root directory of kubernetes repository, for finding test files. Default assumes working directory is repository root")
provider = flag.String("provider", "", "The name of the Kubernetes provider")
testList util.StringList
)
@ -40,5 +42,9 @@ func init() {
func main() {
util.InitFlags()
goruntime.GOMAXPROCS(goruntime.NumCPU())
e2e.RunE2ETests(*authConfig, *certDir, *host, *repoRoot, testList)
if *provider == "" {
glog.Error("e2e needs the have the --provider flag set")
os.Exit(1)
}
e2e.RunE2ETests(*authConfig, *certDir, *host, *repoRoot, *provider, testList)
}

View File

@ -1,97 +0,0 @@
#!/bin/bash
# Copyright 2014 Google Inc. 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.
# Launches a container and verifies it can be reached. Assumes that
# we're being called by hack/e2e-test.sh (we use some env vars it sets up).
set -o errexit
set -o nounset
set -o pipefail
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../..
source "${KUBE_ROOT}/cluster/kube-env.sh"
source "${KUBE_ROOT}/cluster/$KUBERNETES_PROVIDER/util.sh"
function teardown() {
echo "Cleaning up test artifacts"
$KUBECFG stop my-hostname
$KUBECFG rm my-hostname
}
trap "teardown" EXIT
# Determine which pod image to launch (e.g. private.sh launches a different one).
pod_img_srv="${POD_IMG_SRV:-kubernetes/serve_hostname}"
# Launch some pods.
num_pods=2
$KUBECFG -p 8080:9376 run "${pod_img_srv}" ${num_pods} my-hostname
# List the pods.
pod_id_list=$($KUBECFG '-template={{range.items}}{{.id}} {{end}}' -l name=my-hostname list pods)
echo "pod_id_list: ${pod_id_list}"
if [[ -z "${pod_id_list:-}" ]]; then
echo "Pod ID list is empty. It should have a set of pods to verify."
exit 1
fi
# Pod turn up on a clean cluster can take a while for the docker image pull.
all_running=0
for i in $(seq 1 24); do
echo "Waiting for pods to come up."
sleep 5
all_running=1
for id in $pod_id_list; do
current_status=$($KUBECFG '-template={{.currentState.status}}' get pods/$id) || true
if [[ "$current_status" != "Running" ]]; then
all_running=0
break
fi
done
if [[ "${all_running}" == 1 ]]; then
break
fi
done
if [[ "${all_running}" == 0 ]]; then
echo "Pods did not come up in time"
exit 1
fi
# let images stabilize
echo "Letting images stabilize"
sleep 5
# Verify that something is listening.
for id in ${pod_id_list}; do
ip=$($KUBECFG '-template={{.currentState.hostIP}}' get pods/$id)
echo "Trying to reach server that should be running at ${ip}:8080..."
server_running=0
for i in $(seq 1 5); do
echo "--- trial ${i}"
output=$(curl -s -connect-timeout 1 "http://${ip}:8080" || true)
if echo $output | grep "${id}" &> /dev/null; then
server_running=1
break
fi
sleep 2
done
if [[ "${server_running}" -ne 1 ]]; then
echo "Server never running at ${ip}:8080..."
exit 1
fi
done
exit 0

View File

@ -82,4 +82,4 @@ else
auth_config=()
fi
"${e2e}" "${auth_config[@]:+${auth_config[@]}}" --host="https://${KUBE_MASTER_IP-}"
"${e2e}" "${auth_config[@]:+${auth_config[@]}}" --host="https://${KUBE_MASTER_IP-}" --provider="${KUBERNETES_PROVIDER}"

View File

@ -1,36 +0,0 @@
#!/bin/bash
# Copyright 2014 Google Inc. 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.
# Launches a container and verifies it can be reached. Assumes that
# we're being called by hack/e2e-test.sh (we use some env vars it sets up).
set -o errexit
set -o nounset
set -o pipefail
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../..
source "${KUBE_ROOT}/cluster/kube-env.sh"
source "${KUBE_ROOT}/cluster/$KUBERNETES_PROVIDER/util.sh"
# Private image works only on GCE and GKE.
if [[ "${KUBERNETES_PROVIDER}" != "gce" ]] && [[ "${KUBERNETES_PROVIDER}" != "gke" ]]; then
echo "WARNING: Skipping private.sh for cloud provider: ${KUBERNETES_PROVIDER}."
exit 0
fi
# Run the basic.sh test, but using this image.
export POD_IMG_SRV="container.cloud.google.com/_b_k8s_test/serve_hostname"
source "${KUBE_ROOT}/hack/e2e-suite/basic.sh"

View File

@ -1,5 +1,5 @@
/*
Copyright 2014 Google Inc. All rights reserved.
Copyright 2015 Google Inc. 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.
@ -28,8 +28,13 @@ import (
"github.com/golang/glog"
)
func TestBasic(c *client.Client) bool {
// A basic test to check the deployment of an image using
// a replication controller. The image serves its hostname
// which is checked for each replica.
func TestBasicImage(c *client.Client, image string) bool {
ns := api.NamespaceDefault
// TODO(satnam6502): Generate a unique name to allow
// parallel executions of this test.
name := "my-hostname"
replicas := 2
@ -45,9 +50,13 @@ func TestBasic(c *client.Client) bool {
glog.Infof("Found a straggler %s controller", name)
// Delete any pods controlled by this replicaiton controller.
cnt.Spec.Replicas = 0
c.ReplicationControllers(ns).Update(&cnt)
if _, err := c.ReplicationControllers(ns).Update(&cnt); err != nil {
glog.Warningf("Failed to resize straggler controller to zero: %v", err)
}
// Delete the controller
c.ReplicationControllers(ns).Delete(name)
if err = c.ReplicationControllers(ns).Delete(name); err != nil {
glog.Warningf("Failed to delete straggler replicatior controller: %v", err)
}
break
}
}
@ -56,6 +65,7 @@ func TestBasic(c *client.Client) bool {
// that serves its hostname on port 8080.
// The source for the Docker containter kubernetes/serve_hostname is
// in contrib/for-demos/serve_hostname
glog.Infof("Creating replication controller %s", name)
controller, err := c.ReplicationControllers(ns).Create(&api.ReplicationController{
ObjectMeta: api.ObjectMeta{
Name: name,
@ -73,7 +83,7 @@ func TestBasic(c *client.Client) bool {
Containers: []api.Container{
{
Name: name,
Image: "kubernetes/serve_hostname",
Image: image,
Ports: []api.Port{{ContainerPort: 9376, HostPort: 8080}},
},
},
@ -152,3 +162,9 @@ func TestBasic(c *client.Client) bool {
return true
}
// TestBasic performs the TestBasicImage check with the
// image kubernetes/serve_hostname
func TestBasic(c *client.Client) bool {
return TestBasicImage(c, "kubernetes/serve_hostname")
}

View File

@ -51,21 +51,23 @@ func outputTAPSummary(infoList []testInfo) {
}
}
func RunE2ETests(authConfig, certDir, host, repoRoot string, testList []string) {
testContext = testContextType{authConfig, certDir, host, repoRoot}
// Run each Go end-to-end-test. This function assumes the
// creation of a test cluster.
func RunE2ETests(authConfig, certDir, host, repoRoot, provider string, testList []string) {
testContext = testContextType{authConfig, certDir, host, repoRoot, provider}
util.ReallyCrash = true
util.InitLogs()
defer util.FlushLogs()
// TODO: Associate a timeout with each test individually.
go func() {
defer util.FlushLogs()
time.Sleep(5 * time.Minute)
time.Sleep(10 * time.Minute)
glog.Fatalf("This test has timed out. Cleanup not guaranteed.")
}()
c := loadClientOrDie()
// Define the tests. Important: for a clean test grid, please keep ids for a test constant.
tests := []testSpec{
{TestKubernetesROService, "TestKubernetesROService", 1},
{TestKubeletSendsEvent, "TestKubeletSendsEvent", 2},
@ -75,6 +77,7 @@ func RunE2ETests(authConfig, certDir, host, repoRoot string, testList []string)
{TestClusterDNS, "TestClusterDNS", 6},
{TestPodHasServiceEnvVars, "TestPodHasServiceEnvVars", 7},
{TestBasic, "TestBasic", 8},
{TestPrivate, "TestPrivate", 9},
}
validTestNames := util.NewStringSet()

35
test/e2e/private.go Normal file
View File

@ -0,0 +1,35 @@
/*
Copyright 2015 Google Inc. 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
import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/golang/glog"
)
// A basic test to check the deployment of the
// container.cloud.google.com/_b_k8s_test/serve_hostname image
// with the TestBasicImage test. This test is only supported
// for the providers GCE and GKE.
func TestPrivate(c *client.Client) bool {
if testContext.provider != "gce" && testContext.provider != "gke" {
glog.Infof("Skipping test private which is only supported for proivders gce and gke (not %s)", testContext.provider)
return true
}
glog.Info("Calling out to TestBasic")
return TestBasicImage(c, "container.cloud.google.com/_b_k8s_test/serve_hostname")
}

View File

@ -34,6 +34,7 @@ type testContextType struct {
certDir string
host string
repoRoot string
provider string
}
var testContext testContextType