Skip to content

Commit

Permalink
fix e2e when managed cluster do not on hub (stolostron#188)
Browse files Browse the repository at this point in the history
  • Loading branch information
ldpliu authored Jul 30, 2020
1 parent f8dfb42 commit 773d947
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 34 deletions.
1 change: 1 addition & 0 deletions test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ The tests contained in this repository will test the core functionality of Multi

* A Kubernetes cluster with Multicloud Management installed
* Before running testing, kubeconfig file for cluster admin should be in place. Test suites try to load the configuration file from either `$HOME/.kube/config` or the path set by environment variable `KUBECONFIG`.
* If you want to run e2e locally, when managedcluster do not deployed on hub, please set env `export SINGLE_MANAGED_CLUSTER_ON_HUB=FALSE`.

## How to run

Expand Down
5 changes: 3 additions & 2 deletions test/e2e/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ import (
)

const (
kubeConfigFileEnv = "KUBECONFIG"
SingleManagedOnHub = true
kubeConfigFileEnv = "KUBECONFIG"
//Managedcluster deployed on hub
SingleManagedOnHub = "SINGLE_MANAGED_CLUSTER_ON_HUB"
)

var ManagedClusterGVR schema.GroupVersionResource = schema.GroupVersionResource{
Expand Down
77 changes: 45 additions & 32 deletions test/e2e/tests/actions/actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
package actions_test

import (
"os"
"strings"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/open-cluster-management/multicloud-operators-foundation/test/e2e/common"
Expand All @@ -19,6 +22,8 @@ const (
actionDeploymentNameSpace = "default"
)

var singleManagedOnHub = true

var actionGVR = schema.GroupVersionResource{
Group: "action.open-cluster-management.io",
Version: "v1beta1",
Expand All @@ -38,6 +43,10 @@ var (

var _ = BeforeSuite(func() {
var err error
managedOnHub := os.Getenv(common.SingleManagedOnHub)
if strings.ToLower(managedOnHub) == "false" {
singleManagedOnHub = false
}
dynamicClient, err = common.NewDynamicClient()
Ω(err).ShouldNot(HaveOccurred())

Expand All @@ -63,11 +72,10 @@ var _ = Describe("Testing ManagedClusterAction when Agent is ok", func() {
obj *unstructured.Unstructured
err error
)

Context("Creating a CreateManagedClusterAction", func() {
It("should create successfully", func() {
Context("Creating a UpdateManagedClusterAction when resource do not exist", func() {
It("Should create update managedclusteraction successfully", func() {
// load object from json template
obj, err = common.LoadResourceFromJSON(template.ManagedClusterActionCreateTemplate)
obj, err = common.LoadResourceFromJSON(template.ManagedClusterActionUpdateTemplate)
Ω(err).ShouldNot(HaveOccurred())

err = unstructured.SetNestedField(obj.Object, realCluster.GetName(), "metadata", "namespace")
Expand Down Expand Up @@ -100,26 +108,19 @@ var _ = Describe("Testing ManagedClusterAction when Agent is ok", func() {
}

return condition["status"], nil
}, eventuallyTimeout, eventuallyInterval).Should(Equal("True"))
}, eventuallyTimeout, eventuallyInterval).Should(Equal("False"))
})
if common.SingleManagedOnHub {
It("deployment should be created successfully in managedcluster", func() {
Eventually(func() (interface{}, error) {
return common.HasResource(dynamicClient, depGVR, actionDeploymentNameSpace, actionDeploymentName)
}, eventuallyTimeout, eventuallyInterval).Should(BeTrue())
})
}

It("should delete successfully", func() {
err := common.DeleteResource(dynamicClient, actionGVR, realCluster.GetName(), obj.GetName())
Ω(err).ShouldNot(HaveOccurred())
})
})

Context("Creating a UpdateManagedClusterAction", func() {
Context("Creating a DeleteManagedClusterAction when resource do not exist", func() {
It("Should create update managedclusteraction successfully", func() {
// load object from json template
obj, err = common.LoadResourceFromJSON(template.ManagedClusterActionUpdateTemplate)
obj, err = common.LoadResourceFromJSON(template.ManagedClusterActionDeleteTemplate)
Ω(err).ShouldNot(HaveOccurred())

err = unstructured.SetNestedField(obj.Object, realCluster.GetName(), "metadata", "namespace")
Expand Down Expand Up @@ -152,19 +153,26 @@ var _ = Describe("Testing ManagedClusterAction when Agent is ok", func() {
}

return condition["status"], nil
}, eventuallyTimeout, eventuallyInterval).Should(Equal("True"))
}, eventuallyTimeout, eventuallyInterval).Should(Equal("False"))
})

It("deployment should be deleted successfully in managedcluster", func() {
if singleManagedOnHub {
Eventually(func() (interface{}, error) {
return common.HasResource(dynamicClient, depGVR, actionDeploymentNameSpace, actionDeploymentName)
}, eventuallyTimeout, eventuallyInterval).ShouldNot(BeTrue())
}
})

It("should delete successfully", func() {
err := common.DeleteResource(dynamicClient, actionGVR, realCluster.GetName(), obj.GetName())
Ω(err).ShouldNot(HaveOccurred())
})
})

Context("Creating a DeleteManagedClusterAction", func() {
It("Should create update managedclusteraction successfully", func() {
Context("Creating a CreateManagedClusterAction", func() {
It("should create successfully", func() {
// load object from json template
obj, err = common.LoadResourceFromJSON(template.ManagedClusterActionDeleteTemplate)
obj, err = common.LoadResourceFromJSON(template.ManagedClusterActionCreateTemplate)
Ω(err).ShouldNot(HaveOccurred())

err = unstructured.SetNestedField(obj.Object, realCluster.GetName(), "metadata", "namespace")
Expand Down Expand Up @@ -199,20 +207,22 @@ var _ = Describe("Testing ManagedClusterAction when Agent is ok", func() {
return condition["status"], nil
}, eventuallyTimeout, eventuallyInterval).Should(Equal("True"))
})
if common.SingleManagedOnHub {
It("deployment should be deleted successfully in managedcluster", func() {
It("deployment should be created successfully in managedcluster", func() {
if singleManagedOnHub {
Eventually(func() (interface{}, error) {
return common.HasResource(dynamicClient, depGVR, actionDeploymentNameSpace, actionDeploymentName)
}, eventuallyTimeout, eventuallyInterval).ShouldNot(BeTrue())
})
}
}, eventuallyTimeout, eventuallyInterval).Should(BeTrue())

}
})

It("should delete successfully", func() {
err := common.DeleteResource(dynamicClient, actionGVR, realCluster.GetName(), obj.GetName())
Ω(err).ShouldNot(HaveOccurred())
})
})
Context("Creating a UpdateManagedClusterAction when resource do not exist", func() {

Context("Creating a UpdateManagedClusterAction", func() {
It("Should create update managedclusteraction successfully", func() {
// load object from json template
obj, err = common.LoadResourceFromJSON(template.ManagedClusterActionUpdateTemplate)
Expand Down Expand Up @@ -248,7 +258,7 @@ var _ = Describe("Testing ManagedClusterAction when Agent is ok", func() {
}

return condition["status"], nil
}, eventuallyTimeout, eventuallyInterval).Should(Equal("False"))
}, eventuallyTimeout, eventuallyInterval).Should(Equal("True"))
})

It("should delete successfully", func() {
Expand All @@ -257,7 +267,7 @@ var _ = Describe("Testing ManagedClusterAction when Agent is ok", func() {
})
})

Context("Creating a DeleteManagedClusterAction when resource do not exist", func() {
Context("Creating a DeleteManagedClusterAction", func() {
It("Should create update managedclusteraction successfully", func() {
// load object from json template
obj, err = common.LoadResourceFromJSON(template.ManagedClusterActionDeleteTemplate)
Expand Down Expand Up @@ -293,21 +303,24 @@ var _ = Describe("Testing ManagedClusterAction when Agent is ok", func() {
}

return condition["status"], nil
}, eventuallyTimeout, eventuallyInterval).Should(Equal("False"))
}, eventuallyTimeout, eventuallyInterval).Should(Equal("True"))
})
if common.SingleManagedOnHub {
It("deployment should be deleted successfully in managedcluster", func() {

It("deployment should be deleted successfully in managedcluster", func() {

if singleManagedOnHub {
Eventually(func() (interface{}, error) {
return common.HasResource(dynamicClient, depGVR, actionDeploymentNameSpace, actionDeploymentName)
}, eventuallyTimeout, eventuallyInterval).ShouldNot(BeTrue())
})
}
}
})

It("should delete successfully", func() {
err := common.DeleteResource(dynamicClient, actionGVR, realCluster.GetName(), obj.GetName())
Ω(err).ShouldNot(HaveOccurred())
})
})

})

var _ = Describe("Testing ManagedClusterAction when agent is lost", func() {
Expand Down

0 comments on commit 773d947

Please sign in to comment.