fix test/e2e/gke_node_pools.go

This commit is contained in:
hwdef 2019-08-27 13:28:16 +08:00
parent 12e6930d8a
commit 3035943c30

View File

@ -21,7 +21,6 @@ import (
"os/exec" "os/exec"
"k8s.io/kubernetes/test/e2e/framework" "k8s.io/kubernetes/test/e2e/framework"
e2elog "k8s.io/kubernetes/test/e2e/framework/log"
"github.com/onsi/ginkgo" "github.com/onsi/ginkgo"
) )
@ -35,13 +34,13 @@ var _ = framework.KubeDescribe("GKE node pools [Feature:GKENodePool]", func() {
}) })
ginkgo.It("should create a cluster with multiple node pools [Feature:GKENodePool]", func() { ginkgo.It("should create a cluster with multiple node pools [Feature:GKENodePool]", func() {
e2elog.Logf("Start create node pool test") framework.Logf("Start create node pool test")
testCreateDeleteNodePool(f, "test-pool") testCreateDeleteNodePool(f, "test-pool")
}) })
}) })
func testCreateDeleteNodePool(f *framework.Framework, poolName string) { func testCreateDeleteNodePool(f *framework.Framework, poolName string) {
e2elog.Logf("Create node pool: %q in cluster: %q", poolName, framework.TestContext.CloudConfig.Cluster) framework.Logf("Create node pool: %q in cluster: %q", poolName, framework.TestContext.CloudConfig.Cluster)
clusterStr := fmt.Sprintf("--cluster=%s", framework.TestContext.CloudConfig.Cluster) clusterStr := fmt.Sprintf("--cluster=%s", framework.TestContext.CloudConfig.Cluster)
@ -49,50 +48,50 @@ func testCreateDeleteNodePool(f *framework.Framework, poolName string) {
poolName, poolName,
clusterStr, clusterStr,
"--num-nodes=2").CombinedOutput() "--num-nodes=2").CombinedOutput()
e2elog.Logf("\n%s", string(out)) framework.Logf("\n%s", string(out))
if err != nil { if err != nil {
e2elog.Failf("Failed to create node pool %q. Err: %v\n%v", poolName, err, string(out)) framework.Failf("Failed to create node pool %q. Err: %v\n%v", poolName, err, string(out))
} }
e2elog.Logf("Successfully created node pool %q.", poolName) framework.Logf("Successfully created node pool %q.", poolName)
out, err = exec.Command("gcloud", "container", "node-pools", "list", out, err = exec.Command("gcloud", "container", "node-pools", "list",
clusterStr).CombinedOutput() clusterStr).CombinedOutput()
if err != nil { if err != nil {
e2elog.Failf("Failed to list node pools from cluster %q. Err: %v\n%v", framework.TestContext.CloudConfig.Cluster, err, string(out)) framework.Failf("Failed to list node pools from cluster %q. Err: %v\n%v", framework.TestContext.CloudConfig.Cluster, err, string(out))
} }
e2elog.Logf("Node pools:\n%s", string(out)) framework.Logf("Node pools:\n%s", string(out))
e2elog.Logf("Checking that 2 nodes have the correct node pool label.") framework.Logf("Checking that 2 nodes have the correct node pool label.")
nodeCount := nodesWithPoolLabel(f, poolName) nodeCount := nodesWithPoolLabel(f, poolName)
if nodeCount != 2 { if nodeCount != 2 {
e2elog.Failf("Wanted 2 nodes with node pool label, got: %v", nodeCount) framework.Failf("Wanted 2 nodes with node pool label, got: %v", nodeCount)
} }
e2elog.Logf("Success, found 2 nodes with correct node pool labels.") framework.Logf("Success, found 2 nodes with correct node pool labels.")
e2elog.Logf("Deleting node pool: %q in cluster: %q", poolName, framework.TestContext.CloudConfig.Cluster) framework.Logf("Deleting node pool: %q in cluster: %q", poolName, framework.TestContext.CloudConfig.Cluster)
out, err = exec.Command("gcloud", "container", "node-pools", "delete", out, err = exec.Command("gcloud", "container", "node-pools", "delete",
poolName, poolName,
clusterStr, clusterStr,
"-q").CombinedOutput() "-q").CombinedOutput()
e2elog.Logf("\n%s", string(out)) framework.Logf("\n%s", string(out))
if err != nil { if err != nil {
e2elog.Failf("Failed to delete node pool %q. Err: %v\n%v", poolName, err, string(out)) framework.Failf("Failed to delete node pool %q. Err: %v\n%v", poolName, err, string(out))
} }
e2elog.Logf("Successfully deleted node pool %q.", poolName) framework.Logf("Successfully deleted node pool %q.", poolName)
out, err = exec.Command("gcloud", "container", "node-pools", "list", out, err = exec.Command("gcloud", "container", "node-pools", "list",
clusterStr).CombinedOutput() clusterStr).CombinedOutput()
if err != nil { if err != nil {
e2elog.Failf("\nFailed to list node pools from cluster %q. Err: %v\n%v", framework.TestContext.CloudConfig.Cluster, err, string(out)) framework.Failf("\nFailed to list node pools from cluster %q. Err: %v\n%v", framework.TestContext.CloudConfig.Cluster, err, string(out))
} }
e2elog.Logf("\nNode pools:\n%s", string(out)) framework.Logf("\nNode pools:\n%s", string(out))
e2elog.Logf("Checking that no nodes have the deleted node pool's label.") framework.Logf("Checking that no nodes have the deleted node pool's label.")
nodeCount = nodesWithPoolLabel(f, poolName) nodeCount = nodesWithPoolLabel(f, poolName)
if nodeCount != 0 { if nodeCount != 0 {
e2elog.Failf("Wanted 0 nodes with node pool label, got: %v", nodeCount) framework.Failf("Wanted 0 nodes with node pool label, got: %v", nodeCount)
} }
e2elog.Logf("Success, found no nodes with the deleted node pool's label.") framework.Logf("Success, found no nodes with the deleted node pool's label.")
} }
// nodesWithPoolLabel returns the number of nodes that have the "gke-nodepool" // nodesWithPoolLabel returns the number of nodes that have the "gke-nodepool"