github.com/jingruilea/kubeedge@v1.2.0-beta.0.0.20200410162146-4bb8902b3879/tests/e2e/deployment/deployment_test.go (about) 1 /* 2 Copyright 2019 The KubeEdge Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package deployment 18 19 import ( 20 "net/http" 21 "time" 22 23 . "github.com/onsi/ginkgo" 24 . "github.com/onsi/gomega" 25 appsv1 "k8s.io/api/apps/v1" 26 corev1 "k8s.io/api/core/v1" 27 28 "github.com/kubeedge/kubeedge/tests/e2e/constants" 29 . "github.com/kubeedge/kubeedge/tests/e2e/testsuite" 30 "github.com/kubeedge/kubeedge/tests/e2e/utils" 31 ) 32 33 var DeploymentTestTimerGroup *utils.TestTimerGroup = utils.NewTestTimerGroup() 34 35 //Run Test cases 36 var _ = Describe("Application deployment test in E2E scenario", func() { 37 var UID string 38 var testTimer *utils.TestTimer 39 var testDescription GinkgoTestDescription 40 Context("Test application deployment and delete deployment using deployment spec", func() { 41 BeforeEach(func() { 42 // Get current test description 43 testDescription = CurrentGinkgoTestDescription() 44 // Start test timer 45 testTimer = DeploymentTestTimerGroup.NewTestTimer(testDescription.TestText) 46 }) 47 AfterEach(func() { 48 // End test timer 49 testTimer.End() 50 // Print result 51 testTimer.PrintResult() 52 var podlist corev1.PodList 53 var deploymentList appsv1.DeploymentList 54 err := utils.GetDeployments(&deploymentList, ctx.Cfg.K8SMasterForKubeEdge+constants.DeploymentHandler) 55 Expect(err).To(BeNil()) 56 for _, deployment := range deploymentList.Items { 57 if deployment.Name == UID { 58 label := nodeName 59 podlist, err = utils.GetPods(ctx.Cfg.K8SMasterForKubeEdge+constants.AppHandler, label) 60 Expect(err).To(BeNil()) 61 StatusCode := utils.DeleteDeployment(ctx.Cfg.K8SMasterForKubeEdge+constants.DeploymentHandler, deployment.Name) 62 Expect(StatusCode).Should(Equal(http.StatusOK)) 63 } 64 } 65 utils.CheckPodDeleteState(ctx.Cfg.K8SMasterForKubeEdge+constants.AppHandler, podlist) 66 utils.PrintTestcaseNameandStatus() 67 }) 68 69 It("E2E_APP_DEPLOYMENT_1: Create deployment and check the pods are coming up correctly", func() { 70 replica := 1 71 //Generate the random string and assign as a UID 72 UID = "edgecore-depl-app-" + utils.GetRandomString(5) 73 CreateDeploymentTest(replica, UID, nodeName, nodeSelector, ctx) 74 }) 75 It("E2E_APP_DEPLOYMENT_2: Create deployment with replicas and check the pods are coming up correctly", func() { 76 replica := 3 77 //Generate the random string and assign as a UID 78 UID = "edgecore-depl-app-" + utils.GetRandomString(5) 79 CreateDeploymentTest(replica, UID, nodeName, nodeSelector, ctx) 80 }) 81 82 It("E2E_APP_DEPLOYMENT_3: Create deployment and check deployment ctrler re-creating pods when user deletes the pods manually", func() { 83 replica := 3 84 //Generate the random string and assign as a UID 85 UID = "edgecore-depl-app-" + utils.GetRandomString(5) 86 podlist := CreateDeploymentTest(replica, UID, nodeName, nodeSelector, ctx) 87 for _, pod := range podlist.Items { 88 _, StatusCode := utils.DeletePods(ctx.Cfg.K8SMasterForKubeEdge + constants.AppHandler + "/" + pod.Name) 89 Expect(StatusCode).Should(Equal(http.StatusOK)) 90 } 91 utils.CheckPodDeleteState(ctx.Cfg.K8SMasterForKubeEdge+constants.AppHandler, podlist) 92 label := nodeName 93 podlist, err := utils.GetPods(ctx.Cfg.K8SMasterForKubeEdge+constants.AppHandler, label) 94 Expect(err).To(BeNil()) 95 Expect(len(podlist.Items)).Should(Equal(replica)) 96 utils.WaitforPodsRunning(ctx.Cfg.KubeConfigPath, podlist, 240*time.Second) 97 }) 98 99 }) 100 Context("Test application deployment using Pod spec", func() { 101 BeforeEach(func() { 102 // Get current test description 103 testDescription = CurrentGinkgoTestDescription() 104 // Start test timer 105 testTimer = DeploymentTestTimerGroup.NewTestTimer(testDescription.TestText) 106 }) 107 AfterEach(func() { 108 // End test timer 109 testTimer.End() 110 // Print result 111 testTimer.PrintResult() 112 var podlist corev1.PodList 113 label := nodeName 114 podlist, err := utils.GetPods(ctx.Cfg.K8SMasterForKubeEdge+constants.AppHandler, label) 115 Expect(err).To(BeNil()) 116 for _, pod := range podlist.Items { 117 _, StatusCode := utils.DeletePods(ctx.Cfg.K8SMasterForKubeEdge + constants.AppHandler + "/" + pod.Name) 118 Expect(StatusCode).Should(Equal(http.StatusOK)) 119 } 120 utils.CheckPodDeleteState(ctx.Cfg.K8SMasterForKubeEdge+constants.AppHandler, podlist) 121 utils.PrintTestcaseNameandStatus() 122 }) 123 124 It("E2E_POD_DEPLOYMENT_1: Create a pod and check the pod is coming up correclty", func() { 125 //Generate the random string and assign as podName 126 podName := "pod-app-" + utils.GetRandomString(5) 127 pod := utils.NewPodObj(podName, ctx.Cfg.AppImageUrl[0], nodeSelector) 128 129 CreatePodTest(nodeName, podName, ctx, pod) 130 }) 131 132 It("E2E_POD_DEPLOYMENT_2: Create the pod and delete pod happening successfully", func() { 133 //Generate the random string and assign as podName 134 podName := "pod-app-" + utils.GetRandomString(5) 135 pod := utils.NewPodObj(podName, ctx.Cfg.AppImageUrl[0], nodeSelector) 136 137 podlist := CreatePodTest(nodeName, podName, ctx, pod) 138 for _, pod := range podlist.Items { 139 _, StatusCode := utils.DeletePods(ctx.Cfg.K8SMasterForKubeEdge + constants.AppHandler + "/" + pod.Name) 140 Expect(StatusCode).Should(Equal(http.StatusOK)) 141 } 142 utils.CheckPodDeleteState(ctx.Cfg.K8SMasterForKubeEdge+constants.AppHandler, podlist) 143 }) 144 It("E2E_POD_DEPLOYMENT_3: Create pod and delete the pod successfully, and delete already deleted pod and check the behaviour", func() { 145 //Generate the random string and assign as podName 146 podName := "pod-app-" + utils.GetRandomString(5) 147 pod := utils.NewPodObj(podName, ctx.Cfg.AppImageUrl[0], nodeSelector) 148 149 podlist := CreatePodTest(nodeName, podName, ctx, pod) 150 for _, pod := range podlist.Items { 151 _, StatusCode := utils.DeletePods(ctx.Cfg.K8SMasterForKubeEdge + constants.AppHandler + "/" + pod.Name) 152 Expect(StatusCode).Should(Equal(http.StatusOK)) 153 } 154 utils.CheckPodDeleteState(ctx.Cfg.K8SMasterForKubeEdge+constants.AppHandler, podlist) 155 _, StatusCode := utils.DeletePods(ctx.Cfg.K8SMasterForKubeEdge + constants.AppHandler + "/" + UID) 156 Expect(StatusCode).Should(Equal(http.StatusNotFound)) 157 }) 158 It("E2E_POD_DEPLOYMENT_4: Create and delete pod multiple times and check all the Pod created and deleted successfully", func() { 159 //Generate the random string and assign as a UID 160 for i := 0; i < 10; i++ { 161 //Generate the random string and assign as podName 162 podName := "pod-app-" + utils.GetRandomString(5) 163 pod := utils.NewPodObj(podName, ctx.Cfg.AppImageUrl[0], nodeSelector) 164 165 podlist := CreatePodTest(nodeName, podName, ctx, pod) 166 for _, pod := range podlist.Items { 167 _, StatusCode := utils.DeletePods(ctx.Cfg.K8SMasterForKubeEdge + constants.AppHandler + "/" + pod.Name) 168 Expect(StatusCode).Should(Equal(http.StatusOK)) 169 } 170 utils.CheckPodDeleteState(ctx.Cfg.K8SMasterForKubeEdge+constants.AppHandler, podlist) 171 } 172 }) 173 It("E2E_POD_DEPLOYMENT_5: Create pod with hostpath volume successfully", func() { 174 //Generate the random string and assign as podName 175 podName := "pod-app-" + utils.GetRandomString(5) 176 pod := utils.NewPodObj(podName, ctx.Cfg.AppImageUrl[0], nodeSelector) 177 178 pod.Spec.Containers[0].VolumeMounts = []corev1.VolumeMount{{ 179 Name: "hp", 180 MountPath: "/hp", 181 }} 182 pod.Spec.Volumes = []corev1.Volume{{ 183 Name: "hp", 184 VolumeSource: corev1.VolumeSource{ 185 HostPath: &corev1.HostPathVolumeSource{Path: "/tmp"}, 186 }, 187 }} 188 189 podlist := CreatePodTest(nodeName, podName, ctx, pod) 190 for _, pod := range podlist.Items { 191 _, StatusCode := utils.DeletePods(ctx.Cfg.K8SMasterForKubeEdge + constants.AppHandler + "/" + pod.Name) 192 Expect(StatusCode).Should(Equal(http.StatusOK)) 193 } 194 utils.CheckPodDeleteState(ctx.Cfg.K8SMasterForKubeEdge+constants.AppHandler, podlist) 195 }) 196 }) 197 })