diff options
| author | wackxu <xushiwei5@huawei.com> | 2022-06-20 20:12:29 +0800 |
|---|---|---|
| committer | wackxu <xushiwei5@huawei.com> | 2022-06-20 20:12:29 +0800 |
| commit | 3f4a5dd8321752ab7b8406bc3fc3d76657363938 (patch) | |
| tree | eac49b2a6148faa85816ca46ec32970b32c57816 /tests | |
| parent | Merge pull request #3938 from fujitatomoya/bugfix/20220617-typo-nitpicks (diff) | |
| download | kubeedge-3f4a5dd8321752ab7b8406bc3fc3d76657363938.tar.gz | |
remove stale performance tests and stub for cloudcore and edgecore
Signed-off-by: wackxu <xushiwei5@huawei.com>
Diffstat (limited to 'tests')
28 files changed, 0 insertions, 3121 deletions
diff --git a/tests/performance/assets/01-configmap.yaml b/tests/performance/assets/01-configmap.yaml deleted file mode 100644 index 6a21331c4..000000000 --- a/tests/performance/assets/01-configmap.yaml +++ /dev/null @@ -1,43 +0,0 @@ -apiVersion: v1 -kind: ConfigMap -metadata: - name: cloudcore-configmap - namespace: default - labels: - k8s-app: kubeedge - kubeedge: cloudcore -data: - controller.yaml: | - controller: - kube: - master: http://192.168.20.128:8080 - namespace: "" - content_type: "application/vnd.kubernetes.protobuf" - qps: 5 - burst: 10 - node_update_frequency: 10 - kubeconfig: "" #Enter path to kubeconfig file to enable https connection to k8s apiserver - cloudhub: - protocol_websocket: true # enable websocket protocol - port: 10000 # open port for websocket server - protocol_quic: true # enable quic protocol - quic_port: 10001 # open prot for quic server - max_incomingstreams: 10000 # the max incoming stream for quic server - address: 0.0.0.0 - ca: /etc/kubeedge/certs/rootCA.crt - cert: /etc/kubeedge/certs/edge.crt - key: /etc/kubeedge/certs/edge.key - keepalive-interval: 30 - write-timeout: 30 - node-limit: 10 - devicecontroller: - kube: - master: http://192.168.20.128:8080 - namespace: "" - content_type: "application/vnd.kubernetes.protobuf" - qps: 5 - burst: 10 - kubeconfig: "" - modules.yaml: | - modules: - enabled: [controller, cloudhub, controllerstub] diff --git a/tests/performance/assets/02-edgeconfigmap.yaml b/tests/performance/assets/02-edgeconfigmap.yaml deleted file mode 100644 index 45fb4095e..000000000 --- a/tests/performance/assets/02-edgeconfigmap.yaml +++ /dev/null @@ -1,68 +0,0 @@ -apiVersion: v1 -kind: ConfigMap -metadata: - name: edgecore-configmap - namespace: default - labels: - k8s-app: kubeedge - kubeedge: edgenode -data: - edge.yaml: | - mqtt: - server: tcp://127.0.0.1:1883 # external mqtt broker url. - internal-server: tcp://127.0.0.1:1884 # internal mqtt broker url. - mode: 0 # 0: internal mqtt broker enable only. 1: internal and external mqtt broker enable. 2: external mqtt broker enable only. - qos: 0 # 0: QOSAtMostOnce, 1: QOSAtLeastOnce, 2: QOSExactlyOnce. - retain: false # if the flag set true, server will store the message and can be delivered to future subscribers. - session-queue-size: 100 # A size of how many sessions will be handled. default to 100. - edgehub: - websocket: - url: wss://192.168.20.107:31379/e632aba927ea4ac2b575ec1603d56f10/perf-node-o19egaee6o/events - cafile: /etc/kubeedge/certs/rootCA.crt - certfile: /etc/kubeedge/certs/edge.crt - keyfile: /etc/kubeedge/certs/edge.key - handshake-timeout: 30 #second - write-deadline: 15 # second - read-deadline: 15 # second - quic: - url: 192.168.20.107:31771 - cafile: /etc/kubeedge/certs/rootCA.crt - certfile: /etc/kubeedge/certs/edge.crt - keyfile: /etc/kubeedge/certs/edge.key - handshake-timeout: 30 #second - write-deadline: 15 # second - read-deadline: 15 # second - controller: - protocol: quic - placement: false - heartbeat: 15 # second - refresh-ak-sk-interval: 10 # minute - auth-info-files-path: /var/IEF/secret - placement-url: https://10.154.193.32:7444/v1/placement_external/message_queue - project-id: e632aba927ea4ac2b575ec1603d56f10 - node-id: perf-node-o19egaee6o - edged: - register-node-namespace: default - hostname-override: perf-node-o19egaee6o - interface-name: eth0 - edged-memory-capacity-bytes: 7852396000 - node-status-update-frequency: 10 # second - device-plugin-enabled: false - gpu-plugin-enabled: false - image-gc-high-threshold: 80 # percent - image-gc-low-threshold: 40 # percent - maximum-dead-containers-per-container: 1 - docker-address: tcp://localhost:2375 - version: v1.15.0-kubeedge-v1.0.0 - runtime-type: docker - remote-runtime-endpoint: unix:///var/run/dockershim.sock - remote-image-endpoint: unix:///var/run/dockershim.sock - runtime-request-timeout: 2 - podsandbox-image: kubeedge/pause:3.1 - cgroup-driver: cgroupfs - node-ip: "" - cluster-dns: "" - cluster-domain: "" - modules.yaml: | - modules: - enabled: [eventbus, servicebus, websocket, metaManager, edged, twin, dbTest, handlerstub] diff --git a/tests/performance/common/common.go b/tests/performance/common/common.go deleted file mode 100644 index e75a8a727..000000000 --- a/tests/performance/common/common.go +++ /dev/null @@ -1,351 +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 common - -import ( - "bytes" - "encoding/json" - "fmt" - "io" - "math" - "net/http" - "os/exec" - "sort" - "strconv" - "strings" - "time" - - "github.com/onsi/gomega" - v1 "k8s.io/api/core/v1" - - "github.com/kubeedge/kubeedge/tests/e2e/utils" - "github.com/kubeedge/kubeedge/tests/stubs/common/constants" - "github.com/kubeedge/kubeedge/tests/stubs/common/types" -) - -//K8s resource handlers -const ( - AppHandler = "/api/v1/namespaces/default/pods" - NodeHandler = "/api/v1/nodes" - DeploymentHandler = "/apis/apps/v1/namespaces/default/deployments" - ConfigmapHandler = "/api/v1/namespaces/default/configmaps" - ServiceHandler = "/api/v1/namespaces/default/services" - NodelabelKey = "k8snode" - NodelabelVal = "kb-perf-node" -) - -var ( - chconfigmapRet = make(chan error) - Deployments []string - NodeInfo = make(map[string][]string) - CloudConfigMap string - CloudCoreDeployment string - ToTaint bool - IsQuicProtocol bool -) - -func HandleCloudDeployment(cloudConfigMap, cloudCoreDeployment, apiserver2, confighdl, deploymenthdl, imgURL string, nodelimit int) error { - nodes := strconv.FormatInt(int64(nodelimit), 10) - cmd := exec.Command("bash", "-x", "scripts/update_configmap.sh", "create_cloud_config", "", apiserver2, cloudConfigMap, nodes) - err := utils.PrintCombinedOutput(cmd) - gomega.Expect(err).Should(gomega.BeNil()) - go utils.HandleConfigmap(chconfigmapRet, http.MethodPost, confighdl, false) - ret := <-chconfigmapRet - gomega.Expect(ret).To(gomega.BeNil()) - utils.ProtocolQuic = IsQuicProtocol - //Handle cloudCore deployment - go utils.HandleDeployment(true, false, http.MethodPost, deploymenthdl, cloudCoreDeployment, imgURL, "", cloudConfigMap, 1) - - return nil -} - -func CreateConfigMapforEdgeCore(cloudhub, cmHandler, nodeHandler string, numOfNodes int) { - //Create edgecore configMaps based on the users choice of edgecore deployment. - for i := 0; i < numOfNodes; i++ { - nodeName := "perf-node-" + utils.GetRandomString(10) - nodeSelector := "node-" + utils.GetRandomString(5) - configmap := "edgecore-configmap-" + utils.GetRandomString(5) - //Register EdgeNodes to K8s Master - go func() { - err := utils.RegisterNodeToMaster(nodeName, nodeHandler, nodeSelector) - fmt.Printf("register node to master faiiled with error: %v\n", err) - }() - cmd := exec.Command("bash", "-x", "scripts/update_configmap.sh", "create_edge_config", nodeName, cloudhub, configmap) - err := utils.PrintCombinedOutput(cmd) - gomega.Expect(err).Should(gomega.BeNil()) - //Create ConfigMaps for Each EdgeNode created - go utils.HandleConfigmap(chconfigmapRet, http.MethodPost, cmHandler, true) - ret := <-chconfigmapRet - gomega.Expect(ret).To(gomega.BeNil()) - //Store the ConfigMap against each edgenode - NodeInfo[nodeName] = append(NodeInfo[nodeName], configmap, nodeSelector) - } -} - -func HandleEdgeCorePodDeployment(depHandler, imgURL, podHandler, nodeHandler string, numOfNodes int) v1.PodList { - replica := 1 - //Create edgeCore deployments as per users configuration - for _, configmap := range NodeInfo { - UID := "edgecore-deployment-" + utils.GetRandomString(5) - go utils.HandleDeployment(false, true, http.MethodPost, depHandler, UID, imgURL, "", configmap[0], replica) - Deployments = append(Deployments, UID) - } - time.Sleep(2 * time.Second) - podlist, err := utils.GetPods(podHandler, "") - gomega.Expect(err).To(gomega.BeNil()) - utils.CheckPodRunningState(podHandler, podlist) - - //Check All EdgeNode are in Running state - gomega.Eventually(func() int { - count := 0 - for edgenodeName := range NodeInfo { - status := utils.CheckNodeReadyStatus(nodeHandler, edgenodeName) - utils.Infof("Node Name: %v, Node Status: %v", edgenodeName, status) - if status == "Running" { - count++ - } - } - return count - }, "1200s", "2s").Should(gomega.Equal(numOfNodes), "Nodes register to the k8s master is unsuccessful !!") - - return podlist -} - -func HandleEdgeDeployment(cloudhub, depHandler, nodeHandler, cmHandler, imgURL, podHandler string, numOfNodes int) v1.PodList { - CreateConfigMapforEdgeCore(cloudhub, cmHandler, nodeHandler, numOfNodes) - podlist := HandleEdgeCorePodDeployment(depHandler, imgURL, podHandler, nodeHandler, numOfNodes) - return podlist -} - -func DeleteEdgeDeployments(apiServerForRegisterNode, apiServerForDeployments string, nodes int) { - //delete confogMap - for _, configmap := range NodeInfo { - go utils.HandleConfigmap(chconfigmapRet, http.MethodDelete, apiServerForDeployments+ConfigmapHandler+"/"+configmap[0], false) - ret := <-chconfigmapRet - gomega.Expect(ret).To(gomega.BeNil()) - } - //delete edgenode deployment - for _, depName := range Deployments { - go utils.HandleDeployment(true, true, http.MethodDelete, apiServerForDeployments+DeploymentHandler+"/"+depName, "", "", "", "", 0) - } - //delete edgenodes - for edgenodeName := range NodeInfo { - err := utils.DeRegisterNodeFromMaster(apiServerForRegisterNode+NodeHandler, edgenodeName) - if err != nil { - utils.Fatalf("DeRegisterNodeFromMaster failed: %v", err) - } - } - //Verify deployments, configmaps, nodes are deleted successfully - gomega.Eventually(func() int { - count := 0 - for _, depName := range Deployments { - statusCode := utils.VerifyDeleteDeployment(apiServerForDeployments + DeploymentHandler + "/" + depName) - if statusCode == 404 { - count++ - } - } - return count - }, "60s", "4s").Should(gomega.Equal(len(Deployments)), "EdgeNode deployments delete unsuccessful !!") - - gomega.Eventually(func() int { - count := 0 - for _, configmap := range NodeInfo { - statusCode, _ := utils.GetConfigmap(apiServerForDeployments + ConfigmapHandler + "/" + configmap[0]) - if statusCode == 404 { - count++ - } - } - return count - }, "60s", "4s").Should(gomega.Equal(len(Deployments)), "EdgeNode configMaps delete unsuccessful !!") - - gomega.Eventually(func() int { - count := 0 - for edgenodeName := range NodeInfo { - status := utils.CheckNodeDeleteStatus(apiServerForRegisterNode+NodeHandler, edgenodeName) - utils.Infof("Node Name: %v, Node Status: %v", edgenodeName, status) - if status == 404 { - count++ - } - } - return count - }, "60s", "4s").Should(gomega.Equal(nodes), "EdgeNode deleton is unsuccessful !!") - //Cleanup globals - NodeInfo = map[string][]string{} - Deployments = nil -} - -func DeleteCloudDeployment(apiserver string) { - //delete cloud deployment - go utils.HandleDeployment(true, true, http.MethodDelete, apiserver+DeploymentHandler+"/"+CloudCoreDeployment, "", "", "", "", 0) - //delete cloud configMap - go utils.HandleConfigmap(chconfigmapRet, http.MethodDelete, apiserver+ConfigmapHandler+"/"+CloudConfigMap, false) - ret := <-chconfigmapRet - gomega.Expect(ret).To(gomega.BeNil()) - //delete cloud svc - StatusCode := utils.DeleteSvc(apiserver + ServiceHandler + "/" + CloudCoreDeployment) - gomega.Expect(StatusCode).Should(gomega.Equal(http.StatusOK)) -} - -func ApplyLabel(nodeHandler string) error { - var isMasterNode bool - nodes := utils.GetNodes(nodeHandler) - for _, node := range nodes.Items { - isMasterNode = false - for key := range node.Labels { - if strings.Contains(key, "node-role.kubernetes.io/master") { - isMasterNode = true - break - } - } - if !isMasterNode { - if err := utils.ApplyLabelToNode(nodeHandler+"/"+node.Name, NodelabelKey, NodelabelVal); err != nil { - return err - } - } - } - return nil -} - -// AddFakePod adds a fake pod -func AddFakePod(ControllerHubURL string, pod types.FakePod) { - reqBody, err := json.Marshal(pod) - if err != nil { - utils.Fatalf("Unmarshal HTTP Response has failed: %v", err) - } - - resp, err := SendHTTPRequest(http.MethodPost, - ControllerHubURL+constants.PodResource, - bytes.NewBuffer(reqBody)) - if err != nil { - utils.Fatalf("Frame HTTP request failed: %v", err) - } - - if resp != nil { - defer resp.Body.Close() - - contents, err := io.ReadAll(resp.Body) - if err != nil { - utils.Fatalf("HTTP Response reading has failed: %v", err) - } - - if contents != nil { - utils.Infof("AddPod response: %v", contents) - } else { - utils.Infof("AddPod response: nil") - } - } -} - -// DeleteFakePod deletes a fake pod -func DeleteFakePod(ControllerHubURL string, pod types.FakePod) { - resp, err := SendHTTPRequest(http.MethodDelete, - ControllerHubURL+constants.PodResource+ - "?name="+pod.Name+"&namespace="+pod.Namespace+"&nodename="+pod.NodeName, - nil) - if err != nil { - utils.Fatalf("Frame HTTP request failed: %v", err) - } - - if resp != nil { - defer resp.Body.Close() - - contents, err := io.ReadAll(resp.Body) - if err != nil { - utils.Fatalf("HTTP Response reading has failed: %v", err) - } - - if contents != nil { - utils.Infof("DeletePod response: %v", contents) - } else { - utils.Infof("DeletePod response: nil") - } - } -} - -// ListFakePods lists all fake pods -func ListFakePods(ControllerHubURL string) []types.FakePod { - pods := []types.FakePod{} - resp, err := SendHTTPRequest(http.MethodGet, ControllerHubURL+constants.PodResource, nil) - if err != nil { - utils.Fatalf("Frame HTTP request failed: %v", err) - } - - if resp != nil { - defer resp.Body.Close() - - contents, err := io.ReadAll(resp.Body) - if err != nil { - utils.Fatalf("HTTP Response reading has failed: %v", err) - } - - err = json.Unmarshal(contents, &pods) - if err != nil { - utils.Fatalf("Unmarshal message content with error: %s", err) - } - } - - utils.Infof("ListPods result: %d", len(pods)) - return pods -} - -// SendHTTPRequest launches a http request -func SendHTTPRequest(method, reqAPI string, body io.Reader) (*http.Response, error) { - var resp *http.Response - client := &http.Client{} - req, err := http.NewRequest(method, reqAPI, body) - if err != nil { - utils.Fatalf("Frame HTTP request failed: %v", err) - return resp, err - } - req.Header.Set("Content-Type", "application/json") - t := time.Now() - resp, err = client.Do(req) - if err != nil { - utils.Fatalf("HTTP request is failed :%v", err) - return resp, err - } - if resp != nil { - utils.Infof("%s %s %v in %v", req.Method, req.URL, resp.Status, time.Since(t)) - } - return resp, nil -} - -// GetLatency calculates latency based on different percent -func GetLatency(pods []types.FakePod) types.Latency { - latency := types.Latency{} - if len(pods) > 0 { - // Sort fake pods - sort.Stable(types.FakePodSort(pods)) - - // Get 50% throughputs latency - index50 := int(math.Ceil(float64(len(pods)) * 0.50)) - latency.Percent50 = time.Duration(pods[index50-1].RunningTime - pods[index50-1].CreateTime) - - // Get 90% throughputs latency - index90 := int(math.Ceil(float64(len(pods)) * 0.90)) - latency.Percent90 = time.Duration(pods[index90-1].RunningTime - pods[index90-1].CreateTime) - - // Get 99% throughputs latency - index99 := int(math.Ceil(float64(len(pods)) * 0.99)) - latency.Percent99 = time.Duration(pods[index99-1].RunningTime - pods[index99-1].CreateTime) - - // Get 100% throughputs latency - index100 := int(math.Ceil(float64(len(pods)) * 1.00)) - latency.Percent100 = time.Duration(pods[index100-1].RunningTime - pods[index100-1].CreateTime) - } - return latency -} diff --git a/tests/performance/hubtest/hubtest_suite_test.go b/tests/performance/hubtest/hubtest_suite_test.go deleted file mode 100644 index 00ec64b65..000000000 --- a/tests/performance/hubtest/hubtest_suite_test.go +++ /dev/null @@ -1,117 +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 hubtest - -import ( - "fmt" - "strings" - "testing" - "time" - - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - v1 "k8s.io/api/core/v1" - - "github.com/kubeedge/kubeedge/tests/e2e/utils" - . "github.com/kubeedge/kubeedge/tests/performance/common" - "github.com/kubeedge/viaduct/pkg/api" -) - -// configs across the package -var ( - ctx *utils.TestContext - cfg utils.Config - cloudHubURL string - wsscloudHubURL string - quiccloudHubURL string - controllerHubURL string -) - -func TestKubeEdgeK8SDeployment(t *testing.T) { - // Init params - var podlist v1.PodList - RegisterFailHandler(Fail) - - // Init suite - var _ = BeforeSuite(func() { - // Init config - utils.Infof("KubeEdge hub performance test begin!") - cfg = utils.LoadConfig() - ctx = utils.NewTestContext(cfg) - - //apply label to all cluster nodes, use the selector to deploy all edgenodes to cluster nodes - err := ApplyLabel(ctx.Cfg.K8SMasterForProvisionEdgeNodes + NodeHandler) - Expect(err).Should(BeNil()) - - // Deploy KubeEdge Cloud Part as a k8s deployment into KubeEdge Cluster - CloudConfigMap = "cloudcore-configmap-" + utils.GetRandomString(5) - CloudCoreDeployment = "cloudcore-deployment-" + utils.GetRandomString(5) - //protocol to be used for test between edge and cloud - if ctx.Cfg.Protocol == api.ProtocolTypeQuic { - IsQuicProtocol = true - } else { - IsQuicProtocol = false - } - err = HandleCloudDeployment( - CloudConfigMap, - CloudCoreDeployment, - ctx.Cfg.K8SMasterForKubeEdge, - ctx.Cfg.K8SMasterForKubeEdge+ConfigmapHandler, - ctx.Cfg.K8SMasterForKubeEdge+DeploymentHandler, - ctx.Cfg.CloudImageURL, - ctx.Cfg.NumOfNodes) - Expect(err).Should(BeNil()) - time.Sleep(1 * time.Second) - - // Get KubeEdge Cloud Part host ip - podlist, err = utils.GetPods(ctx.Cfg.K8SMasterForKubeEdge+AppHandler, "") - Expect(err).To(BeNil()) - cloudPartHostIP := "" - for _, pod := range podlist.Items { - if strings.Contains(pod.Name, "cloudcore-deployment") { - cloudPartHostIP = pod.Status.HostIP - break - } - } - - // Check if KubeEdge Cloud Part is running - utils.CheckPodRunningState(ctx.Cfg.K8SMasterForKubeEdge+AppHandler, podlist) - time.Sleep(5 * time.Second) - - // Create NodePort Service for KubeEdge Cloud Part - err = utils.ExposeCloudService(CloudCoreDeployment, ctx.Cfg.K8SMasterForKubeEdge+ServiceHandler) - Expect(err).Should(BeNil()) - - // Get NodePort Service to access KubeEdge Cloud Part from KubeEdge Edge Nodes - wsPort, quicNodePort := utils.GetServicePort(CloudCoreDeployment, ctx.Cfg.K8SMasterForKubeEdge+ServiceHandler) - quiccloudHubURL = fmt.Sprintf("%s:%d", cloudPartHostIP, quicNodePort) - wsscloudHubURL = fmt.Sprintf("wss://%s:%d", cloudPartHostIP, wsPort) - if IsQuicProtocol { - cloudHubURL = quiccloudHubURL - } else { - cloudHubURL = wsscloudHubURL - } - controllerHubURL = fmt.Sprintf("http://%s:%d", cloudPartHostIP, ctx.Cfg.ControllerStubPort) - }) - AfterSuite(func() { - By("KubeEdge hub performance test end!") - // Delete KubeEdge Cloud Part deployment - DeleteCloudDeployment(ctx.Cfg.K8SMasterForKubeEdge) - // Check if KubeEdge Cloud Part is deleted - utils.CheckPodDeleteState(ctx.Cfg.K8SMasterForKubeEdge+AppHandler, podlist) - }) - RunSpecs(t, "KubeEdge hub performance test suite") -} diff --git a/tests/performance/hubtest/hubtest_test.go b/tests/performance/hubtest/hubtest_test.go deleted file mode 100644 index 240bbb085..000000000 --- a/tests/performance/hubtest/hubtest_test.go +++ /dev/null @@ -1,113 +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 hubtest - -import ( - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - metav1 "k8s.io/api/core/v1" - - "github.com/kubeedge/kubeedge/tests/e2e/utils" - . "github.com/kubeedge/kubeedge/tests/performance/common" - "github.com/kubeedge/kubeedge/tests/stubs/common/constants" - "github.com/kubeedge/kubeedge/tests/stubs/common/types" -) - -var _ = Describe("KubeEdge hub performance test", func() { - Context("Test different numbers of Pods on different numbers of Edge Nodes", func() { - // Init params - var podlist metav1.PodList - var numOfEdgeNodes int - var numOfPodsPerEdgeNode int - var podsInfo map[string]types.FakePod - var pods []types.FakePod - var latency types.Latency - - BeforeEach(func() { - // Create Edge Nodes - numOfEdgeNodes = 10 - podlist = HandleEdgeDeployment(cloudHubURL, ctx.Cfg.K8SMasterForProvisionEdgeNodes+DeploymentHandler, ctx.Cfg.K8SMasterForKubeEdge+NodeHandler, - ctx.Cfg.K8SMasterForProvisionEdgeNodes+ConfigmapHandler, ctx.Cfg.EdgeImageURL, ctx.Cfg.K8SMasterForProvisionEdgeNodes+AppHandler, numOfEdgeNodes) - }) - - AfterEach(func() { - // Get latency - if len(pods) > 0 { - latency = GetLatency(pods) - utils.Infof("HubTest 50 percent latency: %s", latency.Percent50.String()) - utils.Infof("HubTest 90 percent latency: %s", latency.Percent90.String()) - utils.Infof("HubTest 99 percent latency: %s", latency.Percent99.String()) - utils.Infof("HubTest 100 percent latency: %s", latency.Percent100.String()) - } - - // Delete Pods - for _, p := range podsInfo { - DeleteFakePod(controllerHubURL, p) - } - // Check All Pods are deleted - Eventually(func() int { - ps := ListFakePods(controllerHubURL) - return len(ps) - }, "240s", "4s").Should(Equal(0), "Wait for Pods deleted timeout") - - // Delete Edge Nodes - DeleteEdgeDeployments(ctx.Cfg.K8SMasterForKubeEdge, ctx.Cfg.K8SMasterForProvisionEdgeNodes, numOfEdgeNodes) - utils.CheckDeploymentPodDeleteState(ctx.Cfg.K8SMasterForProvisionEdgeNodes+AppHandler, podlist) - }) - - Measure("PERF_HUBTEST_NODES_10_PODS_10: Create 10 Edge Nodes, Deploy 10 Pods per Edge Node, Measure startup time of Pods", func(b Benchmarker) { - // Measure startup time - hubTestRuntime := b.Time("runtime", func() { - // Create Pods on Edge Nodes - numOfPodsPerEdgeNode = 10 - podsInfo = make(map[string]types.FakePod) - pods = make([]types.FakePod, 0) - // Loop for Pod Numbers - for i := 0; i < numOfPodsPerEdgeNode; i++ { - // Loop for Edge Node Numbers - for nodeName := range NodeInfo { - // Construct fake pods - var pod types.FakePod - pod.Name = nodeName + "-fakepod-" + utils.GetRandomString(10) - pod.Namespace = constants.NamespaceDefault - pod.NodeName = nodeName - pod.Status = constants.PodPending - // Add fake pod - go AddFakePod(controllerHubURL, pod) - // Store fake pod - podsInfo[pod.Name] = pod - } - } - - // Check all pods are running - Eventually(func() int { - count := 0 - // List all pods status - pods = ListFakePods(controllerHubURL) - // Get current pod numbers which are running - for _, p := range pods { - if p.Status == constants.PodRunning { - count++ - } - } - utils.Infof("Current running pods count: %d", count) - return count - }, "240s", "100ms").Should(Equal(numOfEdgeNodes*numOfPodsPerEdgeNode), "Wait for Pods in running status timeout") - }) - utils.Infof("HubTest runtime stats: %+v", hubTestRuntime) - }, 5) - }) -}) diff --git a/tests/performance/loadtest/loadtest_suite_test.go b/tests/performance/loadtest/loadtest_suite_test.go deleted file mode 100644 index 3e16055c1..000000000 --- a/tests/performance/loadtest/loadtest_suite_test.go +++ /dev/null @@ -1,121 +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 loadtest - -import ( - "net" - "net/url" - "strconv" - "strings" - "testing" - "time" - - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - metav1 "k8s.io/api/core/v1" - - "github.com/kubeedge/kubeedge/tests/e2e/utils" - . "github.com/kubeedge/kubeedge/tests/performance/common" - "github.com/kubeedge/viaduct/pkg/api" -) - -//context to load config and access across the package -var ( - ctx *utils.TestContext - cfg utils.Config - nodeSelector string - cloudHubURL string - wsscloudHubURL string - quiccloudHubURL string - cloudCoreNodeName string -) - -func TestEdgecoreK8sDeployment(t *testing.T) { - var cloudCoreHostIP string - var podlist metav1.PodList - //var toTaint bool - RegisterFailHandler(Fail) - var _ = BeforeSuite(func() { - utils.Infof("Kubeedge deployment Load test Begin !!") - cfg = utils.LoadConfig() - ctx = utils.NewTestContext(cfg) - //apply label to all cluster nodes, use the selector to deploy all edgenodes to cluster nodes - err := ApplyLabel(ctx.Cfg.K8SMasterForProvisionEdgeNodes + NodeHandler) - Expect(err).Should(BeNil()) - //Create configMap for CloudCore - CloudConfigMap = "cloudcore-configmap-" + utils.GetRandomString(5) - CloudCoreDeployment = "cloudcore-deployment-" + utils.GetRandomString(5) - //protocol to be used for test between edge and cloud - if ctx.Cfg.Protocol == api.ProtocolTypeQuic { - IsQuicProtocol = true - } else { - IsQuicProtocol = false - } - //Deploye cloudcore as a k8s resource to cluster-1 - err = HandleCloudDeployment(CloudConfigMap, CloudCoreDeployment, ctx.Cfg.K8SMasterForKubeEdge, - ctx.Cfg.K8SMasterForKubeEdge+ConfigmapHandler, ctx.Cfg.K8SMasterForKubeEdge+DeploymentHandler, ctx.Cfg.CloudImageURL, ctx.Cfg.NumOfNodes) - Expect(err).Should(BeNil()) - time.Sleep(1 * time.Second) - //Get the cloudCore pod Node name and IP - podlist, err = utils.GetPods(ctx.Cfg.K8SMasterForKubeEdge+AppHandler, "") - Expect(err).To(BeNil()) - for _, pod := range podlist.Items { - if strings.Contains(pod.Name, "cloudcore-deployment") { - cloudCoreHostIP = pod.Status.HostIP - cloudCoreNodeName = pod.Spec.NodeName - break - } - } - utils.CheckPodRunningState(ctx.Cfg.K8SMasterForKubeEdge+AppHandler, podlist) - time.Sleep(5 * time.Second) - //Create service for cloud - err = utils.ExposeCloudService(CloudCoreDeployment, ctx.Cfg.K8SMasterForKubeEdge+ServiceHandler) - Expect(err).Should(BeNil()) - //Create a nodePort Service to access the cloud Service from the cluster nodes - wsPort, quicPort := utils.GetServicePort(CloudCoreDeployment, ctx.Cfg.K8SMasterForKubeEdge+ServiceHandler) - wsNodePort := strconv.FormatInt(int64(wsPort), 10) - quicNodePort := strconv.FormatInt(int64(quicPort), 10) - quiccloudHubURL = net.JoinHostPort(cloudCoreHostIP, quicNodePort) - cloudHubURL = quiccloudHubURL - wsscloudHubURL = (&url.URL{ - Scheme: "wss", - Host: net.JoinHostPort(cloudCoreHostIP, wsNodePort), - }).String() - cloudHubURL = wsscloudHubURL - - //Deploye edgecore as a k8s resource to cluster-2 - podlist = HandleEdgeDeployment(cloudHubURL, ctx.Cfg.K8SMasterForProvisionEdgeNodes+DeploymentHandler, ctx.Cfg.K8SMasterForKubeEdge+NodeHandler, - ctx.Cfg.K8SMasterForProvisionEdgeNodes+ConfigmapHandler, ctx.Cfg.EdgeImageURL, ctx.Cfg.K8SMasterForProvisionEdgeNodes+AppHandler, ctx.Cfg.NumOfNodes) - - //skip the pod scheduling in k8s node while kubeedge nodes are available to schedule - ToTaint = true - err = utils.TaintEdgeDeployedNode(ToTaint, ctx.Cfg.K8SMasterForKubeEdge+NodeHandler+"/"+cloudCoreNodeName) - Expect(err).Should(BeNil()) - ToTaint = false - }) - AfterSuite(func() { - By("Kubeedge deployment Load test End !!....!") - - DeleteEdgeDeployments(ctx.Cfg.K8SMasterForKubeEdge, ctx.Cfg.K8SMasterForProvisionEdgeNodes, ctx.Cfg.NumOfNodes) - utils.CheckDeploymentPodDeleteState(ctx.Cfg.K8SMasterForProvisionEdgeNodes, podlist) - //untaint Node - err := utils.TaintEdgeDeployedNode(ToTaint, ctx.Cfg.K8SMasterForKubeEdge+NodeHandler+"/"+cloudCoreNodeName) - Expect(err).Should(BeNil()) - DeleteCloudDeployment(ctx.Cfg.K8SMasterForKubeEdge) - }) - - RunSpecs(t, "kubeedge Performance Load test Suite") -} diff --git a/tests/performance/loadtest/loadtest_test.go b/tests/performance/loadtest/loadtest_test.go deleted file mode 100644 index 8d285a81b..000000000 --- a/tests/performance/loadtest/loadtest_test.go +++ /dev/null @@ -1,536 +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 loadtest - -import ( - "net/http" - "os/exec" - "strings" - "time" - - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - v1 "k8s.io/api/apps/v1" - metav1 "k8s.io/api/core/v1" - - "github.com/kubeedge/kubeedge/tests/e2e/utils" - . "github.com/kubeedge/kubeedge/tests/performance/common" -) - -var DeploymentTestTimerGroup *utils.TestTimerGroup = utils.NewTestTimerGroup() - -//RestartEdgeNodePodsToUseQuicProtocol function to switch the protocol and re-initialize the edgecore -func RestartEdgeNodePodsToUseQuicProtocol() error { - var EdgeNodePods []string - chconfigmapRet := make(chan error) - for nodeName, conf := range NodeInfo { - for range conf { - cmd := exec.Command("bash", "-x", "scripts/update_configmap.sh", "create_edge_config", nodeName, quiccloudHubURL, conf[0]) - err := utils.PrintCombinedOutput(cmd) - Expect(err).Should(BeNil()) - //Create ConfigMaps for Each EdgeNode created - go utils.HandleConfigmap(chconfigmapRet, http.MethodPatch, ctx.Cfg.K8SMasterForProvisionEdgeNodes+ConfigmapHandler+"/"+conf[0], true) - ret := <-chconfigmapRet - Expect(ret).To(BeNil()) - } - } - - pods, err := utils.GetPods(ctx.Cfg.K8SMasterForProvisionEdgeNodes+AppHandler, "") - Expect(err).To(BeNil()) - for _, pod := range pods.Items { - if strings.Contains(pod.Name, "edgecore-deployment") { - //EdgeNodePodHost = pod.Spec.NodeName - EdgeNodePods = append(EdgeNodePods, pod.Name) - } - } - - for i := range EdgeNodePods { - utils.DeletePods(ctx.Cfg.K8SMasterForProvisionEdgeNodes + AppHandler + "/" + EdgeNodePods[i]) - } - - Eventually(func() int { - var count int - for i := range EdgeNodePods { - status, statusCode := utils.GetPodState(ctx.Cfg.K8SMasterForProvisionEdgeNodes + AppHandler + "/" + EdgeNodePods[i]) - utils.Infof("PodName: %s status: %s StatusCode: %d", EdgeNodePods[i], status, statusCode) - if statusCode == 404 { - count++ - } - } - return count - }, "1200s", "4s").Should(Equal(len(EdgeNodePods)), "Delete Application deployment is Unsuccessful, Pods are not deleted within the time") - - newpods, err := utils.GetPods(ctx.Cfg.K8SMasterForProvisionEdgeNodes+AppHandler, "") - Expect(err).To(BeNil()) - - Eventually(func() int { - var count int - for _, pod := range newpods.Items { - state, _ := utils.GetPodState(ctx.Cfg.K8SMasterForProvisionEdgeNodes + AppHandler + "/" + pod.Name) - utils.Infof("PodName: %s PodStatus: %s", pod.Name, state) - if state == "Running" { - count++ - } - } - return count - }, "1200s", "2s").Should(Equal(ctx.Cfg.NumOfNodes), "New Pods has not come to Running State") - - //Check All EdgeNode are in Running state - Eventually(func() int { - count := 0 - for edgenodeName := range NodeInfo { - status := utils.CheckNodeReadyStatus(ctx.Cfg.K8SMasterForKubeEdge+NodeHandler, edgenodeName) - utils.Infof("Node Name: %v, Node Status: %v", edgenodeName, status) - if status == "Running" { - count++ - } - } - return count - }, "60s", "2s").Should(Equal(ctx.Cfg.NumOfNodes), "Nodes register to the k8s master is unsuccessful !!") - - return nil -} - -func PullImageInAllEdgeNodes(appDeployments []string) { - var deploymentList v1.DeploymentList - var podlist metav1.PodList - for kubenode, val := range NodeInfo { - UID := "edgecore-app-" + utils.GetRandomString(5) - IsAppDeployed := utils.HandleDeployment(false, false, http.MethodPost, ctx.Cfg.K8SMasterForKubeEdge+DeploymentHandler, UID, ctx.Cfg.AppImageURL[1], val[1], val[0], 1) - Expect(IsAppDeployed).Should(BeTrue()) - appDeployments = append(appDeployments, UID) - err := utils.GetDeployments(&deploymentList, ctx.Cfg.K8SMasterForKubeEdge+DeploymentHandler) - Expect(err).To(BeNil()) - for _, deployment := range deploymentList.Items { - if deployment.Name == UID { - label := kubenode - podlist, err = utils.GetPods(ctx.Cfg.K8SMasterForKubeEdge+AppHandler, label) - Expect(err).To(BeNil()) - break - } - } - utils.CheckPodRunningState(ctx.Cfg.K8SMasterForKubeEdge+AppHandler, podlist) - } - //after pulling image to all edgenodes, delete the deployments on respective edgenodes - for i := range appDeployments { - IsAppDeployed := utils.HandleDeployment(false, false, http.MethodDelete, ctx.Cfg.K8SMasterForKubeEdge+DeploymentHandler+"/"+appDeployments[i], "", ctx.Cfg.AppImageURL[1], nodeSelector, "", 10) - Expect(IsAppDeployed).Should(BeTrue()) - } - podlist, err := utils.GetPods(ctx.Cfg.K8SMasterForKubeEdge+AppHandler, "") - Expect(err).To(BeNil()) - utils.CheckPodDeleteState(ctx.Cfg.K8SMasterForKubeEdge+AppHandler, podlist) - appDeployments = nil -} - -//Run Test cases -var _ = Describe("Application deployment test in Perfronace test EdgeNodes", func() { - var UID string - var testTimer *utils.TestTimer - var testDescription GinkgoTestDescription - var podlist metav1.PodList - var appDeployments []string - - Context("Pull images to all KubeEdge nodes", func() { - FIt("PULL_IMAGE_ALL_KUBEEDGE_NODES: Pull image to all KubeEdge edge nodes", func() { - PullImageInAllEdgeNodes(appDeployments) - }) - }) - - Context("Test application deployment on Kubeedge EdgeNodes Through Websocket", func() { - BeforeEach(func() { - testDescription = CurrentGinkgoTestDescription() - testTimer = DeploymentTestTimerGroup.NewTestTimer(testDescription.TestText) - }) - AfterEach(func() { - // End test timer - testTimer.End() - // Print result - testTimer.PrintResult() - IsAppDeployed := utils.HandleDeployment(false, false, http.MethodDelete, ctx.Cfg.K8SMasterForKubeEdge+DeploymentHandler+"/"+UID, "", ctx.Cfg.AppImageURL[1], nodeSelector, "", 10) - Expect(IsAppDeployed).Should(BeTrue()) - - utils.CheckPodDeleteState(ctx.Cfg.K8SMasterForKubeEdge+AppHandler, podlist) - podlist = metav1.PodList{} - }) - - Measure("WSS_MEASURE_PERF_LOADTEST_NODES_10: Create 10 KubeEdge Node Deployment, Measure time for application comes into Running state", func(b Benchmarker) { - podlist = metav1.PodList{} - runtime := b.Time("runtime", func() { - var deploymentList v1.DeploymentList - podlist = metav1.PodList{} - replica := 10 - //Generate the random string and assign as a UID - UID = "edgecore-app-" + utils.GetRandomString(5) - IsAppDeployed := utils.HandleDeployment(false, false, http.MethodPost, ctx.Cfg.K8SMasterForKubeEdge+DeploymentHandler, UID, ctx.Cfg.AppImageURL[1], "", "", replica) - Expect(IsAppDeployed).Should(BeTrue()) - err := utils.GetDeployments(&deploymentList, ctx.Cfg.K8SMasterForKubeEdge+DeploymentHandler) - Expect(err).To(BeNil()) - for _, deployment := range deploymentList.Items { - if deployment.Name == UID { - //label := nodeName - time.Sleep(2 * time.Second) - podlist, err = utils.GetPods(ctx.Cfg.K8SMasterForKubeEdge+AppHandler, "") - Expect(err).To(BeNil()) - break - } - } - utils.CheckPodRunningState(ctx.Cfg.K8SMasterForKubeEdge+AppHandler, podlist) - }) - - utils.Infof("Runtime stats: %+v", runtime) - - }, 5) - - Measure("WSS_MEASURE_PERF_LOADTEST_NODES_20: Create 20 KubeEdge Node Deployment, Measure time for application comes into Running state", func(b Benchmarker) { - podlist = metav1.PodList{} - runtime := b.Time("runtime", func() { - var deploymentList v1.DeploymentList - podlist = metav1.PodList{} - replica := 20 - //Generate the random string and assign as a UID - UID = "edgecore-app-" + utils.GetRandomString(5) - IsAppDeployed := utils.HandleDeployment(false, false, http.MethodPost, ctx.Cfg.K8SMasterForKubeEdge+DeploymentHandler, UID, ctx.Cfg.AppImageURL[1], "", "", replica) - Expect(IsAppDeployed).Should(BeTrue()) - err := utils.GetDeployments(&deploymentList, ctx.Cfg.K8SMasterForKubeEdge+DeploymentHandler) - Expect(err).To(BeNil()) - for _, deployment := range deploymentList.Items { - if deployment.Name == UID { - //label := nodeName - time.Sleep(2 * time.Second) - podlist, err = utils.GetPods(ctx.Cfg.K8SMasterForKubeEdge+AppHandler, "") - Expect(err).To(BeNil()) - break - } - } - utils.CheckPodRunningState(ctx.Cfg.K8SMasterForKubeEdge+AppHandler, podlist) - }) - - utils.Infof("Runtime stats: %+v", runtime) - - }, 5) - - Measure("WSS_MEASURE_PERF_LOADTEST_NODES_50: Create 50 KubeEdge Node Deployment, Measure time for application comes into Running state", func(b Benchmarker) { - podlist = metav1.PodList{} - runtime := b.Time("runtime", func() { - var deploymentList v1.DeploymentList - podlist = metav1.PodList{} - replica := 50 - //Generate the random string and assign as a UID - UID = "edgecore-app-" + utils.GetRandomString(5) - IsAppDeployed := utils.HandleDeployment(false, false, http.MethodPost, ctx.Cfg.K8SMasterForKubeEdge+DeploymentHandler, UID, ctx.Cfg.AppImageURL[1], "", "", replica) - Expect(IsAppDeployed).Should(BeTrue()) - err := utils.GetDeployments(&deploymentList, ctx.Cfg.K8SMasterForKubeEdge+DeploymentHandler) - Expect(err).To(BeNil()) - for _, deployment := range deploymentList.Items { - if deployment.Name == UID { - //label := nodeName - time.Sleep(2 * time.Second) - podlist, err = utils.GetPods(ctx.Cfg.K8SMasterForKubeEdge+AppHandler, "") - Expect(err).To(BeNil()) - break - } - } - utils.CheckPodRunningState(ctx.Cfg.K8SMasterForKubeEdge+AppHandler, podlist) - }) - - utils.Infof("Runtime stats: %+v", runtime) - - }, 5) - Measure("WSS_MEASURE_PERF_NODETEST_NODES_75: Create 75 KubeEdge Node Deployment, Measure time for application comes into Running state", func(b Benchmarker) { - podlist = metav1.PodList{} - runtime := b.Time("runtime", func() { - var deploymentList v1.DeploymentList - podlist = metav1.PodList{} - replica := 75 - //Generate the random string and assign as a UID - UID = "edgecore-app-" + utils.GetRandomString(5) - IsAppDeployed := utils.HandleDeployment(false, false, http.MethodPost, ctx.Cfg.K8SMasterForKubeEdge+DeploymentHandler, UID, ctx.Cfg.AppImageURL[1], "", "", replica) - Expect(IsAppDeployed).Should(BeTrue()) - err := utils.GetDeployments(&deploymentList, ctx.Cfg.K8SMasterForKubeEdge+DeploymentHandler) - Expect(err).To(BeNil()) - for _, deployment := range deploymentList.Items { - if deployment.Name == UID { - //label := nodeName - time.Sleep(2 * time.Second) - podlist, err = utils.GetPods(ctx.Cfg.K8SMasterForKubeEdge+AppHandler, "") - Expect(err).To(BeNil()) - break - } - } - utils.CheckPodRunningState(ctx.Cfg.K8SMasterForKubeEdge+AppHandler, podlist) - }) - - utils.Infof("Runtime stats: %+v", runtime) - - }, 5) - Measure("WSS_MEASURE_PERF_NODETEST_NODES_100: Create 100 KubeEdge Node Deployment, Measure time for application comes into Running state", func(b Benchmarker) { - podlist = metav1.PodList{} - runtime := b.Time("runtime", func() { - var deploymentList v1.DeploymentList - podlist = metav1.PodList{} - replica := 100 - //Generate the random string and assign as a UID - UID = "edgecore-app-" + utils.GetRandomString(5) - IsAppDeployed := utils.HandleDeployment(false, false, http.MethodPost, ctx.Cfg.K8SMasterForKubeEdge+DeploymentHandler, UID, ctx.Cfg.AppImageURL[1], "", "", replica) - Expect(IsAppDeployed).Should(BeTrue()) - err := utils.GetDeployments(&deploymentList, ctx.Cfg.K8SMasterForKubeEdge+DeploymentHandler) - Expect(err).To(BeNil()) - for _, deployment := range deploymentList.Items { - if deployment.Name == UID { - //label := nodeName - time.Sleep(2 * time.Second) - podlist, err = utils.GetPods(ctx.Cfg.K8SMasterForKubeEdge+AppHandler, "") - Expect(err).To(BeNil()) - break - } - } - utils.CheckPodRunningState(ctx.Cfg.K8SMasterForKubeEdge+AppHandler, podlist) - }) - - utils.Infof("Runtime stats: %+v", runtime) - }, 5) - }) - - Context("stress test on single Kubeedge EdgeNode", func() { - var appDeployments []string - BeforeEach(func() { - testDescription = CurrentGinkgoTestDescription() - testTimer = DeploymentTestTimerGroup.NewTestTimer(testDescription.TestText) - }) - AfterEach(func() { - // End test timer - testTimer.End() - // Print result - testTimer.PrintResult() - for i := range appDeployments { - IsAppDeployed := utils.HandleDeployment(false, false, http.MethodDelete, ctx.Cfg.K8SMasterForKubeEdge+DeploymentHandler+"/"+appDeployments[i], "", ctx.Cfg.AppImageURL[1], nodeSelector, "", 10) - Expect(IsAppDeployed).Should(BeTrue()) - } - utils.CheckPodDeleteState(ctx.Cfg.K8SMasterForKubeEdge+AppHandler, podlist) - podlist = metav1.PodList{} - appDeployments = nil - }) - - It("QUIC_APP_DEPLOYMENT_1: Switch to Quic and pull the image in all KubeEdge nodes", func() { - err := RestartEdgeNodePodsToUseQuicProtocol() - Expect(err).To(BeNil()) - PullImageInAllEdgeNodes(appDeployments) - }) - - FMeasure("MEASURE_PERF_NODETEST_SINGLE_NODE_1: Create 100 application Deployments, Measure Pod Running time", func(b Benchmarker) { - podlist = metav1.PodList{} - var err error - var nodeSelector string - var nodeName string - for key, val := range NodeInfo { - nodeSelector = val[1] - nodeName = key - break - } - b.Time("MEASURE_PERF_NODETEST_SINGLE_NODE_1", func() { - replica := 1 - for i := 0; i < 100; i++ { - //Generate the random string and assign as a UID - UID = "edgecore-app-" + utils.GetRandomString(5) - appDeployments = append(appDeployments, UID) - go utils.HandleDeployment(false, false, http.MethodPost, ctx.Cfg.K8SMasterForKubeEdge+DeploymentHandler, - UID, ctx.Cfg.AppImageURL[1], nodeSelector, "", replica) - } - time.Sleep(10 * time.Second) - podlist, err = utils.GetPods(ctx.Cfg.K8SMasterForKubeEdge+AppHandler, nodeName) - Expect(err).To(BeNil()) - utils.CheckPodRunningState(ctx.Cfg.K8SMasterForKubeEdge+AppHandler, podlist) - }) - }, 5) - - Measure("MEASURE_PERF_NODETEST_SINGLE_NODE_1: Create 100 application Deployments while each deployment have 100 replica, Measure Pod Running time", func(b Benchmarker) { - podlist = metav1.PodList{} - var err error - var nodeSelector string - //var nodeName string - b.Time("MEASURE_PERF_NODETEST_SINGLE_NODE_1", func() { - replica := 10 - for _, val := range NodeInfo { - nodeSelector = val[1] - //Generate the random string and assign as a UID - UID = "edgecore-app-" + utils.GetRandomString(5) - appDeployments = append(appDeployments, UID) - go utils.HandleDeployment(false, false, http.MethodPost, ctx.Cfg.K8SMasterForKubeEdge+DeploymentHandler, - UID, ctx.Cfg.AppImageURL[1], nodeSelector, "", replica) - - } - time.Sleep(10 * time.Second) - podlist, err = utils.GetPods(ctx.Cfg.K8SMasterForKubeEdge+AppHandler, "") - Expect(err).To(BeNil()) - utils.CheckPodRunningState(ctx.Cfg.K8SMasterForKubeEdge+AppHandler, podlist) - }) - }, 1) - }) - - Context("Test application deployment on Kubeedge EdgeNodes with Quic Protocol", func() { - var appDeployments []string - BeforeEach(func() { - testDescription = CurrentGinkgoTestDescription() - testTimer = DeploymentTestTimerGroup.NewTestTimer(testDescription.TestText) - }) - AfterEach(func() { - // End test timer - testTimer.End() - // Print result - testTimer.PrintResult() - IsAppDeployed := utils.HandleDeployment(false, false, http.MethodDelete, ctx.Cfg.K8SMasterForKubeEdge+DeploymentHandler+"/"+UID, "", ctx.Cfg.AppImageURL[1], nodeSelector, "", 10) - Expect(IsAppDeployed).Should(BeTrue()) - - utils.CheckPodDeleteState(ctx.Cfg.K8SMasterForKubeEdge+AppHandler, podlist) - podlist = metav1.PodList{} - }) - - It("QUIC_APP_DEPLOYMENT_1: Switch to Quic and pull the image in all KubeEdge nodes", func() { - err := RestartEdgeNodePodsToUseQuicProtocol() - Expect(err).To(BeNil()) - PullImageInAllEdgeNodes(appDeployments) - }) - - Measure("QUIC_MEASURE_PERF_NODETEST_NODES_1: Create 1 KubeEdge Node Deployment, Measure time for application comes into Running state", func(b Benchmarker) { - - runtime := b.Time("QUIC_MEASURE_PERF_NODETEST_NODES_1", func() { - var deploymentList v1.DeploymentList - podlist = metav1.PodList{} - replica := 1 - //Generate the random string and assign as a UID - UID = "edgecore-app-" + utils.GetRandomString(5) - IsAppDeployed := utils.HandleDeployment(false, false, http.MethodPost, ctx.Cfg.K8SMasterForKubeEdge+DeploymentHandler, UID, ctx.Cfg.AppImageURL[1], "", "", replica) - Expect(IsAppDeployed).Should(BeTrue()) - err := utils.GetDeployments(&deploymentList, ctx.Cfg.K8SMasterForKubeEdge+DeploymentHandler) - Expect(err).To(BeNil()) - for _, deployment := range deploymentList.Items { - if deployment.Name == UID { - //label := nodeName - time.Sleep(2 * time.Second) - podlist, err = utils.GetPods(ctx.Cfg.K8SMasterForKubeEdge+AppHandler, "") - Expect(err).To(BeNil()) - break - } - } - utils.CheckPodRunningState(ctx.Cfg.K8SMasterForKubeEdge+AppHandler, podlist) - }) - utils.Infof("Runtime stats: %+v", runtime) - }, 5) - - Measure("QUIC_MEASURE_PERF_NODETEST_NODES_10: Create 10 KubeEdge Node Deployment, Measure time for application comes into Running state", func(b Benchmarker) { - runtime := b.Time("QUIC_MEASURE_PERF_NODETEST_NODES_10", func() { - var deploymentList v1.DeploymentList - podlist = metav1.PodList{} - replica := 10 - //Generate the random string and assign as a UID - UID = "edgecore-app-" + utils.GetRandomString(5) - IsAppDeployed := utils.HandleDeployment(false, false, http.MethodPost, ctx.Cfg.K8SMasterForKubeEdge+DeploymentHandler, UID, ctx.Cfg.AppImageURL[1], "", "", replica) - Expect(IsAppDeployed).Should(BeTrue()) - err := utils.GetDeployments(&deploymentList, ctx.Cfg.K8SMasterForKubeEdge+DeploymentHandler) - Expect(err).To(BeNil()) - for _, deployment := range deploymentList.Items { - if deployment.Name == UID { - //label := nodeName - time.Sleep(2 * time.Second) - podlist, err = utils.GetPods(ctx.Cfg.K8SMasterForKubeEdge+AppHandler, "") - Expect(err).To(BeNil()) - break - } - } - utils.CheckPodRunningState(ctx.Cfg.K8SMasterForKubeEdge+AppHandler, podlist) - }) - - utils.Infof("Runtime stats: %+v", runtime) - - }, 5) - - Measure("QUIC_MEASURE_PERF_NODETEST_NODES_50: Create 50 KubeEdge Node Deployment, Measure time for application comes into Running state", func(b Benchmarker) { - runtime := b.Time("QUIC_MEASURE_PERF_NODETEST_NODES_50", func() { - var deploymentList v1.DeploymentList - podlist = metav1.PodList{} - replica := 50 - //Generate the random string and assign as a UID - UID = "edgecore-app-" + utils.GetRandomString(5) - IsAppDeployed := utils.HandleDeployment(false, false, http.MethodPost, ctx.Cfg.K8SMasterForKubeEdge+DeploymentHandler, UID, ctx.Cfg.AppImageURL[1], "", "", replica) - Expect(IsAppDeployed).Should(BeTrue()) - err := utils.GetDeployments(&deploymentList, ctx.Cfg.K8SMasterForKubeEdge+DeploymentHandler) - Expect(err).To(BeNil()) - for _, deployment := range deploymentList.Items { - if deployment.Name == UID { - //label := nodeName - time.Sleep(2 * time.Second) - podlist, err = utils.GetPods(ctx.Cfg.K8SMasterForKubeEdge+AppHandler, "") - Expect(err).To(BeNil()) - break - } - } - utils.CheckPodRunningState(ctx.Cfg.K8SMasterForKubeEdge+AppHandler, podlist) - }) - - utils.Infof("Runtime stats: %+v", runtime) - - }, 5) - Measure("QUIC_MEASURE_PERF_NODETEST_NODES_75: Create 75 KubeEdge Node Deployment, Measure time for application comes into Running state", func(b Benchmarker) { - runtime := b.Time("QUIC_MEASURE_PERF_NODETEST_NODES_75", func() { - var deploymentList v1.DeploymentList - podlist = metav1.PodList{} - replica := 75 - //Generate the random string and assign as a UID - UID = "edgecore-app-" + utils.GetRandomString(5) - IsAppDeployed := utils.HandleDeployment(false, false, http.MethodPost, ctx.Cfg.K8SMasterForKubeEdge+DeploymentHandler, UID, ctx.Cfg.AppImageURL[1], "", "", replica) - Expect(IsAppDeployed).Should(BeTrue()) - err := utils.GetDeployments(&deploymentList, ctx.Cfg.K8SMasterForKubeEdge+DeploymentHandler) - Expect(err).To(BeNil()) - for _, deployment := range deploymentList.Items { - if deployment.Name == UID { - //label := nodeName - time.Sleep(2 * time.Second) - podlist, err = utils.GetPods(ctx.Cfg.K8SMasterForKubeEdge+AppHandler, "") - Expect(err).To(BeNil()) - break - } - } - utils.CheckPodRunningState(ctx.Cfg.K8SMasterForKubeEdge+AppHandler, podlist) - }) - utils.Infof("Runtime stats: %+v", runtime) - - }, 5) - Measure("QUIC_MEASURE_PERF_NODETEST_NODES_100: Create 100 KubeEdge Node Deployment, Measure time for application comes into Running state", func(b Benchmarker) { - runtime := b.Time("QUIC_MEASURE_PERF_NODETEST_NODES_100", func() { - var deploymentList v1.DeploymentList - podlist = metav1.PodList{} - replica := 100 - //Generate the random string and assign as a UID - UID = "edgecore-app-" + utils.GetRandomString(5) - IsAppDeployed := utils.HandleDeployment(false, false, http.MethodPost, ctx.Cfg.K8SMasterForKubeEdge+DeploymentHandler, UID, ctx.Cfg.AppImageURL[1], "", "", replica) - Expect(IsAppDeployed).Should(BeTrue()) - err := utils.GetDeployments(&deploymentList, ctx.Cfg.K8SMasterForKubeEdge+DeploymentHandler) - Expect(err).To(BeNil()) - for _, deployment := range deploymentList.Items { - if deployment.Name == UID { - //label := nodeName - time.Sleep(2 * time.Second) - podlist, err = utils.GetPods(ctx.Cfg.K8SMasterForKubeEdge+AppHandler, "") - Expect(err).To(BeNil()) - break - } - } - utils.CheckPodRunningState(ctx.Cfg.K8SMasterForKubeEdge+AppHandler, podlist) - }) - utils.Infof("Runtime stats: %+v", runtime) - }, 5) - }) -}) diff --git a/tests/performance/nodedensity/nodedensity_suite_test.go b/tests/performance/nodedensity/nodedensity_suite_test.go deleted file mode 100644 index 8cc47fdc9..000000000 --- a/tests/performance/nodedensity/nodedensity_suite_test.go +++ /dev/null @@ -1,104 +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 nodedensity - -import ( - "net" - "net/url" - "strconv" - "strings" - "testing" - "time" - - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - metav1 "k8s.io/api/core/v1" - - "github.com/kubeedge/kubeedge/tests/e2e/utils" - . "github.com/kubeedge/kubeedge/tests/performance/common" - "github.com/kubeedge/viaduct/pkg/api" -) - -//context to load config and access across the package -var ( - ctx *utils.TestContext - cfg utils.Config - cloudHubURL string - wsscloudHubURL string - quiccloudHubURL string -) - -func TestEdgecoreK8sDeployment(t *testing.T) { - var cloudCoreHostIP string - var podlist metav1.PodList - //var toTaint bool - RegisterFailHandler(Fail) - var _ = BeforeSuite(func() { - utils.Infof("Kubeedge deployment Load test Begin !!") - cfg = utils.LoadConfig() - ctx = utils.NewTestContext(cfg) - //apply label to all cluster nodes, use the selector to deploy all edgenodes to cluster nodes - err := ApplyLabel(ctx.Cfg.K8SMasterForProvisionEdgeNodes + NodeHandler) - Expect(err).Should(BeNil()) - //Create configMap for CloudCore - CloudConfigMap = "cloudcore-configmap-" + utils.GetRandomString(5) - CloudCoreDeployment = "cloudcore-deployment-" + utils.GetRandomString(5) - //protocol to be used for test between edge and cloud - if ctx.Cfg.Protocol == api.ProtocolTypeQuic { - IsQuicProtocol = true - } else { - IsQuicProtocol = false - } - //Deploye cloudcore as a k8s resource to cluster-1 - err = HandleCloudDeployment(CloudConfigMap, CloudCoreDeployment, ctx.Cfg.K8SMasterForKubeEdge, - ctx.Cfg.K8SMasterForKubeEdge+ConfigmapHandler, ctx.Cfg.K8SMasterForKubeEdge+DeploymentHandler, ctx.Cfg.CloudImageURL, ctx.Cfg.NumOfNodes) - Expect(err).Should(BeNil()) - time.Sleep(1 * time.Second) - //Get the cloudCore pod Node name and IP - podlist, err = utils.GetPods(ctx.Cfg.K8SMasterForKubeEdge+AppHandler, "") - Expect(err).To(BeNil()) - for _, pod := range podlist.Items { - if strings.Contains(pod.Name, "cloudcore-deployment") { - cloudCoreHostIP = pod.Status.HostIP - break - } - } - utils.CheckPodRunningState(ctx.Cfg.K8SMasterForKubeEdge+AppHandler, podlist) - time.Sleep(300 * time.Second) - //Create service for cloud - err = utils.ExposeCloudService(CloudCoreDeployment, ctx.Cfg.K8SMasterForKubeEdge+ServiceHandler) - Expect(err).Should(BeNil()) - //Create a nodePort Service to access the cloud Service from the cluster nodes - wsPort, quicPort := utils.GetServicePort(CloudCoreDeployment, ctx.Cfg.K8SMasterForKubeEdge+ServiceHandler) - wsNodePort := strconv.FormatInt(int64(wsPort), 10) - quicNodePort := strconv.FormatInt(int64(quicPort), 10) - quiccloudHubURL = net.JoinHostPort(cloudCoreHostIP, quicNodePort) - cloudHubURL = quiccloudHubURL - wsscloudHubURL = (&url.URL{ - Scheme: "wss", - Host: net.JoinHostPort(cloudCoreHostIP, wsNodePort), - }).String() - cloudHubURL = wsscloudHubURL - }) - AfterSuite(func() { - By("Kubeedge deployment Load test End !!....!") - - DeleteCloudDeployment(ctx.Cfg.K8SMasterForKubeEdge) - utils.CheckPodDeleteState(ctx.Cfg.K8SMasterForKubeEdge+AppHandler, podlist) - }) - - RunSpecs(t, "kubeedge Performance Load test Suite") -} diff --git a/tests/performance/nodedensity/nodedensity_test.go b/tests/performance/nodedensity/nodedensity_test.go deleted file mode 100644 index 541c4302c..000000000 --- a/tests/performance/nodedensity/nodedensity_test.go +++ /dev/null @@ -1,98 +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 nodedensity - -import ( - . "github.com/onsi/ginkgo" - metav1 "k8s.io/api/core/v1" - - "github.com/kubeedge/kubeedge/tests/e2e/utils" - . "github.com/kubeedge/kubeedge/tests/performance/common" -) - -var DeploymentTestTimerGroup *utils.TestTimerGroup = utils.NewTestTimerGroup() -var _ = Describe("Application deployment test in Perfronace test EdgeNodes", func() { - - Context("Test application deployment on specific EdgeNode", func() { - var testTimer *utils.TestTimer - var testDescription GinkgoTestDescription - var podlist metav1.PodList - var NoOfEdgeNodes int - - BeforeEach(func() { - testDescription = CurrentGinkgoTestDescription() - testTimer = DeploymentTestTimerGroup.NewTestTimer(testDescription.TestText) - }) - AfterEach(func() { - // End test timer - testTimer.End() - // Print result - testTimer.PrintResult() - DeleteEdgeDeployments(ctx.Cfg.K8SMasterForKubeEdge, ctx.Cfg.K8SMasterForProvisionEdgeNodes, NoOfEdgeNodes) - utils.CheckDeploymentPodDeleteState(ctx.Cfg.K8SMasterForProvisionEdgeNodes+AppHandler, podlist) - }) - - Measure("PERF_NODETEST_NODES_1: Create 1 KubeEdge Node Deployment, Measure Node Ready time", func(b Benchmarker) { - podlist = metav1.PodList{} - NoOfEdgeNodes = 1 - CreateConfigMapforEdgeCore(cloudHubURL, ctx.Cfg.K8SMasterForProvisionEdgeNodes+ConfigmapHandler, - ctx.Cfg.K8SMasterForKubeEdge+NodeHandler, NoOfEdgeNodes) - runtime := b.Time("PERF_NODETEST_NODES_1", func() { - podlist = HandleEdgeCorePodDeployment(ctx.Cfg.K8SMasterForProvisionEdgeNodes+DeploymentHandler, - ctx.Cfg.EdgeImageURL, ctx.Cfg.K8SMasterForProvisionEdgeNodes+AppHandler, - ctx.Cfg.K8SMasterForKubeEdge+NodeHandler, NoOfEdgeNodes) - }) - utils.Infof("Runtime stats: %+v", runtime) - }, 5) - Measure("PERF_NODETEST_NODES_5: Create 5 KubeEdge Node Deployment, Measure Node Ready time", func(b Benchmarker) { - podlist = metav1.PodList{} - NoOfEdgeNodes = 5 - CreateConfigMapforEdgeCore(cloudHubURL, ctx.Cfg.K8SMasterForProvisionEdgeNodes+ConfigmapHandler, - ctx.Cfg.K8SMasterForKubeEdge+NodeHandler, NoOfEdgeNodes) - runtime := b.Time("PERF_NODETEST_NODES_1", func() { - podlist = HandleEdgeCorePodDeployment(ctx.Cfg.K8SMasterForProvisionEdgeNodes+DeploymentHandler, - ctx.Cfg.EdgeImageURL, ctx.Cfg.K8SMasterForProvisionEdgeNodes+AppHandler, - ctx.Cfg.K8SMasterForKubeEdge+NodeHandler, NoOfEdgeNodes) - }) - utils.Infof("Runtime stats: %+v", runtime) - }, 5) - - Measure("PERF_NODETEST_NODES_10: Create 10 KubeEdge Node Deployment, Measure Node Ready time", func(b Benchmarker) { - podlist = metav1.PodList{} - NoOfEdgeNodes = 10 - CreateConfigMapforEdgeCore(cloudHubURL, ctx.Cfg.K8SMasterForProvisionEdgeNodes+ConfigmapHandler, - ctx.Cfg.K8SMasterForKubeEdge+NodeHandler, NoOfEdgeNodes) - runtime := b.Time("PERF_NODETEST_NODES_1", func() { - podlist = HandleEdgeCorePodDeployment(ctx.Cfg.K8SMasterForProvisionEdgeNodes+DeploymentHandler, - ctx.Cfg.EdgeImageURL, ctx.Cfg.K8SMasterForProvisionEdgeNodes+AppHandler, - ctx.Cfg.K8SMasterForKubeEdge+NodeHandler, NoOfEdgeNodes) - }) - utils.Infof("Runtime stats: %+v", runtime) - }, 5) - Measure("PERF_NODETEST_NODES_20: Create 20 KubeEdge Node Deployment, Measure Node Ready time", func(b Benchmarker) { - podlist = metav1.PodList{} - NoOfEdgeNodes = 50 - CreateConfigMapforEdgeCore(cloudHubURL, ctx.Cfg.K8SMasterForProvisionEdgeNodes+ConfigmapHandler, - ctx.Cfg.K8SMasterForKubeEdge+NodeHandler, NoOfEdgeNodes) - runtime := b.Time("PERF_NODETEST_NODES_1", func() { - podlist = HandleEdgeCorePodDeployment(ctx.Cfg.K8SMasterForProvisionEdgeNodes+DeploymentHandler, - ctx.Cfg.EdgeImageURL, ctx.Cfg.K8SMasterForProvisionEdgeNodes+AppHandler, - ctx.Cfg.K8SMasterForKubeEdge+NodeHandler, NoOfEdgeNodes) - }) - utils.Infof("Runtime stats: %+v", runtime) - }, 5) - }) -}) diff --git a/tests/performance/scripts/build_upload_image.sh b/tests/performance/scripts/build_upload_image.sh deleted file mode 100755 index 0ad5cc9de..000000000 --- a/tests/performance/scripts/build_upload_image.sh +++ /dev/null @@ -1,31 +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. - -SRC_DIR=${GOPATH}/src/github.com/kubeedge/kubeedge - -imageRepo=$1 - -if [ ! -z $(docker images -q ${imageRepo}/edgecore:latest) ];then - echo "Image exist locally !!" - docker rmi -f $(docker images -q ${imageRepo}/edgecore:latest) -fi - -cd ${SRC_DIR} - -docker build -t ${imageRepo}/edgecore:latest -f ${SRC_DIR}/build/edge/Dockerfile . - -docker push ${imageRepo}/edgecore:latest - -echo "edgecore image successfully built and pushed to repository !!" diff --git a/tests/performance/scripts/compileperf.sh b/tests/performance/scripts/compileperf.sh deleted file mode 100755 index 449943307..000000000 --- a/tests/performance/scripts/compileperf.sh +++ /dev/null @@ -1,31 +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. - -cd `dirname $0` -workdir=`pwd` -cd $workdir - -cd ../ -echo $PWD - -compiletest=$1 -#compile all test if user doesn't specify the test else compile only specified tests. -if [ $# -eq 0 ] - then - echo "compiling all Performance tests !!" - ginkgo build -r -else - ginkgo build -r $compiletest -fi diff --git a/tests/performance/scripts/jenkins.sh b/tests/performance/scripts/jenkins.sh deleted file mode 100755 index 8aaef7a02..000000000 --- a/tests/performance/scripts/jenkins.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. - -if [ "${1}" == "--help" ]; then - cat <<EOF -Usage: $(basename $0) <tests> - - <tests> the performance tests will be performed, it could be one of [loadtest, nodedensity, hubtest], - empty means all the performance tests will be performed. -Examples: - $(basename $0) - $(basename $0) loadtest - $(basename $0) nodedensity - $(basename $0) hubtest - -EOF - exit 0 -fi - -echo $PWD -curpath=$PWD -PWD=${curpath}/tests/performance -sudo rm -rf $PWD/loadtest/loadtest.test -sudo rm -rf $PWD/nodedensity/nodedensity.test -sudo rm -rf $PWD/hubtest/hubtest.test - -go install github.com/onsi/ginkgo/ginkgo@latest -sudo cp $GOPATH/bin/ginkgo /usr/bin/ -# Specify the module name to compile in below command -bash -x $PWD/scripts/compileperf.sh $1 - -:> /tmp/testcase.log -bash -x ${PWD}/scripts/runperf.sh $1 -#stop the edgecore after the test completion -grep -e "Running Suite" -e "SUCCESS\!" -e "FAIL\!" /tmp/performace_test.log | sed -r 's/\x1B\[([0-9];)?([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g' | sed -r 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g' -echo "Performance Test Final Summary Report" -echo "===============================================" -echo "Total Number of Test cases = `grep "Ran " /tmp/loadtest_perf.log | awk '{sum+=$2} END {print sum}'`" -passed=`grep -e "SUCCESS\!" -e "FAIL\!" /tmp/performace_test.log | awk '{print $3}' | sed -r "s/\x1B\[([0-9];)?([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g" | awk '{sum+=$1} END {print sum}'` -echo "Number of Test cases PASSED = $passed" -fail=`grep -e "SUCCESS\!" -e "FAIL\!" /tmp/performace_test.log | awk '{print $6}' | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g" | awk '{sum+=$1} END {print sum}'` -echo "Number of Test cases FAILED = $fail" -echo "==================Result Summary=======================" - -if [ "$fail" != "0" ];then - echo "Performance tests has failures, Please check !!" - exit 1 -else - echo "Performance tests successfully passed all the tests !!" - exit 0 -fi diff --git a/tests/performance/scripts/runperf.sh b/tests/performance/scripts/runperf.sh deleted file mode 100755 index 79ebf99ce..000000000 --- a/tests/performance/scripts/runperf.sh +++ /dev/null @@ -1,55 +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. - -cd `dirname $0` -workdir=`pwd` -cd $workdir - -debugflag="-v 6 -alsologtostderr" - -runtest=$1 - -export K8SMasterForKubeEdge=http://121.244.95.60:12436 -export K8SMasterForProvisionEdgeNodes=http://121.244.95.60:12458 -#setup env -cd ../ -#Pre-configurations required for running the suite. -#Any new config addition required corresponding code changes. -cat >config.json<<END -{ - "image_url": ["nginx", "hello-world"], - "k8smasterforkubeedge": "$K8SMasterForKubeEdge", - "node_num": 500, - "imagerepo": "kubeedge", - "k8smasterforprovisionedgenodes": "$K8SMasterForProvisionEdgeNodes", - "cloudimageurl": "kubeedge/edgecontroller-test:v1.0.0", - "edgeimageurl": "kubeedge/edgecore-test:v1.0.0", - "namespace":"default", - "controllerstubport": 54321, - "protocol": "websocket" -} -END - - -if [ $# -eq 0 ] - then - #run testcase - ./loadtest/loadtest.test $debugflag 2>&1 | tee /tmp/perf_test.log && cat /tmp/perf_test.log >> /tmp/performace_test.log && :> /tmp/perf_test.log - ./nodedensity/nodedensity.test $debugflag 2>&1 | tee /tmp/perf_test.log && cat /tmp/perf_test.log >> /tmp/performace_test.log && :> /tmp/perf_test.log - ./hubtest/hubtest.test $debugflag 2>&1 | tee /tmp/perf_test.log && cat /tmp/perf_test.log >> /tmp/performace_test.log && :> /tmp/perf_test.log -else - ./$runtest/$runtest.test $debugflag 2>&1 | tee /tmp/perf_test.log && cat /tmp/perf_test.log >> /tmp/performace_test.log && :> /tmp/perf_test.log -fi diff --git a/tests/performance/scripts/update_configmap.sh b/tests/performance/scripts/update_configmap.sh deleted file mode 100755 index bb1e646de..000000000 --- a/tests/performance/scripts/update_configmap.sh +++ /dev/null @@ -1,56 +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. - -SRC_DIR=${GOPATH}/src/github.com/kubeedge/kubeedge -EDGE_PATH=${SRC_DIR}/tests/performance/assets/02-edgeconfigmap.yaml -CLOUD_PATH=${SRC_DIR}/tests/performance/assets/01-configmap.yaml - -nodename=$2 -Url=$3 -configmapName=$4 -nodelimit=$5 - - -create_edge_config() { - if [ ! -f ${EDGE_PATH} ]; then - echo "There is no 03-configmap-edgenodeconf.yaml!" - exit 1 - fi - echo "file found !!!!!!!!!!!!!" - sed -i "s|namespace: .*|namespace: default|g" ${EDGE_PATH} - sed -i "s|name: edgecore-configmap.*|name: ${configmapName}|g" ${EDGE_PATH} - sed -i "s|node-id: .*|node-id: ${nodename}|g" ${EDGE_PATH} - sed -i "s|hostname-override: .*|hostname-override: ${nodename}|g" ${EDGE_PATH} - if [[ ${Url} == *"wss"* ]]; then - sed -i "20s|url: .*|url: ${Url}/e632aba927ea4ac2b575ec1603d56f10/${nodename}/events|g" ${EDGE_PATH} - sed -i "s|protocol: .*|protocol: websocket|g" ${EDGE_PATH} - else - sed -i "28s|url: .*|url: ${Url}|g" ${EDGE_PATH} - sed -i "s|protocol: .*|protocol: quic|g" ${EDGE_PATH} - fi -} - -create_cloud_config() { - if [ ! -f ${CLOUD_PATH} ]; then - echo "There is no 01-configmap.yaml!" - exit 1 - fi - echo "file found !!!!!!!!!!!!!" - sed -i "s|master: .*|master: ${Url}|g" ${CLOUD_PATH} - sed -i "s|name: .*|name: ${configmapName}|g" ${CLOUD_PATH} - sed -i "s|node-limit: .*|node-limit: ${nodelimit}|g" ${CLOUD_PATH} -} - -"$@"
\ No newline at end of file diff --git a/tests/stubs/cloud/controllerstub/downstream.go b/tests/stubs/cloud/controllerstub/downstream.go deleted file mode 100644 index 788fce2d3..000000000 --- a/tests/stubs/cloud/controllerstub/downstream.go +++ /dev/null @@ -1,58 +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 controllerstub - -import ( - "k8s.io/klog/v2" - - beehiveContext "github.com/kubeedge/beehive/pkg/core/context" - "github.com/kubeedge/kubeedge/tests/stubs/common/constants" -) - -// NewDownstreamController creates a downstream controller -func NewDownstreamController(pm *PodManager) (*DownstreamController, error) { - // New downstream controller - dc := &DownstreamController{podManager: pm} - return dc, nil -} - -// DownstreamController receives http request and send to cloudhub -type DownstreamController struct { - podManager *PodManager -} - -// Start DownstreamController -func (dc *DownstreamController) Start() error { - klog.Infof("Start downstream controller") - go dc.SyncPods() - return nil -} - -// SyncPods is used to send message to cloudhub -func (dc *DownstreamController) SyncPods() { - for { - select { - case <-beehiveContext.Done(): - klog.Info("Stop sync pod") - return - case msg := <-dc.podManager.GetEvent(): - klog.Infof("Send message to cloudhub: %v", *msg) - beehiveContext.Send(constants.CloudHub, *msg) - klog.Info("Finish send message to cloudhub") - } - } -} diff --git a/tests/stubs/cloud/controllerstub/module.go b/tests/stubs/cloud/controllerstub/module.go deleted file mode 100644 index 89077addd..000000000 --- a/tests/stubs/cloud/controllerstub/module.go +++ /dev/null @@ -1,92 +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 controllerstub - -import ( - "net/http" - - "k8s.io/klog/v2" - - "github.com/kubeedge/beehive/pkg/core" - "github.com/kubeedge/kubeedge/tests/stubs/common/constants" -) - -// Init module -func init() { - core.Register(&ControllerStub{}) -} - -// HandlerStub definition -type ControllerStub struct { -} - -var _ core.Module = (*ControllerStub)(nil) - -func (*ControllerStub) Enable() bool { - return true -} - -// Return module name -func (*ControllerStub) Name() string { - return constants.ControllerStub -} - -// Return module group -func (*ControllerStub) Group() string { - return constants.ControllerGroup -} - -// Start controller hub -func (cs *ControllerStub) Start() { - // New pod manager - pm, err := NewPodManager() - if err != nil { - klog.Errorf("Failed to create pod manager with error: %v", err) - return - } - - // Start downstream controller - downstream, err := NewDownstreamController(pm) - if err != nil { - klog.Errorf("New downstream controller failed with error: %v", err) - return - } - if err := downstream.Start(); err != nil { - klog.Errorf("Start downstream controller failed with error: %v", err) - return - } - - // Start upstream controller - upstream, err := NewUpstreamController(pm) - if err != nil { - klog.Errorf("New upstream controller failed with error: %v", err) - return - } - if err := upstream.Start(); err != nil { - klog.Errorf("Start upstream controller failed with error: %v", err) - return - } - - // Start http server - http.HandleFunc(constants.PodResource, pm.PodHandlerFunc) - klog.Info("Start http service") - go func() { - if err := http.ListenAndServe(":54321", nil); err != nil { - klog.Errorf("Start http service failed with error: %v", err) - } - }() -} diff --git a/tests/stubs/cloud/controllerstub/podmanager.go b/tests/stubs/cloud/controllerstub/podmanager.go deleted file mode 100644 index 6d3123c22..000000000 --- a/tests/stubs/cloud/controllerstub/podmanager.go +++ /dev/null @@ -1,200 +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 controllerstub - -import ( - "bytes" - "encoding/json" - "io" - "net/http" - "sync" - "time" - - "k8s.io/klog/v2" - - "github.com/kubeedge/beehive/pkg/core/model" - "github.com/kubeedge/kubeedge/tests/stubs/common/constants" - "github.com/kubeedge/kubeedge/tests/stubs/common/types" - "github.com/kubeedge/kubeedge/tests/stubs/common/utils" -) - -// NewPodManager creates pod manger -func NewPodManager() (*PodManager, error) { - event := make(chan *model.Message, 1024) - pm := &PodManager{event: event} - return pm, nil -} - -// PodManager is a manager watch pod change event -type PodManager struct { - // event - event chan *model.Message - // pods map - pods sync.Map -} - -// GetEvent return a channel which receives event -func (pm *PodManager) GetEvent() chan *model.Message { - return pm.event -} - -// AddPod adds pod in cache -func (pm *PodManager) AddPod(k string, v types.FakePod) { - pm.pods.Store(k, v) -} - -// DeletePod deletes pod in cache -func (pm *PodManager) DeletePod(k string) { - pm.pods.Delete(k) -} - -// UpdatePodStatus update pod status in cache -func (pm *PodManager) UpdatePodStatus(k string, s string) { - v, ok := pm.pods.Load(k) - if ok { - pod := v.(types.FakePod) - // Status becomes running in the first time - if pod.Status != s && s == constants.PodRunning { - pod.RunningTime = time.Now().UnixNano() - } - pod.Status = s - pm.pods.Store(k, pod) - } -} - -// GetPod gets pod from cache -func (pm *PodManager) GetPod(key string) types.FakePod { - v, ok := pm.pods.Load(key) - if ok { - return v.(types.FakePod) - } - return types.FakePod{} -} - -// ListPods lists all pods in cache -func (pm *PodManager) ListPods() []types.FakePod { - pods := make([]types.FakePod, 0) - pm.pods.Range(func(k, v interface{}) bool { - pods = append(pods, v.(types.FakePod)) - return true - }) - return pods -} - -// PodHandlerFunc is used to receive and process message -func (pm *PodManager) PodHandlerFunc(w http.ResponseWriter, req *http.Request) { - switch req.Method { - case http.MethodGet: - // List Pod - klog.V(4).Infof("Receive list pod request") - pods := pm.ListPods() - klog.V(4).Infof("Current pods number: %v", len(pods)) - rspBodyBytes := new(bytes.Buffer) - if err := json.NewEncoder(rspBodyBytes).Encode(pods); err != nil { - klog.Errorf("Encode to json file with error: %v", err) - return - } - if _, err := w.Write(rspBodyBytes.Bytes()); err != nil { - klog.Errorf("Write error: %v", err) - return - } - klog.V(4).Infof("Finish list pod request") - case http.MethodPost: - klog.V(4).Infof("Receive add pod request") - var p types.FakePod - // Get request body - if req.Body != nil { - body, err := io.ReadAll(req.Body) - if err != nil { - klog.Errorf("Read body error %v", err) - if _, err := w.Write([]byte("Read request body error")); err != nil { - klog.Errorf("Write error: %v", err) - } - return - } - klog.V(4).Infof("Request body is %s", string(body)) - if err = json.Unmarshal(body, &p); err != nil { - klog.Errorf("Unmarshal request body error %v", err) - if _, err := w.Write([]byte("Unmarshal request body error")); err != nil { - klog.Errorf("Wrire body error %v", err) - } - return - } - } - // Add Pod - ns := constants.NamespaceDefault - if p.Namespace != "" { - ns = p.Namespace - } - - // Build Add message - msg := model.NewMessage("") - resource, err := utils.BuildResource(p.NodeName, p.Namespace, model.ResourceTypePod, p.Name) - if err != nil { - klog.Errorf("Build message resource failed with error: %s", err) - if _, err := w.Write([]byte("Build message resource failed with error")); err != nil { - klog.Errorf("Write body error %v", err) - } - return - } - msg.Content = p - msg.BuildRouter(constants.ControllerStub, constants.GroupResource, resource, model.InsertOperation) - - // Add pod in cache - p.CreateTime = time.Now().UnixNano() - pm.AddPod(ns+"/"+p.Name, p) - - // Send msg - pm.event <- msg - klog.V(4).Infof("Finish add pod request") - - case http.MethodDelete: - // Delete Pod - klog.V(4).Infof("Receive delete pod request") - params := req.URL.Query() - ns := params.Get("namespace") - if ns == "" { - ns = constants.NamespaceDefault - } - nodename := params.Get("nodename") - name := params.Get("name") - klog.V(4).Infof("Pod Namespace: %s NodeName: %s Name: %s", ns, nodename, name) - - // Build delete message - msg := model.NewMessage("") - resource, err := utils.BuildResource(nodename, ns, model.ResourceTypePod, name) - if err != nil { - klog.Errorf("Build message resource failed with error: %s", err) - if _, err := w.Write([]byte("Build message resource failed with error")); err != nil { - klog.Errorf("write error: %v", err) - } - return - } - msg.Content = pm.GetPod(ns + "/" + name) - msg.BuildRouter(constants.ControllerStub, constants.GroupResource, resource, model.DeleteOperation) - - // Delete pod in cache - pm.DeletePod(ns + "/" + name) - - // Send msg - pm.event <- msg - klog.V(4).Infof("Finish delete pod request") - - default: - klog.Errorf("Http type: %s unsupported", req.Method) - } -} diff --git a/tests/stubs/cloud/controllerstub/upstream.go b/tests/stubs/cloud/controllerstub/upstream.go deleted file mode 100644 index fd3c82191..000000000 --- a/tests/stubs/cloud/controllerstub/upstream.go +++ /dev/null @@ -1,126 +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 controllerstub - -import ( - "encoding/json" - - "k8s.io/klog/v2" - - beehiveContext "github.com/kubeedge/beehive/pkg/core/context" - "github.com/kubeedge/beehive/pkg/core/model" - "github.com/kubeedge/kubeedge/tests/stubs/common/constants" - "github.com/kubeedge/kubeedge/tests/stubs/common/types" - "github.com/kubeedge/kubeedge/tests/stubs/common/utils" -) - -// NewUpstreamController creates a upstream controller -func NewUpstreamController(pm *PodManager) (*UpstreamController, error) { - // New upstream controller - uc := &UpstreamController{podManager: pm} - return uc, nil -} - -// UpstreamController subscribe messages from edge -type UpstreamController struct { - podManager *PodManager - podStatusChan chan model.Message -} - -// Start UpstreamController -func (uc *UpstreamController) Start() error { - klog.Infof("Start upstream controller") - uc.podStatusChan = make(chan model.Message, 1024) - - go uc.WaitforMessage() - go uc.UpdatePodStatus() - - return nil -} - -// WaitforMessage from cloudhub -func (uc *UpstreamController) WaitforMessage() { - for { - select { - case <-beehiveContext.Done(): - klog.Infof("Stop waiting for message") - return - default: - } - // Receive message from cloudhub - msg, err := beehiveContext.Receive(constants.ControllerStub) - if err != nil { - klog.Errorf("Receive message failed: %v", err) - continue - } - klog.V(4).Infof("Receive message: %v", msg) - - // Get resource type in message - resourceType, err := utils.GetResourceType(msg) - if err != nil { - klog.Errorf("Get message: %s resource type with error: %v", msg.GetID(), err) - continue - } - klog.Infof("Message: %s resource type: %s", msg.GetID(), resourceType) - - switch resourceType { - case model.ResourceTypePodStatus: - uc.podStatusChan <- msg - default: - klog.V(4).Infof("Message: %s, resource type: %s unsupported", msg.GetID(), resourceType) - } - } -} - -// UpdatePodStatus is used to update pod status in cache map -func (uc *UpstreamController) UpdatePodStatus() { - for { - select { - case <-beehiveContext.Done(): - klog.Infof("Stop updatePodStatus") - return - case msg := <-uc.podStatusChan: - klog.Infof("Message: %s operation: %s resource: %s", - msg.GetID(), msg.GetOperation(), msg.GetResource()) - switch msg.GetOperation() { - case model.UpdateOperation: - // get message content data - data, err := msg.GetContentData() - if err != nil { - klog.Warningf("message: %s process failure, get content data failed: %s", msg.GetID(), err) - continue - } - - // Get pod - var pod types.FakePod - if err := json.Unmarshal(data, &pod); err != nil { - klog.Errorf("Unmarshal content failed with error: %s, %v", msg.GetID(), err) - continue - } - - // Update pod status in cache - uc.podManager.UpdatePodStatus(pod.Namespace+"/"+pod.Name, pod.Status) - - klog.Infof("Pod namespace: %s name: %s status: %s", - pod.Namespace, pod.Name, pod.Status) - default: - klog.V(4).Infof("Pod operation: %s unsupported", msg.GetOperation()) - } - klog.V(4).Infof("Message: %s process successfully", msg.GetID()) - } - } -} diff --git a/tests/stubs/common/constants/constants.go b/tests/stubs/common/constants/constants.go deleted file mode 100644 index ae60b3497..000000000 --- a/tests/stubs/common/constants/constants.go +++ /dev/null @@ -1,54 +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 constants - -const ( - - // Modules - CloudHub = "cloudhub" - EdgeHub = "edgehub" - ControllerStub = "controllerstub" - HandlerStub = "handlerstub" - - // Group - ControllerGroup = "controller" - HubGroup = "hub" - MetaGroup = "meta" - - ResourceSliceLength = 5 - ResourceSliceLengthQuery = 4 - ResourceNodeIndex = 0 - ResourceNodeIDIndex = 1 - ResourceNamespaceIndex = 2 - ResourceResourceTypeIndex = 3 - ResourceResourceNameIndex = 4 - ResourceNode = "node" - - // Group - GroupResource = "resource" - NamespaceDefault = "default" - - // Pod status - - PodResource = "/pods" - - PodPending = "Pending" - PodRunning = "Running" - PodSucceeded = "Succeeded" - PodFailed = "Failed" - PodUnknown = "Unknown" -) diff --git a/tests/stubs/common/types/types.go b/tests/stubs/common/types/types.go deleted file mode 100644 index 75c528d62..000000000 --- a/tests/stubs/common/types/types.go +++ /dev/null @@ -1,52 +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 types - -import "time" - -// FakePod -type FakePod struct { - Namespace string `json:"namespace,omitempty"` - Name string `json:"name,omitempty"` - NodeName string `json:"nodename,omitempty"` - Status string `json:"status,omitempty"` - CreateTime int64 `json:"createtime,omitempty"` - RunningTime int64 `json:"runningtime,omitempty"` -} - -// FakePodSort -type FakePodSort []FakePod - -func (s FakePodSort) Len() int { - return len(s) -} - -func (s FakePodSort) Swap(i, j int) { - s[i], s[j] = s[j], s[i] -} - -func (s FakePodSort) Less(i, j int) bool { - return s[i].RunningTime-s[i].CreateTime < s[j].RunningTime-s[j].CreateTime -} - -// Latency -type Latency struct { - Percent50 time.Duration `json:"percent50,omitempty"` - Percent90 time.Duration `json:"percent90,omitempty"` - Percent99 time.Duration `json:"percent99,omitempty"` - Percent100 time.Duration `json:"percent100,omitempty"` -} diff --git a/tests/stubs/common/utils/utils.go b/tests/stubs/common/utils/utils.go deleted file mode 100644 index e328002c6..000000000 --- a/tests/stubs/common/utils/utils.go +++ /dev/null @@ -1,88 +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 utils - -import ( - "fmt" - "strings" - - "github.com/kubeedge/beehive/pkg/core/model" - constants "github.com/kubeedge/kubeedge/common/constants" - testconstants "github.com/kubeedge/kubeedge/tests/stubs/common/constants" -) - -// BuildResource return a string as "beehive/pkg/core/model".Message.Router.Resource -func BuildResource(nodeID, namespace, resourceType, resourceID string) (resource string, err error) { - if nodeID == "" || namespace == "" || resourceType == "" { - err = fmt.Errorf("Required parameter are not set (node id, namespace or resource type)") - return - } - resource = fmt.Sprintf("%s%s%s%s%s%s%s", testconstants.ResourceNode, constants.ResourceSep, nodeID, constants.ResourceSep, namespace, constants.ResourceSep, resourceType) - if resourceID != "" { - resource += fmt.Sprintf("%s%s", constants.ResourceSep, resourceID) - } - return -} - -// GetNodeID from "beehive/pkg/core/model".Message.Router.Resource -func GetNodeID(msg model.Message) (string, error) { - sli := strings.Split(msg.GetResource(), constants.ResourceSep) - if len(sli) <= testconstants.ResourceNodeIDIndex { - return "", fmt.Errorf("node id not found") - } - return sli[testconstants.ResourceNodeIDIndex], nil -} - -// GetNamespace from "beehive/pkg/core/model".Model.Router.Resource -func GetNamespace(msg model.Message) (string, error) { - sli := strings.Split(msg.GetResource(), constants.ResourceSep) - if len(sli) <= testconstants.ResourceNamespaceIndex { - return "", fmt.Errorf("namespace not found") - } - return sli[testconstants.ResourceNamespaceIndex], nil -} - -// GetResourceType from "beehive/pkg/core/model".Model.Router.Resource -func GetResourceType(msg model.Message) (string, error) { - sli := strings.Split(msg.GetResource(), constants.ResourceSep) - if len(sli) <= testconstants.ResourceResourceTypeIndex { - return "", fmt.Errorf("resource type not found") - } - return sli[testconstants.ResourceResourceTypeIndex], nil -} - -// GetResourceName from "beehive/pkg/core/model".Model.Router.Resource -func GetResourceName(msg model.Message) (string, error) { - sli := strings.Split(msg.GetResource(), constants.ResourceSep) - if len(sli) <= testconstants.ResourceResourceNameIndex { - return "", fmt.Errorf("resource name not found") - } - return sli[testconstants.ResourceResourceNameIndex], nil -} - -// ParseResourceEdge parses resource at edge and returns namespace, resource_type, resource_id. -// If operation of msg is query list, return namespace, pod. -func ParseResourceEdge(resource string, operation string) (string, string, string, error) { - resourceSplits := strings.Split(resource, "/") - if len(resourceSplits) == 3 { - return resourceSplits[0], resourceSplits[1], resourceSplits[2], nil - } else if operation == model.QueryOperation || operation == model.ResponseOperation && len(resourceSplits) == 2 { - return resourceSplits[0], resourceSplits[1], "", nil - } else { - return "", "", "", fmt.Errorf("resource: %s format incorrect, or Operation: %s is not query/response", resource, operation) - } -} diff --git a/tests/stubs/devices/mockserver.go b/tests/stubs/devices/mockserver.go deleted file mode 100644 index b718928df..000000000 --- a/tests/stubs/devices/mockserver.go +++ /dev/null @@ -1,92 +0,0 @@ -package devices - -import ( - "context" - "flag" - "fmt" - "os" - "time" - - "github.com/paypal/gatt" - "github.com/paypal/gatt/examples/option" - "github.com/paypal/gatt/examples/service" - "k8s.io/klog/v2" - - "github.com/kubeedge/kubeedge/tests/stubs/devices/services" -) - -const openBeaconUUID = "AA6062F098CA42118EC4193EB73CCEB6" - -var timeDuration *int - -func createServiceAndAdvertise(d gatt.Device, s gatt.State) { - // Setup GAP and GATT services for Linux implementation. - if err := d.AddService(service.NewGapService("SensorTagMock")); err != nil { - klog.Errorf("failed to add service SensorTagMock, error: %v", err) - } - - if err := d.AddService(service.NewGattService()); err != nil { - klog.Errorf("failed to add service, error: %v", err) - } - - // Creating a temperature reading service - temperatureSvc := services.NewTemperatureService() - if err := d.AddService(temperatureSvc); err != nil { - klog.Errorf("failed to add service, error: %v", err) - } - - // Advertise device name and service's UUIDs. - klog.Info("Advertising device name and service UUID") - if err := d.AdvertiseNameAndServices("mock temp sensor model", []gatt.UUID{temperatureSvc.UUID()}); err != nil { - klog.Errorf("failed to mock temp sensor model, error: %v", err) - } - - // Advertise as an OpenBeacon iBeacon - klog.Info("Advertise as an OpenBeacon iBeacon") - if err := d.AdvertiseIBeacon(gatt.MustParseUUID(openBeaconUUID), 1, 2, -59); err != nil { - klog.Errorf("Failed to advertise, error: %v", err) - } -} - -//usage is responsible for setting up the default settings of all defined command-line flags for klog. -func usage() { - flag.PrintDefaults() - os.Exit(2) -} - -//init for getting command line arguments -func init() { - flag.Usage = usage - timeDuration = flag.Int("duration", 5, "time duration for which server should be run") - flag.Parse() -} - -func main() { - d, err := gatt.NewDevice(option.DefaultServerOptions...) - if err != nil { - klog.Fatalf("Failed to open device, err: %s", err) - } - - // Register optional handlers. - d.Handle( - gatt.CentralConnected(func(c gatt.Central) { fmt.Println("Connect: ", c.ID()) }), - gatt.CentralDisconnected(func(c gatt.Central) { fmt.Println("Disconnect: ", c.ID()) }), - ) - - duration := time.Duration(*timeDuration) * time.Minute - ctx, cancel := context.WithTimeout(context.Background(), duration) - defer cancel() - if err := d.Init(createServiceAndAdvertise); err != nil { - klog.Errorf("Failed to create service, err: %s", err) - } - - <-ctx.Done() - klog.Info("Stopping server and cleaning up") - if err := d.StopAdvertising(); err != nil { - klog.Fatalf("failed to stop advertising, err: %v", err) - } - if err := d.RemoveAllServices(); err != nil { - klog.Fatalf("failed to remove all services, err: %v", err) - } - klog.Info("Stopped advertising and removed all services!!!!") -} diff --git a/tests/stubs/devices/services/temperature.go b/tests/stubs/devices/services/temperature.go deleted file mode 100644 index 7157dd932..000000000 --- a/tests/stubs/devices/services/temperature.go +++ /dev/null @@ -1,81 +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 services - -import ( - "fmt" - - "github.com/paypal/gatt" -) - -const ( - // serviceUUID is characteristic UUID for creating a new temperature service. - serviceUUID = "09fc95c0-c111-11e3-9904-0002a5d5c51b" - // readCharacteristicUUID is characteristic UUID for reading temperature. - readCharacteristicUUID = "11fac9e0-c111-11e3-9246-0002a5d5c51b" - // writeCharacteristicUUID is characteristic UUID for writing temperature. - writeCharacteristicUUID = "16fe0d80-c111-11e3-b8c8-0002a5d5c51b" - // readWrittenDataCharacteristicUUID is characteristic UUID for reading data written to connected device. - readWrittenDataCharacteristicUUID = "1c927b50-c116-11e3-8a33-0800200c9a66" - // dataConverterUUID is characteristic UUID for data conversion. - dataConverterUUID = "2d816a41-d335-44f5-7b55-9000200c8a77" - // twinStateUUID is characteristic UUID for changing twin state of device. - twinStateUUID = "3d816a41-e336-55e5-7c66-8000100d8a44" -) - -var dataWrite string -var write bool -var state string - -func NewTemperatureService() *gatt.Service { - temp := 36 - s := gatt.NewService(gatt.MustParseUUID(serviceUUID)) - - s.AddCharacteristic(gatt.MustParseUUID(readCharacteristicUUID)).HandleReadFunc( - func(rsp gatt.ResponseWriter, req *gatt.ReadRequest) { - fmt.Fprintf(rsp, "%d", temp) - }) - - s.AddCharacteristic(gatt.MustParseUUID(writeCharacteristicUUID)).HandleWriteFunc( - func(r gatt.Request, data []byte) (status byte) { - fmt.Println("Wrote:", string(data)) - write = true - dataWrite = string(data) - return gatt.StatusSuccess - }) - - s.AddCharacteristic(gatt.MustParseUUID(readWrittenDataCharacteristicUUID)).HandleReadFunc( - func(rsp gatt.ResponseWriter, req *gatt.ReadRequest) { - if write { - fmt.Fprintf(rsp, "%s", dataWrite) - } - }) - - s.AddCharacteristic(gatt.MustParseUUID(dataConverterUUID)).HandleReadFunc( - func(rsp gatt.ResponseWriter, req *gatt.ReadRequest) { - data := []uint8{32, 10, 248, 12} - fmt.Fprintf(rsp, "%s", data) - }) - - s.AddCharacteristic(gatt.MustParseUUID(twinStateUUID)).HandleWriteFunc( - func(r gatt.Request, data []byte) (status byte) { - state = "Red" - return gatt.StatusSuccess - }) - - return s -} diff --git a/tests/stubs/edge/handlerstub/message.go b/tests/stubs/edge/handlerstub/message.go deleted file mode 100644 index 8e1dfc473..000000000 --- a/tests/stubs/edge/handlerstub/message.go +++ /dev/null @@ -1,143 +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 handlerstub - -import ( - "encoding/json" - - "k8s.io/klog/v2" - - beehiveContext "github.com/kubeedge/beehive/pkg/core/context" - "github.com/kubeedge/beehive/pkg/core/model" - "github.com/kubeedge/kubeedge/edge/pkg/common/util" - "github.com/kubeedge/kubeedge/tests/stubs/common/constants" - "github.com/kubeedge/kubeedge/tests/stubs/common/types" -) - -// WaitforMessage is used to receive and process message -func (hs *HandlerStub) WaitforMessage() { - go func() { - for { - select { - case <-beehiveContext.Done(): - klog.Warning("stop waiting for message") - return - default: - } - if msg, err := beehiveContext.Receive(hs.Name()); err == nil { - klog.V(4).Infof("Receive a message %v", msg) - hs.ProcessMessage(msg) - } else { - klog.Errorf("Failed to receive message %v with error: %v", msg, err) - } - } - }() -} - -// ProcessMessage based on the operation type -func (hs *HandlerStub) ProcessMessage(msg model.Message) { - klog.V(4).Infof("Begin to process message %v", msg) - operation := msg.GetOperation() - switch operation { - case model.InsertOperation: - hs.ProcessInsert(msg) - case model.DeleteOperation: - hs.ProcessDelete(msg) - default: - klog.V(4).Infof("Unsupported message: %s operation: %s", msg.GetID(), operation) - } - klog.V(4).Infof("End to process message %v", msg) -} - -// ProcessInsert message -func (hs *HandlerStub) ProcessInsert(msg model.Message) { - // Get resource type - _, resType, _, err := util.ParseResourceEdge(msg.GetResource(), msg.GetOperation()) - if err != nil { - klog.Errorf("failed to parse the Resource: %v", err) - return - } - - if resType == model.ResourceTypePod { - // receive pod add event - klog.V(4).Infof("Message content: %v", msg) - - // get message content data - data, err := msg.GetContentData() - if err != nil { - klog.Warningf("message: %s process failure, get content data failed: %s", msg.GetID(), err) - return - } - - // Get pod - var pod types.FakePod - if err := json.Unmarshal(data, &pod); err != nil { - klog.Errorf("Unmarshal content failed with error: %s, %v", msg.GetID(), err) - return - } - - // Build Add message - pod.Status = constants.PodRunning - respMessage := model.NewMessage("") - resource := pod.Namespace + "/" + model.ResourceTypePodStatus + "/" + pod.Name - respMessage.Content = pod - respMessage.BuildRouter(constants.HandlerStub, constants.GroupResource, resource, model.UpdateOperation) - - hs.SendToCloud(respMessage) - - // Add pod in cache - hs.podManager.AddPod(pod.Namespace+"/"+pod.Name, pod) - } -} - -// ProcessDelete message -func (hs *HandlerStub) ProcessDelete(msg model.Message) { - // Get resource type - _, resType, _, err := util.ParseResourceEdge(msg.GetResource(), msg.GetOperation()) - if err != nil { - klog.Errorf("failed to parse the Resource: %v", err) - return - } - - if resType == model.ResourceTypePod { - // Receive pod delete event - klog.V(4).Infof("Message content: %v", msg) - - // get message content data - data, err := msg.GetContentData() - if err != nil { - klog.Warningf("message: %s process failure, get content data failed with error: %s", msg.GetID(), err) - return - } - - // Get pod - var pod types.FakePod - if err := json.Unmarshal(data, &pod); err != nil { - klog.Errorf("Unmarshal content failed with error: %s, %v", msg.GetID(), err) - return - } - // Delete pod in cache - hs.podManager.DeletePod(pod.Namespace + "/" + pod.Name) - } -} - -// SendToCloud sends message to cloudhub by edgehub -func (hs *HandlerStub) SendToCloud(msg *model.Message) { - klog.V(4).Infof("Begin to send message %v", *msg) - beehiveContext.SendToGroup(constants.HubGroup, *msg) - klog.V(4).Infof("End to send message %v", *msg) -} diff --git a/tests/stubs/edge/handlerstub/module.go b/tests/stubs/edge/handlerstub/module.go deleted file mode 100644 index f559809eb..000000000 --- a/tests/stubs/edge/handlerstub/module.go +++ /dev/null @@ -1,76 +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 handlerstub - -import ( - "k8s.io/klog/v2" - - "github.com/kubeedge/beehive/pkg/core" - "github.com/kubeedge/kubeedge/tests/stubs/common/constants" -) - -// Init module -func init() { - core.Register(&HandlerStub{}) -} - -// HandlerStub definition -type HandlerStub struct { - podManager *PodManager -} - -var _ core.Module = (*HandlerStub)(nil) - -func (*HandlerStub) Enable() bool { - return true -} - -// Return module name -func (*HandlerStub) Name() string { - return constants.HandlerStub -} - -// Return module group -func (*HandlerStub) Group() string { - return constants.MetaGroup -} - -// Start handler hub -func (hs *HandlerStub) Start() { - // New pod manager - pm, err := NewPodManager() - if err != nil { - klog.Errorf("Failed to create pod manager with error: %v", err) - return - } - hs.podManager = pm - - // Wait for message - klog.Infof("Wait for message") - hs.WaitforMessage() - - // Start upstream controller - upstream, err := NewUpstreamController(pm) - if err != nil { - klog.Errorf("New upstream controller failed with error: %v", err) - return - } - if err := upstream.Start(); err != nil { - klog.Errorf("Failed to start upstream with error: %v", err) - return - } -} diff --git a/tests/stubs/edge/handlerstub/podmanager.go b/tests/stubs/edge/handlerstub/podmanager.go deleted file mode 100644 index 71501c81a..000000000 --- a/tests/stubs/edge/handlerstub/podmanager.go +++ /dev/null @@ -1,55 +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 handlerstub - -import ( - "sync" - - "github.com/kubeedge/kubeedge/tests/stubs/common/types" -) - -// NewPodManager creates pod manager -func NewPodManager() (*PodManager, error) { - pm := &PodManager{} - return pm, nil -} - -// PodManager is a manager watch pod change event -type PodManager struct { - // pods map - pods sync.Map -} - -// AddPod adds pod in cache -func (pm *PodManager) AddPod(k string, v types.FakePod) { - pm.pods.Store(k, v) -} - -// DeletePod deletes pod in cache -func (pm *PodManager) DeletePod(k string) { - pm.pods.Delete(k) -} - -// ListPods lists all pods in cache -func (pm *PodManager) ListPods() []types.FakePod { - pods := make([]types.FakePod, 0) - pm.pods.Range(func(k, v interface{}) bool { - pods = append(pods, v.(types.FakePod)) - return true - }) - return pods -} diff --git a/tests/stubs/edge/handlerstub/upstream.go b/tests/stubs/edge/handlerstub/upstream.go deleted file mode 100644 index 8cac60aad..000000000 --- a/tests/stubs/edge/handlerstub/upstream.go +++ /dev/null @@ -1,72 +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 handlerstub - -import ( - "time" - - "k8s.io/klog/v2" - - beehiveContext "github.com/kubeedge/beehive/pkg/core/context" - "github.com/kubeedge/beehive/pkg/core/model" - "github.com/kubeedge/kubeedge/tests/stubs/common/constants" -) - -// NewUpstreamController creates a upstream controller -func NewUpstreamController(pm *PodManager) (*UpstreamController, error) { - // New upstream controller - dc := &UpstreamController{podManager: pm} - return dc, nil -} - -// UpstreamController sends message to edghub -type UpstreamController struct { - podManager *PodManager -} - -// Start upstream -func (dc *UpstreamController) Start() error { - klog.Infof("Start upstream controller") - go dc.SyncPods() - return nil -} - -// SyncPods is used to send simulation messages to edgehub periodically -func (dc *UpstreamController) SyncPods() { - for { - select { - case <-beehiveContext.Done(): - klog.Infof("Stop sync pods") - return - default: - } - pods := dc.podManager.ListPods() - klog.V(4).Infof("Current pods number is: %v", len(pods)) - for _, pod := range pods { - // Periodic sync message - msg := model.NewMessage("") - resource := pod.Namespace + "/" + model.ResourceTypePodStatus + "/" + pod.Name - msg.Content = pod - msg.BuildRouter(constants.HandlerStub, constants.GroupResource, resource, model.UpdateOperation) - - klog.V(4).Infof("Begin to sync message: %v", *msg) - beehiveContext.SendToGroup(constants.HubGroup, *msg) - klog.V(4).Infof("End to sync message: %v", *msg) - } - time.Sleep(5 * time.Second) - } -} diff --git a/tests/stubs/example/main.go b/tests/stubs/example/main.go deleted file mode 100644 index 7109b38f3..000000000 --- a/tests/stubs/example/main.go +++ /dev/null @@ -1,145 +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 main - -import ( - "bytes" - "encoding/json" - "flag" - "io" - "net/http" - "time" - - "github.com/spf13/pflag" - "k8s.io/klog/v2" - - "github.com/kubeedge/kubeedge/tests/stubs/common/constants" - "github.com/kubeedge/kubeedge/tests/stubs/common/types" -) - -const ( - // Modules - ControllerHubURL = "http://127.0.0.1:54321" -) - -func main() { - var pod types.FakePod - - klog.InitFlags(nil) - pflag.CommandLine.AddGoFlagSet(flag.CommandLine) - pflag.Parse() - - pod.Name = "TestPod" - pod.Namespace = constants.NamespaceDefault - pod.NodeName = "edgenode1" - pod.Status = constants.PodPending - - AddPod(pod) - ListPods() - - time.Sleep(10 * time.Second) - ListPods() - - DeletePod(pod) - - time.Sleep(10 * time.Second) - ListPods() -} - -// AddPod adds a fake pod -func AddPod(pod types.FakePod) { - reqBody, err := json.Marshal(pod) - if err != nil { - klog.Errorf("Unmarshal HTTP Response has failed: %v", err) - } - - resp, err := SendHTTPRequest(http.MethodPost, - ControllerHubURL+constants.PodResource, - bytes.NewBuffer(reqBody)) - if err != nil { - klog.Errorf("Frame HTTP request failed: %v", err) - } - defer resp.Body.Close() - - contents, err := io.ReadAll(resp.Body) - if err != nil { - klog.Errorf("HTTP Response reading has failed: %v", err) - } - - klog.V(4).Infof("AddPod response: %v", contents) -} - -// DeletePod deletes a fake pod -func DeletePod(pod types.FakePod) { - resp, err := SendHTTPRequest(http.MethodDelete, - ControllerHubURL+constants.PodResource+ - "?name="+pod.Name+"&namespace="+pod.Namespace+"&nodename="+pod.NodeName, - nil) - if err != nil { - klog.Errorf("Frame HTTP request failed: %v", err) - } - defer resp.Body.Close() - - contents, err := io.ReadAll(resp.Body) - if err != nil { - klog.Errorf("HTTP Response reading has failed: %v", err) - } - - klog.V(4).Infof("DeletePod response: %v", contents) -} - -// ListPods lists all pods -func ListPods() { - resp, err := SendHTTPRequest(http.MethodGet, ControllerHubURL+constants.PodResource, nil) - if err != nil { - klog.Errorf("Frame HTTP request failed: %v", err) - } - defer resp.Body.Close() - - contents, err := io.ReadAll(resp.Body) - if err != nil { - klog.Errorf("HTTP Response reading has failed: %v", err) - } - - pods := []types.FakePod{} - err = json.Unmarshal(contents, &pods) - if err != nil { - klog.Errorf("Unmarshal message content with error: %s", err) - } - - klog.V(4).Infof("ListPods result: %v", pods) -} - -// SendHTTPRequest launches a http request -func SendHTTPRequest(method, reqAPI string, body io.Reader) (*http.Response, error) { - var resp *http.Response - client := &http.Client{} - req, err := http.NewRequest(method, reqAPI, body) - if err != nil { - klog.Errorf("Frame HTTP request failed: %v", err) - return resp, err - } - req.Header.Set("Content-Type", "application/json") - t := time.Now() - resp, err = client.Do(req) - klog.V(4).Infof("%s %s %v in %v", req.Method, req.URL, resp.Status, time.Since(t)) - if err != nil { - klog.Errorf("HTTP request is failed :%v", err) - return resp, err - } - return resp, nil -} |
