Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tidb stability test main function #306

Merged
merged 14 commits into from
Mar 12, 2019
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ images/tidb-operator-e2e/tidb-operator/
tmp/
data/
.idea
cscope.files
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are these files?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's ctags generate files only use for me

tags
filenametags

# ginkgo test coverage
*.coverprofile
Expand Down
13 changes: 13 additions & 0 deletions pkg/label/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
package label

import (
"fmt"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"strings"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import (
       "fmt"
        "strings" 

         metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
         "k8s.io/apimachinery/pkg/labels"
)

format code

)

const (
Expand Down Expand Up @@ -138,3 +140,14 @@ func (l Label) LabelSelector() *metav1.LabelSelector {
func (l Label) Labels() map[string]string {
return l
}

//Labels convers label to string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// String converts label to a string

func (l Label) String() string {
var arr []string

for k, v := range l {
arr = append(arr, fmt.Sprintf("%s=%s", k, v))
}

return strings.Join(arr, ",")
}
114 changes: 87 additions & 27 deletions tests/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"strings"
"time"

_ "github.com/go-sql-driver/mysql"
"github.com/golang/glog"
"github.com/pingcap/kvproto/pkg/metapb"
"github.com/pingcap/tidb-operator/pkg/apis/pingcap.com/v1alpha1"
Expand All @@ -43,6 +44,11 @@ func NewOperatorActions(cli versioned.Interface, kubeCli kubernetes.Interface) O
}
}

const (
DefaultPollTimeout time.Duration = 10 * time.Minute
DefaultPollInterval time.Duration = 1 * time.Minute
)

type OperatorActions interface {
DeployOperator(info *OperatorInfo) error
CleanOperator(info *OperatorInfo) error
Expand All @@ -56,14 +62,16 @@ type OperatorActions interface {
ScaleTidbCluster(info *TidbClusterInfo) error
UpgradeTidbCluster(info *TidbClusterInfo) error
DeployAdHocBackup(info *TidbClusterInfo) error
CleanAdHocBackup(info *TidbClusterInfo) error
CheckAdHocBackup(info *TidbClusterInfo) error
DeployScheduledBackup(info *TidbClusterInfo) error
CleanScheduledBackup(info *TidbClusterInfo) error
DeployIncrementalBackup(info *TidbClusterInfo) error
CleanIncrementalBackup(info *TidbClusterInfo) error
Restore(from *TidbClusterInfo, jobName string, to *TidbClusterInfo) error
CheckScheduledBackup(info *TidbClusterInfo) error
DeployIncrementalBackup(from *TidbClusterInfo, to *TidbClusterInfo) error
CheckIncrementalBackup(info *TidbClusterInfo) error
Restore(from *TidbClusterInfo, to *TidbClusterInfo) error
CheckRestore(from *TidbClusterInfo, to *TidbClusterInfo) error
DeployMonitor(info *TidbClusterInfo) error
CleanMonitor(info *TidbClusterInfo) error
ForceDeploy(info *TidbClusterInfo) error
}

type FaultTriggerActions interface {
Expand Down Expand Up @@ -204,6 +212,10 @@ func (oa *operatorActions) DumpAllLogs(info *OperatorInfo, clusterInfo *TidbClus
}

func (oa *operatorActions) DeployTidbCluster(info *TidbClusterInfo) error {
glog.Infof("begin to deploy tidb cluster")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

print more info about the cluster, like name and namespace

defer func() {
glog.Infof("deploy tidb cluster end")
}()
cmd := fmt.Sprintf("helm install /charts/%s/tidb-cluster --name %s --namespace %s --set-string %s",
info.OperatorTag, info.ClusterName, info.Namespace, info.HelmSetString())
if res, err := exec.Command("/bin/sh", "-c", cmd).CombinedOutput(); err != nil {
Expand All @@ -215,10 +227,13 @@ func (oa *operatorActions) DeployTidbCluster(info *TidbClusterInfo) error {
}

func (oa *operatorActions) CleanTidbCluster(info *TidbClusterInfo) error {
glog.Infof("begin to clean tidb cluster")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

defer func() {
glog.Infof("clean tidb cluster end")
}()
charts := []string{
info.ClusterName,
fmt.Sprintf("%s-backup", info.ClusterName),
fmt.Sprintf("%s-restore", info.ClusterName),
}
for _, chartName := range charts {
res, err := exec.Command("helm", "del", "--purge", chartName).CombinedOutput()
Expand All @@ -228,10 +243,14 @@ func (oa *operatorActions) CleanTidbCluster(info *TidbClusterInfo) error {
}
}

resources := []string{"cronjobs", "jobs", "pods", "pvc"}
//for the test should add two clusters in a namespace, so we
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete these lines.

//has to use clustername as an label.
setStr := label.New().Instance(info.ClusterName).String()

resources := []string{"pvc"}
for _, resource := range resources {
if res, err := exec.Command("kubectl", "delete", resource, "-n", info.Namespace,
"--all").CombinedOutput(); err != nil {
if res, err := exec.Command("kubectl", "delete", resource, "-n", info.Namespace, "-l",
setStr).CombinedOutput(); err != nil {
return fmt.Errorf("failed to delete %s: %v, %s", resource, err, string(res))
}
}
Expand All @@ -245,7 +264,7 @@ func (oa *operatorActions) CleanTidbCluster(info *TidbClusterInfo) error {
}

pollFn := func() (bool, error) {
if res, err := exec.Command("kubectl", "get", "po", "--output=name", "-n", info.Namespace).
if res, err := exec.Command("kubectl", "get", "po", "--output=name", "-n", info.Namespace, "-l", setStr).
CombinedOutput(); err != nil || len(res) != 0 {
glog.Infof("waiting for tidbcluster: %s/%s pods deleting, %v, [%s]",
info.Namespace, info.ClusterName, err, string(res))
Expand All @@ -262,16 +281,19 @@ func (oa *operatorActions) CleanTidbCluster(info *TidbClusterInfo) error {
info.Namespace, info.ClusterName, err, string(res))
return false, nil
}

return true, nil
}
return wait.PollImmediate(1*time.Minute, 5*time.Minute, pollFn)
return wait.PollImmediate(DefaultPollInterval, DefaultPollTimeout, pollFn)
}

func (oa *operatorActions) CheckTidbClusterStatus(info *TidbClusterInfo) error {
glog.Infof("begin to check tidb cluster")
defer func() {
glog.Infof("check tidb cluster end")
}()
ns := info.Namespace
tcName := info.ClusterName
if err := wait.PollImmediate(1*time.Minute, 10*time.Minute, func() (bool, error) {
if err := wait.PollImmediate(DefaultPollInterval, DefaultPollTimeout, func() (bool, error) {
var tc *v1alpha1.TidbCluster
var err error
if tc, err = oa.cli.PingcapV1alpha1().TidbClusters(ns).Get(tcName, metav1.GetOptions{}); err != nil {
Expand All @@ -285,20 +307,30 @@ func (oa *operatorActions) CheckTidbClusterStatus(info *TidbClusterInfo) error {
if b, err := oa.tikvMembersReadyFn(tc); !b && err == nil {
return false, nil
}

glog.Infof("check tidb cluster begin tidbMembersReadyFn")
if b, err := oa.tidbMembersReadyFn(tc); !b && err == nil {
return false, nil
}

glog.Infof("check tidb cluster begin reclaimPolicySyncFn")
if b, err := oa.reclaimPolicySyncFn(tc); !b && err == nil {
return false, nil
}

glog.Infof("check tidb cluster begin metaSyncFn")
if b, err := oa.metaSyncFn(tc); err != nil {
return false, err
} else if !b && err == nil {
return false, nil
}

glog.Infof("check tidb cluster begin schedulerHAFn")
if b, err := oa.schedulerHAFn(tc); !b && err == nil {
return false, nil
}

glog.Infof("check tidb cluster begin passwordIsSet")
if b, err := oa.passwordIsSet(info); !b && err == nil {
return false, nil
}
Expand All @@ -319,19 +351,10 @@ func (oa *operatorActions) StopInsertDataTo(info *TidbClusterInfo) error {
return nil
}

func (oa *operatorActions) ScaleTidbCluster(info *TidbClusterInfo) error { return nil }
func (oa *operatorActions) UpgradeTidbCluster(info *TidbClusterInfo) error { return nil }
func (oa *operatorActions) DeployAdHocBackup(info *TidbClusterInfo) error { return nil }
func (oa *operatorActions) CleanAdHocBackup(info *TidbClusterInfo) error { return nil }
func (oa *operatorActions) DeployScheduledBackup(info *TidbClusterInfo) error { return nil }
func (oa *operatorActions) CleanScheduledBackup(info *TidbClusterInfo) error { return nil }
func (oa *operatorActions) DeployIncrementalBackup(info *TidbClusterInfo) error { return nil }
func (oa *operatorActions) CleanIncrementalBackup(info *TidbClusterInfo) error { return nil }
func (oa *operatorActions) Restore(from *TidbClusterInfo, jobName string, to *TidbClusterInfo) error {
return nil
}
func (oa *operatorActions) DeployMonitor(info *TidbClusterInfo) error { return nil }
func (oa *operatorActions) CleanMonitor(info *TidbClusterInfo) error { return nil }
func (oa *operatorActions) ScaleTidbCluster(info *TidbClusterInfo) error { return nil }
func (oa *operatorActions) UpgradeTidbCluster(info *TidbClusterInfo) error { return nil }
func (oa *operatorActions) DeployMonitor(info *TidbClusterInfo) error { return nil }
func (oa *operatorActions) CleanMonitor(info *TidbClusterInfo) error { return nil }

func (oa *operatorActions) pdMembersReadyFn(tc *v1alpha1.TidbCluster) (bool, error) {
tcName := tc.GetName()
Expand Down Expand Up @@ -729,7 +752,7 @@ func (oa *operatorActions) schedulerHAFn(tc *v1alpha1.TidbCluster) (bool, error)
nodeName, len(nodeMap[nodeName]), totalCount)
}
}
return false, nil
return true, nil
}

components := []string{label.PDLabelVal, label.TiKVLabelVal}
Expand Down Expand Up @@ -811,3 +834,40 @@ func checkoutTag(tagName string) error {

return nil
}

func (oa *operatorActions) DeployScheduledBackup(info *TidbClusterInfo) error {
return nil
}

func (oa *operatorActions) CheckScheduledBackup(info *TidbClusterInfo) error {
return nil
}

func (oa *operatorActions) DeployAdHocBackup(info *TidbClusterInfo) error {
return nil
}

func (oa *operatorActions) CheckAdHocBackup(info *TidbClusterInfo) error {
return nil
}

func (oa *operatorActions) DeployIncrementalBackup(from *TidbClusterInfo, to *TidbClusterInfo) error {
return nil
}

func (oa *operatorActions) CheckIncrementalBackup(info *TidbClusterInfo) error {
return nil

}

func (oa *operatorActions) Restore(from *TidbClusterInfo, to *TidbClusterInfo) error {
return nil
}

func (oa *operatorActions) CheckRestore(from *TidbClusterInfo, to *TidbClusterInfo) error {
return nil
}

func (oa *operatorActions) ForceDeploy(info *TidbClusterInfo) error {
return nil
}
22 changes: 22 additions & 0 deletions tests/cmd/e2e/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,26 @@ func main() {
if err := oa.CheckTidbClusterStatus(clusterInfo); err != nil {
glog.Fatal(err)
}

restoreClusterInfo := &tests.TidbClusterInfo{
Namespace: "tidb",
ClusterName: "demo2",
OperatorTag: "v1.0.0-beta.1-p2",
PDImage: "pingcap/pd:v2.1.3",
TiKVImage: "pingcap/tikv:v2.1.3",
TiDBImage: "pingcap/tidb:v2.1.3",
StorageClassName: "local-storage",
Password: "admin",
Args: map[string]string{},
}

if err := oa.CleanTidbCluster(restoreClusterInfo); err != nil {
glog.Fatal(err)
}
if err := oa.DeployTidbCluster(restoreClusterInfo); err != nil {
glog.Fatal(err)
}
if err := oa.CheckTidbClusterStatus(restoreClusterInfo); err != nil {
glog.Fatal(err)
}
}