github.com/midokura/kubeedge@v1.2.0-mido.0/tests/performance/hubtest/hubtest_suite_test.go (about)

     1  /*
     2  Copyright 2019 The KubeEdge Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8     http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  package hubtest
    17  
    18  import (
    19  	"fmt"
    20  	"strings"
    21  	"testing"
    22  	"time"
    23  
    24  	. "github.com/onsi/ginkgo"
    25  	. "github.com/onsi/gomega"
    26  	v1 "k8s.io/api/core/v1"
    27  
    28  	"github.com/kubeedge/kubeedge/tests/e2e/utils"
    29  	. "github.com/kubeedge/kubeedge/tests/performance/common"
    30  	"github.com/kubeedge/viaduct/pkg/api"
    31  )
    32  
    33  // configs across the package
    34  var (
    35  	ctx              *utils.TestContext
    36  	cfg              utils.Config
    37  	cloudHubURL      string
    38  	wsscloudHubURL   string
    39  	quiccloudHubURL  string
    40  	controllerHubURL string
    41  )
    42  
    43  func TestKubeEdgeK8SDeployment(t *testing.T) {
    44  	// Init params
    45  	var podlist v1.PodList
    46  	RegisterFailHandler(Fail)
    47  
    48  	// Init suite
    49  	var _ = BeforeSuite(func() {
    50  		// Init config
    51  		utils.Infof("KubeEdge hub performance test begin!")
    52  		cfg = utils.LoadConfig()
    53  		ctx = utils.NewTestContext(cfg)
    54  
    55  		//apply label to all cluster nodes, use the selector to deploy all edgenodes to cluster nodes
    56  		err := ApplyLabel(ctx.Cfg.K8SMasterForProvisionEdgeNodes + NodeHandler)
    57  		Expect(err).Should(BeNil())
    58  
    59  		// Deploy KubeEdge Cloud Part as a k8s deployment into KubeEdge Cluster
    60  		CloudConfigMap = "cloudcore-configmap-" + utils.GetRandomString(5)
    61  		CloudCoreDeployment = "cloudcore-deployment-" + utils.GetRandomString(5)
    62  		//protocol to be used for test between edge and cloud
    63  		if ctx.Cfg.Protocol == api.ProtocolTypeQuic {
    64  			IsQuicProtocol = true
    65  		} else {
    66  			IsQuicProtocol = false
    67  		}
    68  		err = HandleCloudDeployment(
    69  			CloudConfigMap,
    70  			CloudCoreDeployment,
    71  			ctx.Cfg.K8SMasterForKubeEdge,
    72  			ctx.Cfg.K8SMasterForKubeEdge+ConfigmapHandler,
    73  			ctx.Cfg.K8SMasterForKubeEdge+DeploymentHandler,
    74  			ctx.Cfg.CloudImageUrl,
    75  			ctx.Cfg.NumOfNodes)
    76  		Expect(err).Should(BeNil())
    77  		time.Sleep(1 * time.Second)
    78  
    79  		// Get KubeEdge Cloud Part host ip
    80  		podlist, err = utils.GetPods(ctx.Cfg.K8SMasterForKubeEdge+AppHandler, "")
    81  		Expect(err).To(BeNil())
    82  		cloudPartHostIP := ""
    83  		for _, pod := range podlist.Items {
    84  			if strings.Contains(pod.Name, "cloudcore-deployment") {
    85  				cloudPartHostIP = pod.Status.HostIP
    86  				break
    87  			}
    88  		}
    89  
    90  		// Check if KubeEdge Cloud Part is running
    91  		utils.CheckPodRunningState(ctx.Cfg.K8SMasterForKubeEdge+AppHandler, podlist)
    92  		time.Sleep(5 * time.Second)
    93  
    94  		// Create NodePort Service for KubeEdge Cloud Part
    95  		err = utils.ExposeCloudService(CloudCoreDeployment, ctx.Cfg.K8SMasterForKubeEdge+ServiceHandler)
    96  		Expect(err).Should(BeNil())
    97  
    98  		// Get NodePort Service to access KubeEdge Cloud Part from KubeEdge Edge Nodes
    99  		wsPort, quicNodePort := utils.GetServicePort(CloudCoreDeployment, ctx.Cfg.K8SMasterForKubeEdge+ServiceHandler)
   100  		quiccloudHubURL = fmt.Sprintf("%s:%d", cloudPartHostIP, quicNodePort)
   101  		wsscloudHubURL = fmt.Sprintf("wss://%s:%d", cloudPartHostIP, wsPort)
   102  		if IsQuicProtocol {
   103  			cloudHubURL = quiccloudHubURL
   104  		} else {
   105  			cloudHubURL = wsscloudHubURL
   106  		}
   107  		controllerHubURL = fmt.Sprintf("http://%s:%d", cloudPartHostIP, ctx.Cfg.ControllerStubPort)
   108  	})
   109  	AfterSuite(func() {
   110  		By("KubeEdge hub performance test end!")
   111  		// Delete KubeEdge Cloud Part deployment
   112  		DeleteCloudDeployment(ctx.Cfg.K8SMasterForKubeEdge)
   113  		// Check if KubeEdge Cloud Part is deleted
   114  		utils.CheckPodDeleteState(ctx.Cfg.K8SMasterForKubeEdge+AppHandler, podlist)
   115  	})
   116  	RunSpecs(t, "KubeEdge hub performance test suite")
   117  }