diff --git a/test/Makefile b/test/Makefile index c7ecf62c..a535b623 100644 --- a/test/Makefile +++ b/test/Makefile @@ -159,6 +159,7 @@ deploy_project: HELM_OPTION+=" --set kdoctorAgent.ingress.enable=false " ; \ fi ; \ HELM_OPTION+=" --set feature.aggregateReport.enabled=true " ; \ + HELM_OPTION+=" --set feature.nethttp_defaultConcurrency=10 " ; \ HELM_OPTION+=" --set feature.aggregateReport.controller.reportHostPath=/var/run/kdoctor/controller " ; \ HELM_OPTION+=" --set kdoctorAgent.debug.logLevel=debug --set kdoctorController.debug.logLevel=debug " ; \ HELM_OPTION+=" --set kdoctorAgent.prometheus.enabled=true --set kdoctorController.prometheus.enabled=true " ; \ diff --git a/test/docs/AppHttpHealth.md b/test/docs/AppHttpHealth.md new file mode 100644 index 00000000..67a1dfd2 --- /dev/null +++ b/test/docs/AppHttpHealth.md @@ -0,0 +1,17 @@ +# E2E Cases for AppHttpHealth + +| Case ID | Title | Priority | Smoke | Status | Other | +|---------|-----------------------------------------------------------------------------|----------|-------|--------|-------------| +| A00001 | Successfully http testing appHttpHealth method GET case | p1 | | done | | +| A00002 | Failed http testing appHttpHealth due to status code case | p1 | | done | | +| A00003 | Failed http testing appHttpHealth due to delay case | p1 | | done | | +| A00004 | Successfully https testing appHttpHealth method GET case | p1 | | done | | +| A00005 | Failed https testing appHttpHealth due to tls case | p1 | | done | | +| A00006 | Successfully http testing appHttpHealth method PUT case | p1 | | done | | +| A00007 | Successfully http testing appHttpHealth method POST With Body case | p1 | | done | | +| A00008 | Successfully http testing appHttpHealth method HEAD case | p1 | | done | | +| A00009 | Successfully http testing appHttpHealth method PATCH case | p1 | | done | | +| A000010 | Successfully http testing appHttpHealth method OPTIONS case | p1 | | done | | +| A000011 | After QPS is specified, the number of requests meets the requirements case | p1 | | done | | +| A000012 | Successfully http testing appHttpHealth due to success rate case | p1 | | done | | +| A000013 | Successfully https testing appHttpHealth method GET Protocol Http2 case | p1 | | done | | diff --git a/test/docs/NetReach.md b/test/docs/NetReach.md new file mode 100644 index 00000000..bce65531 --- /dev/null +++ b/test/docs/NetReach.md @@ -0,0 +1,8 @@ +# E2E Cases for IP NetReach + +| Case ID | Title | Priority | Smoke | Status | Other | +|--------|-------------------------------------------------------------|----------|-------|--------|-------------| +| B00001 | Successfully dual testing netReach case | p1 | | done | | +| B00002 | Successfully ipv4 testing netReach case | p1 | | done | | +| B00003 | Successfully ipv6 testing netReach case | p1 | | done | | + diff --git a/test/docs/schedule.md b/test/docs/schedule.md new file mode 100644 index 00000000..12fa397f --- /dev/null +++ b/test/docs/schedule.md @@ -0,0 +1,9 @@ +# E2E Cases for IP schedule + +| Case ID | Title | Priority | Smoke | Status | Other | +|---------|-------------------------------------------------|----------|-------|--------|-------------| +| C00001 | Successfully testing NetReach crontab case | p1 | | done | | +| C00002 | Successfully testing AppHttpHealth crontab case | p1 | | done | | +| C00003 | Successfully testing NetReach sample case | p1 | | done | | +| C00004 | Successfully testing AppHttpHealth sample case | p1 | | done | | + diff --git a/test/e2e/apphttphealth/apphttphealth_suite_test.go b/test/e2e/apphttphealth/apphttphealth_suite_test.go new file mode 100644 index 00000000..ae6b5fe9 --- /dev/null +++ b/test/e2e/apphttphealth/apphttphealth_suite_test.go @@ -0,0 +1,49 @@ +// Copyright 2023 Authors of kdoctor-io +// SPDX-License-Identifier: Apache-2.0 + +package apphttphealth_test + +import ( + kdoctor_v1beta1 "github.com/kdoctor-io/kdoctor/pkg/k8s/apis/kdoctor.io/v1beta1" + "github.com/kdoctor-io/kdoctor/test/e2e/common" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + e2e "github.com/spidernet-io/e2eframework/framework" + "k8s.io/apimachinery/pkg/runtime" + "testing" +) + +func TestNetReach(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "AppHttpHealth Suite") +} + +var frame *e2e.Framework +var testSvcIP string +var testPodIPs = make([]string, 0) +var httpPort = 80 +var httpsPort = 443 + +var _ = BeforeSuite(func() { + defer GinkgoRecover() + var e error + frame, e = e2e.NewFramework(GinkgoT(), []func(*runtime.Scheme) error{kdoctor_v1beta1.AddToScheme}) + Expect(e).NotTo(HaveOccurred()) + + testSvc, e := frame.GetService(common.KDoctorTestSVCName, common.KDoctorTestDSNamespace) + Expect(e).NotTo(HaveOccurred(), "get kdoctor test service") + testSvcIP = testSvc.Spec.ClusterIP + GinkgoWriter.Println("get test service ip %v", testSvcIP) + + testDS, e := frame.GetDaemonSet(common.KDoctorAgentDSName, common.KDoctorAgentNS) + Expect(e).NotTo(HaveOccurred(), "get kdoctor test daemonset") + + testPods, e := frame.GetDaemonSetPodList(testDS) + Expect(e).NotTo(HaveOccurred(), "get kdoctor test pod list") + + for _, v := range testPods.Items { + testPodIPs = append(testPodIPs, v.Status.PodIP) + } + GinkgoWriter.Println("get test pod ips %v", testPodIPs) + +}) diff --git a/test/e2e/apphttphealth/apphttphealth_test.go b/test/e2e/apphttphealth/apphttphealth_test.go new file mode 100644 index 00000000..20b1aa72 --- /dev/null +++ b/test/e2e/apphttphealth/apphttphealth_test.go @@ -0,0 +1,651 @@ +// Copyright 2023 Authors of kdoctor-io +// SPDX-License-Identifier: Apache-2.0 + +package apphttphealth_test + +import ( + "fmt" + "github.com/kdoctor-io/kdoctor/pkg/k8s/apis/kdoctor.io/v1beta1" + "github.com/kdoctor-io/kdoctor/pkg/pluginManager" + "github.com/kdoctor-io/kdoctor/test/e2e/common" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + "github.com/spidernet-io/e2eframework/tools" +) + +var _ = Describe("testing appHttpHealth test ", Label("appHttpHealth"), func() { + + It("success http testing appHttpHealth method GET", Label("A00001"), func() { + var e error + successRate := float64(1) + successMean := int64(1500) + crontab := "0 1" + appHttpHealthName := "apphttphealth-get" + tools.RandomName() + + appHttpHealth := new(v1beta1.AppHttpHealthy) + appHttpHealth.Name = appHttpHealthName + + // successCondition + successCondition := new(v1beta1.NetSuccessCondition) + successCondition.SuccessRate = &successRate + successCondition.MeanAccessDelayInMs = &successMean + appHttpHealth.Spec.SuccessCondition = successCondition + + // target + target := new(v1beta1.AppHttpHealthyTarget) + target.Method = "GET" + target.Host = fmt.Sprintf("http://%s:%d", testSvcIP, httpPort) + appHttpHealth.Spec.Target = target + + // request + request := new(v1beta1.NetHttpRequest) + request.PerRequestTimeoutInMS = 1000 + request.QPS = 1 + request.DurationInSecond = 5 + appHttpHealth.Spec.Request = request + + // Schedule + Schedule := new(v1beta1.SchedulePlan) + Schedule.Schedule = &crontab + Schedule.RoundNumber = 1 + Schedule.RoundTimeoutMinute = 1 + appHttpHealth.Spec.Schedule = Schedule + + e = frame.CreateResource(appHttpHealth) + Expect(e).NotTo(HaveOccurred(), "create appHttpHealth resource") + + e = common.WaitKdoctorTaskDone(frame, appHttpHealth, pluginManager.KindNameAppHttpHealthy, 120) + Expect(e).NotTo(HaveOccurred(), "wait appHttpHealth task finish") + + taskResult, e := common.GetKdoctorTaskResult(frame, appHttpHealth, pluginManager.KindNameAppHttpHealthy) + Expect(e).NotTo(HaveOccurred(), "get appHttpHealth task result") + Expect(taskResult).Should(BeTrue(), "task result need success") + + }) + + It("failed http testing appHttpHealth due to status code", Label("A00002"), func() { + var e error + successRate := float64(1) + successMean := int64(1500) + crontab := "0 1" + expectStatusCode := 205 + appHttpHealthName := "apphttphealth-get" + tools.RandomName() + + appHttpHealth := new(v1beta1.AppHttpHealthy) + appHttpHealth.Name = appHttpHealthName + + // successCondition + successCondition := new(v1beta1.NetSuccessCondition) + successCondition.SuccessRate = &successRate + successCondition.MeanAccessDelayInMs = &successMean + successCondition.StatusCode = &expectStatusCode + appHttpHealth.Spec.SuccessCondition = successCondition + + // target + target := new(v1beta1.AppHttpHealthyTarget) + target.Method = "GET" + target.Host = fmt.Sprintf("http://%s:%d", testSvcIP, httpPort) + appHttpHealth.Spec.Target = target + + // request + request := new(v1beta1.NetHttpRequest) + request.PerRequestTimeoutInMS = 1000 + request.QPS = 1 + request.DurationInSecond = 5 + appHttpHealth.Spec.Request = request + + // Schedule + Schedule := new(v1beta1.SchedulePlan) + Schedule.Schedule = &crontab + Schedule.RoundNumber = 1 + Schedule.RoundTimeoutMinute = 1 + appHttpHealth.Spec.Schedule = Schedule + + e = frame.CreateResource(appHttpHealth) + Expect(e).NotTo(HaveOccurred(), "create appHttpHealth resource") + + e = common.WaitKdoctorTaskDone(frame, appHttpHealth, pluginManager.KindNameAppHttpHealthy, 120) + Expect(e).NotTo(HaveOccurred(), "wait appHttpHealth task finish") + + taskResult, e := common.GetKdoctorTaskResult(frame, appHttpHealth, pluginManager.KindNameAppHttpHealthy) + Expect(e).NotTo(HaveOccurred(), "get appHttpHealth task result") + Expect(taskResult).Should(BeFalse(), "task result need failed") + + }) + + It("Failed http testing appHttpHealth due to delay ", Label("A00003"), func() { + var e error + successRate := float64(1) + successMean := int64(200) + crontab := "0 1" + appHttpHealthName := "apphttphealth-get" + tools.RandomName() + + appHttpHealth := new(v1beta1.AppHttpHealthy) + appHttpHealth.Name = appHttpHealthName + + // successCondition + successCondition := new(v1beta1.NetSuccessCondition) + successCondition.SuccessRate = &successRate + successCondition.MeanAccessDelayInMs = &successMean + appHttpHealth.Spec.SuccessCondition = successCondition + + // target + target := new(v1beta1.AppHttpHealthyTarget) + target.Method = "GET" + target.Host = fmt.Sprintf("http://%s:%d/?delay=1", testSvcIP, httpPort) + appHttpHealth.Spec.Target = target + + // request + request := new(v1beta1.NetHttpRequest) + request.PerRequestTimeoutInMS = 1000 + request.QPS = 1 + request.DurationInSecond = 5 + appHttpHealth.Spec.Request = request + + // Schedule + Schedule := new(v1beta1.SchedulePlan) + Schedule.Schedule = &crontab + Schedule.RoundNumber = 1 + Schedule.RoundTimeoutMinute = 1 + appHttpHealth.Spec.Schedule = Schedule + + e = frame.CreateResource(appHttpHealth) + Expect(e).NotTo(HaveOccurred(), "create appHttpHealth resource") + + e = common.WaitKdoctorTaskDone(frame, appHttpHealth, pluginManager.KindNameAppHttpHealthy, 120) + Expect(e).NotTo(HaveOccurred(), "wait appHttpHealth task finish") + + taskResult, e := common.GetKdoctorTaskResult(frame, appHttpHealth, pluginManager.KindNameAppHttpHealthy) + Expect(e).NotTo(HaveOccurred(), "get appHttpHealth task result") + Expect(taskResult).Should(BeFalse(), "task result need failed") + + }) + + It("success https testing appHttpHealth method GET", Label("A00004"), func() { + var e error + successRate := float64(1) + successMean := int64(1500) + crontab := "0 1" + appHttpHealthName := "apphttphealth-get" + tools.RandomName() + + appHttpHealth := new(v1beta1.AppHttpHealthy) + appHttpHealth.Name = appHttpHealthName + + // successCondition + successCondition := new(v1beta1.NetSuccessCondition) + successCondition.SuccessRate = &successRate + successCondition.MeanAccessDelayInMs = &successMean + appHttpHealth.Spec.SuccessCondition = successCondition + + // target + target := new(v1beta1.AppHttpHealthyTarget) + target.Method = "GET" + target.Host = fmt.Sprintf("https://%s:%d", testSvcIP, httpsPort) + target.TlsSecretName = &common.TlsClientName + target.TlsSecretNamespace = &common.TlsClientNamespace + appHttpHealth.Spec.Target = target + + // request + request := new(v1beta1.NetHttpRequest) + request.PerRequestTimeoutInMS = 1000 + request.QPS = 1 + request.DurationInSecond = 5 + appHttpHealth.Spec.Request = request + + // Schedule + Schedule := new(v1beta1.SchedulePlan) + Schedule.Schedule = &crontab + Schedule.RoundNumber = 1 + Schedule.RoundTimeoutMinute = 1 + appHttpHealth.Spec.Schedule = Schedule + + e = frame.CreateResource(appHttpHealth) + Expect(e).NotTo(HaveOccurred(), "create appHttpHealth resource") + + e = common.WaitKdoctorTaskDone(frame, appHttpHealth, pluginManager.KindNameAppHttpHealthy, 120) + Expect(e).NotTo(HaveOccurred(), "wait appHttpHealth task finish") + + taskResult, e := common.GetKdoctorTaskResult(frame, appHttpHealth, pluginManager.KindNameAppHttpHealthy) + Expect(e).NotTo(HaveOccurred(), "get appHttpHealth task result") + Expect(taskResult).Should(BeTrue(), "task result need success") + + }) + + It("failed https testing appHttpHealth due to tls", Label("A00005"), func() { + var e error + successRate := float64(1) + successMean := int64(1500) + crontab := "0 1" + appHttpHealthName := "apphttphealth-get" + tools.RandomName() + + appHttpHealth := new(v1beta1.AppHttpHealthy) + appHttpHealth.Name = appHttpHealthName + + // successCondition + successCondition := new(v1beta1.NetSuccessCondition) + successCondition.SuccessRate = &successRate + successCondition.MeanAccessDelayInMs = &successMean + appHttpHealth.Spec.SuccessCondition = successCondition + + // target + target := new(v1beta1.AppHttpHealthyTarget) + target.Method = "GET" + target.Host = fmt.Sprintf("https://%s:%d", testSvcIP, httpsPort) + appHttpHealth.Spec.Target = target + + // request + request := new(v1beta1.NetHttpRequest) + request.PerRequestTimeoutInMS = 1000 + request.QPS = 1 + request.DurationInSecond = 5 + appHttpHealth.Spec.Request = request + + // Schedule + Schedule := new(v1beta1.SchedulePlan) + Schedule.Schedule = &crontab + Schedule.RoundNumber = 1 + Schedule.RoundTimeoutMinute = 1 + appHttpHealth.Spec.Schedule = Schedule + + e = frame.CreateResource(appHttpHealth) + Expect(e).NotTo(HaveOccurred(), "create appHttpHealth resource") + + e = common.WaitKdoctorTaskDone(frame, appHttpHealth, pluginManager.KindNameAppHttpHealthy, 120) + Expect(e).NotTo(HaveOccurred(), "wait appHttpHealth task finish") + + taskResult, e := common.GetKdoctorTaskResult(frame, appHttpHealth, pluginManager.KindNameAppHttpHealthy) + Expect(e).NotTo(HaveOccurred(), "get appHttpHealth task result") + Expect(taskResult).Should(BeTrue(), "task result need success") + + }) + + It("Successfully http testing appHttpHealth method PUT ", Label("A00006"), func() { + var e error + successRate := float64(1) + successMean := int64(1500) + crontab := "0 1" + appHttpHealthName := "apphttphealth-put" + tools.RandomName() + + appHttpHealth := new(v1beta1.AppHttpHealthy) + appHttpHealth.Name = appHttpHealthName + + // successCondition + successCondition := new(v1beta1.NetSuccessCondition) + successCondition.SuccessRate = &successRate + successCondition.MeanAccessDelayInMs = &successMean + appHttpHealth.Spec.SuccessCondition = successCondition + + // target + target := new(v1beta1.AppHttpHealthyTarget) + target.Method = "PUT" + target.Host = fmt.Sprintf("http://%s:%d", testSvcIP, httpPort) + appHttpHealth.Spec.Target = target + + // request + request := new(v1beta1.NetHttpRequest) + request.PerRequestTimeoutInMS = 1000 + request.QPS = 1 + request.DurationInSecond = 5 + appHttpHealth.Spec.Request = request + + // Schedule + Schedule := new(v1beta1.SchedulePlan) + Schedule.Schedule = &crontab + Schedule.RoundNumber = 1 + Schedule.RoundTimeoutMinute = 1 + appHttpHealth.Spec.Schedule = Schedule + + e = frame.CreateResource(appHttpHealth) + Expect(e).NotTo(HaveOccurred(), "create appHttpHealth resource") + + e = common.WaitKdoctorTaskDone(frame, appHttpHealth, pluginManager.KindNameAppHttpHealthy, 120) + Expect(e).NotTo(HaveOccurred(), "wait appHttpHealth task finish") + + taskResult, e := common.GetKdoctorTaskResult(frame, appHttpHealth, pluginManager.KindNameAppHttpHealthy) + Expect(e).NotTo(HaveOccurred(), "get appHttpHealth task result") + Expect(taskResult).Should(BeTrue(), "task result need success") + + }) + + It("Successfully http testing appHttpHealth method POST With Body", Label("A00007"), func() { + var e error + successRate := float64(1) + successMean := int64(1500) + crontab := "0 1" + appHttpHealthName := "apphttphealth-post" + tools.RandomName() + + appHttpHealth := new(v1beta1.AppHttpHealthy) + appHttpHealth.Name = appHttpHealthName + + // successCondition + successCondition := new(v1beta1.NetSuccessCondition) + successCondition.SuccessRate = &successRate + successCondition.MeanAccessDelayInMs = &successMean + appHttpHealth.Spec.SuccessCondition = successCondition + + // target + target := new(v1beta1.AppHttpHealthyTarget) + target.Method = "POST" + target.Host = fmt.Sprintf("http://%s:%d", testSvcIP, httpPort) + target.BodyConfigName = &common.BodyConfigMapName + target.BodyConfigNamespace = &common.BodyConfigMapNamespace + target.Header = []string{"Content-Type: application/json"} + appHttpHealth.Spec.Target = target + + // request + request := new(v1beta1.NetHttpRequest) + request.PerRequestTimeoutInMS = 1000 + request.QPS = 1 + request.DurationInSecond = 5 + appHttpHealth.Spec.Request = request + + // Schedule + Schedule := new(v1beta1.SchedulePlan) + Schedule.Schedule = &crontab + Schedule.RoundNumber = 1 + Schedule.RoundTimeoutMinute = 1 + appHttpHealth.Spec.Schedule = Schedule + + e = frame.CreateResource(appHttpHealth) + Expect(e).NotTo(HaveOccurred(), "create appHttpHealth resource") + + e = common.WaitKdoctorTaskDone(frame, appHttpHealth, pluginManager.KindNameAppHttpHealthy, 120) + Expect(e).NotTo(HaveOccurred(), "wait appHttpHealth task finish") + + taskResult, e := common.GetKdoctorTaskResult(frame, appHttpHealth, pluginManager.KindNameAppHttpHealthy) + Expect(e).NotTo(HaveOccurred(), "get appHttpHealth task result") + Expect(taskResult).Should(BeTrue(), "task result need success") + + }) + + It("Successfully http testing appHttpHealth method HEAD", Label("A00008"), func() { + var e error + successRate := float64(1) + successMean := int64(1500) + crontab := "0 1" + appHttpHealthName := "apphttphealth-head" + tools.RandomName() + + appHttpHealth := new(v1beta1.AppHttpHealthy) + appHttpHealth.Name = appHttpHealthName + + // successCondition + successCondition := new(v1beta1.NetSuccessCondition) + successCondition.SuccessRate = &successRate + successCondition.MeanAccessDelayInMs = &successMean + appHttpHealth.Spec.SuccessCondition = successCondition + + // target + target := new(v1beta1.AppHttpHealthyTarget) + target.Method = "HEAD" + target.Host = fmt.Sprintf("http://%s:%d", testSvcIP, httpPort) + appHttpHealth.Spec.Target = target + + // request + request := new(v1beta1.NetHttpRequest) + request.PerRequestTimeoutInMS = 1000 + request.QPS = 1 + request.DurationInSecond = 5 + appHttpHealth.Spec.Request = request + + // Schedule + Schedule := new(v1beta1.SchedulePlan) + Schedule.Schedule = &crontab + Schedule.RoundNumber = 1 + Schedule.RoundTimeoutMinute = 1 + appHttpHealth.Spec.Schedule = Schedule + + e = frame.CreateResource(appHttpHealth) + Expect(e).NotTo(HaveOccurred(), "create appHttpHealth resource") + + e = common.WaitKdoctorTaskDone(frame, appHttpHealth, pluginManager.KindNameAppHttpHealthy, 120) + Expect(e).NotTo(HaveOccurred(), "wait appHttpHealth task finish") + + taskResult, e := common.GetKdoctorTaskResult(frame, appHttpHealth, pluginManager.KindNameAppHttpHealthy) + Expect(e).NotTo(HaveOccurred(), "get appHttpHealth task result") + Expect(taskResult).Should(BeTrue(), "task result need success") + + }) + + It("Successfully http testing appHttpHealth method PATCH", Label("A00009"), func() { + var e error + successRate := float64(1) + successMean := int64(1500) + crontab := "0 1" + appHttpHealthName := "apphttphealth-patch" + tools.RandomName() + + appHttpHealth := new(v1beta1.AppHttpHealthy) + appHttpHealth.Name = appHttpHealthName + + // successCondition + successCondition := new(v1beta1.NetSuccessCondition) + successCondition.SuccessRate = &successRate + successCondition.MeanAccessDelayInMs = &successMean + appHttpHealth.Spec.SuccessCondition = successCondition + + // target + target := new(v1beta1.AppHttpHealthyTarget) + target.Method = "PATCH" + target.Host = fmt.Sprintf("http://%s:%d", testSvcIP, httpPort) + appHttpHealth.Spec.Target = target + + // request + request := new(v1beta1.NetHttpRequest) + request.PerRequestTimeoutInMS = 1000 + request.QPS = 1 + request.DurationInSecond = 5 + appHttpHealth.Spec.Request = request + + // Schedule + Schedule := new(v1beta1.SchedulePlan) + Schedule.Schedule = &crontab + Schedule.RoundNumber = 1 + Schedule.RoundTimeoutMinute = 1 + appHttpHealth.Spec.Schedule = Schedule + + e = frame.CreateResource(appHttpHealth) + Expect(e).NotTo(HaveOccurred(), "create appHttpHealth resource") + + e = common.WaitKdoctorTaskDone(frame, appHttpHealth, pluginManager.KindNameAppHttpHealthy, 120) + Expect(e).NotTo(HaveOccurred(), "wait appHttpHealth task finish") + + taskResult, e := common.GetKdoctorTaskResult(frame, appHttpHealth, pluginManager.KindNameAppHttpHealthy) + Expect(e).NotTo(HaveOccurred(), "get appHttpHealth task result") + Expect(taskResult).Should(BeTrue(), "task result need success") + + }) + + It("Successfully http testing appHttpHealth method OPTIONS", Label("A00010"), func() { + var e error + successRate := float64(1) + successMean := int64(1500) + crontab := "0 1" + appHttpHealthName := "apphttphealth-options" + tools.RandomName() + + appHttpHealth := new(v1beta1.AppHttpHealthy) + appHttpHealth.Name = appHttpHealthName + + // successCondition + successCondition := new(v1beta1.NetSuccessCondition) + successCondition.SuccessRate = &successRate + successCondition.MeanAccessDelayInMs = &successMean + appHttpHealth.Spec.SuccessCondition = successCondition + + // target + target := new(v1beta1.AppHttpHealthyTarget) + target.Method = "OPTIONS" + target.Host = fmt.Sprintf("http://%s:%d", testSvcIP, httpPort) + appHttpHealth.Spec.Target = target + + // request + request := new(v1beta1.NetHttpRequest) + request.PerRequestTimeoutInMS = 1000 + request.QPS = 1 + request.DurationInSecond = 5 + appHttpHealth.Spec.Request = request + + // Schedule + Schedule := new(v1beta1.SchedulePlan) + Schedule.Schedule = &crontab + Schedule.RoundNumber = 1 + Schedule.RoundTimeoutMinute = 1 + appHttpHealth.Spec.Schedule = Schedule + + e = frame.CreateResource(appHttpHealth) + Expect(e).NotTo(HaveOccurred(), "create appHttpHealth resource") + + e = common.WaitKdoctorTaskDone(frame, appHttpHealth, pluginManager.KindNameAppHttpHealthy, 120) + Expect(e).NotTo(HaveOccurred(), "wait appHttpHealth task finish") + + taskResult, e := common.GetKdoctorTaskResult(frame, appHttpHealth, pluginManager.KindNameAppHttpHealthy) + Expect(e).NotTo(HaveOccurred(), "get appHttpHealth task result") + Expect(taskResult).Should(BeTrue(), "task result need success") + + }) + + It("After QPS is specified, the number of requests meets the requirements", Label("A000011"), func() { + var e error + successRate := float64(1) + successMean := int64(1500) + crontab := "0 1" + appHttpHealthName := "apphttphealth-head" + tools.RandomName() + + appHttpHealth := new(v1beta1.AppHttpHealthy) + appHttpHealth.Name = appHttpHealthName + + // successCondition + successCondition := new(v1beta1.NetSuccessCondition) + successCondition.SuccessRate = &successRate + successCondition.MeanAccessDelayInMs = &successMean + appHttpHealth.Spec.SuccessCondition = successCondition + + // target + target := new(v1beta1.AppHttpHealthyTarget) + target.Method = "GET" + target.Host = fmt.Sprintf("http://%s:%d", testSvcIP, httpPort) + appHttpHealth.Spec.Target = target + + // request + request := new(v1beta1.NetHttpRequest) + request.PerRequestTimeoutInMS = 1000 + request.QPS = 1 + request.DurationInSecond = 5 + appHttpHealth.Spec.Request = request + + // Schedule + Schedule := new(v1beta1.SchedulePlan) + Schedule.Schedule = &crontab + Schedule.RoundNumber = 1 + Schedule.RoundTimeoutMinute = 1 + appHttpHealth.Spec.Schedule = Schedule + + e = frame.CreateResource(appHttpHealth) + Expect(e).NotTo(HaveOccurred(), "create appHttpHealth resource") + + e = common.WaitKdoctorTaskDone(frame, appHttpHealth, pluginManager.KindNameAppHttpHealthy, 120) + Expect(e).NotTo(HaveOccurred(), "wait appHttpHealth task finish") + + taskResult, e := common.GetKdoctorTaskResult(frame, appHttpHealth, pluginManager.KindNameAppHttpHealthy) + Expect(e).NotTo(HaveOccurred(), "get appHttpHealth task result") + Expect(taskResult).Should(BeTrue(), "task result need success") + + }) + + It("Successfully http testing appHttpHealth due to success rate", Label("A000012"), func() { + var e error + successRate := float64(0.2) + successMean := int64(1200) + crontab := "0 1" + appHttpHealthName := "apphttphealth-get" + tools.RandomName() + + appHttpHealth := new(v1beta1.AppHttpHealthy) + appHttpHealth.Name = appHttpHealthName + + // successCondition + successCondition := new(v1beta1.NetSuccessCondition) + successCondition.SuccessRate = &successRate + successCondition.MeanAccessDelayInMs = &successMean + appHttpHealth.Spec.SuccessCondition = successCondition + + // target + target := new(v1beta1.AppHttpHealthyTarget) + target.Method = "GET" + target.Host = fmt.Sprintf("http://%s:%d/delay?=1", testSvcIP, httpPort) + appHttpHealth.Spec.Target = target + + // request + request := new(v1beta1.NetHttpRequest) + request.PerRequestTimeoutInMS = 1000 + request.QPS = 1 + request.DurationInSecond = 5 + appHttpHealth.Spec.Request = request + + // Schedule + Schedule := new(v1beta1.SchedulePlan) + Schedule.Schedule = &crontab + Schedule.RoundNumber = 1 + Schedule.RoundTimeoutMinute = 1 + appHttpHealth.Spec.Schedule = Schedule + + e = frame.CreateResource(appHttpHealth) + Expect(e).NotTo(HaveOccurred(), "create appHttpHealth resource") + + e = common.WaitKdoctorTaskDone(frame, appHttpHealth, pluginManager.KindNameAppHttpHealthy, 120) + Expect(e).NotTo(HaveOccurred(), "wait appHttpHealth task finish") + + taskResult, e := common.GetKdoctorTaskResult(frame, appHttpHealth, pluginManager.KindNameAppHttpHealthy) + Expect(e).NotTo(HaveOccurred(), "get appHttpHealth task result") + Expect(taskResult).Should(BeTrue(), "task result need success") + + }) + + It("Successfully https testing appHttpHealth method GET Protocol Http2", Label("A000013"), func() { + var e error + successRate := float64(1) + successMean := int64(1500) + crontab := "0 1" + appHttpHealthName := "apphttphealth-get" + tools.RandomName() + + appHttpHealth := new(v1beta1.AppHttpHealthy) + appHttpHealth.Name = appHttpHealthName + + // successCondition + successCondition := new(v1beta1.NetSuccessCondition) + successCondition.SuccessRate = &successRate + successCondition.MeanAccessDelayInMs = &successMean + appHttpHealth.Spec.SuccessCondition = successCondition + + // target + target := new(v1beta1.AppHttpHealthyTarget) + target.Method = "GET" + target.Host = fmt.Sprintf("http://%s:%d", testSvcIP, httpPort) + target.TlsSecretName = &common.TlsClientName + target.TlsSecretNamespace = &common.TlsClientNamespace + target.Http2 = true + appHttpHealth.Spec.Target = target + + // request + request := new(v1beta1.NetHttpRequest) + request.PerRequestTimeoutInMS = 1000 + request.QPS = 1 + request.DurationInSecond = 5 + appHttpHealth.Spec.Request = request + + // Schedule + Schedule := new(v1beta1.SchedulePlan) + Schedule.Schedule = &crontab + Schedule.RoundNumber = 1 + Schedule.RoundTimeoutMinute = 1 + appHttpHealth.Spec.Schedule = Schedule + + e = frame.CreateResource(appHttpHealth) + Expect(e).NotTo(HaveOccurred(), "create appHttpHealth resource") + + e = common.WaitKdoctorTaskDone(frame, appHttpHealth, pluginManager.KindNameAppHttpHealthy, 120) + Expect(e).NotTo(HaveOccurred(), "wait appHttpHealth task finish") + + taskResult, e := common.GetKdoctorTaskResult(frame, appHttpHealth, pluginManager.KindNameAppHttpHealthy) + Expect(e).NotTo(HaveOccurred(), "get appHttpHealth task result") + Expect(taskResult).Should(BeTrue(), "task result need success") + + }) +}) diff --git a/test/e2e/common/constants.go b/test/e2e/common/constants.go new file mode 100644 index 00000000..bcb8cbc7 --- /dev/null +++ b/test/e2e/common/constants.go @@ -0,0 +1,24 @@ +package common + +var ( + MultusDefaultAnnotationKey = "v1.multus-cni.io/default-network" + MultusAddonAnnotation_Key = "k8s.v1.cni.cncf.io/networks" +) + +var ( + MultusNamespace = "kube-system" + MultusCRName = "ptp" + + KDoctorAgentNS = "kube-system" + KDoctorAgentDSName = "kdoctor-agent" + + KDoctorTestDSName = "kdoctor-test" + KDoctorTestSVCName = "kdoctor-test" + KDoctorTestDSNamespace = "kube-system" + + TlsClientName = "kdoctor-agent-client-cert" + TlsClientNamespace = "kube-system" + + BodyConfigMapName = "kdoctor-test-body" + BodyConfigMapNamespace = "kube-system" +) diff --git a/test/e2e/common/tools.go b/test/e2e/common/tools.go new file mode 100644 index 00000000..d7f1568d --- /dev/null +++ b/test/e2e/common/tools.go @@ -0,0 +1,172 @@ +// Copyright 2023 Authors of kdoctor-io +// SPDX-License-Identifier: Apache-2.0 + +package common + +import ( + "fmt" + "github.com/kdoctor-io/kdoctor/pkg/pluginManager" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "time" + + v1 "github.com/kdoctor-io/kdoctor/pkg/k8s/apis/kdoctor.io/v1beta1" + frame "github.com/spidernet-io/e2eframework/framework" + "sigs.k8s.io/controller-runtime/pkg/client" +) + +func WaitKdoctorTaskDone(f *frame.Framework, task client.Object, taskKind string, timeout int) error { + interval := time.Duration(10) + switch taskKind { + case pluginManager.KindNameNetReach: + fake := &v1.NetReach{ + ObjectMeta: metav1.ObjectMeta{ + Name: task.GetName(), + }, + } + key := client.ObjectKeyFromObject(fake) + after := time.After(time.Duration(timeout) * time.Second) + + for { + select { + case <-after: + return fmt.Errorf("timeout wait task NetReach %s finish", task.GetName()) + default: + rs := &v1.NetReach{} + if err := f.GetResource(key, rs); err != nil { + return fmt.Errorf("failed get resource NetReach %s", task.GetName()) + } + if rs.Status.Finish { + return nil + } + time.Sleep(time.Second * interval) + } + } + case pluginManager.KindNameAppHttpHealthy: + fake := &v1.AppHttpHealthy{ + ObjectMeta: metav1.ObjectMeta{ + Name: task.GetName(), + }, + } + key := client.ObjectKeyFromObject(fake) + after := time.After(time.Duration(timeout) * time.Second) + + for { + select { + case <-after: + return fmt.Errorf("timeout wait task AppHttpHealthy %s finish", task.GetName()) + default: + rs := &v1.AppHttpHealthy{} + if err := f.GetResource(key, rs); err != nil { + return fmt.Errorf("failed get resource AppHttpHealthy %s", task.GetName()) + } + if rs.Status.Finish { + return nil + } + time.Sleep(time.Second * interval) + } + } + case pluginManager.KindNameNetdns: + fake := &v1.Netdns{ + ObjectMeta: metav1.ObjectMeta{ + Name: task.GetName(), + }, + } + key := client.ObjectKeyFromObject(fake) + after := time.After(time.Duration(timeout) * time.Second) + + for { + select { + case <-after: + return fmt.Errorf("timeout wait task Netdns %s finish", task.GetName()) + default: + rs := &v1.NetReach{} + if err := f.GetResource(key, rs); err != nil { + return fmt.Errorf("failed get resource Netdns %s", task.GetName()) + } + if rs.Status.Finish { + return nil + } + time.Sleep(time.Second * interval) + } + } + default: + return fmt.Errorf("unknown task type: %s", task.GetObjectKind().GroupVersionKind().Kind) + } + +} + +func GetKdoctorTaskResult(f *frame.Framework, task client.Object, taskKind string) (bool, error) { + var statusFail = "fail" + switch taskKind { + case pluginManager.KindNameNetReach: + fake := &v1.NetReach{ + ObjectMeta: metav1.ObjectMeta{ + Name: task.GetName(), + }, + } + key := client.ObjectKeyFromObject(fake) + + // TODO ii2day Query through the aggregation API + rs := &v1.NetReach{} + if err := f.GetResource(key, rs); err != nil { + return false, fmt.Errorf("failed get resource NetReach %s", task.GetName()) + } + + for _, t := range rs.Status.History { + if t.Status == statusFail { + return false, nil + } + } + + case pluginManager.KindNameAppHttpHealthy: + fake := &v1.AppHttpHealthy{ + ObjectMeta: metav1.ObjectMeta{ + Name: task.GetName(), + }, + } + key := client.ObjectKeyFromObject(fake) + // TODO ii2day Query through the aggregation API + rs := &v1.AppHttpHealthy{} + if err := f.GetResource(key, rs); err != nil { + return false, fmt.Errorf("failed get resource AppHttpHealthy %s", task.GetName()) + } + + for _, t := range rs.Status.History { + if t.Status == statusFail { + return false, nil + } + } + case pluginManager.KindNameNetdns: + fake := &v1.Netdns{ + ObjectMeta: metav1.ObjectMeta{ + Name: task.GetName(), + }, + } + key := client.ObjectKeyFromObject(fake) + // TODO ii2day Query through the aggregation API + rs := &v1.Netdns{} + if err := f.GetResource(key, rs); err != nil { + return false, fmt.Errorf("failed get resource Netdns %s", task.GetName()) + } + + for _, t := range rs.Status.History { + if t.Status == statusFail { + return false, nil + } + } + default: + return false, fmt.Errorf("unknown task type ") + } + + return true, nil +} + +func GetRequestCount(ip string) int { + + return 0 +} + +func DeleteRequestCount(ip string) error { + + return nil +} diff --git a/test/e2e/example/example_suite_test.go b/test/e2e/example/example_suite_test.go deleted file mode 100644 index f676830e..00000000 --- a/test/e2e/example/example_suite_test.go +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2023 Authors of kdoctor-io -// SPDX-License-Identifier: Apache-2.0 -package example_test - -import ( - "testing" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - e2e "github.com/spidernet-io/e2eframework/framework" - // "k8s.io/apimachinery/pkg/runtime" -) - -func TestAssignIP(t *testing.T) { - RegisterFailHandler(Fail) - RunSpecs(t, "example Suite") -} - -var frame *e2e.Framework - -var _ = BeforeSuite(func() { - defer GinkgoRecover() - var e error - frame, e = e2e.NewFramework(GinkgoT(), nil) - Expect(e).NotTo(HaveOccurred()) - -}) diff --git a/test/e2e/example/example_test.go b/test/e2e/example/example_test.go deleted file mode 100644 index 4fbcc688..00000000 --- a/test/e2e/example/example_test.go +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2023 Authors of kdoctor-io -// SPDX-License-Identifier: Apache-2.0 -package example_test - -import ( - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" -) - -var _ = Describe("example ", Label("example"), func() { - - It("example", Label("example-1"), func() { - GinkgoWriter.Printf("cluster information: %+v \n", frame.Info) - - d, e := frame.GetDaemonSet("test", "default") - Expect(e).NotTo(HaveOccurred(), "failed to get daemonset ") - GinkgoWriter.Printf("daemonset: %+v \n", d) - }) -}) diff --git a/test/e2e/netreach/netreach_suite_test.go b/test/e2e/netreach/netreach_suite_test.go new file mode 100644 index 00000000..01547d6f --- /dev/null +++ b/test/e2e/netreach/netreach_suite_test.go @@ -0,0 +1,45 @@ +// Copyright 2023 Authors of kdoctor-io +// SPDX-License-Identifier: Apache-2.0 + +package netreach_test + +import ( + kdoctor_v1beta1 "github.com/kdoctor-io/kdoctor/pkg/k8s/apis/kdoctor.io/v1beta1" + "github.com/kdoctor-io/kdoctor/test/e2e/common" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + e2e "github.com/spidernet-io/e2eframework/framework" + v1 "k8s.io/api/apps/v1" + "k8s.io/apimachinery/pkg/runtime" + "testing" + // "k8s.io/apimachinery/pkg/runtime" +) + +func TestNetReach(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "NetReach Suite") +} + +var frame *e2e.Framework +var agentDS *v1.DaemonSet +var _ = BeforeSuite(func() { + defer GinkgoRecover() + var e error + frame, e = e2e.NewFramework(GinkgoT(), []func(*runtime.Scheme) error{kdoctor_v1beta1.AddToScheme}) + Expect(e).NotTo(HaveOccurred()) + + agentDS, e = frame.GetDaemonSet(common.KDoctorAgentDSName, common.KDoctorAgentNS) + Expect(e).NotTo(HaveOccurred(), "get kdoctor-agent daemonset") + + // add agent multus network + // TODO ii2day + //agentDS.Annotations[common.MultusDefaultAnnotationKey] = fmt.Sprintf("%s/%s", common.MultusNamespace, common.MultusCRName) + //agentDS.Annotations[common.MultusAddonAnnotation_Key] = fmt.Sprintf("%s/%s", common.MultusNamespace, common.MultusCRName) + // + //e = frame.UpdateResource(agentDS) + //Expect(e).NotTo(HaveOccurred()) + //ctx, cancel := context.WithTimeout(context.Background(), time.Second*30) + //defer cancel() + //agentDS, e = frame.WaitDaemonSetReady(common.KDoctorAgentDSName, common.KDoctorAgentNS, ctx) + //Expect(e).NotTo(HaveOccurred()) +}) diff --git a/test/e2e/netreach/netreach_test.go b/test/e2e/netreach/netreach_test.go new file mode 100644 index 00000000..4fb0083f --- /dev/null +++ b/test/e2e/netreach/netreach_test.go @@ -0,0 +1,184 @@ +// Copyright 2023 Authors of kdoctor-io +// SPDX-License-Identifier: Apache-2.0 + +package netreach_test + +import ( + "github.com/kdoctor-io/kdoctor/pkg/k8s/apis/kdoctor.io/v1beta1" + "github.com/kdoctor-io/kdoctor/pkg/pluginManager" + "github.com/kdoctor-io/kdoctor/test/e2e/common" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + "github.com/spidernet-io/e2eframework/tools" +) + +var _ = Describe("testing netReach ", Label("netReach"), func() { + + It("success dual testing netReach", Label("B00001"), func() { + var e error + successRate := float64(1) + successMean := int64(1500) + testIPv4 := true + testIPv6 := true + crontab := "0 1" + netReachName := "netreach-dual-" + tools.RandomName() + + netReach := new(v1beta1.NetReach) + netReach.Name = netReachName + + // successCondition + successCondition := new(v1beta1.NetSuccessCondition) + successCondition.SuccessRate = &successRate + successCondition.MeanAccessDelayInMs = &successMean + netReach.Spec.SuccessCondition = successCondition + + // target + target := new(v1beta1.NetReachTarget) + target.Ingress = true + target.LoadBalancer = true + target.ClusterIP = true + target.Endpoint = true + target.NodePort = true + target.MultusInterface = false + target.IPv4 = &testIPv4 + target.IPv6 = &testIPv6 + netReach.Spec.Target = target + + // request + request := new(v1beta1.NetHttpRequest) + request.PerRequestTimeoutInMS = 1000 + request.QPS = 1 + request.DurationInSecond = 5 + netReach.Spec.Request = request + + // Schedule + Schedule := new(v1beta1.SchedulePlan) + Schedule.Schedule = &crontab + Schedule.RoundNumber = 1 + Schedule.RoundTimeoutMinute = 1 + netReach.Spec.Schedule = Schedule + + e = frame.CreateResource(netReach) + Expect(e).NotTo(HaveOccurred(), "create netReach resource") + + e = common.WaitKdoctorTaskDone(frame, netReach, pluginManager.KindNameNetReach, 120) + Expect(e).NotTo(HaveOccurred(), "wait netReach task finish") + + taskResult, e := common.GetKdoctorTaskResult(frame, netReach, pluginManager.KindNameNetReach) + Expect(e).NotTo(HaveOccurred(), "get netReach task result") + Expect(taskResult).Should(BeTrue(), "task result need success") + + }) + + It("success ipv4 testing netReach", Label("B00002"), func() { + var e error + successRate := float64(1) + successMean := int64(1500) + testIPv4 := true + testIPv6 := false + crontab := "0 1" + netReachName := "netreach-ipv4-" + tools.RandomName() + + netReach := new(v1beta1.NetReach) + netReach.Name = netReachName + + // successCondition + successCondition := new(v1beta1.NetSuccessCondition) + successCondition.SuccessRate = &successRate + successCondition.MeanAccessDelayInMs = &successMean + netReach.Spec.SuccessCondition = successCondition + + // target + target := new(v1beta1.NetReachTarget) + target.Ingress = true + target.LoadBalancer = true + target.ClusterIP = true + target.Endpoint = true + target.NodePort = true + target.MultusInterface = false + target.IPv4 = &testIPv4 + target.IPv6 = &testIPv6 + netReach.Spec.Target = target + + // request + request := new(v1beta1.NetHttpRequest) + request.PerRequestTimeoutInMS = 1000 + request.QPS = 1 + request.DurationInSecond = 5 + netReach.Spec.Request = request + + // Schedule + Schedule := new(v1beta1.SchedulePlan) + Schedule.Schedule = &crontab + Schedule.RoundNumber = 1 + Schedule.RoundTimeoutMinute = 1 + netReach.Spec.Schedule = Schedule + + e = frame.CreateResource(netReach) + Expect(e).NotTo(HaveOccurred(), "create netReach resource") + + e = common.WaitKdoctorTaskDone(frame, netReach, pluginManager.KindNameNetReach, 120) + Expect(e).NotTo(HaveOccurred(), "wait netReach task finish") + + taskResult, e := common.GetKdoctorTaskResult(frame, netReach, pluginManager.KindNameNetReach) + Expect(e).NotTo(HaveOccurred(), "get netReach task result") + Expect(taskResult).Should(BeTrue(), "task result need success") + + }) + + It("success ipv6 testing netReach", Label("B00003"), func() { + var e error + successRate := float64(1) + successMean := int64(1500) + testIPv4 := false + testIPv6 := true + crontab := "0 1" + netReachName := "netreach-dual-" + tools.RandomName() + + netReach := new(v1beta1.NetReach) + netReach.Name = netReachName + + // successCondition + successCondition := new(v1beta1.NetSuccessCondition) + successCondition.SuccessRate = &successRate + successCondition.MeanAccessDelayInMs = &successMean + netReach.Spec.SuccessCondition = successCondition + + // target + target := new(v1beta1.NetReachTarget) + target.Ingress = true + target.LoadBalancer = true + target.ClusterIP = true + target.Endpoint = true + target.NodePort = true + target.MultusInterface = false + target.IPv4 = &testIPv4 + target.IPv6 = &testIPv6 + netReach.Spec.Target = target + + // request + request := new(v1beta1.NetHttpRequest) + request.PerRequestTimeoutInMS = 1000 + request.QPS = 1 + request.DurationInSecond = 5 + netReach.Spec.Request = request + + // Schedule + Schedule := new(v1beta1.SchedulePlan) + Schedule.Schedule = &crontab + Schedule.RoundNumber = 1 + Schedule.RoundTimeoutMinute = 1 + netReach.Spec.Schedule = Schedule + + e = frame.CreateResource(netReach) + Expect(e).NotTo(HaveOccurred(), "create netReach resource") + + e = common.WaitKdoctorTaskDone(frame, netReach, pluginManager.KindNameNetReach, 120) + Expect(e).NotTo(HaveOccurred(), "wait netReach task finish") + + taskResult, e := common.GetKdoctorTaskResult(frame, netReach, pluginManager.KindNameNetReach) + Expect(e).NotTo(HaveOccurred(), "get netReach task result") + Expect(taskResult).Should(BeTrue(), "task result need success") + + }) +})