Skip to content

Commit

Permalink
refactor stability main function (#363)
Browse files Browse the repository at this point in the history
* refactor stability main function
  • Loading branch information
weekface authored and xiaojingchen committed Apr 4, 2019
1 parent f3bfb48 commit 7b9ced3
Show file tree
Hide file tree
Showing 22 changed files with 888 additions and 896 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ tests/images/stability-test/bin/
tests/images/e2e/bin/
tests/images/fault-trigger/bin/
tests/images/e2e/tidb-cluster/
tests/images/e2e/tidb-backup/
tests/images/e2e/tidb-operator/
*.tar
tmp/
Expand Down
464 changes: 137 additions & 327 deletions tests/actions.go

Large diffs are not rendered by default.

23 changes: 20 additions & 3 deletions tests/backup/backupcase.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ import (

type BackupCase struct {
operator tests.OperatorActions
srcCluster *tests.TidbClusterInfo
desCluster *tests.TidbClusterInfo
srcCluster *tests.TidbClusterConfig
desCluster *tests.TidbClusterConfig
}

func NewBackupCase(operator tests.OperatorActions, srcCluster *tests.TidbClusterInfo, desCluster *tests.TidbClusterInfo) *BackupCase {
func NewBackupCase(operator tests.OperatorActions, srcCluster *tests.TidbClusterConfig, desCluster *tests.TidbClusterConfig) *BackupCase {
return &BackupCase{
operator: operator,
srcCluster: srcCluster,
Expand All @@ -36,6 +36,11 @@ func NewBackupCase(operator tests.OperatorActions, srcCluster *tests.TidbCluster
}

func (bc *BackupCase) Run() error {
//err := bc.operator.StopInsertDataTo(bc.srcCluster)
//if err != nil {
// glog.Errorf("cluster:[%s] stop insert data failed,error: %v", bc.srcCluster.ClusterName, err)
// return err
//}

err := bc.operator.DeployAdHocBackup(bc.srcCluster)
if err != nil {
Expand Down Expand Up @@ -114,5 +119,17 @@ func (bc *BackupCase) Run() error {
return fmt.Errorf("cluster:[%s] the src cluster data[%d] is not equals des cluster data[%d]", bc.srcCluster.FullName(), srcCount, desCount)
}

//err = bc.operator.BeginInsertDataTo(bc.srcCluster)
//if err != nil {
// glog.Errorf("cluster:[%s] begin insert data failed,error: %v", bc.srcCluster.ClusterName, err)
// return err
//}

return nil
}

func (bc *BackupCase) RunOrDie() {
if err := bc.Run(); err != nil {
panic(err)
}
}
18 changes: 9 additions & 9 deletions tests/cluster_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strconv"
)

func (tc *TidbClusterInfo) set(name string, value string) (string, bool) {
func (tc *TidbClusterConfig) set(name string, value string) (string, bool) {
// NOTE: not thread-safe, maybe make info struct immutable
if tc.Args == nil {
tc.Args = make(map[string]string)
Expand All @@ -15,43 +15,43 @@ func (tc *TidbClusterInfo) set(name string, value string) (string, bool) {
return origVal, ok
}

func (tc *TidbClusterInfo) ScalePD(replicas uint) *TidbClusterInfo {
func (tc *TidbClusterConfig) ScalePD(replicas uint) *TidbClusterConfig {
tc.set("pd.replicas", strconv.Itoa(int(replicas)))
return tc
}

func (tc *TidbClusterInfo) ScaleTiKV(replicas uint) *TidbClusterInfo {
func (tc *TidbClusterConfig) ScaleTiKV(replicas uint) *TidbClusterConfig {
tc.set("tikv.replicas", strconv.Itoa(int(replicas)))
return tc
}

func (tc *TidbClusterInfo) ScaleTiDB(replicas uint) *TidbClusterInfo {
func (tc *TidbClusterConfig) ScaleTiDB(replicas uint) *TidbClusterConfig {
tc.set("tidb.replicas", strconv.Itoa(int(replicas)))
return tc
}

func (tc *TidbClusterInfo) UpgradePD(image string) *TidbClusterInfo {
func (tc *TidbClusterConfig) UpgradePD(image string) *TidbClusterConfig {
tc.PDImage = image
return tc
}

func (tc *TidbClusterInfo) UpgradeTiKV(image string) *TidbClusterInfo {
func (tc *TidbClusterConfig) UpgradeTiKV(image string) *TidbClusterConfig {
tc.TiKVImage = image
return tc
}

func (tc *TidbClusterInfo) UpgradeTiDB(image string) *TidbClusterInfo {
func (tc *TidbClusterConfig) UpgradeTiDB(image string) *TidbClusterConfig {
tc.TiDBImage = image
return tc
}

func (tc *TidbClusterInfo) UpgradeAll(tag string) *TidbClusterInfo {
func (tc *TidbClusterConfig) UpgradeAll(tag string) *TidbClusterConfig {
return tc.
UpgradePD("pingcap/pd:" + tag).
UpgradeTiKV("pingcap/tikv:" + tag).
UpgradeTiDB("pingcap/tidb:" + tag)
}

func (tc *TidbClusterInfo) DSN(dbName string) string {
func (tc *TidbClusterConfig) DSN(dbName string) string {
return fmt.Sprintf("root:%s@tcp(%s-tidb.%s:4000)/%s", tc.Password, tc.ClusterName, tc.Namespace, dbName)
}
28 changes: 8 additions & 20 deletions tests/cmd/e2e/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@ import (

"github.com/golang/glog"
"github.com/jinzhu/copier"
"github.com/pingcap/tidb-operator/pkg/client/clientset/versioned"
"k8s.io/apiserver/pkg/util/logs"

"github.com/pingcap/tidb-operator/tests"
"github.com/pingcap/tidb-operator/tests/backup"
"github.com/pingcap/tidb-operator/tests/pkg/client"
"github.com/pingcap/tidb-operator/tests/pkg/workload"
"github.com/pingcap/tidb-operator/tests/pkg/workload/ddl"
"k8s.io/apiserver/pkg/util/logs"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
)

func main() {
Expand All @@ -39,22 +38,11 @@ func main() {
glog.Fatalf("failed to parse config: %v", err)
}

cfg, err := rest.InClusterConfig()
if err != nil {
glog.Fatalf("failed to get config: %v", err)
}
cli, err := versioned.NewForConfig(cfg)
if err != nil {
glog.Fatalf("failed to create Clientset: %v", err)
}
kubeCli, err := kubernetes.NewForConfig(cfg)
if err != nil {
glog.Fatalf("failed to get kubernetes Clientset: %v", err)
}
cli, kubeCli := client.NewCliOrDie()

oa := tests.NewOperatorActions(cli, kubeCli, conf)

operatorInfo := &tests.OperatorInfo{
operatorInfo := &tests.OperatorConfig{
Namespace: "pingcap",
ReleaseName: "operator",
Image: conf.OperatorImage,
Expand All @@ -64,7 +52,7 @@ func main() {
LogLevel: "2",
}

initTidbVersion, err := conf.GetInitTidbVersion()
initTidbVersion, err := conf.GetTiDBVersion()
if err != nil {
glog.Fatal(err)
}
Expand All @@ -73,7 +61,7 @@ func main() {

name1 := "e2e-cluster1"
name2 := "e2e-cluster2"
clusterInfos := []*tests.TidbClusterInfo{
clusterInfos := []*tests.TidbClusterConfig{
{
Namespace: name1,
ClusterName: name1,
Expand Down Expand Up @@ -249,7 +237,7 @@ func main() {

// backup and restore
backupClusterInfo := clusterInfos[0]
restoreClusterInfo := &tests.TidbClusterInfo{}
restoreClusterInfo := &tests.TidbClusterConfig{}
copier.Copy(restoreClusterInfo, backupClusterInfo)
restoreClusterInfo.ClusterName = restoreClusterInfo.ClusterName + "-other"
restoreClusterInfo.InitSecretName = fmt.Sprintf("%s-set-secret", restoreClusterInfo.ClusterName)
Expand Down
Loading

0 comments on commit 7b9ced3

Please sign in to comment.