github.com/jingruilea/kubeedge@v1.2.0-beta.0.0.20200410162146-4bb8902b3879/edge/test/integration/appdeployment/application_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 application_test
    18  
    19  import (
    20  	"net/http"
    21  	"time"
    22  
    23  	. "github.com/onsi/ginkgo"
    24  	. "github.com/onsi/gomega"
    25  	"k8s.io/api/core/v1"
    26  	"k8s.io/apimachinery/pkg/api/resource"
    27  	"k8s.io/apimachinery/pkg/util/intstr"
    28  
    29  	"github.com/kubeedge/kubeedge/edge/test/integration/utils/common"
    30  	"github.com/kubeedge/kubeedge/edge/test/integration/utils/edge"
    31  	. "github.com/kubeedge/kubeedge/edge/test/integration/utils/helpers"
    32  )
    33  
    34  const (
    35  	AppHandler = "/pods"
    36  )
    37  
    38  //Run Test cases
    39  var _ = Describe("Application deployment in edgecore Testing", func() {
    40  	var UID string
    41  	Context("Test application deployment and delete deployment", func() {
    42  		BeforeEach(func() {
    43  		})
    44  		AfterEach(func() {
    45  			IsAppDeleted := HandleAddAndDeletePods(http.MethodDelete, ctx.Cfg.TestManager+AppHandler, UID, []v1.Container{{Name: UID, Image: ctx.Cfg.AppImageURL[0], ImagePullPolicy: v1.PullIfNotPresent}}, v1.RestartPolicyOnFailure)
    46  			Expect(IsAppDeleted).Should(BeTrue())
    47  			CheckPodDeletion(ctx.Cfg.EdgedEndpoint+AppHandler, UID)
    48  			time.Sleep(2 * time.Second)
    49  			common.PrintTestcaseNameandStatus()
    50  		})
    51  
    52  		It("TC_TEST_APP_DEPLOYMENT_1: Test application deployment in edgecore", func() {
    53  			//Generate the random string and assign as a UID
    54  			UID = "deployment-app-" + edge.GetRandomString(10)
    55  			IsAppDeployed := HandleAddAndDeletePods(http.MethodPut, ctx.Cfg.TestManager+AppHandler, UID, []v1.Container{{Name: UID, Image: ctx.Cfg.AppImageURL[0], ImagePullPolicy: v1.PullIfNotPresent}}, v1.RestartPolicyOnFailure)
    56  			Expect(IsAppDeployed).Should(BeTrue())
    57  			time.Sleep(2 * time.Second)
    58  			CheckPodRunningState(ctx.Cfg.EdgedEndpoint+AppHandler, UID)
    59  		})
    60  
    61  		It("TC_TEST_APP_DEPLOYMENT_2: Test List application deployment in edgecore", func() {
    62  			//Generate the random string and assign as a UID
    63  			UID = "deployment-app-" + edge.GetRandomString(10)
    64  			IsAppDeployed := HandleAddAndDeletePods(http.MethodPut, ctx.Cfg.TestManager+AppHandler, UID, []v1.Container{{Name: UID, Image: ctx.Cfg.AppImageURL[0], ImagePullPolicy: v1.PullIfNotPresent}}, v1.RestartPolicyOnFailure)
    65  			Expect(IsAppDeployed).Should(BeTrue())
    66  			time.Sleep(2 * time.Second)
    67  			CheckPodRunningState(ctx.Cfg.EdgedEndpoint+AppHandler, UID)
    68  			pods, err := GetPods(ctx.Cfg.EdgedEndpoint + AppHandler)
    69  			Expect(err).To(BeNil())
    70  			common.Infof("Get pods from Edged is Successful !!")
    71  			for index := range pods.Items {
    72  				pod := &pods.Items[index]
    73  				common.Infof("PodName: %s PodStatus: %s", pod.Name, pod.Status.Phase)
    74  			}
    75  		})
    76  
    77  		It("TC_TEST_APP_DEPLOYMENT_3: Test application deployment delete from edgecore", func() {
    78  			//Generate the random string and assign as a UID
    79  			UID = "deployment-app-" + edge.GetRandomString(10)
    80  			IsAppDeployed := HandleAddAndDeletePods(http.MethodPut, ctx.Cfg.TestManager+AppHandler, UID, []v1.Container{{Name: UID, Image: ctx.Cfg.AppImageURL[1], ImagePullPolicy: v1.PullIfNotPresent}}, v1.RestartPolicyOnFailure)
    81  			Expect(IsAppDeployed).Should(BeTrue())
    82  			CheckPodRunningState(ctx.Cfg.EdgedEndpoint+AppHandler, UID)
    83  			IsAppDeleted := HandleAddAndDeletePods(http.MethodDelete, ctx.Cfg.TestManager+AppHandler, UID, []v1.Container{{Name: UID, Image: ctx.Cfg.AppImageURL[1], ImagePullPolicy: v1.PullIfNotPresent}}, v1.RestartPolicyOnFailure)
    84  			Expect(IsAppDeleted).Should(BeTrue())
    85  			CheckPodDeletion(ctx.Cfg.EdgedEndpoint+AppHandler, UID)
    86  		})
    87  
    88  		It("TC_TEST_APP_DEPLOYMENT_4: Test application deployment delete from edgecore", func() {
    89  			//Generate the random string and assign as a UID
    90  			UID = "deployment-app-" + edge.GetRandomString(10)
    91  			for i := 0; i < 2; i++ {
    92  				UID = "deployment-app-" + edge.GetRandomString(10)
    93  				IsAppDeployed := HandleAddAndDeletePods(http.MethodPut, ctx.Cfg.TestManager+AppHandler, UID, []v1.Container{{Name: UID, Image: ctx.Cfg.AppImageURL[i], ImagePullPolicy: v1.PullIfNotPresent}}, v1.RestartPolicyOnFailure)
    94  				Expect(IsAppDeployed).Should(BeTrue())
    95  				CheckPodRunningState(ctx.Cfg.EdgedEndpoint+AppHandler, UID)
    96  				time.Sleep(5 * time.Second)
    97  			}
    98  		})
    99  
   100  		It("TC_TEST_APP_DEPLOYMENT_5: Test application deployment delete from edgecore", func() {
   101  			var apps []string
   102  			//Generate the random string and assign as a UID
   103  			UID = "deployment-app-" + edge.GetRandomString(10)
   104  			for i := 0; i < 2; i++ {
   105  				UID = "deployment-app-" + edge.GetRandomString(10)
   106  				IsAppDeployed := HandleAddAndDeletePods(http.MethodPut, ctx.Cfg.TestManager+AppHandler, UID, []v1.Container{{Name: UID, Image: ctx.Cfg.AppImageURL[i], ImagePullPolicy: v1.PullIfNotPresent}}, v1.RestartPolicyOnFailure)
   107  				Expect(IsAppDeployed).Should(BeTrue())
   108  				CheckPodRunningState(ctx.Cfg.EdgedEndpoint+AppHandler, UID)
   109  				apps = append(apps, UID)
   110  				time.Sleep(5 * time.Second)
   111  			}
   112  			for i, appname := range apps {
   113  				IsAppDeleted := HandleAddAndDeletePods(http.MethodDelete, ctx.Cfg.TestManager+AppHandler, appname, []v1.Container{{Name: UID, Image: ctx.Cfg.AppImageURL[i], ImagePullPolicy: v1.PullIfNotPresent}}, v1.RestartPolicyOnFailure)
   114  				Expect(IsAppDeleted).Should(BeTrue())
   115  				CheckPodDeletion(ctx.Cfg.EdgedEndpoint+AppHandler, appname)
   116  			}
   117  		})
   118  
   119  		It("TC_TEST_APP_DEPLOYMENT_6: Test application deployment with restart policy : no restart", func() {
   120  			//Generate the random string and assign as a UID
   121  			UID = "deployment-app-" + edge.GetRandomString(10)
   122  			IsAppDeployed := HandleAddAndDeletePods(http.MethodPut, ctx.Cfg.TestManager+AppHandler, UID, []v1.Container{{Name: UID, Image: ctx.Cfg.AppImageURL[0], ImagePullPolicy: v1.PullIfNotPresent}}, v1.RestartPolicyNever)
   123  			Expect(IsAppDeployed).Should(BeTrue())
   124  			time.Sleep(2 * time.Second)
   125  			CheckPodRunningState(ctx.Cfg.EdgedEndpoint+AppHandler, UID)
   126  		})
   127  
   128  		It("TC_TEST_APP_DEPLOYMENT_7: Test application deployment with restrat policy : always", func() {
   129  			//Generate the random string and assign as a UID
   130  			UID = "deployment-app-" + edge.GetRandomString(10)
   131  			IsAppDeployed := HandleAddAndDeletePods(http.MethodPut, ctx.Cfg.TestManager+AppHandler, UID, []v1.Container{{Name: UID, Image: ctx.Cfg.AppImageURL[0], ImagePullPolicy: v1.PullIfNotPresent}}, v1.RestartPolicyAlways)
   132  			Expect(IsAppDeployed).Should(BeTrue())
   133  			time.Sleep(2 * time.Second)
   134  			CheckPodRunningState(ctx.Cfg.EdgedEndpoint+AppHandler, UID)
   135  		})
   136  
   137  		It("TC_TEST_APP_DEPLOYMENT_8: Test application deployment without liveness probe and service probe", func() {
   138  			//Generate the random string and assign as a UID
   139  			UID = "deployment-app-" + edge.GetRandomString(10)
   140  			IsAppDeployed := HandleAddAndDeletePods(http.MethodPut, ctx.Cfg.TestManager+AppHandler, UID, []v1.Container{{Name: UID, Image: ctx.Cfg.AppImageURL[0], ImagePullPolicy: v1.PullIfNotPresent}}, v1.RestartPolicyOnFailure)
   141  			Expect(IsAppDeployed).Should(BeTrue())
   142  			CheckPodRunningState(ctx.Cfg.EdgedEndpoint+AppHandler, UID)
   143  			IsAppDeleted := HandleAddAndDeletePods(http.MethodDelete, ctx.Cfg.TestManager+AppHandler, UID, []v1.Container{{Name: UID, Image: ctx.Cfg.AppImageURL[0], ImagePullPolicy: v1.PullIfNotPresent}}, v1.RestartPolicyOnFailure)
   144  			Expect(IsAppDeleted).Should(BeTrue())
   145  			CheckPodDeletion(ctx.Cfg.EdgedEndpoint+AppHandler, UID)
   146  		})
   147  
   148  		It("TC_TEST_APP_DEPLOYMENT_9: Test application deployment with liveness probe ", func() {
   149  			//Generate the random string and assign as a UID
   150  			UID = "deployment-app-" + edge.GetRandomString(10)
   151  			httpact := v1.HTTPGetAction{Path: "/var/lib/edged", Scheme: "HTTP", Port: intstr.IntOrString{Type: intstr.Type(1), IntVal: 1884, StrVal: "1884"}}
   152  			handler := v1.Handler{HTTPGet: &httpact}
   153  			probe := v1.Probe{Handler: handler, TimeoutSeconds: 1, InitialDelaySeconds: 10, PeriodSeconds: 15}
   154  			IsAppDeployed := HandleAddAndDeletePods(http.MethodPut, ctx.Cfg.TestManager+AppHandler, UID, []v1.Container{{Name: UID, Image: ctx.Cfg.AppImageURL[0], LivenessProbe: &probe, ImagePullPolicy: v1.PullIfNotPresent}}, v1.RestartPolicyOnFailure)
   155  			Expect(IsAppDeployed).Should(BeTrue())
   156  			CheckPodRunningState(ctx.Cfg.EdgedEndpoint+AppHandler, UID)
   157  			IsAppDeleted := HandleAddAndDeletePods(http.MethodDelete, ctx.Cfg.TestManager+AppHandler, UID, []v1.Container{{Name: UID, Image: ctx.Cfg.AppImageURL[0], LivenessProbe: &probe, ImagePullPolicy: v1.PullIfNotPresent}}, v1.RestartPolicyOnFailure)
   158  			Expect(IsAppDeleted).Should(BeTrue())
   159  			CheckPodDeletion(ctx.Cfg.EdgedEndpoint+AppHandler, UID)
   160  		})
   161  
   162  		It("TC_TEST_APP_DEPLOYMENT_10: Test application deployment with Service probe", func() {
   163  			//Generate the random string and assign as a UID
   164  			UID = "deployment-app-" + edge.GetRandomString(10)
   165  			httpact := v1.HTTPGetAction{Path: "/var/lib/edged", Scheme: "HTTP", Port: intstr.IntOrString{Type: intstr.Type(1), IntVal: 10255, StrVal: "10255"}}
   166  			handler := v1.Handler{HTTPGet: &httpact}
   167  			probe := v1.Probe{Handler: handler, TimeoutSeconds: 1, InitialDelaySeconds: 10, PeriodSeconds: 15}
   168  			IsAppDeployed := HandleAddAndDeletePods(http.MethodPut, ctx.Cfg.TestManager+AppHandler, UID, []v1.Container{{Name: UID, Image: ctx.Cfg.AppImageURL[0], ReadinessProbe: &probe, ImagePullPolicy: v1.PullIfNotPresent}}, v1.RestartPolicyOnFailure)
   169  			Expect(IsAppDeployed).Should(BeTrue())
   170  			CheckPodRunningState(ctx.Cfg.EdgedEndpoint+AppHandler, UID)
   171  			IsAppDeleted := HandleAddAndDeletePods(http.MethodDelete, ctx.Cfg.TestManager+AppHandler, UID, []v1.Container{{Name: UID, Image: ctx.Cfg.AppImageURL[0], LivenessProbe: &probe, ImagePullPolicy: v1.PullIfNotPresent}}, v1.RestartPolicyOnFailure)
   172  			Expect(IsAppDeleted).Should(BeTrue())
   173  			CheckPodDeletion(ctx.Cfg.EdgedEndpoint+AppHandler, UID)
   174  		})
   175  
   176  		It("TC_TEST_APP_DEPLOYMENT_11: Test application deployment with resource memory limit", func() {
   177  			//Generate the random string and assign as a UID
   178  			UID = "deployment-app-" + edge.GetRandomString(10)
   179  			memory, err2 := resource.ParseQuantity("1024Mi")
   180  			if err2 != nil {
   181  				common.Infof("memory error")
   182  			}
   183  			limit := v1.ResourceList{v1.ResourceMemory: memory}
   184  			r := v1.ResourceRequirements{Limits: limit}
   185  
   186  			IsAppDeployed := HandleAddAndDeletePods(http.MethodPut, ctx.Cfg.TestManager+AppHandler, UID, []v1.Container{{Name: UID, Image: ctx.Cfg.AppImageURL[0], Resources: r, ImagePullPolicy: v1.PullIfNotPresent}}, v1.RestartPolicyOnFailure)
   187  			Expect(IsAppDeployed).Should(BeTrue())
   188  			time.Sleep(2 * time.Second)
   189  			CheckPodRunningState(ctx.Cfg.EdgedEndpoint+AppHandler, UID)
   190  			IsAppDeleted := HandleAddAndDeletePods(http.MethodDelete, ctx.Cfg.TestManager+AppHandler, UID, []v1.Container{{Name: UID, Image: ctx.Cfg.AppImageURL[0], Resources: r, ImagePullPolicy: v1.PullIfNotPresent}}, v1.RestartPolicyOnFailure)
   191  			Expect(IsAppDeleted).Should(BeTrue())
   192  			CheckPodDeletion(ctx.Cfg.EdgedEndpoint+AppHandler, UID)
   193  		})
   194  
   195  		It("TC_TEST_APP_DEPLOYMENT_12: Test application deployment with resource cpu limit", func() {
   196  			//Generate the random string and assign as a UID
   197  			UID = "deployment-app-" + edge.GetRandomString(10)
   198  			cpu, err := resource.ParseQuantity("0.75")
   199  			if err != nil {
   200  				common.Infof("cpu resource parsing error")
   201  			}
   202  			limit := v1.ResourceList{v1.ResourceCPU: cpu}
   203  			r := v1.ResourceRequirements{Limits: limit}
   204  
   205  			IsAppDeployed := HandleAddAndDeletePods(http.MethodPut, ctx.Cfg.TestManager+AppHandler, UID, []v1.Container{{Name: UID, Image: ctx.Cfg.AppImageURL[0], Resources: r, ImagePullPolicy: v1.PullIfNotPresent}}, v1.RestartPolicyOnFailure)
   206  			Expect(IsAppDeployed).Should(BeTrue())
   207  			time.Sleep(2 * time.Second)
   208  			CheckPodRunningState(ctx.Cfg.EdgedEndpoint+AppHandler, UID)
   209  			IsAppDeleted := HandleAddAndDeletePods(http.MethodDelete, ctx.Cfg.TestManager+AppHandler, UID, []v1.Container{{Name: UID, Image: ctx.Cfg.AppImageURL[0], Resources: r, ImagePullPolicy: v1.PullIfNotPresent}}, v1.RestartPolicyOnFailure)
   210  			Expect(IsAppDeleted).Should(BeTrue())
   211  			CheckPodDeletion(ctx.Cfg.EdgedEndpoint+AppHandler, UID)
   212  		})
   213  
   214  		It("TC_TEST_APP_DEPLOYMENT_13: Test application deployment with resource memory and cpu limit less than requested", func() {
   215  			//Generate the random string and assign as a UID
   216  			UID = "deployment-app-" + edge.GetRandomString(10)
   217  			cpu, err := resource.ParseQuantity("0.25")
   218  			if err != nil {
   219  				common.Infof("cpu error")
   220  			}
   221  			memory, err := resource.ParseQuantity("256M")
   222  			if err != nil {
   223  				common.Infof("memory error")
   224  			}
   225  			cpuReq, err := resource.ParseQuantity("0.50")
   226  			memoReq, err := resource.ParseQuantity("512Mi")
   227  			limit := v1.ResourceList{v1.ResourceCPU: cpu, v1.ResourceMemory: memory}
   228  			request := v1.ResourceList{v1.ResourceCPU: cpuReq, v1.ResourceMemory: memoReq}
   229  			r := v1.ResourceRequirements{Limits: limit, Requests: request}
   230  
   231  			IsAppDeployed := HandleAddAndDeletePods(http.MethodPut, ctx.Cfg.TestManager+AppHandler, UID, []v1.Container{{Name: UID, Image: ctx.Cfg.AppImageURL[0], Resources: r, ImagePullPolicy: v1.PullIfNotPresent}}, v1.RestartPolicyOnFailure)
   232  			Expect(IsAppDeployed).Should(BeTrue())
   233  			time.Sleep(2 * time.Second)
   234  			CheckPodRunningState(ctx.Cfg.EdgedEndpoint+AppHandler, UID)
   235  			IsAppDeleted := HandleAddAndDeletePods(http.MethodDelete, ctx.Cfg.TestManager+AppHandler, UID, []v1.Container{{Name: UID, Image: ctx.Cfg.AppImageURL[0], Resources: r, ImagePullPolicy: v1.PullIfNotPresent}}, v1.RestartPolicyOnFailure)
   236  			Expect(IsAppDeleted).Should(BeTrue())
   237  			CheckPodDeletion(ctx.Cfg.EdgedEndpoint+AppHandler, UID)
   238  		})
   239  
   240  		It("TC_TEST_APP_DEPLOYMENT_14: Test application deployment with requested and limit values of resource memory and cpu ", func() {
   241  			//Generate the random string and assign as a UID
   242  			UID = "deployment-app-" + edge.GetRandomString(10)
   243  			cpu, err := resource.ParseQuantity("0.75")
   244  			if err != nil {
   245  				common.Infof("cpu error")
   246  			}
   247  			memory, err2 := resource.ParseQuantity("1024Mi")
   248  			if err2 != nil {
   249  				common.Infof("memory error")
   250  			}
   251  			cpuReq, err := resource.ParseQuantity("0.25")
   252  			memoReq, err := resource.ParseQuantity("512Mi")
   253  			limit := v1.ResourceList{v1.ResourceCPU: cpu, v1.ResourceMemory: memory}
   254  			request := v1.ResourceList{v1.ResourceCPU: cpuReq, v1.ResourceMemory: memoReq}
   255  			r := v1.ResourceRequirements{Limits: limit, Requests: request}
   256  			IsAppDeployed := HandleAddAndDeletePods(http.MethodPut, ctx.Cfg.TestManager+AppHandler, UID, []v1.Container{{Name: UID, Image: ctx.Cfg.AppImageURL[0], Resources: r, ImagePullPolicy: v1.PullIfNotPresent}}, v1.RestartPolicyOnFailure)
   257  			Expect(IsAppDeployed).Should(BeTrue())
   258  			time.Sleep(2 * time.Second)
   259  			CheckPodRunningState(ctx.Cfg.EdgedEndpoint+AppHandler, UID)
   260  			IsAppDeleted := HandleAddAndDeletePods(http.MethodDelete, ctx.Cfg.TestManager+AppHandler, UID, []v1.Container{{Name: UID, Image: ctx.Cfg.AppImageURL[0], Resources: r, ImagePullPolicy: v1.PullIfNotPresent}}, v1.RestartPolicyOnFailure)
   261  			Expect(IsAppDeleted).Should(BeTrue())
   262  			CheckPodDeletion(ctx.Cfg.EdgedEndpoint+AppHandler, UID)
   263  		})
   264  
   265  		It("TC_TEST_APP_DEPLOYMENT_15: Test application deployment with container network configuration as host", func() {
   266  			//Generate the random string and assign as a UID
   267  			UID = "deployment-app-" + edge.GetRandomString(10)
   268  			IsAppDeployed := HandleAddAndDeletePods(http.MethodPut, ctx.Cfg.TestManager+AppHandler, UID, []v1.Container{{Name: UID, Image: ctx.Cfg.AppImageURL[0], Ports: []v1.ContainerPort{}, ImagePullPolicy: v1.PullIfNotPresent}}, v1.RestartPolicyOnFailure)
   269  			Expect(IsAppDeployed).Should(BeTrue())
   270  			CheckPodRunningState(ctx.Cfg.EdgedEndpoint+AppHandler, UID)
   271  			IsAppDeleted := HandleAddAndDeletePods(http.MethodDelete, ctx.Cfg.TestManager+AppHandler, UID, []v1.Container{{Name: UID, Image: ctx.Cfg.AppImageURL[0], Ports: []v1.ContainerPort{}, ImagePullPolicy: v1.PullIfNotPresent}}, v1.RestartPolicyOnFailure)
   272  			Expect(IsAppDeleted).Should(BeTrue())
   273  			CheckPodDeletion(ctx.Cfg.EdgedEndpoint+AppHandler, UID)
   274  		})
   275  
   276  		It("TC_TEST_APP_DEPLOYMENT_16: Test application deployment with container network configuration as port mapping", func() {
   277  			//Generate the random string and assign as a UID
   278  			UID = "deployment-app-" + edge.GetRandomString(10)
   279  			port := []v1.ContainerPort{{HostPort: 10256, ContainerPort: 10256, Protocol: v1.ProtocolTCP, HostIP: "127.0.0.1"}}
   280  			IsAppDeployed := HandleAddAndDeletePods(http.MethodPut, ctx.Cfg.TestManager+AppHandler, UID, []v1.Container{{Name: UID, Image: ctx.Cfg.AppImageURL[0], Ports: port, ImagePullPolicy: v1.PullIfNotPresent}}, v1.RestartPolicyOnFailure)
   281  			Expect(IsAppDeployed).Should(BeTrue())
   282  			CheckPodRunningState(ctx.Cfg.EdgedEndpoint+AppHandler, UID)
   283  			IsAppDeleted := HandleAddAndDeletePods(http.MethodDelete, ctx.Cfg.TestManager+AppHandler, UID, []v1.Container{{Name: UID, Image: ctx.Cfg.AppImageURL[0], Ports: port, ImagePullPolicy: v1.PullIfNotPresent}}, v1.RestartPolicyOnFailure)
   284  			Expect(IsAppDeleted).Should(BeTrue())
   285  			CheckPodDeletion(ctx.Cfg.EdgedEndpoint+AppHandler, UID)
   286  		})
   287  	})
   288  })