github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/test/e2e/testdata/smoketest/playgroundtest.go (about)

     1  /*
     2  Copyright (C) 2022-2023 ApeCloud Co., Ltd
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package smoketest
    18  
    19  import (
    20  	"log"
    21  	"time"
    22  
    23  	. "github.com/onsi/ginkgo/v2"
    24  	. "github.com/onsi/gomega"
    25  
    26  	. "github.com/1aal/kubeblocks/test/e2e"
    27  	e2eutil "github.com/1aal/kubeblocks/test/e2e/util"
    28  )
    29  
    30  func PlaygroundInit() {
    31  	BeforeEach(func() {
    32  	})
    33  
    34  	AfterEach(func() {
    35  	})
    36  
    37  	Context("KubeBlocks playground init", func() {
    38  		It("install kbcli", func() {
    39  			err := e2eutil.CheckKbcliExists()
    40  			if err != nil {
    41  				log.Println(err)
    42  				installCmd := "curl -fsSL https://kubeblocks.io/installer/install_cli.sh | bash "
    43  				log.Println(installCmd)
    44  				install := e2eutil.ExecuteCommand(installCmd)
    45  				log.Println(install)
    46  			}
    47  		})
    48  		It("kbcli playground init", func() {
    49  			var cmd string
    50  			if len(Provider) > 0 && len(Region) > 0 && len(SecretID) > 0 && len(SecretKey) > 0 {
    51  				var id, key string
    52  				if Provider == "aws" {
    53  					id = "export AWS_ACCESS_KEY_ID=" + SecretID
    54  					key = "export AWS_SECRET_ACCESS_KEY=" + SecretKey
    55  				} else if Provider == "tencentcloud" {
    56  					id = "export TENCENTCLOUD_SECRET_ID=" + SecretID
    57  					key = "export TENCENTCLOUD_SECRET_KEY" + SecretKey
    58  				} else if Provider == "alicloud" {
    59  					id = "export ALICLOUD_ACCESS_KEY=" + SecretID
    60  					key = "export ALICLOUD_SECRET_KEY=" + SecretKey
    61  				} else {
    62  					log.Println("not support " + Provider + " cloud-provider")
    63  				}
    64  				idCmd := e2eutil.ExecuteCommand(id)
    65  				log.Println(idCmd)
    66  				keyCmd := e2eutil.ExecuteCommand(key)
    67  				log.Println(keyCmd)
    68  				cmd = "kbcli playground init --cloud-provider " + Provider + " --region " + Region
    69  				output, err := e2eutil.Check(cmd, "yes\n")
    70  				if err != nil {
    71  					log.Fatalf("Command execution failure: %v\n", err)
    72  				}
    73  				log.Println("Command execution result:", output)
    74  			} else {
    75  				cmd = "kbcli playground init"
    76  				log.Println(cmd)
    77  				init := e2eutil.ExecuteCommand(cmd)
    78  				log.Println(init)
    79  			}
    80  		})
    81  		It("check kbcli playground cluster and pod status", func() {
    82  			checkPlaygroundCluster()
    83  		})
    84  	})
    85  }
    86  
    87  func UninstallKubeblocks() {
    88  	BeforeEach(func() {
    89  	})
    90  
    91  	AfterEach(func() {
    92  	})
    93  	Context("KubeBlocks uninstall", func() {
    94  		It("delete mycluster", func() {
    95  			cmd := "kbcli cluster delete mycluster --auto-approve"
    96  			log.Println(cmd)
    97  			result := e2eutil.ExecuteCommand(cmd)
    98  			Expect(result).Should(BeTrue())
    99  		})
   100  		It("check mycluster and pod", func() {
   101  			cmd := "kbcli cluster list -A"
   102  			Eventually(func(g Gomega) {
   103  				cluster := e2eutil.ExecCommand(cmd)
   104  				g.Expect(e2eutil.StringStrip(cluster)).Should(Equal("Noclusterfound"))
   105  			}, time.Second*10, time.Second*1).Should(Succeed())
   106  			cmd = "kbcli cluster list-instances"
   107  			Eventually(func(g Gomega) {
   108  				instances := e2eutil.ExecCommand(cmd)
   109  				g.Expect(e2eutil.StringStrip(instances)).Should(Equal("Noclusterfound"))
   110  			}, time.Second*10, time.Second*1).Should(Succeed())
   111  		})
   112  		It("kbcli kubeblocks uninstall", func() {
   113  			cmd := "kbcli kubeblocks uninstall --auto-approve --namespace=kb-system"
   114  			log.Println(cmd)
   115  			execResult := e2eutil.ExecuteCommand(cmd)
   116  			log.Println(execResult)
   117  		})
   118  	})
   119  }
   120  
   121  func PlaygroundDestroy() {
   122  	BeforeEach(func() {
   123  	})
   124  
   125  	AfterEach(func() {
   126  	})
   127  
   128  	Context("KubeBlocks playground test", func() {
   129  		It("kbcli playground destroy", func() {
   130  			cmd := "kbcli playground destroy"
   131  			execResult := e2eutil.ExecCommand(cmd)
   132  			log.Println(execResult)
   133  		})
   134  	})
   135  }
   136  
   137  func checkPlaygroundCluster() {
   138  	commond := "kubectl get cluster | awk '{print $1}' | sed 1d"
   139  	log.Println(commond)
   140  	clusterName := e2eutil.ExecCommand(commond)
   141  	Eventually(func(g Gomega) {
   142  		e2eutil.WaitTime(100000)
   143  		podStatusResult := e2eutil.CheckPodStatus(clusterName, "default")
   144  		for _, result := range podStatusResult {
   145  			g.Expect(result).Should(BeTrue())
   146  		}
   147  	}, timeout, interval).Should(Succeed())
   148  	cmd := "kbcli cluster list | grep " + clusterName + " | awk '{print $6}'"
   149  	log.Println(cmd)
   150  	Eventually(func(g Gomega) {
   151  		clusterStatus := e2eutil.ExecCommand(cmd)
   152  		log.Println("clusterStatus is " + e2eutil.StringStrip(clusterStatus))
   153  		g.Expect(e2eutil.StringStrip(clusterStatus)).Should(Equal("Running"))
   154  	}, timeout, interval).Should(Succeed())
   155  }