1. add run_direct.py

v4
vinllen 5 years ago
parent 468de49504
commit 0057189394
  1. 1
      build.sh
  2. 52
      scripts/run_direct.py
  3. 7
      src/integration-test/deploy/deploy.go
  4. 35
      src/integration-test/main/main.go
  5. 13
      src/integration-test/tcase/base.go
  6. 57
      src/integration-test/tcase/standalone2standalone.go

@ -51,6 +51,7 @@ done
# copy scripts # copy scripts
cp scripts/start.sh ${output}/ cp scripts/start.sh ${output}/
cp scripts/stop.sh ${output}/ cp scripts/stop.sh ${output}/
cp scripts/run_direct.py ${output}/
cp -r tools ${output}/ cp -r tools ${output}/
cp -r test ${output}/ cp -r test ${output}/

@ -0,0 +1,52 @@
import os
import getopt
import sys
def usage():
print('|------------------------------------------------------------------------------------------------------------------------------------------------------------------------|')
print('| Usage: ./run_direct.py --src=source_redis_address --srcPasswd=source_password --srcType=source_type(default is \'standalone\') --dst=target_redis_address --dstPasswd=target_redis_address --dstType=target_redis_address(default is \'standalone\') |')
print('|------------------------------------------------------------------------------------------------------------------------------------------------------------------------|')
print('| Like : ./run_direct.py --src=10.1.1.1:3456 --srcPasswd=Test123456 --srcType=standalone --dst=20.1.1.2:15678 --dstPasswd=Test123456 --dstType=standalone |')
print('| Like : ./run_direct.py --src=10.1.1.1:3456;10.1.1.2:5678;10.1.1.3:7890 --srcPasswd=Test123456 --srcType=standalone --dst=20.1.1.1:13456;20.1.1.2:15678 --dstPasswd=Test123456 --dstType=proxy |')
print('|------------------------------------------------------------------------------------------------------------------------------------------------------------------------|')
exit(0)
if __name__ == "__main__":
opts, args = getopt.getopt(sys.argv[1:], "hs:a:t:d:p:e:", ["help", "src=", "srcPasswd=", "srcType=", "dst=", "dstPasswd=", "dstType="])
if len(opts) == 0:
usage()
mp = {}
for key, value in opts:
if key in ("-h", "--help"):
usage()
sys.exit()
if key in ("-s", "--src"):
mp['source.address'] = value
if key in ("-a", "--srcPasswd"):
mp['source.password_raw'] = value
if key in ("-t", "--srcType"):
mp['source.type'] = value
if key in ("-d", "--dst"):
mp['target.address'] = value
if key in ("-p", "--dstPasswd"):
mp['target.password_raw'] = value
if key in ("-e", "--dstType"):
mp['target.type'] = value
mp['id'] = 'redis-shake'
mp['source.type'] = 'standalone' if 'source.type' not in mp else mp['source.type']
mp['target.type'] = 'standalone' if 'target.type' not in mp else mp['source.type']
mp['source.auth_type'] = 'auth'
mp['target.auth_type'] = 'auth'
mp['rewrite'] = 'true'
name = "run_direct.conf"
f = open(name, "w+")
for key, val in mp.items():
f.writelines('%s = %s\n' % (key, val))
f.close()
os.system("./redis-shake.linux -type=sync -conf=%s" % name)
#os.system("./redis-shake.darwin -type=sync -conf=%s" % name)

@ -11,10 +11,13 @@ import (
const ( const (
StandaloneScript = "deploy_standalone.sh" StandaloneScript = "deploy_standalone.sh"
ClusterScript = "deploy_cluster.sh" ClusterScript = "deploy_cluster.sh"
RedisShake = "redis-shake" RedisShake = "redis-shake"
RedisShakeConf = "redis-shake.conf" RedisShakeConf = "redis-shake.conf"
CmdStart = "start"
CmdStop = "stop"
) )
func run(cmd *exec.Cmd) error { func run(cmd *exec.Cmd) error {

@ -1,5 +1,40 @@
package main package main
import (
"pkg/libs/log"
"flag"
"integration-test/tcase"
)
func main() { func main() {
sourcePort := flag.Int("sourcePort", 20001, "source redis port")
targetPort := flag.Int("targetPort", 30001, "target redis port")
log.SetLevel(log.LEVEL_INFO)
log.Infof("run test starts")
source, target := *sourcePort, *targetPort
for _, tc := range tcase.CaseList {
tc.SetInfo(source, target)
if err := tc.Before(); err != nil {
log.Panicf("run case %v before stage failed: %v", tc.Info(), err)
}
if err := tc.Run(); err != nil {
log.Panicf("run case %v run stage failed: %v", tc.Info(), err)
}
if err := tc.Before(); err != nil {
log.Panicf("run case %v after stage failed: %v", tc.Info(), err)
}
// +50 in different case
source += 50
target += 50
}
log.Infof("finish all test case")
} }

@ -0,0 +1,13 @@
package tcase
var (
CaseList = []Base{new(Standalone2StandaloneCase),}
)
type Base interface {
SetInfo(sourcePort, targetPort int) // set
Info() string // name
Before() error // prepare
Run() error // run
After() error // finish
}

@ -0,0 +1,57 @@
package tcase
import (
"integration-test/deploy"
"fmt"
shakeUtils "redis-shake/common"
)
type Standalone2StandaloneCase struct {
SourcePort int
TargetPort int
}
func (s2s *Standalone2StandaloneCase) SetInfo(sourcePort, targetPort int) {
s2s.SourcePort = sourcePort
s2s.TargetPort = targetPort
}
func (s2s *Standalone2StandaloneCase) Info() string {
return fmt.Sprintf("standalone->standalone")
}
func (s2s *Standalone2StandaloneCase) Before() error {
// deploy source redis with given port
if err := deploy.Deploy(deploy.StandaloneScript, s2s.SourcePort, deploy.CmdStart, -1); err != nil {
return fmt.Errorf("deploy source redis failed: %v", err)
}
// deploy target redis with given port
if err := deploy.Deploy(deploy.StandaloneScript, s2s.TargetPort, deploy.CmdStart, -1); err != nil {
return fmt.Errorf("deploy source redis failed: %v", err)
}
return nil
}
func (s2s *Standalone2StandaloneCase) Run() error {
// build client
sourceConn := shakeUtils.OpenRedisConn([]string{fmt.Sprintf(":%d", s2s.SourcePort)}, "auth", "", false, false)
targeteConn := shakeUtils.OpenRedisConn([]string{fmt.Sprintf(":%d", s2s.TargetPort)}, "auth", "", false, false)
}
func (s2s *Standalone2StandaloneCase) After() error {
// close source redis
if err := deploy.Deploy(deploy.StandaloneScript, s2s.SourcePort, deploy.CmdStop, -1); err != nil {
return fmt.Errorf("close source redis failed: %v", err)
}
// close target redis
if err := deploy.Deploy(deploy.StandaloneScript, s2s.TargetPort, deploy.CmdStop, -1); err != nil {
return fmt.Errorf("close source redis failed: %v", err)
}
return nil
}
Loading…
Cancel
Save