diff options
| author | wackxu <xushiwei5@huawei.com> | 2022-11-10 22:20:17 +0800 |
|---|---|---|
| committer | vincentgoat <linguohui1@huawei.com> | 2023-01-16 21:14:53 +0800 |
| commit | 2c3a64bc820413077b0d8ab47c9e67177d29f4a9 (patch) | |
| tree | 56470098c1418dc741f0db658e7d54906a39fde1 /tests/e2e | |
| parent | Merge pull request #4256 from Congrool/cm-ut (diff) | |
| download | kubeedge-2c3a64bc820413077b0d8ab47c9e67177d29f4a9.tar.gz | |
clean up e2e dir
Signed-off-by: wackxu <xushiwei5@huawei.com>
Diffstat (limited to 'tests/e2e')
20 files changed, 462 insertions, 1299 deletions
diff --git a/tests/e2e/deployment/deployment_test.go b/tests/e2e/apps/deployment.go index c8fb1e969..4209cd67f 100644 --- a/tests/e2e/deployment/deployment_test.go +++ b/tests/e2e/apps/deployment.go @@ -14,15 +14,15 @@ See the License for the specific language governing permissions and limitations under the License. */ -package deployment +package apps import ( "context" "fmt" "time" - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" + "github.com/onsi/ginkgo" + "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -31,101 +31,101 @@ import ( clientset "k8s.io/client-go/kubernetes" "github.com/kubeedge/kubeedge/tests/e2e/constants" - . "github.com/kubeedge/kubeedge/tests/e2e/testsuite" + "github.com/kubeedge/kubeedge/tests/e2e/testsuite" "github.com/kubeedge/kubeedge/tests/e2e/utils" ) var DeploymentTestTimerGroup = utils.NewTestTimerGroup() // Run Test cases -var _ = Describe("Application deployment test in E2E scenario", func() { +var _ = GroupDescribe("Application deployment test in E2E scenario", func() { var UID string var testTimer *utils.TestTimer - var testSpecReport GinkgoTestDescription + var testSpecReport ginkgo.GinkgoTestDescription var clientSet clientset.Interface - BeforeEach(func() { - clientSet = utils.NewKubeClient(ctx.Cfg.KubeConfigPath) + ginkgo.BeforeEach(func() { + clientSet = utils.NewKubeClient(utils.LoadConfig().KubeConfigPath) }) - Context("Test application deployment and delete deployment using deployment spec", func() { - BeforeEach(func() { + ginkgo.Context("Test application deployment and delete deployment using deployment spec", func() { + ginkgo.BeforeEach(func() { // Get current test SpecReport - testSpecReport = CurrentGinkgoTestDescription() + testSpecReport = ginkgo.CurrentGinkgoTestDescription() // Start test timer testTimer = DeploymentTestTimerGroup.NewTestTimer(testSpecReport.TestText) }) - AfterEach(func() { + ginkgo.AfterEach(func() { // End test timer testTimer.End() // Print result testTimer.PrintResult() - By(fmt.Sprintf("get deployment %s", UID)) + ginkgo.By(fmt.Sprintf("get deployment %s", UID)) deployment, err := utils.GetDeployment(clientSet, metav1.NamespaceDefault, UID) - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) - By(fmt.Sprintf("list pod for deploy %s", UID)) + ginkgo.By(fmt.Sprintf("list pod for deploy %s", UID)) labelSelector := labels.SelectorFromSet(map[string]string{"app": UID}) _, err = utils.GetPods(clientSet, metav1.NamespaceDefault, labelSelector, nil) - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) - By(fmt.Sprintf("delete deploy %s", UID)) + ginkgo.By(fmt.Sprintf("delete deploy %s", UID)) err = utils.DeleteDeployment(clientSet, deployment.Namespace, deployment.Name) - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) - By(fmt.Sprintf("wait for pod of deploy %s to disappear", UID)) + ginkgo.By(fmt.Sprintf("wait for pod of deploy %s to disappear", UID)) err = utils.WaitForPodsToDisappear(clientSet, metav1.NamespaceDefault, labelSelector, constants.Interval, constants.Timeout) - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) utils.PrintTestcaseNameandStatus() }) - It("E2E_APP_DEPLOYMENT_1: Create deployment and check the pods are coming up correctly", func() { + ginkgo.It("E2E_APP_DEPLOYMENT_1: Create deployment and check the pods are coming up correctly", func() { replica := int32(1) //Generate the random string and assign as a UID UID = "edgecore-depl-app-" + utils.GetRandomString(5) - CreateDeploymentTest(clientSet, replica, UID, ctx) + testsuite.CreateDeploymentTest(clientSet, replica, UID) }) - It("E2E_APP_DEPLOYMENT_2: Create deployment with replicas and check the pods are coming up correctly", func() { + ginkgo.It("E2E_APP_DEPLOYMENT_2: Create deployment with replicas and check the pods are coming up correctly", func() { replica := int32(3) //Generate the random string and assign as a UID UID = "edgecore-depl-app-" + utils.GetRandomString(5) - CreateDeploymentTest(clientSet, replica, UID, ctx) + testsuite.CreateDeploymentTest(clientSet, replica, UID) }) - It("E2E_APP_DEPLOYMENT_3: Create deployment and check deployment ctrler re-creating pods when user deletes the pods manually", func() { + ginkgo.It("E2E_APP_DEPLOYMENT_3: Create deployment and check deployment ctrler re-creating pods when user deletes the pods manually", func() { replica := int32(3) //Generate the random string and assign as a UID UID = "edgecore-depl-app-" + utils.GetRandomString(5) - podList := CreateDeploymentTest(clientSet, replica, UID, ctx) + podList := testsuite.CreateDeploymentTest(clientSet, replica, UID) for _, pod := range podList.Items { err := utils.DeletePod(clientSet, pod.Namespace, pod.Name) - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) } utils.CheckPodDeleteState(clientSet, podList) labelSelector := labels.SelectorFromSet(map[string]string{"app": UID}) podList, err := utils.GetPods(clientSet, metav1.NamespaceDefault, labelSelector, nil) - Expect(err).To(BeNil()) - Expect(len(podList.Items)).Should(Equal(int(replica))) + gomega.Expect(err).To(gomega.BeNil()) + gomega.Expect(len(podList.Items)).Should(gomega.Equal(int(replica))) utils.WaitForPodsRunning(clientSet, podList, 240*time.Second) }) }) - Context("Test application deployment using Pod spec", func() { - BeforeEach(func() { + ginkgo.Context("Test application deployment using Pod spec", func() { + ginkgo.BeforeEach(func() { // Get current test SpecReport - testSpecReport = CurrentGinkgoTestDescription() + testSpecReport = ginkgo.CurrentGinkgoTestDescription() // Start test timer testTimer = DeploymentTestTimerGroup.NewTestTimer(testSpecReport.TestText) }) - AfterEach(func() { + ginkgo.AfterEach(func() { // End test timer testTimer.End() // Print result @@ -133,11 +133,11 @@ var _ = Describe("Application deployment test in E2E scenario", func() { labelSelector := labels.SelectorFromSet(constants.KubeEdgeE2ELabel) podList, err := utils.GetPods(clientSet, metav1.NamespaceDefault, labelSelector, nil) - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) for _, pod := range podList.Items { err = utils.DeletePod(clientSet, pod.Namespace, pod.Name) - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) } utils.CheckPodDeleteState(clientSet, podList) @@ -145,65 +145,65 @@ var _ = Describe("Application deployment test in E2E scenario", func() { utils.PrintTestcaseNameandStatus() }) - It("E2E_POD_DEPLOYMENT_1: Create a pod and check the pod is coming up correctly", func() { + ginkgo.It("E2E_POD_DEPLOYMENT_1: Create a pod and check the pod is coming up correctly", func() { //Generate the random string and assign as podName podName := "pod-app-" + utils.GetRandomString(5) - pod := utils.NewPod(podName, ctx.Cfg.AppImageURL[0]) + pod := utils.NewPod(podName, utils.LoadConfig().AppImageURL[0]) - CreatePodTest(clientSet, pod) + testsuite.CreatePodTest(clientSet, pod) }) - It("E2E_POD_DEPLOYMENT_2: Create the pod and delete pod happening successfully", func() { + ginkgo.It("E2E_POD_DEPLOYMENT_2: Create the pod and delete pod happening successfully", func() { //Generate the random string and assign as podName podName := "pod-app-" + utils.GetRandomString(5) - pod := utils.NewPod(podName, ctx.Cfg.AppImageURL[0]) + pod := utils.NewPod(podName, utils.LoadConfig().AppImageURL[0]) - podList := CreatePodTest(clientSet, pod) + podList := testsuite.CreatePodTest(clientSet, pod) for _, pod := range podList.Items { err := utils.DeletePod(clientSet, pod.Namespace, pod.Name) - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) } utils.CheckPodDeleteState(clientSet, podList) }) - It("E2E_POD_DEPLOYMENT_3: Create pod and delete the pod successfully, and delete already deleted pod and check the behaviour", func() { + ginkgo.It("E2E_POD_DEPLOYMENT_3: Create pod and delete the pod successfully, and delete already deleted pod and check the behaviour", func() { //Generate the random string and assign as podName podName := "pod-app-" + utils.GetRandomString(5) - pod := utils.NewPod(podName, ctx.Cfg.AppImageURL[0]) + pod := utils.NewPod(podName, utils.LoadConfig().AppImageURL[0]) - podList := CreatePodTest(clientSet, pod) + podList := testsuite.CreatePodTest(clientSet, pod) for _, pod := range podList.Items { err := utils.DeletePod(clientSet, pod.Namespace, pod.Name) - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) } utils.CheckPodDeleteState(clientSet, podList) err := utils.DeletePod(clientSet, pod.Namespace, pod.Name) - Expect(errors.IsNotFound(err)).To(BeTrue()) + gomega.Expect(errors.IsNotFound(err)).To(gomega.BeTrue()) }) - It("E2E_POD_DEPLOYMENT_4: Create and delete pod multiple times and check all the Pod created and deleted successfully", func() { + ginkgo.It("E2E_POD_DEPLOYMENT_4: Create and delete pod multiple times and check all the Pod created and deleted successfully", func() { //Generate the random string and assign as a UID for i := 0; i < 10; i++ { //Generate the random string and assign as podName podName := "pod-app-" + utils.GetRandomString(5) - pod := utils.NewPod(podName, ctx.Cfg.AppImageURL[0]) + pod := utils.NewPod(podName, utils.LoadConfig().AppImageURL[0]) - podList := CreatePodTest(clientSet, pod) + podList := testsuite.CreatePodTest(clientSet, pod) for _, pod := range podList.Items { err := utils.DeletePod(clientSet, pod.Namespace, pod.Name) - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) } utils.CheckPodDeleteState(clientSet, podList) } }) - It("E2E_POD_DEPLOYMENT_5: Create pod with hostpath volume successfully", func() { + ginkgo.It("E2E_POD_DEPLOYMENT_5: Create pod with hostpath volume successfully", func() { //Generate the random string and assign as podName podName := "pod-app-" + utils.GetRandomString(5) - pod := utils.NewPod(podName, ctx.Cfg.AppImageURL[0]) + pod := utils.NewPod(podName, utils.LoadConfig().AppImageURL[0]) pod.Spec.Containers[0].VolumeMounts = []corev1.VolumeMount{{ Name: "hp", @@ -216,98 +216,98 @@ var _ = Describe("Application deployment test in E2E scenario", func() { }, }} - podList := CreatePodTest(clientSet, pod) + podList := testsuite.CreatePodTest(clientSet, pod) for _, pod := range podList.Items { err := utils.DeletePod(clientSet, pod.Namespace, pod.Name) - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) } utils.CheckPodDeleteState(clientSet, podList) }) }) - Context("StatefulSet lifecycle test in edge node", func() { - BeforeEach(func() { + ginkgo.Context("StatefulSet lifecycle test in edge node", func() { + ginkgo.BeforeEach(func() { // Get current test SpecReport - testSpecReport = CurrentGinkgoTestDescription() + testSpecReport = ginkgo.CurrentGinkgoTestDescription() // Start test timer testTimer = DeploymentTestTimerGroup.NewTestTimer(testSpecReport.TestText) }) - AfterEach(func() { + ginkgo.AfterEach(func() { // End test timer testTimer.End() // Print result testTimer.PrintResult() - By(fmt.Sprintf("get StatefulSet %s", UID)) + ginkgo.By(fmt.Sprintf("get StatefulSet %s", UID)) statefulSet, err := utils.GetStatefulSet(clientSet, metav1.NamespaceDefault, UID) - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) - By(fmt.Sprintf("list pod for StatefulSet %s", UID)) + ginkgo.By(fmt.Sprintf("list pod for StatefulSet %s", UID)) labelSelector := labels.SelectorFromSet(map[string]string{"app": UID}) _, err = utils.GetPods(clientSet, metav1.NamespaceDefault, labelSelector, nil) - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) - By(fmt.Sprintf("delete StatefulSet %s", UID)) + ginkgo.By(fmt.Sprintf("delete StatefulSet %s", UID)) err = utils.DeleteStatefulSet(clientSet, statefulSet.Namespace, statefulSet.Name) - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) - By(fmt.Sprintf("wait for pod of StatefulSet %s disappear", UID)) + ginkgo.By(fmt.Sprintf("wait for pod of StatefulSet %s disappear", UID)) err = utils.WaitForPodsToDisappear(clientSet, metav1.NamespaceDefault, labelSelector, constants.Interval, constants.Timeout) - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) utils.PrintTestcaseNameandStatus() }) - It("Basic StatefulSet test", func() { + ginkgo.It("Basic StatefulSet test", func() { replica := int32(2) // Generate the random string and assign as a UID UID = "edge-statefulset-" + utils.GetRandomString(5) - By(fmt.Sprintf("create StatefulSet %s", UID)) - d := utils.NewTestStatefulSet(UID, ctx.Cfg.AppImageURL[1], replica) + ginkgo.By(fmt.Sprintf("create StatefulSet %s", UID)) + d := utils.NewTestStatefulSet(UID, utils.LoadConfig().AppImageURL[1], replica) ss, err := utils.CreateStatefulSet(clientSet, d) - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) utils.WaitForStatusReplicas(clientSet, ss, replica) - By(fmt.Sprintf("get pod for StatefulSet %s", UID)) + ginkgo.By(fmt.Sprintf("get pod for StatefulSet %s", UID)) labelSelector := labels.SelectorFromSet(map[string]string{"app": UID}) podList, err := utils.GetPods(clientSet, corev1.NamespaceDefault, labelSelector, nil) - Expect(err).To(BeNil()) - Expect(len(podList.Items)).ShouldNot(Equal(0)) + gomega.Expect(err).To(gomega.BeNil()) + gomega.Expect(len(podList.Items)).ShouldNot(gomega.Equal(0)) - By(fmt.Sprintf("wait for pod of StatefulSet %s running", UID)) + ginkgo.By(fmt.Sprintf("wait for pod of StatefulSet %s running", UID)) utils.WaitForPodsRunning(clientSet, podList, 240*time.Second) }) - It("Delete statefulSet pod multi times", func() { + ginkgo.It("Delete statefulSet pod multi times", func() { replica := int32(2) // Generate the random string and assign as a UID UID = "edge-statefulset-" + utils.GetRandomString(5) - By(fmt.Sprintf("create StatefulSet %s", UID)) - d := utils.NewTestStatefulSet(UID, ctx.Cfg.AppImageURL[1], replica) + ginkgo.By(fmt.Sprintf("create StatefulSet %s", UID)) + d := utils.NewTestStatefulSet(UID, utils.LoadConfig().AppImageURL[1], replica) ss, err := utils.CreateStatefulSet(clientSet, d) - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) utils.WaitForStatusReplicas(clientSet, ss, replica) - By(fmt.Sprintf("get pod for StatefulSet %s", UID)) + ginkgo.By(fmt.Sprintf("get pod for StatefulSet %s", UID)) labelSelector := labels.SelectorFromSet(map[string]string{"app": UID}) podList, err := utils.GetPods(clientSet, corev1.NamespaceDefault, labelSelector, nil) - Expect(err).To(BeNil()) - Expect(len(podList.Items)).ShouldNot(Equal(0)) + gomega.Expect(err).To(gomega.BeNil()) + gomega.Expect(len(podList.Items)).ShouldNot(gomega.Equal(0)) - By(fmt.Sprintf("wait for pod of StatefulSet %s running", UID)) + ginkgo.By(fmt.Sprintf("wait for pod of StatefulSet %s running", UID)) utils.WaitForPodsRunning(clientSet, podList, 240*time.Second) deletePodName := fmt.Sprintf("%s-1", UID) for i := 0; i < 5; i++ { - By(fmt.Sprintf("delete pod %s", deletePodName)) + ginkgo.By(fmt.Sprintf("delete pod %s", deletePodName)) err = utils.DeletePod(clientSet, "default", deletePodName) - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) - By(fmt.Sprintf("wait for pod %s running again", fmt.Sprintf("%s-1", UID))) + ginkgo.By(fmt.Sprintf("wait for pod %s running again", fmt.Sprintf("%s-1", UID))) err = wait.Poll(5*time.Second, 120*time.Second, func() (bool, error) { pod, err := clientSet.CoreV1().Pods("default").Get(context.TODO(), deletePodName, metav1.GetOptions{}) if err != nil { @@ -318,7 +318,7 @@ var _ = Describe("Application deployment test in E2E scenario", func() { } return false, nil }) - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) } }) }) diff --git a/tests/e2e/edgesite/edgesite_suite_test.go b/tests/e2e/apps/framework.go index 298a4a765..75c6431fb 100644 --- a/tests/e2e/edgesite/edgesite_suite_test.go +++ b/tests/e2e/apps/framework.go @@ -1,5 +1,5 @@ /* -Copyright 2019 The KubeEdge Authors. +Copyright 2022 The KubeEdge Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -14,13 +14,11 @@ See the License for the specific language governing permissions and limitations under the License. */ -package edgesite +package apps -import ( - "github.com/kubeedge/kubeedge/tests/e2e/utils" -) +import "github.com/onsi/ginkgo" -var ( - //context to load config and access across the package - ctx *utils.TestContext -) +// GroupDescribe annotates the test with the group label. +func GroupDescribe(text string, body func()) bool { + return ginkgo.Describe("[KubeEdge-APPS] "+text, body) +} diff --git a/tests/e2e/constants/constants.go b/tests/e2e/constants/constants.go index 6ae2a4378..8e259b393 100644 --- a/tests/e2e/constants/constants.go +++ b/tests/e2e/constants/constants.go @@ -8,6 +8,8 @@ const ( E2ELabelKey = "kubeedge" E2ELabelValue = "e2e-test" + + NodeName = "edge-node" ) var ( diff --git a/tests/e2e/deployment/device_crd_test.go b/tests/e2e/device/device.go index 38d9cdfb7..d2501d30f 100644 --- a/tests/e2e/deployment/device_crd_test.go +++ b/tests/e2e/device/device.go @@ -14,20 +14,21 @@ See the License for the specific language governing permissions and limitations under the License. */ -package deployment +package device import ( "context" "net/http" "time" - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" + "github.com/onsi/ginkgo" + "github.com/onsi/gomega" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" clientset "k8s.io/client-go/kubernetes" edgeclientset "github.com/kubeedge/kubeedge/pkg/client/clientset/versioned" + "github.com/kubeedge/kubeedge/tests/e2e/constants" "github.com/kubeedge/kubeedge/tests/e2e/utils" ) @@ -35,191 +36,189 @@ const ( off = "OFF" ) -var CRDTestTimerGroup = utils.NewTestTimerGroup() - // Run Test cases -var _ = Describe("Device Management test in E2E scenario", func() { +var _ = GroupDescribe("Device Management test in E2E scenario", func() { var testTimer *utils.TestTimer - var testSpecReport GinkgoTestDescription + var testSpecReport ginkgo.GinkgoTestDescription var clientSet clientset.Interface var edgeClientSet edgeclientset.Interface - BeforeEach(func() { - clientSet = utils.NewKubeClient(ctx.Cfg.KubeConfigPath) - edgeClientSet = utils.NewKubeEdgeClient(ctx.Cfg.KubeConfigPath) + ginkgo.BeforeEach(func() { + clientSet = utils.NewKubeClient(utils.LoadConfig().KubeConfigPath) + edgeClientSet = utils.NewKubeEdgeClient(utils.LoadConfig().KubeConfigPath) }) - Context("Test Device Model Creation, Updation and deletion", func() { - BeforeEach(func() { + ginkgo.Context("Test Device Model Creation, Updation and deletion", func() { + ginkgo.BeforeEach(func() { // Delete any pre-existing device models list, err := utils.ListDeviceModel(edgeClientSet, "default") - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) for _, model := range list { err := utils.HandleDeviceModel(edgeClientSet, http.MethodDelete, model.Name, "") - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) } // Get current test SpecReport - testSpecReport = CurrentGinkgoTestDescription() + testSpecReport = ginkgo.CurrentGinkgoTestDescription() // Start test timer - testTimer = CRDTestTimerGroup.NewTestTimer(testSpecReport.TestText) + testTimer = utils.CRDTestTimerGroup.NewTestTimer(testSpecReport.TestText) }) - AfterEach(func() { + ginkgo.AfterEach(func() { // End test timer testTimer.End() // Print result testTimer.PrintResult() // Delete the device models created list, err := utils.ListDeviceModel(edgeClientSet, "default") - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) for _, model := range list { err := utils.HandleDeviceModel(edgeClientSet, http.MethodDelete, model.Name, "") - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) } utils.PrintTestcaseNameandStatus() }) - It("E2E_CREATE_DEVICE_MODEL_1: Create device model for LED device (No Protocol)", func() { + ginkgo.It("E2E_CREATE_DEVICE_MODEL_1: Create device model for LED device (No Protocol)", func() { err := utils.HandleDeviceModel(edgeClientSet, http.MethodPost, "", "led") - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) newLedDeviceModel := utils.NewLedDeviceModel() deviceModelList, err := utils.ListDeviceModel(edgeClientSet, "default") - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) - Expect(utils.CheckDeviceModelExists(deviceModelList, &newLedDeviceModel)).To(BeNil()) + gomega.Expect(utils.CheckDeviceModelExists(deviceModelList, &newLedDeviceModel)).To(gomega.BeNil()) }) - It("E2E_CREATE_DEVICE_MODEL_2: Create device model for bluetooth protocol", func() { + ginkgo.It("E2E_CREATE_DEVICE_MODEL_2: Create device model for bluetooth protocol", func() { err := utils.HandleDeviceModel(edgeClientSet, http.MethodPost, "", "bluetooth") - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) newBluetoothDeviceModel := utils.NewBluetoothDeviceModel() deviceModelList, err := utils.ListDeviceModel(edgeClientSet, "default") - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) - Expect(utils.CheckDeviceModelExists(deviceModelList, &newBluetoothDeviceModel)).To(BeNil()) + gomega.Expect(utils.CheckDeviceModelExists(deviceModelList, &newBluetoothDeviceModel)).To(gomega.BeNil()) }) - It("E2E_CREATE_DEVICE_MODEL_3: Create device model for modbus protocol", func() { + ginkgo.It("E2E_CREATE_DEVICE_MODEL_3: Create device model for modbus protocol", func() { err := utils.HandleDeviceModel(edgeClientSet, http.MethodPost, "", "modbus") - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) newModbusDeviceMode := utils.NewModbusDeviceModel() deviceModelList, err := utils.ListDeviceModel(edgeClientSet, "default") - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) - Expect(utils.CheckDeviceModelExists(deviceModelList, &newModbusDeviceMode)).To(BeNil()) + gomega.Expect(utils.CheckDeviceModelExists(deviceModelList, &newModbusDeviceMode)).To(gomega.BeNil()) }) - It("E2E_UPDATE_DEVICE_MODEL_1: Update device model for LED device (No Protocol)", func() { + ginkgo.It("E2E_UPDATE_DEVICE_MODEL_1: Update device model for LED device (No Protocol)", func() { err := utils.HandleDeviceModel(edgeClientSet, http.MethodPost, "", "led") - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) err = utils.HandleDeviceModel(edgeClientSet, http.MethodPatch, utils.UpdatedLedDeviceModel().Name, "led") - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) updatedLedDeviceModel := utils.UpdatedLedDeviceModel() deviceModelList, err := utils.ListDeviceModel(edgeClientSet, "default") - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) - Expect(utils.CheckDeviceModelExists(deviceModelList, &updatedLedDeviceModel)).To(BeNil()) + gomega.Expect(utils.CheckDeviceModelExists(deviceModelList, &updatedLedDeviceModel)).To(gomega.BeNil()) }) - It("E2E_UPDATE_DEVICE_MODEL_2: Update device model for bluetooth protocol", func() { + ginkgo.It("E2E_UPDATE_DEVICE_MODEL_2: Update device model for bluetooth protocol", func() { err := utils.HandleDeviceModel(edgeClientSet, http.MethodPost, "", "bluetooth") - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) err = utils.HandleDeviceModel(edgeClientSet, http.MethodPatch, utils.UpdatedBluetoothDeviceModel().Name, "bluetooth") - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) updatedBluetoothDeviceModel := utils.UpdatedBluetoothDeviceModel() deviceModelList, err := utils.ListDeviceModel(edgeClientSet, "default") - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) - Expect(utils.CheckDeviceModelExists(deviceModelList, &updatedBluetoothDeviceModel)).To(BeNil()) + gomega.Expect(utils.CheckDeviceModelExists(deviceModelList, &updatedBluetoothDeviceModel)).To(gomega.BeNil()) }) - It("E2E_UPDATE_DEVICE_MODEL_3: Update device model for modbus protocol", func() { + ginkgo.It("E2E_UPDATE_DEVICE_MODEL_3: Update device model for modbus protocol", func() { err := utils.HandleDeviceModel(edgeClientSet, http.MethodPost, "", "modbus") - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) err = utils.HandleDeviceModel(edgeClientSet, http.MethodPatch, utils.UpdatedModbusDeviceModel().Name, "modbus") - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) updatedModbusDeviceModel := utils.UpdatedModbusDeviceModel() deviceModelList, err := utils.ListDeviceModel(edgeClientSet, "default") - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) - Expect(utils.CheckDeviceModelExists(deviceModelList, &updatedModbusDeviceModel)).To(BeNil()) + gomega.Expect(utils.CheckDeviceModelExists(deviceModelList, &updatedModbusDeviceModel)).To(gomega.BeNil()) }) - It("E2E_UPDATE_DEVICE_MODEL_4: Update device model for incorrect device model", func() { + ginkgo.It("E2E_UPDATE_DEVICE_MODEL_4: Update device model for incorrect device model", func() { err := utils.HandleDeviceModel(edgeClientSet, http.MethodPost, "", "led") - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) err = utils.HandleDeviceModel(edgeClientSet, http.MethodPatch, utils.UpdatedLedDeviceModel().Name, "incorrect-model") - Expect(err).NotTo(BeNil()) + gomega.Expect(err).NotTo(gomega.BeNil()) }) - It("E2E_DELETE_DEVICE_MODEL_1: Delete non existent device model(No Protocol)", func() { + ginkgo.It("E2E_DELETE_DEVICE_MODEL_1: Delete non existent device model(No Protocol)", func() { err := utils.HandleDeviceModel(edgeClientSet, http.MethodDelete, utils.NewLedDeviceModel().Name, "") - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) }) }) - Context("Test Device Instance Creation, Updation and Deletion", func() { - BeforeEach(func() { + ginkgo.Context("Test Device Instance Creation, Updation and Deletion", func() { + ginkgo.BeforeEach(func() { // Delete the device instances created deviceInstanceList, err := utils.ListDevice(edgeClientSet, "default") - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) for _, device := range deviceInstanceList { - err := utils.HandleDeviceInstance(edgeClientSet, http.MethodDelete, nodeName, device.Name, "") - Expect(err).To(BeNil()) + err := utils.HandleDeviceInstance(edgeClientSet, http.MethodDelete, constants.NodeName, device.Name, "") + gomega.Expect(err).To(gomega.BeNil()) } // Delete any pre-existing device models list, err := utils.ListDeviceModel(edgeClientSet, "default") - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) for _, model := range list { err := utils.HandleDeviceModel(edgeClientSet, http.MethodDelete, model.Name, "") - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) } utils.TwinResult = utils.DeviceTwinResult{} // Get current test SpecReport - testSpecReport = CurrentGinkgoTestDescription() + testSpecReport = ginkgo.CurrentGinkgoTestDescription() // Start test timer - testTimer = CRDTestTimerGroup.NewTestTimer(testSpecReport.TestText) + testTimer = utils.CRDTestTimerGroup.NewTestTimer(testSpecReport.TestText) }) - AfterEach(func() { + ginkgo.AfterEach(func() { // End test timer testTimer.End() // Print result testTimer.PrintResult() // Delete the device instances created deviceInstanceList, err := utils.ListDevice(edgeClientSet, "default") - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) for _, device := range deviceInstanceList { - err := utils.HandleDeviceInstance(edgeClientSet, http.MethodDelete, nodeName, device.Name, "") - Expect(err).To(BeNil()) + err := utils.HandleDeviceInstance(edgeClientSet, http.MethodDelete, constants.NodeName, device.Name, "") + gomega.Expect(err).To(gomega.BeNil()) } // Delete the device models created list, err := utils.ListDeviceModel(edgeClientSet, "default") - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) for _, model := range list { err := utils.HandleDeviceModel(edgeClientSet, http.MethodDelete, model.Name, "") - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) } utils.PrintTestcaseNameandStatus() }) - It("E2E_CREATE_DEVICE_1: Create device instance for LED device (No Protocol)", func() { + ginkgo.It("E2E_CREATE_DEVICE_1: Create device instance for LED device (No Protocol)", func() { err := utils.HandleDeviceModel(edgeClientSet, http.MethodPost, "", "led") - Expect(err).To(BeNil()) - err = utils.HandleDeviceInstance(edgeClientSet, http.MethodPost, nodeName, "", "led") - Expect(err).To(BeNil()) - newLedDevice := utils.NewLedDeviceInstance(nodeName) + gomega.Expect(err).To(gomega.BeNil()) + err = utils.HandleDeviceInstance(edgeClientSet, http.MethodPost, constants.NodeName, "", "led") + gomega.Expect(err).To(gomega.BeNil()) + newLedDevice := utils.NewLedDeviceInstance(constants.NodeName) deviceInstanceList, err := utils.ListDevice(edgeClientSet, "default") - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) err = utils.CheckDeviceExists(deviceInstanceList, &newLedDevice) - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) time.Sleep(3 * time.Second) - configMap, err := clientSet.CoreV1().ConfigMaps("default").Get(context.TODO(), "device-profile-config-"+nodeName, metav1.GetOptions{}) - Expect(err).To(BeNil()) + configMap, err := clientSet.CoreV1().ConfigMaps("default").Get(context.TODO(), "device-profile-config-"+constants.NodeName, metav1.GetOptions{}) + gomega.Expect(err).To(gomega.BeNil()) - isEqual := utils.CompareConfigMaps(*configMap, utils.NewConfigMapLED(nodeName)) - Expect(isEqual).Should(Equal(true)) - go utils.TwinSubscribe(utils.NewLedDeviceInstance(nodeName).Name) - Eventually(func() bool { + isEqual := utils.CompareConfigMaps(*configMap, utils.NewConfigMapLED(constants.NodeName)) + gomega.Expect(isEqual).Should(gomega.Equal(true)) + go utils.TwinSubscribe(utils.NewLedDeviceInstance(constants.NodeName).Name) + gomega.Eventually(func() bool { return utils.TwinResult.Twin != nil - }, "20s", "2s").Should(Equal(true), "Device information not reaching edge!!") + }, "20s", "2s").Should(gomega.Equal(true), "Device information not reaching edge!!") stringValue := "ON" expectedTwin := map[string]*utils.MsgTwin{ "power-status": { @@ -232,32 +231,32 @@ var _ = Describe("Device Management test in E2E scenario", func() { }, } isEqual = utils.CompareTwin(utils.TwinResult.Twin, expectedTwin) - Expect(isEqual).Should(Equal(true)) + gomega.Expect(isEqual).Should(gomega.Equal(true)) }) - It("E2E_CREATE_DEVICE_2: Create device instance for bluetooth protocol", func() { + ginkgo.It("E2E_CREATE_DEVICE_2: Create device instance for bluetooth protocol", func() { err := utils.HandleDeviceModel(edgeClientSet, http.MethodPost, "", "bluetooth") - Expect(err).To(BeNil()) - err = utils.HandleDeviceInstance(edgeClientSet, http.MethodPost, nodeName, "", "bluetooth") - Expect(err).To(BeNil()) - newBluetoothDevice := utils.NewBluetoothDeviceInstance(nodeName) + gomega.Expect(err).To(gomega.BeNil()) + err = utils.HandleDeviceInstance(edgeClientSet, http.MethodPost, constants.NodeName, "", "bluetooth") + gomega.Expect(err).To(gomega.BeNil()) + newBluetoothDevice := utils.NewBluetoothDeviceInstance(constants.NodeName) deviceInstanceList, err := utils.ListDevice(edgeClientSet, "default") - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) err = utils.CheckDeviceExists(deviceInstanceList, &newBluetoothDevice) - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) time.Sleep(3 * time.Second) - configMap, err := clientSet.CoreV1().ConfigMaps("default").Get(context.TODO(), "device-profile-config-"+nodeName, metav1.GetOptions{}) - Expect(err).To(BeNil()) + configMap, err := clientSet.CoreV1().ConfigMaps("default").Get(context.TODO(), "device-profile-config-"+constants.NodeName, metav1.GetOptions{}) + gomega.Expect(err).To(gomega.BeNil()) - isEqual := utils.CompareConfigMaps(*configMap, utils.NewConfigMapBluetooth(nodeName)) - Expect(isEqual).Should(Equal(true)) - go utils.TwinSubscribe(utils.NewBluetoothDeviceInstance(nodeName).Name) - Eventually(func() bool { + isEqual := utils.CompareConfigMaps(*configMap, utils.NewConfigMapBluetooth(constants.NodeName)) + gomega.Expect(isEqual).Should(gomega.Equal(true)) + go utils.TwinSubscribe(utils.NewBluetoothDeviceInstance(constants.NodeName).Name) + gomega.Eventually(func() bool { return utils.TwinResult.Twin != nil - }, "20s", "2s").Should(Equal(true), "Device information not reaching edge!!") + }, "20s", "2s").Should(gomega.Equal(true), "Device information not reaching edge!!") ioData := "1" expectedTwin := map[string]*utils.MsgTwin{ "io-data": { @@ -270,32 +269,32 @@ var _ = Describe("Device Management test in E2E scenario", func() { }, } isEqual = utils.CompareTwin(utils.TwinResult.Twin, expectedTwin) - Expect(isEqual).Should(Equal(true)) + gomega.Expect(isEqual).Should(gomega.Equal(true)) }) - It("E2E_CREATE_DEVICE_3: Create device instance for modbus protocol", func() { + ginkgo.It("E2E_CREATE_DEVICE_3: Create device instance for modbus protocol", func() { err := utils.HandleDeviceModel(edgeClientSet, http.MethodPost, "", "modbus") - Expect(err).To(BeNil()) - err = utils.HandleDeviceInstance(edgeClientSet, http.MethodPost, nodeName, "", "modbus") - Expect(err).To(BeNil()) - newModbusDevice := utils.NewModbusDeviceInstance(nodeName) + gomega.Expect(err).To(gomega.BeNil()) + err = utils.HandleDeviceInstance(edgeClientSet, http.MethodPost, constants.NodeName, "", "modbus") + gomega.Expect(err).To(gomega.BeNil()) + newModbusDevice := utils.NewModbusDeviceInstance(constants.NodeName) deviceInstanceList, err := utils.ListDevice(edgeClientSet, "default") - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) err = utils.CheckDeviceExists(deviceInstanceList, &newModbusDevice) - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) time.Sleep(3 * time.Second) - configMap, err := clientSet.CoreV1().ConfigMaps("default").Get(context.TODO(), "device-profile-config-"+nodeName, metav1.GetOptions{}) - Expect(err).To(BeNil()) + configMap, err := clientSet.CoreV1().ConfigMaps("default").Get(context.TODO(), "device-profile-config-"+constants.NodeName, metav1.GetOptions{}) + gomega.Expect(err).To(gomega.BeNil()) - isEqual := utils.CompareConfigMaps(*configMap, utils.NewConfigMapModbus(nodeName)) - Expect(isEqual).Should(Equal(true)) - go utils.TwinSubscribe(utils.NewModbusDeviceInstance(nodeName).Name) - Eventually(func() bool { + isEqual := utils.CompareConfigMaps(*configMap, utils.NewConfigMapModbus(constants.NodeName)) + gomega.Expect(isEqual).Should(gomega.Equal(true)) + go utils.TwinSubscribe(utils.NewModbusDeviceInstance(constants.NodeName).Name) + gomega.Eventually(func() bool { return utils.TwinResult.Twin != nil - }, "20s", "2s").Should(Equal(true), "Device information not reaching edge!!") + }, "20s", "2s").Should(gomega.Equal(true), "Device information not reaching edge!!") stringValue := off expectedTwin := map[string]*utils.MsgTwin{ "temperature-enable": { @@ -308,32 +307,32 @@ var _ = Describe("Device Management test in E2E scenario", func() { }, } isEqual = utils.CompareTwin(utils.TwinResult.Twin, expectedTwin) - Expect(isEqual).Should(Equal(true)) + gomega.Expect(isEqual).Should(gomega.Equal(true)) }) - It("E2E_CREATE_DEVICE_4: Create device instance for customized protocol", func() { + ginkgo.It("E2E_CREATE_DEVICE_4: Create device instance for customized protocol", func() { err := utils.HandleDeviceModel(edgeClientSet, http.MethodPost, "", "customized") - Expect(err).To(BeNil()) - err = utils.HandleDeviceInstance(edgeClientSet, http.MethodPost, nodeName, "", "customized") - Expect(err).To(BeNil()) - newCustomizedDevice := utils.NewCustomizedDeviceInstance(nodeName) + gomega.Expect(err).To(gomega.BeNil()) + err = utils.HandleDeviceInstance(edgeClientSet, http.MethodPost, constants.NodeName, "", "customized") + gomega.Expect(err).To(gomega.BeNil()) + newCustomizedDevice := utils.NewCustomizedDeviceInstance(constants.NodeName) deviceInstanceList, err := utils.ListDevice(edgeClientSet, "default") - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) err = utils.CheckDeviceExists(deviceInstanceList, &newCustomizedDevice) - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) time.Sleep(3 * time.Second) - configMap, err := clientSet.CoreV1().ConfigMaps("default").Get(context.TODO(), "device-profile-config-"+nodeName, metav1.GetOptions{}) - Expect(err).To(BeNil()) + configMap, err := clientSet.CoreV1().ConfigMaps("default").Get(context.TODO(), "device-profile-config-"+constants.NodeName, metav1.GetOptions{}) + gomega.Expect(err).To(gomega.BeNil()) - isEqual := utils.CompareConfigMaps(*configMap, utils.NewConfigMapCustomized(nodeName)) - Expect(isEqual).Should(Equal(true)) - go utils.TwinSubscribe(utils.NewCustomizedDeviceInstance(nodeName).Name) - Eventually(func() bool { + isEqual := utils.CompareConfigMaps(*configMap, utils.NewConfigMapCustomized(constants.NodeName)) + gomega.Expect(isEqual).Should(gomega.Equal(true)) + go utils.TwinSubscribe(utils.NewCustomizedDeviceInstance(constants.NodeName).Name) + gomega.Eventually(func() bool { return utils.TwinResult.Twin != nil - }, "20s", "2s").Should(Equal(true), "Device information not reaching edge!!") + }, "20s", "2s").Should(gomega.Equal(true), "Device information not reaching edge!!") stringValue := "OFF" expectedTwin := map[string]*utils.MsgTwin{ "temperature-enable": { @@ -346,17 +345,17 @@ var _ = Describe("Device Management test in E2E scenario", func() { }, } isEqual = utils.CompareTwin(utils.TwinResult.Twin, expectedTwin) - Expect(isEqual).Should(Equal(true)) + gomega.Expect(isEqual).Should(gomega.Equal(true)) }) - It("E2E_UPDATE_DEVICE_1: Update device instance for LED device (No Protocol)", func() { + ginkgo.It("E2E_UPDATE_DEVICE_1: Update device instance for LED device (No Protocol)", func() { err := utils.HandleDeviceModel(edgeClientSet, http.MethodPost, "", "led") - Expect(err).To(BeNil()) - err = utils.HandleDeviceInstance(edgeClientSet, http.MethodPost, nodeName, "", "led") - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) + err = utils.HandleDeviceInstance(edgeClientSet, http.MethodPost, constants.NodeName, "", "led") + gomega.Expect(err).To(gomega.BeNil()) - newLedDevice := utils.NewLedDeviceInstance(nodeName) + newLedDevice := utils.NewLedDeviceInstance(constants.NodeName) time.Sleep(2 * time.Second) - Eventually(func() bool { + gomega.Eventually(func() bool { deviceInstanceList, err := utils.ListDevice(edgeClientSet, "default") if err != nil { return false @@ -364,23 +363,23 @@ var _ = Describe("Device Management test in E2E scenario", func() { err = utils.CheckDeviceExists(deviceInstanceList, &newLedDevice) return err == nil - }, "20s", "2s").Should(Equal(true), "Device creation is not finished!!") + }, "20s", "2s").Should(gomega.Equal(true), "Device creation is not finished!!") - err = utils.HandleDeviceInstance(edgeClientSet, http.MethodPatch, nodeName, utils.UpdatedLedDeviceInstance(nodeName).Name, "led") - Expect(err).To(BeNil()) - updatedLedDevice := utils.UpdatedLedDeviceInstance(nodeName) + err = utils.HandleDeviceInstance(edgeClientSet, http.MethodPatch, constants.NodeName, utils.UpdatedLedDeviceInstance(constants.NodeName).Name, "led") + gomega.Expect(err).To(gomega.BeNil()) + updatedLedDevice := utils.UpdatedLedDeviceInstance(constants.NodeName) time.Sleep(2 * time.Second) deviceInstanceList, err := utils.ListDevice(edgeClientSet, "default") - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) err = utils.CheckDeviceExists(deviceInstanceList, &updatedLedDevice) - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) - go utils.TwinSubscribe(utils.UpdatedLedDeviceInstance(nodeName).Name) - Eventually(func() bool { + go utils.TwinSubscribe(utils.UpdatedLedDeviceInstance(constants.NodeName).Name) + gomega.Eventually(func() bool { return utils.TwinResult.Twin != nil - }, "20s", "2s").Should(Equal(true), "Device information not reaching edge!!") + }, "20s", "2s").Should(gomega.Equal(true), "Device information not reaching edge!!") stringValue := off expectedTwin := map[string]*utils.MsgTwin{ "power-status": { @@ -393,17 +392,17 @@ var _ = Describe("Device Management test in E2E scenario", func() { }, } isEqual := utils.CompareTwin(utils.TwinResult.Twin, expectedTwin) - Expect(isEqual).Should(Equal(true)) + gomega.Expect(isEqual).Should(gomega.Equal(true)) }) - It("E2E_UPDATE_DEVICE_2: Update device instance for bluetooth protocol", func() { + ginkgo.It("E2E_UPDATE_DEVICE_2: Update device instance for bluetooth protocol", func() { err := utils.HandleDeviceModel(edgeClientSet, http.MethodPost, "", "bluetooth") - Expect(err).To(BeNil()) - err = utils.HandleDeviceInstance(edgeClientSet, http.MethodPost, nodeName, "", "bluetooth") - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) + err = utils.HandleDeviceInstance(edgeClientSet, http.MethodPost, constants.NodeName, "", "bluetooth") + gomega.Expect(err).To(gomega.BeNil()) - newBluetoothDevice := utils.NewBluetoothDeviceInstance(nodeName) + newBluetoothDevice := utils.NewBluetoothDeviceInstance(constants.NodeName) time.Sleep(2 * time.Second) - Eventually(func() bool { + gomega.Eventually(func() bool { deviceInstanceList, err := utils.ListDevice(edgeClientSet, "default") if err != nil { return false @@ -411,23 +410,23 @@ var _ = Describe("Device Management test in E2E scenario", func() { err = utils.CheckDeviceExists(deviceInstanceList, &newBluetoothDevice) return err == nil - }, "20s", "2s").Should(Equal(true), "Device creation is not finished!!") + }, "20s", "2s").Should(gomega.Equal(true), "Device creation is not finished!!") - err = utils.HandleDeviceInstance(edgeClientSet, http.MethodPatch, nodeName, utils.UpdatedBluetoothDeviceInstance(nodeName).Name, "bluetooth") - Expect(err).To(BeNil()) - updatedBluetoothDevice := utils.UpdatedBluetoothDeviceInstance(nodeName) + err = utils.HandleDeviceInstance(edgeClientSet, http.MethodPatch, constants.NodeName, utils.UpdatedBluetoothDeviceInstance(constants.NodeName).Name, "bluetooth") + gomega.Expect(err).To(gomega.BeNil()) + updatedBluetoothDevice := utils.UpdatedBluetoothDeviceInstance(constants.NodeName) time.Sleep(2 * time.Second) deviceInstanceList, err := utils.ListDevice(edgeClientSet, "default") - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) err = utils.CheckDeviceExists(deviceInstanceList, &updatedBluetoothDevice) - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) - go utils.TwinSubscribe(utils.UpdatedBluetoothDeviceInstance(nodeName).Name) - Eventually(func() bool { + go utils.TwinSubscribe(utils.UpdatedBluetoothDeviceInstance(constants.NodeName).Name) + gomega.Eventually(func() bool { return utils.TwinResult.Twin != nil - }, "20s", "2s").Should(Equal(true), "Device information not reaching edge!!") + }, "20s", "2s").Should(gomega.Equal(true), "Device information not reaching edge!!") ioData := "1" expectedTwin := map[string]*utils.MsgTwin{ "io-data": { @@ -440,17 +439,17 @@ var _ = Describe("Device Management test in E2E scenario", func() { }, } isEqual := utils.CompareTwin(utils.TwinResult.Twin, expectedTwin) - Expect(isEqual).Should(Equal(true)) + gomega.Expect(isEqual).Should(gomega.Equal(true)) }) - It("E2E_UPDATE_DEVICE_3: Update device instance for modbus protocol", func() { + ginkgo.It("E2E_UPDATE_DEVICE_3: Update device instance for modbus protocol", func() { err := utils.HandleDeviceModel(edgeClientSet, http.MethodPost, "", "modbus") - Expect(err).To(BeNil()) - err = utils.HandleDeviceInstance(edgeClientSet, http.MethodPost, nodeName, "", "modbus") - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) + err = utils.HandleDeviceInstance(edgeClientSet, http.MethodPost, constants.NodeName, "", "modbus") + gomega.Expect(err).To(gomega.BeNil()) - newModbusDevice := utils.NewModbusDeviceInstance(nodeName) + newModbusDevice := utils.NewModbusDeviceInstance(constants.NodeName) time.Sleep(2 * time.Second) - Eventually(func() bool { + gomega.Eventually(func() bool { deviceInstanceList, err := utils.ListDevice(edgeClientSet, "default") if err != nil { return false @@ -458,23 +457,23 @@ var _ = Describe("Device Management test in E2E scenario", func() { err = utils.CheckDeviceExists(deviceInstanceList, &newModbusDevice) return err == nil - }, "20s", "2s").Should(Equal(true), "Device creation is not finished!!") + }, "20s", "2s").Should(gomega.Equal(true), "Device creation is not finished!!") - err = utils.HandleDeviceInstance(edgeClientSet, http.MethodPatch, nodeName, utils.UpdatedModbusDeviceInstance(nodeName).Name, "modbus") - Expect(err).To(BeNil()) - updatedModbusDevice := utils.UpdatedModbusDeviceInstance(nodeName) + err = utils.HandleDeviceInstance(edgeClientSet, http.MethodPatch, constants.NodeName, utils.UpdatedModbusDeviceInstance(constants.NodeName).Name, "modbus") + gomega.Expect(err).To(gomega.BeNil()) + updatedModbusDevice := utils.UpdatedModbusDeviceInstance(constants.NodeName) time.Sleep(2 * time.Second) deviceInstanceList, err := utils.ListDevice(edgeClientSet, "default") - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) err = utils.CheckDeviceExists(deviceInstanceList, &updatedModbusDevice) - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) - go utils.TwinSubscribe(utils.UpdatedModbusDeviceInstance(nodeName).Name) - Eventually(func() bool { + go utils.TwinSubscribe(utils.UpdatedModbusDeviceInstance(constants.NodeName).Name) + gomega.Eventually(func() bool { return utils.TwinResult.Twin != nil - }, "20s", "2s").Should(Equal(true), "Device information not reaching edge!!") + }, "20s", "2s").Should(gomega.Equal(true), "Device information not reaching edge!!") stringValue := "ON" expectedTwin := map[string]*utils.MsgTwin{ "temperature-enable": { @@ -487,164 +486,164 @@ var _ = Describe("Device Management test in E2E scenario", func() { }, } isEqual := utils.CompareTwin(utils.TwinResult.Twin, expectedTwin) - Expect(isEqual).Should(Equal(true)) + gomega.Expect(isEqual).Should(gomega.Equal(true)) }) - It("E2E_UPDATE_DEVICE_4: Update device instance for incorrect device instance", func() { + ginkgo.It("E2E_UPDATE_DEVICE_4: Update device instance for incorrect device instance", func() { err := utils.HandleDeviceModel(edgeClientSet, http.MethodPost, "", "led") - Expect(err).To(BeNil()) - err = utils.HandleDeviceInstance(edgeClientSet, http.MethodPost, nodeName, "", "led") - Expect(err).To(BeNil()) - err = utils.HandleDeviceInstance(edgeClientSet, http.MethodPatch, nodeName, utils.UpdatedLedDeviceInstance(nodeName).Name, "incorrect-instance") - Expect(err).NotTo(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) + err = utils.HandleDeviceInstance(edgeClientSet, http.MethodPost, constants.NodeName, "", "led") + gomega.Expect(err).To(gomega.BeNil()) + err = utils.HandleDeviceInstance(edgeClientSet, http.MethodPatch, constants.NodeName, utils.UpdatedLedDeviceInstance(constants.NodeName).Name, "incorrect-instance") + gomega.Expect(err).NotTo(gomega.BeNil()) }) - It("E2E_UPDATE_DEVICE_4: Update device instance data and twin for modbus protocol", func() { + ginkgo.It("E2E_UPDATE_DEVICE_4: Update device instance data and twin for modbus protocol", func() { err := utils.HandleDeviceModel(edgeClientSet, http.MethodPost, "", "modbus") - Expect(err).To(BeNil()) - err = utils.HandleDeviceInstance(edgeClientSet, http.MethodPost, nodeName, "", "modbus") - Expect(err).To(BeNil()) - newModbusDevice := utils.NewModbusDeviceInstance(nodeName) + gomega.Expect(err).To(gomega.BeNil()) + err = utils.HandleDeviceInstance(edgeClientSet, http.MethodPost, constants.NodeName, "", "modbus") + gomega.Expect(err).To(gomega.BeNil()) + newModbusDevice := utils.NewModbusDeviceInstance(constants.NodeName) deviceInstanceList, err := utils.ListDevice(edgeClientSet, "default") - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) err = utils.CheckDeviceExists(deviceInstanceList, &newModbusDevice) - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) time.Sleep(3 * time.Second) - configMap, err := clientSet.CoreV1().ConfigMaps("default").Get(context.TODO(), "device-profile-config-"+nodeName, metav1.GetOptions{}) - Expect(err).To(BeNil()) + configMap, err := clientSet.CoreV1().ConfigMaps("default").Get(context.TODO(), "device-profile-config-"+constants.NodeName, metav1.GetOptions{}) + gomega.Expect(err).To(gomega.BeNil()) - isEqual := utils.CompareConfigMaps(*configMap, utils.NewConfigMapModbus(nodeName)) - Expect(isEqual).Should(Equal(true)) + isEqual := utils.CompareConfigMaps(*configMap, utils.NewConfigMapModbus(constants.NodeName)) + gomega.Expect(isEqual).Should(gomega.Equal(true)) // update twins and data section should reflect on change on config map - err = utils.HandleDeviceInstance(edgeClientSet, http.MethodPatch, nodeName, utils.UpdatedModbusDeviceInstance(nodeName).Name, "modbus") - Expect(err).To(BeNil()) - updatedModbusDevice := utils.UpdatedModbusDeviceInstance(nodeName) + err = utils.HandleDeviceInstance(edgeClientSet, http.MethodPatch, constants.NodeName, utils.UpdatedModbusDeviceInstance(constants.NodeName).Name, "modbus") + gomega.Expect(err).To(gomega.BeNil()) + updatedModbusDevice := utils.UpdatedModbusDeviceInstance(constants.NodeName) time.Sleep(3 * time.Second) deviceInstanceList, err = utils.ListDevice(edgeClientSet, "default") - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) err = utils.CheckDeviceExists(deviceInstanceList, &updatedModbusDevice) - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) - updatedConfigMap, err := clientSet.CoreV1().ConfigMaps("default").Get(context.TODO(), "device-profile-config-"+nodeName, metav1.GetOptions{}) - Expect(err).To(BeNil()) + updatedConfigMap, err := clientSet.CoreV1().ConfigMaps("default").Get(context.TODO(), "device-profile-config-"+constants.NodeName, metav1.GetOptions{}) + gomega.Expect(err).To(gomega.BeNil()) updatedConfigMap.TypeMeta = metav1.TypeMeta{ Kind: "ConfigMap", APIVersion: "v1", } - isEqual = utils.CompareDeviceProfileInConfigMaps(*updatedConfigMap, utils.UpdatedConfigMapModbusForDataAndTwins(nodeName)) - Expect(isEqual).Should(Equal(true)) + isEqual = utils.CompareDeviceProfileInConfigMaps(*updatedConfigMap, utils.UpdatedConfigMapModbusForDataAndTwins(constants.NodeName)) + gomega.Expect(isEqual).Should(gomega.Equal(true)) }) - It("E2E_DELETE_DEVICE_1: Delete device instance for an existing device (No Protocol)", func() { + ginkgo.It("E2E_DELETE_DEVICE_1: Delete device instance for an existing device (No Protocol)", func() { err := utils.HandleDeviceModel(edgeClientSet, http.MethodPost, "", "led") - Expect(err).To(BeNil()) - err = utils.HandleDeviceInstance(edgeClientSet, http.MethodPost, nodeName, "", "led") - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) + err = utils.HandleDeviceInstance(edgeClientSet, http.MethodPost, constants.NodeName, "", "led") + gomega.Expect(err).To(gomega.BeNil()) time.Sleep(1 * time.Second) - _, err = clientSet.CoreV1().ConfigMaps("default").Get(context.TODO(), "device-profile-config-"+nodeName, metav1.GetOptions{}) - Expect(err).To(BeNil()) + _, err = clientSet.CoreV1().ConfigMaps("default").Get(context.TODO(), "device-profile-config-"+constants.NodeName, metav1.GetOptions{}) + gomega.Expect(err).To(gomega.BeNil()) - err = utils.HandleDeviceInstance(edgeClientSet, http.MethodDelete, nodeName, utils.NewLedDeviceInstance(nodeName).Name, "") - Expect(err).To(BeNil()) + err = utils.HandleDeviceInstance(edgeClientSet, http.MethodDelete, constants.NodeName, utils.NewLedDeviceInstance(constants.NodeName).Name, "") + gomega.Expect(err).To(gomega.BeNil()) time.Sleep(1 * time.Second) - _, err = clientSet.CoreV1().ConfigMaps("default").Get(context.TODO(), "device-profile-config-"+nodeName, metav1.GetOptions{}) - Expect(apierrors.IsNotFound(err)).To(BeTrue()) + _, err = clientSet.CoreV1().ConfigMaps("default").Get(context.TODO(), "device-profile-config-"+constants.NodeName, metav1.GetOptions{}) + gomega.Expect(apierrors.IsNotFound(err)).To(gomega.BeTrue()) }) - It("E2E_DELETE_DEVICE_2: Delete device instance for a non-existing device", func() { - err := utils.HandleDeviceInstance(edgeClientSet, http.MethodDelete, nodeName, utils.NewLedDeviceModel().Name, "") - Expect(err).To(BeNil()) + ginkgo.It("E2E_DELETE_DEVICE_2: Delete device instance for a non-existing device", func() { + err := utils.HandleDeviceInstance(edgeClientSet, http.MethodDelete, constants.NodeName, utils.NewLedDeviceModel().Name, "") + gomega.Expect(err).To(gomega.BeNil()) }) - It("E2E_DELETE_DEVICE_3: Delete device instance without device model", func() { - err := utils.HandleDeviceInstance(edgeClientSet, http.MethodPost, nodeName, "", "led") - Expect(err).To(BeNil()) + ginkgo.It("E2E_DELETE_DEVICE_3: Delete device instance without device model", func() { + err := utils.HandleDeviceInstance(edgeClientSet, http.MethodPost, constants.NodeName, "", "led") + gomega.Expect(err).To(gomega.BeNil()) time.Sleep(1 * time.Second) - _, err = clientSet.CoreV1().ConfigMaps("default").Get(context.TODO(), "device-profile-config-"+nodeName, metav1.GetOptions{}) - Expect(err).To(BeNil()) + _, err = clientSet.CoreV1().ConfigMaps("default").Get(context.TODO(), "device-profile-config-"+constants.NodeName, metav1.GetOptions{}) + gomega.Expect(err).To(gomega.BeNil()) - err = utils.HandleDeviceInstance(edgeClientSet, http.MethodDelete, nodeName, utils.NewLedDeviceInstance(nodeName).Name, "") - Expect(err).To(BeNil()) + err = utils.HandleDeviceInstance(edgeClientSet, http.MethodDelete, constants.NodeName, utils.NewLedDeviceInstance(constants.NodeName).Name, "") + gomega.Expect(err).To(gomega.BeNil()) time.Sleep(1 * time.Second) - _, err = clientSet.CoreV1().ConfigMaps("default").Get(context.TODO(), "device-profile-config-"+nodeName, metav1.GetOptions{}) - Expect(apierrors.IsNotFound(err)).To(BeTrue()) + _, err = clientSet.CoreV1().ConfigMaps("default").Get(context.TODO(), "device-profile-config-"+constants.NodeName, metav1.GetOptions{}) + gomega.Expect(apierrors.IsNotFound(err)).To(gomega.BeTrue()) }) }) - Context("Test Change in device twin", func() { - BeforeEach(func() { + ginkgo.Context("Test Change in device twin", func() { + ginkgo.BeforeEach(func() { // Delete the device instances created deviceInstanceList, err := utils.ListDevice(edgeClientSet, "default") - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) for _, device := range deviceInstanceList { - err := utils.HandleDeviceInstance(edgeClientSet, http.MethodDelete, nodeName, device.Name, "") - Expect(err).To(BeNil()) + err := utils.HandleDeviceInstance(edgeClientSet, http.MethodDelete, constants.NodeName, device.Name, "") + gomega.Expect(err).To(gomega.BeNil()) } // Delete any pre-existing device models list, err := utils.ListDeviceModel(edgeClientSet, "default") - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) for _, model := range list { err := utils.HandleDeviceModel(edgeClientSet, http.MethodDelete, model.Name, "") - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) } utils.TwinResult = utils.DeviceTwinResult{} // Get current test SpecReport - testSpecReport = CurrentGinkgoTestDescription() + testSpecReport = ginkgo.CurrentGinkgoTestDescription() // Start test timer - testTimer = CRDTestTimerGroup.NewTestTimer(testSpecReport.TestText) + testTimer = utils.CRDTestTimerGroup.NewTestTimer(testSpecReport.TestText) }) - AfterEach(func() { + ginkgo.AfterEach(func() { // End test timer testTimer.End() // Print result testTimer.PrintResult() // Delete the device instances created deviceInstanceList, err := utils.ListDevice(edgeClientSet, "default") - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) for _, device := range deviceInstanceList { - err := utils.HandleDeviceInstance(edgeClientSet, http.MethodDelete, nodeName, device.Name, "") - Expect(err).To(BeNil()) + err := utils.HandleDeviceInstance(edgeClientSet, http.MethodDelete, constants.NodeName, device.Name, "") + gomega.Expect(err).To(gomega.BeNil()) } // Delete the device models created list, err := utils.ListDeviceModel(edgeClientSet, "default") - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) for _, model := range list { err := utils.HandleDeviceModel(edgeClientSet, http.MethodDelete, model.Name, "") - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) } utils.PrintTestcaseNameandStatus() }) - It("E2E_TWIN_STATE_1: Change the twin state of an existing device", func() { + ginkgo.It("E2E_TWIN_STATE_1: Change the twin state of an existing device", func() { err := utils.HandleDeviceModel(edgeClientSet, http.MethodPost, "", "led") - Expect(err).To(BeNil()) - err = utils.HandleDeviceInstance(edgeClientSet, http.MethodPost, nodeName, "", "led") - Expect(err).To(BeNil()) - newLedDevice := utils.NewLedDeviceInstance(nodeName) + gomega.Expect(err).To(gomega.BeNil()) + err = utils.HandleDeviceInstance(edgeClientSet, http.MethodPost, constants.NodeName, "", "led") + gomega.Expect(err).To(gomega.BeNil()) + newLedDevice := utils.NewLedDeviceInstance(constants.NodeName) time.Sleep(3 * time.Second) var deviceTwinUpdateMessage utils.DeviceTwinUpdate reportedValue := off deviceTwinUpdateMessage.Twin = map[string]*utils.MsgTwin{ "power-status": {Actual: &utils.TwinValue{Value: &reportedValue}, Metadata: &utils.TypeMetadata{Type: "string"}}, } - err = utils.ChangeTwinValue(deviceTwinUpdateMessage, utils.NewLedDeviceInstance(nodeName).Name) - Expect(err).To(BeNil()) + err = utils.ChangeTwinValue(deviceTwinUpdateMessage, utils.NewLedDeviceInstance(constants.NodeName).Name) + gomega.Expect(err).To(gomega.BeNil()) time.Sleep(3 * time.Second) - newLedDevice = utils.NewLedDeviceInstance(nodeName) + newLedDevice = utils.NewLedDeviceInstance(constants.NodeName) deviceInstanceList, err := utils.ListDevice(edgeClientSet, "default") - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) err = utils.CheckDeviceExists(deviceInstanceList, &newLedDevice) - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) - Expect(deviceInstanceList[0].Status.Twins[0].PropertyName).To(Equal("power-status")) - Expect(deviceInstanceList[0].Status.Twins[0].Reported.Value).To(Equal(off)) + gomega.Expect(deviceInstanceList[0].Status.Twins[0].PropertyName).To(gomega.Equal("power-status")) + gomega.Expect(deviceInstanceList[0].Status.Twins[0].Reported.Value).To(gomega.Equal(off)) }) }) }) diff --git a/tests/e2e/device/framework.go b/tests/e2e/device/framework.go new file mode 100644 index 000000000..83e7a7192 --- /dev/null +++ b/tests/e2e/device/framework.go @@ -0,0 +1,24 @@ +/* +Copyright 2022 The KubeEdge Authors. + +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 device + +import "github.com/onsi/ginkgo" + +// GroupDescribe annotates the test with the group label. +func GroupDescribe(text string, body func()) bool { + return ginkgo.Describe("[KubeEdge-IOT] "+text, body) +} diff --git a/tests/e2e/deployment/e2e_test.go b/tests/e2e/e2e_test.go index 9be6b9916..74f5e2061 100644 --- a/tests/e2e/deployment/e2e_test.go +++ b/tests/e2e/e2e_test.go @@ -14,26 +14,23 @@ See the License for the specific language governing permissions and limitations under the License. */ -package deployment +package e2e import ( "flag" "os" "testing" - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" + "github.com/onsi/ginkgo" + "github.com/onsi/gomega" "github.com/spf13/pflag" + _ "github.com/kubeedge/kubeedge/tests/e2e/apps" + _ "github.com/kubeedge/kubeedge/tests/e2e/device" + _ "github.com/kubeedge/kubeedge/tests/e2e/rule" "github.com/kubeedge/kubeedge/tests/e2e/utils" ) -var ( - nodeName string - // context to load config and access across the package - ctx *utils.TestContext -) - func TestMain(m *testing.M) { utils.CopyFlags(utils.Flags, flag.CommandLine) utils.RegisterFlags(flag.CommandLine) @@ -44,18 +41,16 @@ func TestMain(m *testing.M) { // Function to run the Ginkgo Test func TestE2E(t *testing.T) { - RegisterFailHandler(Fail) - var _ = BeforeSuite(func() { + gomega.RegisterFailHandler(ginkgo.Fail) + var _ = ginkgo.BeforeSuite(func() { utils.Infof("Before Suite Execution") - ctx = utils.NewTestContext(utils.LoadConfig()) - nodeName = "edge-node" err := utils.MqttConnect() - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) }) - AfterSuite(func() { - By("After Suite Execution....!") + ginkgo.AfterSuite(func() { + ginkgo.By("After Suite Execution....!") }) - RunSpecs(t, "kubeedge App Deploymet Suite") + ginkgo.RunSpecs(t, "kubeedge e2e Suite") } diff --git a/tests/e2e/edgesite/edgesite_test.go b/tests/e2e/edgesite/edgesite_test.go deleted file mode 100644 index fe035c61c..000000000 --- a/tests/e2e/edgesite/edgesite_test.go +++ /dev/null @@ -1,198 +0,0 @@ -/* -Copyright 2019 The KubeEdge Authors. - -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 edgesite - -import ( - "fmt" - "time" - - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - metav1 "k8s.io/api/core/v1" - apierrors "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/labels" - clientset "k8s.io/client-go/kubernetes" - - "github.com/kubeedge/kubeedge/tests/e2e/constants" - . "github.com/kubeedge/kubeedge/tests/e2e/testsuite" - "github.com/kubeedge/kubeedge/tests/e2e/utils" -) - -var DeploymentTestTimerGroup = utils.NewTestTimerGroup() - -//Run Test cases -var _ = Describe("Application deployment test in E2E scenario using EdgeSite", func() { - var UID string - var testTimer *utils.TestTimer - var testSpecReport GinkgoTestDescription - - var clientSet clientset.Interface - - BeforeEach(func() { - clientSet = utils.NewKubeClient(ctx.Cfg.KubeConfigPath) - }) - - Context("Test application deployment and delete deployment using deployment spec", func() { - BeforeEach(func() { - // Get current test SpecReport - testSpecReport = CurrentGinkgoTestDescription() - // Start test timer - testTimer = DeploymentTestTimerGroup.NewTestTimer(testSpecReport.TestText) - }) - - AfterEach(func() { - // End test timer - testTimer.End() - // Print result - testTimer.PrintResult() - - By(fmt.Sprintf("get deployment %s", UID)) - deployment, err := utils.GetDeployment(clientSet, metav1.NamespaceDefault, UID) - Expect(err).To(BeNil()) - - By(fmt.Sprintf("list pod for deploy %s", UID)) - labelSelector := labels.SelectorFromSet(map[string]string{"app": UID}) - _, err = utils.GetPods(clientSet, metav1.NamespaceDefault, labelSelector, nil) - Expect(err).To(BeNil()) - - By(fmt.Sprintf("delete deploy %s", UID)) - err = utils.DeleteDeployment(clientSet, deployment.Namespace, deployment.Name) - Expect(err).To(BeNil()) - - By(fmt.Sprintf("wait for pod of deploy %s to disappear", UID)) - err = utils.WaitForPodsToDisappear(clientSet, metav1.NamespaceDefault, labelSelector, constants.Interval, constants.Timeout) - Expect(err).To(BeNil()) - - utils.PrintTestcaseNameandStatus() - }) - - It("E2E_ES_APP_DEPLOYMENT_1: Create deployment and check the pods are coming up correctly", func() { - replica := int32(1) - //Generate the random string and assign as a UID - UID = "edgecore-depl-app-" + utils.GetRandomString(5) - CreateDeploymentTest(clientSet, replica, UID, ctx) - }) - - It("E2E_ES_APP_DEPLOYMENT_2: Create deployment with replicas and check the pods are coming up correctly", func() { - replica := int32(3) - //Generate the random string and assign as a UID - UID = "edgecore-depl-app-" + utils.GetRandomString(5) - CreateDeploymentTest(clientSet, replica, UID, ctx) - }) - - It("E2E_ES_APP_DEPLOYMENT_3: Create deployment and check deployment ctrler re-creating pods when user deletes the pods manually", func() { - replica := int32(3) - //Generate the random string and assign as a UID - UID = "edgecore-depl-app-" + utils.GetRandomString(5) - podList := CreateDeploymentTest(clientSet, replica, UID, ctx) - for _, pod := range podList.Items { - err := utils.DeletePod(clientSet, pod.Namespace, pod.Name) - Expect(err).To(BeNil()) - } - utils.CheckPodDeleteState(clientSet, podList) - - labelSelector := labels.SelectorFromSet(map[string]string{"app": UID}) - podList, err := utils.GetPods(clientSet, metav1.NamespaceDefault, labelSelector, nil) - Expect(err).To(BeNil()) - Expect(len(podList.Items)).Should(Equal(replica)) - - utils.WaitForPodsRunning(clientSet, podList, 240*time.Second) - }) - - }) - Context("Test application deployment using Pod spec using EdgeSite", func() { - BeforeEach(func() { - // Get current test SpecReport - testSpecReport = CurrentGinkgoTestDescription() - // Start test timer - testTimer = DeploymentTestTimerGroup.NewTestTimer(testSpecReport.TestText) - }) - - AfterEach(func() { - // End test timer - testTimer.End() - // Print result - testTimer.PrintResult() - - labelSelector := labels.SelectorFromSet(constants.KubeEdgeE2ELabel) - podList, err := utils.GetPods(clientSet, metav1.NamespaceDefault, labelSelector, nil) - Expect(err).To(BeNil()) - - for _, pod := range podList.Items { - err = utils.DeletePod(clientSet, pod.Namespace, pod.Name) - Expect(err).To(BeNil()) - } - - utils.CheckPodDeleteState(clientSet, podList) - - utils.PrintTestcaseNameandStatus() - }) - - It("E2E_ES_POD_DEPLOYMENT_1: Create a pod and check the pod is coming up correctly", func() { - //Generate the random string and assign as podName - podName := "pod-app-" + utils.GetRandomString(5) - pod := utils.NewPod(podName, ctx.Cfg.AppImageURL[0]) - - CreatePodTest(clientSet, pod) - }) - - It("E2E_ES_POD_DEPLOYMENT_2: Create the pod and delete pod happening successfully", func() { - //Generate the random string and assign as podName - podName := "pod-app-" + utils.GetRandomString(5) - pod := utils.NewPod(podName, ctx.Cfg.AppImageURL[0]) - - podList := CreatePodTest(clientSet, pod) - for _, pod := range podList.Items { - err := utils.DeletePod(clientSet, pod.Namespace, pod.Name) - Expect(err).To(BeNil()) - } - utils.CheckPodDeleteState(clientSet, podList) - }) - - It("E2E_ES_POD_DEPLOYMENT_3: Create pod and delete the pod successfully, and delete already deleted pod and check the behaviour", func() { - //Generate the random string and assign as podName - podName := "pod-app-" + utils.GetRandomString(5) - pod := utils.NewPod(podName, ctx.Cfg.AppImageURL[0]) - - podList := CreatePodTest(clientSet, pod) - for _, pod := range podList.Items { - err := utils.DeletePod(clientSet, pod.Namespace, pod.Name) - Expect(err).To(BeNil()) - } - utils.CheckPodDeleteState(clientSet, podList) - - err := utils.DeletePod(clientSet, pod.Namespace, pod.Name) - Expect(apierrors.IsNotFound(err)).To(BeTrue()) - }) - - It("E2E_ES_POD_DEPLOYMENT_4: Create and delete pod multiple times and check all the Pod created and deleted successfully", func() { - //Generate the random string and assign as a UID - for i := 0; i < 10; i++ { - //Generate the random string and assign as podName - podName := "pod-app-" + utils.GetRandomString(5) - pod := utils.NewPod(podName, ctx.Cfg.AppImageURL[0]) - - podList := CreatePodTest(clientSet, pod) - for _, pod := range podList.Items { - err := utils.DeletePod(clientSet, pod.Namespace, pod.Name) - Expect(err).To(BeNil()) - } - utils.CheckPodDeleteState(clientSet, podList) - } - }) - }) -}) diff --git a/tests/e2e/keadm/keadm_suite_test.go b/tests/e2e/keadm/keadm_suite_test.go deleted file mode 100644 index a8bd3df26..000000000 --- a/tests/e2e/keadm/keadm_suite_test.go +++ /dev/null @@ -1,56 +0,0 @@ -/* -Copyright 2019 The KubeEdge Authors. - -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 keadm - -import ( - "flag" - "os" - "testing" - - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - "github.com/spf13/pflag" - - "github.com/kubeedge/kubeedge/tests/e2e/utils" -) - -var ( - //context to load config and access across the package - ctx *utils.TestContext -) - -func TestMain(m *testing.M) { - utils.CopyFlags(utils.Flags, flag.CommandLine) - utils.RegisterFlags(flag.CommandLine) - pflag.CommandLine.AddGoFlagSet(flag.CommandLine) - pflag.Parse() - os.Exit(m.Run()) -} - -// Function to run the Ginkgo Test -func TestKeadmAppDeployment(t *testing.T) { - RegisterFailHandler(Fail) - var _ = BeforeSuite(func() { - utils.Infof("Before Suite Execution") - ctx = utils.NewTestContext(utils.LoadConfig()) - }) - AfterSuite(func() { - By("After Suite Execution....!") - }) - - RunSpecs(t, "kubeedge App Deploymet Suite") -} diff --git a/tests/e2e/keadm/keadm_test.go b/tests/e2e/keadm/keadm_test.go deleted file mode 100644 index d83056153..000000000 --- a/tests/e2e/keadm/keadm_test.go +++ /dev/null @@ -1,79 +0,0 @@ -/* -Copyright 2019 The KubeEdge Authors. - -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 keadm - -import ( - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - clientset "k8s.io/client-go/kubernetes" - - "github.com/kubeedge/kubeedge/tests/e2e/constants" - . "github.com/kubeedge/kubeedge/tests/e2e/testsuite" - "github.com/kubeedge/kubeedge/tests/e2e/utils" -) - -var DeploymentTestTimerGroup = utils.NewTestTimerGroup() - -//Run Test cases -var _ = Describe("Application deployment test in keadm E2E scenario", func() { - var testTimer *utils.TestTimer - var testSpecReport GinkgoTestDescription - - var clientSet clientset.Interface - - BeforeEach(func() { - clientSet = utils.NewKubeClient(ctx.Cfg.KubeConfigPath) - }) - - Context("Test application deployment using Pod spec", func() { - BeforeEach(func() { - // Get current test SpecReport - testSpecReport = CurrentGinkgoTestDescription() - // Start test timer - testTimer = DeploymentTestTimerGroup.NewTestTimer(testSpecReport.TestText) - }) - AfterEach(func() { - // End test timer - testTimer.End() - // Print result - testTimer.PrintResult() - - labelSelector := labels.SelectorFromSet(constants.KubeEdgeE2ELabel) - podList, err := utils.GetPods(clientSet, metav1.NamespaceDefault, labelSelector, nil) - Expect(err).To(BeNil()) - - for _, pod := range podList.Items { - err = utils.DeletePod(clientSet, pod.Namespace, pod.Name) - Expect(err).To(BeNil()) - } - - utils.CheckPodDeleteState(clientSet, podList) - - utils.PrintTestcaseNameandStatus() - }) - - It("E2E_POD_DEPLOYMENT: Create a pod and check the pod is coming up correctly", func() { - //Generate the random string and assign as podName - podName := "pod-app-" + utils.GetRandomString(5) - pod := utils.NewPod(podName, ctx.Cfg.AppImageURL[0]) - - CreatePodTest(clientSet, pod) - }) - }) -}) diff --git a/tests/e2e/rule/framework.go b/tests/e2e/rule/framework.go new file mode 100644 index 000000000..69077d69a --- /dev/null +++ b/tests/e2e/rule/framework.go @@ -0,0 +1,24 @@ +/* +Copyright 2022 The KubeEdge Authors. + +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 rule + +import "github.com/onsi/ginkgo" + +// GroupDescribe annotates the test with the group label. +func GroupDescribe(text string, body func()) bool { + return ginkgo.Describe("[KubeEdge-RULE] "+text, body) +} diff --git a/tests/e2e/deployment/rule_crd_test.go b/tests/e2e/rule/rule.go index 62e9281a4..1883f178c 100644 --- a/tests/e2e/deployment/rule_crd_test.go +++ b/tests/e2e/rule/rule.go @@ -1,87 +1,87 @@ -package deployment +package rule import ( "bytes" "net/http" "time" - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" + "github.com/onsi/ginkgo" + "github.com/onsi/gomega" v1 "github.com/kubeedge/kubeedge/pkg/apis/rules/v1" edgeclientset "github.com/kubeedge/kubeedge/pkg/client/clientset/versioned" "github.com/kubeedge/kubeedge/tests/e2e/utils" ) -var _ = Describe("Rule Management test in E2E scenario", func() { +var _ = GroupDescribe("Rule Management test in E2E scenario", func() { var testTimer *utils.TestTimer - var testSpecReport GinkgoTestDescription + var testSpecReport ginkgo.GinkgoTestDescription var edgeClientSet edgeclientset.Interface - BeforeEach(func() { - edgeClientSet = utils.NewKubeEdgeClient(ctx.Cfg.KubeConfigPath) + ginkgo.BeforeEach(func() { + edgeClientSet = utils.NewKubeEdgeClient(utils.LoadConfig().KubeConfigPath) }) msg := "Hello World!" - Context("Test rule and ruleendpoint Creation and deletion", func() { - BeforeEach(func() { + ginkgo.Context("Test rule and ruleendpoint Creation and deletion", func() { + ginkgo.BeforeEach(func() { // Delete any pre-existing rules list, err := utils.ListRule(edgeClientSet, "default") - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) for _, rule := range list { err := utils.HandleRule(edgeClientSet, http.MethodDelete, rule.Name, "", "") - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) } // Delete any pre-existing ruleendpoints reList, err := utils.ListRuleEndpoint(edgeClientSet, "default") - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) for _, ruleendpoint := range reList { err := utils.HandleRule(edgeClientSet, http.MethodDelete, ruleendpoint.Name, "", "") - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) } // Get current test SpecReport - testSpecReport = CurrentGinkgoTestDescription() + testSpecReport = ginkgo.CurrentGinkgoTestDescription() // Start test timer - testTimer = CRDTestTimerGroup.NewTestTimer(testSpecReport.TestText) + testTimer = utils.CRDTestTimerGroup.NewTestTimer(testSpecReport.TestText) }) - AfterEach(func() { + ginkgo.AfterEach(func() { // End test timer testTimer.End() // Print result testTimer.PrintResult() list, err := utils.ListRule(edgeClientSet, "default") - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) for _, rule := range list { err := utils.HandleRule(edgeClientSet, http.MethodDelete, rule.Name, "", "") - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) } // Delete ruleendpoints reList, err := utils.ListRuleEndpoint(edgeClientSet, "default") - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) for _, ruleendpoint := range reList { err := utils.HandleRuleEndpoint(edgeClientSet, http.MethodDelete, ruleendpoint.Name, "") - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) } utils.PrintTestcaseNameandStatus() }) - It("E2E_CREATE_RULE_1: Create rule: rest to eventbus.", func() { + ginkgo.It("E2E_CREATE_RULE_1: Create rule: rest to eventbus.", func() { // create rest ruleendpoint err := utils.HandleRuleEndpoint(edgeClientSet, http.MethodPost, "", v1.RuleEndpointTypeRest) - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) // create eventbus ruleendpoint err = utils.HandleRuleEndpoint(edgeClientSet, http.MethodPost, "", v1.RuleEndpointTypeEventBus) - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) // create rule: rest to eventbus. err = utils.HandleRule(edgeClientSet, http.MethodPost, "", v1.RuleEndpointTypeRest, v1.RuleEndpointTypeEventBus) - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) newRule := utils.NewRule(v1.RuleEndpointTypeRest, v1.RuleEndpointTypeEventBus) ruleList, err := utils.ListRule(edgeClientSet, "default") - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) err = utils.CheckRuleExists(ruleList, newRule) - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) b := new(bytes.Buffer) go func() { @@ -94,22 +94,22 @@ var _ = Describe("Rule Management test in E2E scenario", func() { time.Sleep(3 * time.Second) // call rest api to send message to edge. IsSend, statusCode := utils.SendMsg("http://127.0.0.1:9443/edge-node/default/ccc", []byte(msg), nil) - Expect(IsSend).Should(BeTrue()) - Expect(statusCode).Should(Equal(http.StatusOK)) - Eventually(func() bool { + gomega.Expect(IsSend).Should(gomega.BeTrue()) + gomega.Expect(statusCode).Should(gomega.Equal(http.StatusOK)) + gomega.Eventually(func() bool { utils.Infof("receive: %s, msg: %s ", b.String(), msg) return b.String() == msg - }, "30s", "2s").Should(Equal(true), "eventbus not subscribe anything.") + }, "30s", "2s").Should(gomega.Equal(true), "eventbus not subscribe anything.") }) - It("E2E_CREATE_RULE_2: Create rule: eventbus to rest.", func() { + ginkgo.It("E2E_CREATE_RULE_2: Create rule: eventbus to rest.", func() { err := utils.HandleRuleEndpoint(edgeClientSet, http.MethodPost, "", v1.RuleEndpointTypeRest) - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) // create eventbus ruleendpoint err = utils.HandleRuleEndpoint(edgeClientSet, http.MethodPost, "", v1.RuleEndpointTypeEventBus) - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) // create rule: eventbus to rest. err = utils.HandleRule(edgeClientSet, http.MethodPost, "", v1.RuleEndpointTypeEventBus, v1.RuleEndpointTypeRest) - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) b := new(bytes.Buffer) go func() { receiveMsg, err := utils.StartEchoServer() @@ -121,30 +121,30 @@ var _ = Describe("Rule Management test in E2E scenario", func() { time.Sleep(3 * time.Second) // call rest api to send message to edge. err = utils.PublishMqtt("default/test", msg) - Expect(err).Should(BeNil()) - Eventually(func() bool { + gomega.Expect(err).Should(gomega.BeNil()) + gomega.Eventually(func() bool { return b.String() == msg - }, "30s", "2s").Should(Equal(true), "endpoint not listen any request.") + }, "30s", "2s").Should(gomega.Equal(true), "endpoint not listen any request.") }) - It("E2E_CREATE_RULE_3: Create rule: rest to servicebus.", func() { + ginkgo.It("E2E_CREATE_RULE_3: Create rule: rest to servicebus.", func() { // create rest ruleendpoint err := utils.HandleRuleEndpoint(edgeClientSet, http.MethodPost, "", v1.RuleEndpointTypeRest) - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) // create servicebus ruleendpoint err = utils.HandleRuleEndpoint(edgeClientSet, http.MethodPost, "", v1.RuleEndpointTypeServiceBus) - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) // create rule: rest to servicebus err = utils.HandleRule(edgeClientSet, http.MethodPost, "", v1.RuleEndpointTypeRest, v1.RuleEndpointTypeServiceBus) - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) newRule := utils.NewRule(v1.RuleEndpointTypeRest, v1.RuleEndpointTypeServiceBus) ruleList, err := utils.ListRule(edgeClientSet, "default") - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) err = utils.CheckRuleExists(ruleList, newRule) - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) msgHeader := map[string]string{ "user": "I am user", "passwd": "I am passwd", @@ -160,26 +160,26 @@ var _ = Describe("Rule Management test in E2E scenario", func() { time.Sleep(3 * time.Second) // call rest api to send message to edge. IsSend, statusCode := utils.SendMsg("http://127.0.0.1:9443/edge-node/default/ddd", []byte(msg), msgHeader) - Expect(IsSend).Should(BeTrue()) - Expect(statusCode).Should(Equal(http.StatusOK)) - Eventually(func() bool { + gomega.Expect(IsSend).Should(gomega.BeTrue()) + gomega.Expect(statusCode).Should(gomega.Equal(http.StatusOK)) + gomega.Eventually(func() bool { utils.Infof("receive: %s, sent msg: %s ", b.String(), msg) newMsg := "Reply from server: " + msg + " Header of the message: [user]: " + msgHeader["user"] + ", [passwd]: " + msgHeader["passwd"] return b.String() == newMsg - }, "30s", "2s").Should(Equal(true), "servicebus did not return any response.") + }, "30s", "2s").Should(gomega.Equal(true), "servicebus did not return any response.") }) - It("E2E_CREATE_RULE_4: Create rule: servicebus to rest.", func() { + ginkgo.It("E2E_CREATE_RULE_4: Create rule: servicebus to rest.", func() { r := "Hello World" // create rest ruleendpoint err := utils.HandleRuleEndpoint(edgeClientSet, http.MethodPost, "", v1.RuleEndpointTypeRest) - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) // create servicebus ruleendpoint err = utils.HandleRuleEndpoint(edgeClientSet, http.MethodPost, "", v1.RuleEndpointTypeServiceBus) - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) // create rule: servicebus to rest err = utils.HandleRule(edgeClientSet, http.MethodPost, "", v1.RuleEndpointTypeServiceBus, v1.RuleEndpointTypeRest) - Expect(err).To(BeNil()) + gomega.Expect(err).To(gomega.BeNil()) b := new(bytes.Buffer) go func() { receiveMsg, err := utils.StartEchoServer() @@ -190,8 +190,8 @@ var _ = Describe("Rule Management test in E2E scenario", func() { }() time.Sleep(3 * time.Second) resp, err := utils.CallServicebus() - Expect(err).Should(BeNil()) - Expect(resp).Should(Equal(r)) + gomega.Expect(err).Should(gomega.BeNil()) + gomega.Expect(resp).Should(gomega.Equal(r)) }) }) }) diff --git a/tests/e2e/scripts/cleanup.sh b/tests/e2e/scripts/cleanup.sh deleted file mode 100755 index 3829fb28c..000000000 --- a/tests/e2e/scripts/cleanup.sh +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/env bash - -# Copyright 2019 The KubeEdge Authors. -# -# 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. - -setuptype=$1 - -kill_component() { - local component=$1 - if pgrep "$component" &>/dev/null; then - # edgesite process is found, kill the process. - sudo pkill $component &>/dev/null - if [[ "$?" == "0" ]]; then - echo "$component is successfully killed !!" - else - echo "Failed to kill $component process !!" - exit 1 - fi - fi -} - -kill_all_components() { - local components="cloudcore edgecore edgesite" - for component in $components; do - kill_component "$component" - done -} - -cleanup_files(){ - sudo rm -rf /tmp/etc/kubeedge /tmp/var/lib/kubeedge - sudo rm -f tests/e2e/config.json - find -name "*.test" | xargs sudo rm -f -} - -kill_all_components - -cleanup_files diff --git a/tests/e2e/scripts/compile.sh b/tests/e2e/scripts/compile.sh deleted file mode 100755 index 4a9838e9d..000000000 --- a/tests/e2e/scripts/compile.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/bash -ex - -# Copyright 2019 The KubeEdge Authors. -# -# 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. - -cd `dirname $0` -workdir=`pwd` -cd $workdir - -cd ../ -echo $PWD - -compilemodule=$1 -#compile all test if user doesn't specify the test else compile only specified tests. -if [ $# -eq 0 ] -then - echo "compiling all tests !!" - ginkgo build -r -else - ginkgo build -r $compilemodule -fi diff --git a/tests/e2e/scripts/execute.sh b/tests/e2e/scripts/execute.sh deleted file mode 100755 index 11f5b8b30..000000000 --- a/tests/e2e/scripts/execute.sh +++ /dev/null @@ -1,58 +0,0 @@ -#!/bin/bash - -# Copyright 2019 The KubeEdge Authors. -# -# 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. - -set -e - -workdir=`pwd` -cd $workdir - -curpath=$PWD -echo $PWD - -GOPATH=${GOPATH:-$(go env GOPATH)} - -which ginkgo &> /dev/null || ( - go install github.com/onsi/ginkgo/ginkgo@latest - sudo cp $GOPATH/bin/ginkgo /usr/local/bin/ -) - -cleanup() { - bash ${curpath}/tests/e2e/scripts/cleanup.sh -} - -cleanup - -E2E_DIR=${curpath}/tests/e2e -sudo rm -rf ${E2E_DIR}/deployment/deployment.test -sudo rm -rf ${E2E_DIR}/device_crd/device_crd.test - -# Specify the module name to compile in below command -bash -x ${E2E_DIR}/scripts/compile.sh $1 - -ENABLE_DAEMON=true bash -x ${curpath}/hack/local-up-kubeedge.sh || { - echo "failed to start cluster !!!" - exit 1 -} - -kubectl create clusterrolebinding system:anonymous --clusterrole=cluster-admin --user=system:anonymous - -:> /tmp/testcase.log - -export GINKGO_TESTING_RESULT=0 - -trap cleanup EXIT - -bash -x ${E2E_DIR}/scripts/fast_test.sh $1 diff --git a/tests/e2e/scripts/fast_test.sh b/tests/e2e/scripts/fast_test.sh deleted file mode 100755 index 89f3748cf..000000000 --- a/tests/e2e/scripts/fast_test.sh +++ /dev/null @@ -1,57 +0,0 @@ -#!/bin/bash -x - -# Copyright 2019 The KubeEdge Authors. -# -# 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. - -cd `dirname $0` -workdir=`pwd` -cd $workdir - -compilemodule=$1 - -#setup env -cd ../ - -export MASTER_IP=`docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' test-control-plane` -export KUBECONFIG=$HOME/.kube/config -export CHECK_EDGECORE_ENVIRONMENT="false" -export ACK_GINKGO_RC=true - -if [ $# -eq 0 ] -then - #run testcase - ginkgo -v ./deployment/deployment.test -- \ - --image-url=nginx \ - --image-url=nginx \ - --kube-master="https://$MASTER_IP:6443" \ - --kubeconfig=$KUBECONFIG \ - --test.v - GINKGO_TESTING_RESULT=$? -else - ginkgo -v ./$compilemodule/$compilemodule.test -- \ - --image-url=nginx \ - --image-url=nginx \ - --kube-master="https://$MASTER_IP:6443" \ - --kubeconfig=$KUBECONFIG \ - --test.v - GINKGO_TESTING_RESULT=$? -fi - -if [[ $GINKGO_TESTING_RESULT != 0 ]]; then - echo "Integration suite has failures, Please check !!" - exit 1 -else - echo "Integration suite successfully passed all the tests !!" - exit 0 -fi diff --git a/tests/e2e/scripts/generate_cert.sh b/tests/e2e/scripts/generate_cert.sh deleted file mode 100755 index 00144c6e8..000000000 --- a/tests/e2e/scripts/generate_cert.sh +++ /dev/null @@ -1,63 +0,0 @@ -#!/usr/bin/env bash - -# Copyright 2019 The KubeEdge Authors. -# -# 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. - -sudo apt-get install openssl -y - -#Required -commonname=kubeedge - -#Change to your company details -country=IN -state=Karnataka -locality=Bangalore -organization=Htipl -organizationalunit=IT -email=administrator@htipl.com - -#Optional -password=root - -echo "Generating key request for kubeedge" - -# Generete Root Key -sudo openssl genrsa -des3 -passout pass:$password -out rootCA.key 4096 -# Generate Root Certificate -sudo openssl req -x509 -new -nodes -key rootCA.key -sha256 -days 1024 -out rootCA.crt -passin pass:$password \ - -subj "/C=$country/ST=$state/L=$locality/O=$organization/OU=$organizationalunit/CN=$commonname/emailAddress=$email" -# Generate Key -sudo openssl genrsa -out kubeedge.key 2048 -# Generate csr, Fill required details after running the command -sudo openssl req -new -key kubeedge.key -out kubeedge.csr -passin pass:$password \ - -subj "/C=$country/ST=$state/L=$locality/O=$organization/OU=$organizationalunit/CN=$commonname/emailAddress=$email" -# Generate Certificate -sudo openssl x509 -req -in kubeedge.csr -CA rootCA.crt -CAkey rootCA.key -CAcreateserial -out kubeedge.crt -days 500 -sha256 -passin pass:$password - -echo "---------------------------------------------" -echo "-----Certificate Generation is Completed-----" -echo "---------------------------------------------" - -#Generate temparory folder in Edge and Cloud folders to copy certs -sudo mkdir -p $GOPATH/src/github.com/kubeedge/kubeedge/edge/tmp -sudo mkdir -p $GOPATH/src/github.com/kubeedge/kubeedge/cloud/tmp -#Copy the generated certs to respective paths -mkdir -p /tmp/edgecore -mkdir -p /tmp/cloudcore -mkdir -p /tmp/edgesite - -sudo cp -r rootCA.crt rootCA.key kubeedge.crt kubeedge.key /tmp/edgecore -sudo cp -r rootCA.crt rootCA.key kubeedge.crt kubeedge.key /tmp/cloudcore - -echo "-----Certificate are Copied to Edge and Cloud Nodes-----" diff --git a/tests/e2e/scripts/keadm_deprecated_e2e.sh b/tests/e2e/scripts/keadm_deprecated_e2e.sh deleted file mode 100755 index c497e159c..000000000 --- a/tests/e2e/scripts/keadm_deprecated_e2e.sh +++ /dev/null @@ -1,157 +0,0 @@ -#!/usr/bin/env bash - -# Copyright 2020 The KubeEdge Authors. -# -# 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. - -KUBEEDGE_ROOT=$PWD -WORKDIR=$(dirname $0) -E2E_DIR=$(realpath $(dirname $0)/..) - -source "${KUBEEDGE_ROOT}/hack/lib/golang.sh" -source "${KUBEEDGE_ROOT}/hack/lib/install.sh" -kubeedge::version::get_version_info -VERSION=${GIT_VERSION} - -function cleanup() { - sudo pkill edgecore || true - sudo systemctl stop edgecore.service && systemctl disable edgecore.service && rm /etc/systemd/system/edgecore.service || true - sudo rm -rf /var/lib/kubeedge || true - sudo pkill cloudcore || true - kind delete cluster --name test - sudo rm -rf /var/log/kubeedge /etc/kubeedge /etc/systemd/system/edgecore.service $E2E_DIR/keadm/keadm.test $E2E_DIR/config.json - sudo rm -rf ${KUBEEDGE_ROOT}/_output/release/${VERSION}/ -} - -function build_keadm() { - cd $KUBEEDGE_ROOT - make all WHAT=keadm - cd $E2E_DIR - ginkgo build -r keadm/ -} - -function prepare_cluster() { - kind create cluster --name test - - echo "wait the control-plane ready..." - kubectl wait --for=condition=Ready node/test-control-plane --timeout=60s - - kubectl create clusterrolebinding system:anonymous --clusterrole=cluster-admin --user=system:anonymous - - # edge side don't support kind cni now, delete kind cni plugin for workaround - kubectl delete daemonset kindnet -nkube-system -} - -function start_kubeedge() { - local KUBEEDGE_VERSION="$@" - - sudo mkdir -p /var/lib/kubeedge - cd $KUBEEDGE_ROOT - export KUBECONFIG=$HOME/.kube/config - - sudo -E _output/local/bin/keadm deprecated init --kube-config=$KUBECONFIG --advertise-address=127.0.0.1 --kubeedge-version=${KUBEEDGE_VERSION} - export MASTER_IP=`docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' test-control-plane` - - # ensure tokensecret is generated - while true; do - sleep 3 - kubectl get secret -nkubeedge 2>/dev/null | grep -q tokensecret && break - done - - export TOKEN=$(sudo _output/local/bin/keadm gettoken --kube-config=$KUBECONFIG) - sudo systemctl set-environment CHECK_EDGECORE_ENVIRONMENT="false" - sudo -E CHECK_EDGECORE_ENVIRONMENT="false" _output/local/bin/keadm deprecated join --token=$TOKEN --cloudcore-ipport=127.0.0.1:10000 --edgenode-name=edge-node --kubeedge-version=${KUBEEDGE_VERSION} - - # ensure edgenode is ready - while true; do - sleep 3 - kubectl get node | grep edge-node | grep -q -w Ready && break - done -} - -function run_test() { - :> /tmp/testcase.log - cd $E2E_DIR - - export ACK_GINKGO_RC=true - - ginkgo -v ./keadm/keadm.test -- \ - --image-url=nginx \ - --image-url=nginx \ - --kube-master="https://$MASTER_IP:6443" \ - --kubeconfig=$KUBECONFIG \ - --test.v - GINKGO_TESTING_RESULT=$? - - if [[ $GINKGO_TESTING_RESULT != 0 ]]; then - echo "Integration suite has failures, Please check !!" - echo "edgecore logs are as below" - set -x - journalctl -u edgecore.service --no-pager - set +x - echo "=================================================" - echo "=================================================" - echo "cloudcore logs are as below" - set -x - cat /var/log/kubeedge/cloudcore.log - set +x - exit 1 - else - echo "Integration suite successfully passed all the tests !!" - exit 0 - fi -} - -trap cleanup EXIT -trap cleanup ERR - -echo -e "\nUsing latest commit code to do keadm_deprecated_e2e test..." - -echo -e "\nBuilding keadm..." -build_keadm - -export KUBECONFIG=$HOME/.kube/config - -echo -e "\nPreparing cluster..." -prepare_cluster - -install_cni_plugins - -kubeedge_version=${VERSION: 1} -#if we use the local release version compiled with the latest codes, we need to copy release file and checksum file. -sudo mkdir -p /etc/kubeedge - -sudo cp ${KUBEEDGE_ROOT}/_output/release/${VERSION}/kubeedge-${VERSION}-linux-amd64.tar.gz ${KUBEEDGE_ROOT}/_output/release/${VERSION}/checksum_kubeedge-${VERSION}-linux-amd64.tar.gz.txt /etc/kubeedge - -echo -e "\nStarting kubeedge..." ${kubeedge_version} -start_kubeedge ${kubeedge_version} - -echo -e "\nRunning test..." -run_test - -# clean the before test -cleanup - -echo -e "\nUsing latest official release version to do keadm_deprecated_e2e test..." - -echo -e "\nBuilding keadm..." -build_keadm - -echo -e "\nPreparing cluster..." -prepare_cluster - -echo -e "\nStarting kubeedge..." -start_kubeedge "" - -echo -e "\nRunning test..." -run_test diff --git a/tests/e2e/scripts/keadm_e2e.sh b/tests/e2e/scripts/keadm_e2e.sh deleted file mode 100755 index 3e36e429d..000000000 --- a/tests/e2e/scripts/keadm_e2e.sh +++ /dev/null @@ -1,133 +0,0 @@ -#!/usr/bin/env bash - -# Copyright 2021 The KubeEdge Authors. -# -# 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. - -KUBEEDGE_ROOT=$PWD -WORKDIR=$(dirname $0) -E2E_DIR=$(realpath $(dirname $0)/..) -IMAGE_TAG=$(git describe --tags) -KUBEEDGE_VERSION=$IMAGE_TAG - -source "${KUBEEDGE_ROOT}/hack/lib/install.sh" - -function cleanup() { - sudo pkill edgecore || true - helm uninstall cloudcore -n kubeedge && kubectl delete ns kubeedge || true - kind delete cluster --name test - sudo rm -rf /var/log/kubeedge /etc/kubeedge /etc/systemd/system/edgecore.service $E2E_DIR/keadm/keadm.test $E2E_DIR/config.json -} - -function build_ginkgo() { - cd $E2E_DIR - ginkgo build -r keadm/ -} - -function prepare_cluster() { - kind create cluster --name test - - echo "wait the control-plane ready..." - kubectl wait --for=condition=Ready node/test-control-plane --timeout=60s - - kubectl create clusterrolebinding system:anonymous --clusterrole=cluster-admin --user=system:anonymous - - # edge side don't support kind cni now, delete kind cni plugin for workaround - kubectl delete daemonset kindnet -nkube-system -} - -function build_image() { - cd $KUBEEDGE_ROOT - make image WHAT=cloudcore -f $KUBEEDGE_ROOT/Makefile - make image WHAT=installation-package -f $KUBEEDGE_ROOT/Makefile - # convert docker images to cri image, or cri runtime cannot identify the image that already existed on the local host - echo "save docker images to cri images" - docker save kubeedge/cloudcore:$IMAGE_TAG > cloudcore.tar - docker save kubeedge/installation-package:$IMAGE_TAG > installation-package.tar - sudo ctr -n=k8s.io image import cloudcore.tar - sudo ctr -n=k8s.io image import installation-package.tar - # load image to test cluster - kind load docker-image docker.io/kubeedge/cloudcore:$IMAGE_TAG --name test - kind load docker-image docker.io/kubeedge/installation-package:$IMAGE_TAG --name test -} - -function start_kubeedge() { - sudo mkdir -p /var/lib/kubeedge - cd $KUBEEDGE_ROOT - export MASTER_IP=`kubectl get node test-control-plane -o jsonpath={.status.addresses[0].address}` - export KUBECONFIG=$HOME/.kube/config - docker run --rm kubeedge/installation-package:$IMAGE_TAG cat /usr/local/bin/keadm > /usr/local/bin/keadm && chmod +x /usr/local/bin/keadm - - /usr/local/bin/keadm init --advertise-address=$MASTER_IP --profile version=$KUBEEDGE_VERSION --set cloudCore.service.enable=false --kube-config=$KUBECONFIG --force - - # ensure tokensecret is generated - while true; do - sleep 3 - kubectl get secret -nkubeedge 2>/dev/null | grep -q tokensecret && break - done - - cd $KUBEEDGE_ROOT - export TOKEN=$(sudo /usr/local/bin/keadm gettoken --kube-config=$KUBECONFIG) - sudo systemctl set-environment CHECK_EDGECORE_ENVIRONMENT="false" - sudo -E CHECK_EDGECORE_ENVIRONMENT="false" /usr/local/bin/keadm join --token=$TOKEN --cloudcore-ipport=$MASTER_IP:10000 --edgenode-name=edge-node --kubeedge-version=$KUBEEDGE_VERSION - - # ensure edgenode is ready - while true; do - sleep 3 - kubectl get node | grep edge-node | grep -q -w Ready && break - done -} - -function run_test() { - :> /tmp/testcase.log - cd $E2E_DIR - - export ACK_GINKGO_RC=true - - ginkgo -v ./keadm/keadm.test -- \ - --image-url=nginx \ - --image-url=nginx \ - --kube-master="https://$MASTER_IP:6443" \ - --kubeconfig=$KUBECONFIG \ - --test.v - if [[ $? != 0 ]]; then - echo "Integration suite has failures, Please check !!" - exit 1 - else - echo "Integration suite successfully passed all the tests !!" - exit 0 - fi -} - -set -Ee -trap cleanup EXIT -trap cleanup ERR - -echo -e "\nBuilding ginkgo test cases..." -build_ginkgo - -export KUBECONFIG=$HOME/.kube/config - -echo -e "\nPreparing cluster..." -prepare_cluster - -echo -e "\nBuilding cloud image..." -build_image - -install_cni_plugins - -echo -e "\nStarting kubeedge..." -start_kubeedge - -echo -e "\nRunning test..." -run_test diff --git a/tests/e2e/testsuite/testsuite.go b/tests/e2e/testsuite/testsuite.go index 84bad9dbc..a0b8f6d3d 100644 --- a/tests/e2e/testsuite/testsuite.go +++ b/tests/e2e/testsuite/testsuite.go @@ -29,9 +29,9 @@ import ( "github.com/kubeedge/kubeedge/tests/e2e/utils" ) -func CreateDeploymentTest(c clientset.Interface, replica int32, deplName string, ctx *utils.TestContext) *v1.PodList { +func CreateDeploymentTest(c clientset.Interface, replica int32, deplName string) *v1.PodList { ginkgo.By(fmt.Sprintf("create deployment %s", deplName)) - d := utils.NewDeployment(deplName, ctx.Cfg.AppImageURL[1], replica) + d := utils.NewDeployment(deplName, utils.LoadConfig().AppImageURL[1], replica) _, err := utils.CreateDeployment(c, d) gomega.Expect(err).To(gomega.BeNil()) diff --git a/tests/e2e/utils/common.go b/tests/e2e/utils/common.go index 1b389c686..a795f79ca 100644 --- a/tests/e2e/utils/common.go +++ b/tests/e2e/utils/common.go @@ -62,6 +62,8 @@ var ClientOpts *MQTT.ClientOptions var Client MQTT.Client var TwinResult DeviceTwinResult +var CRDTestTimerGroup = NewTestTimerGroup() + // Token interface to validate the MQTT connection. type Token interface { Wait() bool |
