Unverified Commit e634e0a1 authored by Jiahui's avatar Jiahui Committed by GitHub
Browse files

optimize v2 test (#993)

parent 8645fde5
Showing with 124 additions and 120 deletions
+124 -120
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
package test package test
import ( import (
"strconv"
"strings" "strings"
"time" "time"
...@@ -24,7 +23,6 @@ import ( ...@@ -24,7 +23,6 @@ import (
. "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo"
"github.com/alibaba/sealer/test/suites/apply" "github.com/alibaba/sealer/test/suites/apply"
"github.com/alibaba/sealer/test/suites/image"
"github.com/alibaba/sealer/test/testhelper" "github.com/alibaba/sealer/test/testhelper"
"github.com/alibaba/sealer/test/testhelper/settings" "github.com/alibaba/sealer/test/testhelper/settings"
) )
...@@ -41,110 +39,110 @@ var _ = Describe("sealer apply", func() { ...@@ -41,110 +39,110 @@ var _ = Describe("sealer apply", func() {
apply.MarshalClusterToFile(rawClusterFilePath, rawCluster) apply.MarshalClusterToFile(rawClusterFilePath, rawCluster)
} }
}) })
Context("check regular scenario that provider is ali cloud", func() { /* Context("check regular scenario that provider is ali cloud", func() {
var tempFile string var tempFile string
BeforeEach(func() { BeforeEach(func() {
tempFile = testhelper.CreateTempFile() tempFile = testhelper.CreateTempFile()
}) })
AfterEach(func() { AfterEach(func() {
apply.DeleteClusterByFile(settings.GetClusterWorkClusterfile(rawCluster.Name)) apply.DeleteClusterByFile(settings.GetClusterWorkClusterfile(rawCluster.Name))
testhelper.RemoveTempFile(tempFile) testhelper.RemoveTempFile(tempFile)
testhelper.DeleteFileLocally(settings.GetClusterWorkClusterfile(rawCluster.Name)) testhelper.DeleteFileLocally(settings.GetClusterWorkClusterfile(rawCluster.Name))
}) })
It("init, scale up, scale down, clean up", func() { It("init, scale up, scale down, clean up", func() {
// 1,init cluster to 2 nodes and write to disk // 1,init cluster to 2 nodes and write to disk
By("start to init cluster") By("start to init cluster")
sess, err := testhelper.Start(apply.SealerApplyCmd(rawClusterFilePath)) sess, err := testhelper.Start(apply.SealerApplyCmd(rawClusterFilePath))
testhelper.CheckErr(err) testhelper.CheckErr(err)
testhelper.CheckExit0(sess, settings.MaxWaiteTime) testhelper.CheckExit0(sess, settings.MaxWaiteTime)
apply.CheckNodeNumLocally(2) apply.CheckNodeNumLocally(2)
result := testhelper.GetFileDataLocally(settings.GetClusterWorkClusterfile(rawCluster.Name)) result := testhelper.GetFileDataLocally(settings.GetClusterWorkClusterfile(rawCluster.Name))
err = testhelper.WriteFile(tempFile, []byte(result)) err = testhelper.WriteFile(tempFile, []byte(result))
testhelper.CheckErr(err) testhelper.CheckErr(err)
By("Wait for the cluster to be ready", func() { By("Wait for the cluster to be ready", func() {
apply.WaitAllNodeRunning() apply.WaitAllNodeRunning()
}) })
//2,scale up cluster to 6 nodes and write to disk //2,scale up cluster to 6 nodes and write to disk
By("Use join command to add 3master and 3node for scale up cluster in cloud mode", func() { By("Use join command to add 3master and 3node for scale up cluster in cloud mode", func() {
apply.SealerJoin(strconv.Itoa(2), strconv.Itoa(2)) apply.SealerJoin(strconv.Itoa(2), strconv.Itoa(2))
apply.CheckNodeNumLocally(6) apply.CheckNodeNumLocally(6)
}) })
result = testhelper.GetFileDataLocally(settings.GetClusterWorkClusterfile(rawCluster.Name)) result = testhelper.GetFileDataLocally(settings.GetClusterWorkClusterfile(rawCluster.Name))
err = testhelper.WriteFile(tempFile, []byte(result)) err = testhelper.WriteFile(tempFile, []byte(result))
testhelper.CheckErr(err) testhelper.CheckErr(err)
usedCluster := apply.LoadClusterFileFromDisk(tempFile) usedCluster := apply.LoadClusterFileFromDisk(tempFile)
//3,scale down cluster to 4 nodes and write to disk //3,scale down cluster to 4 nodes and write to disk
By("start to scale down cluster") By("start to scale down cluster")
usedCluster.Spec.Nodes.Count = "1" usedCluster.Spec.Nodes.Count = "1"
usedCluster.Spec.Masters.Count = "3" usedCluster.Spec.Masters.Count = "3"
apply.WriteClusterFileToDisk(usedCluster, tempFile) apply.WriteClusterFileToDisk(usedCluster, tempFile)
sess, err = testhelper.Start(apply.SealerApplyCmd(tempFile)) sess, err = testhelper.Start(apply.SealerApplyCmd(tempFile))
testhelper.CheckErr(err) testhelper.CheckErr(err)
testhelper.CheckExit0(sess, settings.MaxWaiteTime) testhelper.CheckExit0(sess, settings.MaxWaiteTime)
apply.CheckNodeNumLocally(4) apply.CheckNodeNumLocally(4)
}) })
})
Context("check regular scenario that provider is container", func() {
tempFile := testhelper.CreateTempFile()
BeforeEach(func() {
rawCluster.Spec.Provider = settings.CONTAINER
apply.MarshalClusterToFile(tempFile, rawCluster)
apply.CheckDockerAndSwapOff()
})
AfterEach(func() {
apply.DeleteClusterByFile(settings.GetClusterWorkClusterfile(rawCluster.Name))
testhelper.RemoveTempFile(tempFile)
testhelper.DeleteFileLocally(settings.GetClusterWorkClusterfile(rawCluster.Name))
})
It("init, scale up, scale down, clean up", func() {
// 1,init cluster to 2 nodes and write to disk
By("start to init cluster")
sess, err := testhelper.Start(apply.SealerApplyCmd(tempFile))
testhelper.CheckErr(err)
testhelper.CheckExit0(sess, settings.MaxWaiteTime)
apply.CheckNodeNumLocally(2)
result := testhelper.GetFileDataLocally(settings.GetClusterWorkClusterfile(rawCluster.Name))
err = testhelper.WriteFile(tempFile, []byte(result))
testhelper.CheckErr(err)
By("Wait for the cluster to be ready", func() {
apply.WaitAllNodeRunning()
})
//2,scale up cluster to 6 nodes and write to disk
By("Use join command to add 2master and 1node for scale up cluster in cloud mode", func() {
apply.SealerJoin(strconv.Itoa(2), strconv.Itoa(1))
apply.CheckNodeNumLocally(5)
}) })
result = testhelper.GetFileDataLocally(settings.GetClusterWorkClusterfile(rawCluster.Name)) Context("check regular scenario that provider is container", func() {
err = testhelper.WriteFile(tempFile, []byte(result)) tempFile := testhelper.CreateTempFile()
testhelper.CheckErr(err) BeforeEach(func() {
usedCluster := apply.LoadClusterFileFromDisk(tempFile) rawCluster.Spec.Provider = settings.CONTAINER
apply.MarshalClusterToFile(tempFile, rawCluster)
//3,scale down cluster to 4 nodes and write to disk apply.CheckDockerAndSwapOff()
By("start to scale down cluster") })
usedCluster.Spec.Nodes.Count = "1"
usedCluster.Spec.Masters.Count = "3" AfterEach(func() {
apply.WriteClusterFileToDisk(usedCluster, tempFile) apply.DeleteClusterByFile(settings.GetClusterWorkClusterfile(rawCluster.Name))
sess, err = testhelper.Start(apply.SealerApplyCmd(tempFile)) testhelper.RemoveTempFile(tempFile)
testhelper.CheckErr(err) testhelper.DeleteFileLocally(settings.GetClusterWorkClusterfile(rawCluster.Name))
testhelper.CheckExit0(sess, settings.MaxWaiteTime) })
apply.CheckNodeNumLocally(4)
image.DoImageOps(settings.SubCmdRmiOfSealer, settings.TestImageName) It("init, scale up, scale down, clean up", func() {
}) // 1,init cluster to 2 nodes and write to disk
By("start to init cluster")
}) sess, err := testhelper.Start(apply.SealerApplyCmd(tempFile))
testhelper.CheckErr(err)
testhelper.CheckExit0(sess, settings.MaxWaiteTime)
apply.CheckNodeNumLocally(2)
result := testhelper.GetFileDataLocally(settings.GetClusterWorkClusterfile(rawCluster.Name))
err = testhelper.WriteFile(tempFile, []byte(result))
testhelper.CheckErr(err)
By("Wait for the cluster to be ready", func() {
apply.WaitAllNodeRunning()
})
//2,scale up cluster to 6 nodes and write to disk
By("Use join command to add 2master and 1node for scale up cluster in cloud mode", func() {
apply.SealerJoin(strconv.Itoa(2), strconv.Itoa(1))
apply.CheckNodeNumLocally(5)
})
result = testhelper.GetFileDataLocally(settings.GetClusterWorkClusterfile(rawCluster.Name))
err = testhelper.WriteFile(tempFile, []byte(result))
testhelper.CheckErr(err)
usedCluster := apply.LoadClusterFileFromDisk(tempFile)
//3,scale down cluster to 4 nodes and write to disk
By("start to scale down cluster")
usedCluster.Spec.Nodes.Count = "1"
usedCluster.Spec.Masters.Count = "3"
apply.WriteClusterFileToDisk(usedCluster, tempFile)
sess, err = testhelper.Start(apply.SealerApplyCmd(tempFile))
testhelper.CheckErr(err)
testhelper.CheckExit0(sess, settings.MaxWaiteTime)
apply.CheckNodeNumLocally(4)
image.DoImageOps(settings.SubCmdRmiOfSealer, settings.TestImageName)
})
})*/
Context("check regular scenario that provider is bare metal, executes machine is master0", func() { Context("check regular scenario that provider is bare metal, executes machine is master0", func() {
var tempFile string var tempFile string
......
...@@ -85,6 +85,7 @@ func LoadPluginFromDisk(clusterFilePath string) []v1.Plugin { ...@@ -85,6 +85,7 @@ func LoadPluginFromDisk(clusterFilePath string) []v1.Plugin {
func GenerateClusterfile(clusterfile string) { func GenerateClusterfile(clusterfile string) {
filepath := GetRawConfigPluginFilePath() filepath := GetRawConfigPluginFilePath()
cluster := LoadClusterFileFromDisk(clusterfile) cluster := LoadClusterFileFromDisk(clusterfile)
cluster.Spec.Env = []string{"env=TestEnv"}
data, err := yaml.Marshal(cluster) data, err := yaml.Marshal(cluster)
testhelper.CheckErr(err) testhelper.CheckErr(err)
appendData := [][]byte{data} appendData := [][]byte{data}
...@@ -122,11 +123,11 @@ func GenerateClusterfile(clusterfile string) { ...@@ -122,11 +123,11 @@ func GenerateClusterfile(clusterfile string) {
} }
func SealerDeleteCmd(clusterFile string) string { func SealerDeleteCmd(clusterFile string) string {
return fmt.Sprintf("%s delete -f %s --force", settings.DefaultSealerBin, clusterFile) return fmt.Sprintf("%s delete -f %s --force -d", settings.DefaultSealerBin, clusterFile)
} }
func SealerApplyCmd(clusterFile string) string { func SealerApplyCmd(clusterFile string) string {
return fmt.Sprintf("%s apply -f %s", settings.DefaultSealerBin, clusterFile) return fmt.Sprintf("%s apply -f %s -d", settings.DefaultSealerBin, clusterFile)
} }
func SealerRunCmd(masters, nodes, passwd string, provider string) string { func SealerRunCmd(masters, nodes, passwd string, provider string) string {
...@@ -142,7 +143,7 @@ func SealerRunCmd(masters, nodes, passwd string, provider string) string { ...@@ -142,7 +143,7 @@ func SealerRunCmd(masters, nodes, passwd string, provider string) string {
if provider != "" { if provider != "" {
provider = fmt.Sprintf("--provider %s", provider) provider = fmt.Sprintf("--provider %s", provider)
} }
return fmt.Sprintf("%s run %s %s %s %s %s", settings.DefaultSealerBin, settings.TestImageName, masters, nodes, passwd, provider) return fmt.Sprintf("%s run %s %s %s %s %s -d", settings.DefaultSealerBin, settings.TestImageName, masters, nodes, passwd, provider)
} }
func SealerRun(masters, nodes, passwd, provider string) { func SealerRun(masters, nodes, passwd, provider string) {
...@@ -156,7 +157,7 @@ func SealerJoinCmd(masters, nodes string) string { ...@@ -156,7 +157,7 @@ func SealerJoinCmd(masters, nodes string) string {
if nodes != "" { if nodes != "" {
nodes = fmt.Sprintf("-n %s", nodes) nodes = fmt.Sprintf("-n %s", nodes)
} }
return fmt.Sprintf("%s join %s %s -c my-test-cluster", settings.DefaultSealerBin, masters, nodes) return fmt.Sprintf("%s join %s %s -c my-test-cluster -d", settings.DefaultSealerBin, masters, nodes)
} }
func SealerJoin(masters, nodes string) { func SealerJoin(masters, nodes string) {
......
...@@ -72,7 +72,7 @@ spec: ...@@ -72,7 +72,7 @@ spec:
type: SHELL type: SHELL
action: Originally action: Originally
data: | data: |
echo "OriginallyShell was successfully run from Clusterfile" echo "$env: OriginallyShell was successfully run from Clusterfile"
--- ---
apiVersion: sealer.aliyun.com/v1alpha1 apiVersion: sealer.aliyun.com/v1alpha1
kind: Plugin kind: Plugin
...@@ -82,7 +82,7 @@ spec: ...@@ -82,7 +82,7 @@ spec:
type: SHELL type: SHELL
action: PostInstall action: PostInstall
data: | data: |
echo "PostInstallShell was successfully run from Clusterfile" echo "$env: PostInstallShell was successfully run from Clusterfile"
--- ---
apiVersion: sealer.aliyun.com/v1alpha1 apiVersion: sealer.aliyun.com/v1alpha1
kind: Plugin kind: Plugin
......
...@@ -91,7 +91,7 @@ func (a *ArgsOfBuild) Build() string { ...@@ -91,7 +91,7 @@ func (a *ArgsOfBuild) Build() string {
if a.BuildType == "" { if a.BuildType == "" {
a.BuildType = settings.LiteBuild a.BuildType = settings.LiteBuild
} }
return fmt.Sprintf("%s build -f %s -t %s -m %s %s", settings.DefaultSealerBin, a.KubeFile, a.ImageName, a.BuildType, a.Context) return fmt.Sprintf("%s build -f %s -t %s -m %s %s -d", settings.DefaultSealerBin, a.KubeFile, a.ImageName, a.BuildType, a.Context)
} }
func NewArgsOfBuild() *ArgsOfBuild { func NewArgsOfBuild() *ArgsOfBuild {
......
...@@ -3,8 +3,8 @@ COPY Clusterfile etc ...@@ -3,8 +3,8 @@ COPY Clusterfile etc
COPY test1 . COPY test1 .
COPY recommended.yaml . COPY recommended.yaml .
COPY Plugins.yaml plugin COPY Plugins.yaml plugin
COPY imageList manifests
CMD kubectl apply -f recommended.yaml CMD kubectl apply -f recommended.yaml
COPY test2 . COPY test2 .
RUN wget -O redis.tar.gz http://download.redis.io/releases/redis-5.0.3.tar.gz RUN wget -O redis.tar.gz http://download.redis.io/releases/redis-5.0.3.tar.gz && tar zxvf redis.tar.gz && rm -f redis.tar.gz
RUN tar zxvf redis.tar.gz
CMD kubectl get nodes CMD kubectl get nodes
\ No newline at end of file
quay.io/tigera/operator:v1.17.4
\ No newline at end of file
FROM sealer-io/test:v1 FROM sealer-io/kubernetes:v1.19.8
COPY test1 . COPY test1 .
COPY recommended.yaml manifests COPY recommended.yaml manifests
COPY test2 . COPY test2 .
COPY test3 . COPY test3 .
RUN wget -O redis.tar.gz http://download.redis.io/releases/redis-5.0.3.tar.gz RUN wget -O redis.tar.gz http://download.redis.io/releases/redis-5.0.3.tar.gz && tar zxvf redis.tar.gz && rm -f redis.tar.gz
RUN tar zxvf redis.tar.gz
CMD ls -l CMD ls -l
COPY imageList manifests COPY imageList manifests
\ No newline at end of file
...@@ -36,15 +36,15 @@ func DoImageOps(action, imageName string) { ...@@ -36,15 +36,15 @@ func DoImageOps(action, imageName string) {
cmd := "" cmd := ""
switch action { switch action {
case settings.SubCmdPullOfSealer: case settings.SubCmdPullOfSealer:
cmd = fmt.Sprintf("%s pull %s", settings.DefaultSealerBin, imageName) cmd = fmt.Sprintf("%s pull %s -d", settings.DefaultSealerBin, imageName)
case settings.SubCmdPushOfSealer: case settings.SubCmdPushOfSealer:
cmd = fmt.Sprintf("%s push %s", settings.DefaultSealerBin, imageName) cmd = fmt.Sprintf("%s push %s -d", settings.DefaultSealerBin, imageName)
case settings.SubCmdRmiOfSealer: case settings.SubCmdRmiOfSealer:
cmd = fmt.Sprintf("%s rmi %s", settings.DefaultSealerBin, imageName) cmd = fmt.Sprintf("%s rmi %s -d", settings.DefaultSealerBin, imageName)
case settings.SubCmdForceRmiOfSealer: case settings.SubCmdForceRmiOfSealer:
cmd = fmt.Sprintf("%s rmi -f %s", settings.DefaultSealerBin, GetImageID(imageName)) cmd = fmt.Sprintf("%s rmi -f %s -d", settings.DefaultSealerBin, GetImageID(imageName))
case settings.SubCmdRunOfSealer: case settings.SubCmdRunOfSealer:
cmd = fmt.Sprintf("%s run %s", settings.DefaultSealerBin, imageName) cmd = fmt.Sprintf("%s run %s -d", settings.DefaultSealerBin, imageName)
case settings.SubCmdListOfSealer: case settings.SubCmdListOfSealer:
cmd = fmt.Sprintf("%s images", settings.DefaultSealerBin) cmd = fmt.Sprintf("%s images", settings.DefaultSealerBin)
} }
......
...@@ -17,6 +17,8 @@ package settings ...@@ -17,6 +17,8 @@ package settings
import ( import (
"os" "os"
"time" "time"
"github.com/alibaba/sealer/logger"
) )
// init test params and settings // init test params and settings
...@@ -39,4 +41,7 @@ func init() { ...@@ -39,4 +41,7 @@ func init() {
if pollingInterval == "" { if pollingInterval == "" {
DefaultPollingInterval = 10 DefaultPollingInterval = 10
} }
logger.InitLogger(logger.Config{
DebugMode: true,
})
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment