parent
468de49504
commit
0057189394
6 changed files with 164 additions and 3 deletions
@ -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) |
@ -1,5 +1,40 @@ |
||||
package main |
||||
|
||||
import ( |
||||
"pkg/libs/log" |
||||
"flag" |
||||
|
||||
"integration-test/tcase" |
||||
) |
||||
|
||||
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…
Reference in new issue