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

ensure test env normal and completed before cases run #386

Merged
merged 3 commits into from
Apr 15, 2019
Merged
Show file tree
Hide file tree
Changes from all 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: 2 additions & 1 deletion tests/cmd/stability/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ func main() {
conf := tests.ParseConfigOrDie()
cli, kubeCli := client.NewCliOrDie()
oa := tests.NewOperatorActions(cli, kubeCli, conf)
fta := tests.NewFaultTriggerAction(cli, kubeCli, conf)
fta.CheckAndRecoverEnvOrDie()

tidbVersion := conf.GetTiDBVersionOrDie()
upgardeTiDBVersions := conf.GetUpgradeTidbVersionsOrDie()
Expand Down Expand Up @@ -203,7 +205,6 @@ func main() {
backup.NewBackupCase(oa, clusterBackupFrom, clusterRestoreTo).RunOrDie()

// stop a node and failover automatically
fta := tests.NewFaultTriggerAction(cli, kubeCli, conf)
physicalNode, node, faultTime := fta.StopNodeOrDie()
oa.CheckFailoverPendingOrDie(allClusters, &faultTime)
oa.CheckFailoverOrDie(allClusters, node)
Expand Down
53 changes: 53 additions & 0 deletions tests/fault.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const (
)

type FaultTriggerActions interface {
CheckAndRecoverEnv() error
CheckAndRecoverEnvOrDie()
StopNode() (string, string, time.Time, error)
StopNodeOrDie() (string, string, time.Time)
StartNode(physicalNode string, node string) error
Expand Down Expand Up @@ -62,6 +64,57 @@ type faultTriggerActions struct {
cfg *Config
}

func (fa *faultTriggerActions) CheckAndRecoverEnv() error {
glog.Infof("ensure all nodes are running")
for _, physicalNode := range fa.cfg.Nodes {
for _, vNode := range physicalNode.Nodes {
err := fa.StartNode(physicalNode.PhysicalNode, vNode)
if err != nil {
return err
}
}
}
glog.Infof("ensure all etcds are running")
err := fa.StartETCD()
if err != nil {
return err
}
glog.Infof("ensure all kubelets are running")
for _, physicalNode := range fa.cfg.Nodes {
for _, vNode := range physicalNode.Nodes {
err := fa.StartKubelet(vNode)
if err != nil {
return err
}
}
}
glog.Infof("ensure all static pods are running")
for _, physicalNode := range fa.cfg.APIServers {
for _, vNode := range physicalNode.Nodes {
err := fa.StartKubeAPIServer(vNode)
if err != nil {
return err
}
err = fa.StartKubeControllerManager(vNode)
if err != nil {
return err
}
err = fa.StartKubeScheduler(vNode)
if err != nil {
return err
}
}
}

return nil
}

func (fa *faultTriggerActions) CheckAndRecoverEnvOrDie() {
if err:=fa.CheckAndRecoverEnv();err!=nil{
glog.Fatal(err)
}
}

func (fa *faultTriggerActions) StopNode() (string, string, time.Time, error) {
now := time.Now()
node, err := getFaultNode(fa.kubeCli)
Expand Down
9 changes: 9 additions & 0 deletions tests/pkg/fault-trigger/manager/static_pod_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package manager

import (
"fmt"
"os"
"os/exec"

"github.com/golang/glog"
Expand Down Expand Up @@ -74,6 +75,10 @@ func (m *Manager) StopKubeControllerManager() error {

func (m *Manager) stopStaticPodService(serviceName string, fileName string) error {
maniest := fmt.Sprintf("%s/%s", staticPodPath, fileName)
if _, err := os.Stat(maniest); os.IsNotExist(err) {
glog.Infof("%s had been stopped before", serviceName)
return nil
}
shell := fmt.Sprintf("mkdir -p %s && mv %s %s", staticPodTmpPath, maniest, staticPodTmpPath)

cmd := exec.Command("/bin/sh", "-c", shell)
Expand All @@ -90,6 +95,10 @@ func (m *Manager) stopStaticPodService(serviceName string, fileName string) erro

func (m *Manager) startStaticPodService(serviceName string, fileName string) error {
maniest := fmt.Sprintf("%s/%s", staticPodTmpPath, fileName)
if _, err := os.Stat(maniest); os.IsNotExist(err) {
glog.Infof("%s had been started before", serviceName)
return nil
}
shell := fmt.Sprintf("mv %s %s", maniest, staticPodPath)

cmd := exec.Command("/bin/sh", "-c", shell)
Expand Down