Fix a failing test case for cluster object creation/deletion

This commit is contained in:
shashidharatd 2017-04-21 16:26:06 +05:30
parent ac90c0e45c
commit 814bb0b80f
2 changed files with 20 additions and 14 deletions

View File

@ -30,6 +30,7 @@ import (
// Create/delete cluster api objects
var _ = framework.KubeDescribe("Federation apiserver [Feature:Federation]", func() {
f := fedframework.NewDefaultFederatedFramework("federation-cluster")
testClusterPrefix := "test"
Describe("Cluster objects [Serial]", func() {
AfterEach(func() {
@ -37,7 +38,7 @@ var _ = framework.KubeDescribe("Federation apiserver [Feature:Federation]", func
// Delete registered clusters.
// This is if a test failed, it should not affect other tests.
clusterList, err := f.FederationClientset.Federation().Clusters().List(metav1.ListOptions{})
clusterList, err := f.FederationClientset.Federation().Clusters().List(metav1.ListOptions{LabelSelector: "prefix=" + testClusterPrefix})
Expect(err).NotTo(HaveOccurred())
for _, cluster := range clusterList.Items {
err := f.FederationClientset.Federation().Clusters().Delete(cluster.Name, &metav1.DeleteOptions{})
@ -50,12 +51,12 @@ var _ = framework.KubeDescribe("Federation apiserver [Feature:Federation]", func
contexts := f.GetUnderlyingFederatedContexts()
framework.Logf("Creating %d cluster objects", len(contexts))
By(fmt.Sprintf("Creating %d cluster objects", len(contexts)))
for _, context := range contexts {
createClusterObjectOrFail(f, &context)
createClusterObjectOrFail(f, &context, testClusterPrefix)
}
framework.Logf("Checking that %d clusters are Ready", len(contexts))
By(fmt.Sprintf("Checking that %d clusters are ready", len(contexts)))
for _, context := range contexts {
fedframework.ClusterIsReadyOrFail(f, context.Name)
}
@ -64,15 +65,16 @@ var _ = framework.KubeDescribe("Federation apiserver [Feature:Federation]", func
// Verify that deletion works.
framework.Logf("Deleting %d clusters", len(contexts))
for _, context := range contexts {
framework.Logf("Deleting cluster object: %s (%s, secret: %s)", context.Name, context.Cluster.Cluster.Server, context.Name)
err := f.FederationClientset.Federation().Clusters().Delete(context.Name, &metav1.DeleteOptions{})
framework.ExpectNoError(err, fmt.Sprintf("unexpected error in deleting cluster %s: %+v", context.Name, err))
framework.Logf("Successfully deleted cluster object: %s (%s, secret: %s)", context.Name, context.Cluster.Cluster.Server, context.Name)
clusterName := testClusterPrefix + context.Name
framework.Logf("Deleting cluster object: %s (%s, secret: %s)", clusterName, context.Cluster.Cluster.Server, context.Name)
err := f.FederationClientset.Federation().Clusters().Delete(clusterName, &metav1.DeleteOptions{})
framework.ExpectNoError(err, fmt.Sprintf("unexpected error in deleting cluster %s: %+v", clusterName, err))
framework.Logf("Successfully deleted cluster object: %s (%s, secret: %s)", clusterName, context.Cluster.Cluster.Server, context.Name)
}
// There should not be any remaining cluster.
framework.Logf("Verifying that zero clusters remain")
clusterList, err := f.FederationClientset.Federation().Clusters().List(metav1.ListOptions{})
framework.Logf("Verifying that zero test clusters remain")
clusterList, err := f.FederationClientset.Federation().Clusters().List(metav1.ListOptions{LabelSelector: "prefix=" + testClusterPrefix})
Expect(err).NotTo(HaveOccurred())
if len(clusterList.Items) != 0 {
framework.Failf("there should not have been any remaining clusters. Found: %+v", clusterList)

View File

@ -53,11 +53,12 @@ const (
var FederationSuite common.Suite
func createClusterObjectOrFail(f *fedframework.Framework, context *fedframework.E2EContext) {
framework.Logf("Creating cluster object: %s (%s, secret: %s)", context.Name, context.Cluster.Cluster.Server, context.Name)
func createClusterObjectOrFail(f *fedframework.Framework, context *fedframework.E2EContext, clusterNamePrefix string) {
clusterName := clusterNamePrefix + context.Name
framework.Logf("Creating cluster object: %s (%s, secret: %s)", clusterName, context.Cluster.Cluster.Server, context.Name)
cluster := federationapi.Cluster{
ObjectMeta: metav1.ObjectMeta{
Name: context.Name,
Name: clusterName,
},
Spec: federationapi.ClusterSpec{
ServerAddressByClientCIDRs: []federationapi.ServerAddressByClientCIDR{
@ -74,9 +75,12 @@ func createClusterObjectOrFail(f *fedframework.Framework, context *fedframework.
},
},
}
if clusterNamePrefix != "" {
cluster.Labels = map[string]string{"prefix": clusterNamePrefix}
}
_, err := f.FederationClientset.Federation().Clusters().Create(&cluster)
framework.ExpectNoError(err, fmt.Sprintf("creating cluster: %+v", err))
framework.Logf("Successfully created cluster object: %s (%s, secret: %s)", context.Name, context.Cluster.Cluster.Server, context.Name)
framework.Logf("Successfully created cluster object: %s (%s, secret: %s)", clusterName, context.Cluster.Cluster.Server, context.Name)
}
// waitForServiceOrFail waits until a service is either present or absent in the cluster specified by clientset.