github.com/sealerio/sealer@v0.11.1-0.20240507115618-f4f89c5853ae/test/sealer_run_test.go (about) 1 // Copyright © 2021 Alibaba Group Holding Ltd. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package test 16 17 import ( 18 "strings" 19 20 "github.com/sealerio/sealer/test/suites/apply" 21 "github.com/sealerio/sealer/test/testhelper" 22 "github.com/sealerio/sealer/test/testhelper/client/k8s" 23 "github.com/sealerio/sealer/test/testhelper/settings" 24 utilsnet "github.com/sealerio/sealer/utils/net" 25 26 . "github.com/onsi/ginkgo" 27 ) 28 29 var _ = Describe("sealer run", func() { 30 31 Context("run on container", func() { 32 var tempFile string 33 apply.CheckDockerAndSwapOff() 34 BeforeEach(func() { 35 tempFile = testhelper.CreateTempFile() 36 }) 37 38 AfterEach(func() { 39 testhelper.RemoveTempFile(tempFile) 40 }) 41 42 It("container run", func() { 43 rawCluster := apply.LoadClusterFileFromDisk(apply.GetRawClusterFilePath()) 44 rawCluster.Spec.Image = settings.TestImageName 45 By("start to prepare infra") 46 usedCluster := apply.CreateContainerInfraAndSave(rawCluster, tempFile) 47 //defer to delete cluster 48 defer func() { 49 apply.CleanUpContainerInfra(usedCluster) 50 }() 51 sshClient := testhelper.NewSSHClientByCluster(usedCluster) 52 testhelper.CheckFuncBeTrue(func() bool { 53 err := sshClient.SSH.Copy(sshClient.RemoteHostIP, settings.DefaultSealerBin, settings.DefaultSealerBin) 54 return err == nil 55 }, settings.MaxWaiteTime) 56 57 By("start to init cluster") 58 masterIPStrs := utilsnet.IPsToIPStrs(usedCluster.Spec.Masters.IPList) 59 masters := strings.Join(masterIPStrs, ",") 60 nodesIPStrs := utilsnet.IPsToIPStrs(usedCluster.Spec.Nodes.IPList) 61 nodes := strings.Join(nodesIPStrs, ",") 62 apply.SendAndRunCluster(sshClient, tempFile, masters, nodes, usedCluster.Spec.SSH.Passwd) 63 client, err := k8s.NewK8sClient(sshClient) 64 testhelper.CheckErr(err) 65 apply.CheckNodeNumWithSSH(client, 2) 66 67 By("Wait for the cluster to be ready", func() { 68 apply.WaitAllNodeRunningBySSH(client) 69 }) 70 }) 71 }) 72 })