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

View File

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