未验证 提交 c72ca2e9 编写于 作者: H huili 提交者: GitHub

Merge pull request #5492 from taosdata/xiaoping/add_test_case

update docker cluster script
...@@ -18,13 +18,15 @@ import argparse ...@@ -18,13 +18,15 @@ import argparse
class BuildDockerCluser: class BuildDockerCluser:
def __init__(self, hostName, user, password, configDir, numOfNodes, clusterVersion): def __init__(self, hostName, user, password, configDir, numOfNodes, clusterVersion, dockerDir, removeFlag):
self.hostName = hostName self.hostName = hostName
self.user = user self.user = user
self.password = password self.password = password
self.configDir = configDir self.configDir = configDir
self.numOfNodes = numOfNodes self.numOfNodes = numOfNodes
self.clusterVersion = clusterVersion self.clusterVersion = clusterVersion
self.dockerDir = dockerDir
self.removeFlag = removeFlag
def getConnection(self): def getConnection(self):
self.conn = taos.connect( self.conn = taos.connect(
...@@ -42,14 +44,17 @@ class BuildDockerCluser: ...@@ -42,14 +44,17 @@ class BuildDockerCluser:
print("start arbitrator") print("start arbitrator")
os.system("docker exec -d $(docker ps|grep tdnode1|awk '{print $1}') tarbitrator") os.system("docker exec -d $(docker ps|grep tdnode1|awk '{print $1}') tarbitrator")
def run(self): def run(self):
if self.numOfNodes < 2 or self.numOfNodes > 5: if self.numOfNodes < 2 or self.numOfNodes > 5:
print("the number of nodes must be between 2 and 5") print("the number of nodes must be between 2 and 5")
exit(0) exit(0)
os.system("./buildClusterEnv.sh -n %d -v %s" % (self.numOfNodes, self.clusterVersion)) print("remove Flag value %s" % self.removeFlag)
if self.removeFlag == False:
os.system("./cleanClusterEnv.sh -d %s" % self.dockerDir)
os.system("./buildClusterEnv.sh -n %d -v %s -d %s" % (self.numOfNodes, self.clusterVersion, self.dockerDir))
self.getConnection() self.getConnection()
self.createDondes() self.createDondes()
self.startArbitrator() self.startArbitrator()
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument( parser.add_argument(
...@@ -91,10 +96,24 @@ parser.add_argument( ...@@ -91,10 +96,24 @@ parser.add_argument(
'-v', '-v',
'--version', '--version',
action='store', action='store',
default='2.0.14.1', default='2.0.17.1',
type=str, type=str,
help='the version of the cluster to be build, Default is 2.0.14.1') help='the version of the cluster to be build, Default is 2.0.17.1')
parser.add_argument(
'-d',
'--docker-dir',
action='store',
default='/data',
type=str,
help='the data dir for docker, default is /data')
parser.add_argument(
'--flag',
action='store_true',
help='remove docker containers flag, default: True')
args = parser.parse_args() args = parser.parse_args()
cluster = BuildDockerCluser(args.host, args.user, args.password, args.config_dir, args.num_of_nodes, args.version) cluster = BuildDockerCluser(args.host, args.user, args.password, args.config_dir, args.num_of_nodes, args.version, args.docker_dir, args.flag)
cluster.run() cluster.run()
\ No newline at end of file
# usage 1: python3 basic.py -n 2 --flag (flag is True)
# usage 2: python3 basic.py -n 2 (flag should be False when it is not specified)
\ No newline at end of file
#!/bin/bash #!/bin/bash
echo "Executing buildClusterEnv.sh" echo "Executing buildClusterEnv.sh"
DOCKER_DIR=/data
CURR_DIR=`pwd` CURR_DIR=`pwd`
if [ $# != 4 ]; then if [ $# != 6 ]; then
echo "argument list need input : " echo "argument list need input : "
echo " -n numOfNodes" echo " -n numOfNodes"
echo " -v version" echo " -v version"
echo " -d docker dir"
exit 1 exit 1
fi fi
NUM_OF_NODES= NUM_OF_NODES=
VERSION= VERSION=
while getopts "n:v:" arg DOCKER_DIR=
while getopts "n:v:d:" arg
do do
case $arg in case $arg in
n) n)
...@@ -20,6 +21,9 @@ do ...@@ -20,6 +21,9 @@ do
;; ;;
v) v)
VERSION=$OPTARG VERSION=$OPTARG
;;
d)
DOCKER_DIR=$OPTARG
;; ;;
?) ?)
echo "unkonwn argument" echo "unkonwn argument"
...@@ -31,29 +35,28 @@ function addTaoscfg { ...@@ -31,29 +35,28 @@ function addTaoscfg {
for i in {1..5} for i in {1..5}
do do
touch /data/node$i/cfg/taos.cfg touch /data/node$i/cfg/taos.cfg
echo 'firstEp tdnode1:6030' > /data/node$i/cfg/taos.cfg echo 'firstEp tdnode1:6030' > $DOCKER_DIR/node$i/cfg/taos.cfg
echo 'fqdn tdnode'$i >> /data/node$i/cfg/taos.cfg echo 'fqdn tdnode'$i >> $DOCKER_DIR/node$i/cfg/taos.cfg
echo 'arbitrator tdnode1:6042' >> /data/node$i/cfg/taos.cfg echo 'arbitrator tdnode1:6042' >> $DOCKER_DIR/node$i/cfg/taos.cfg
done done
} }
function createDIR { function createDIR {
for i in {1..5} for i in {1..5}
do do
mkdir -p /data/node$i/data mkdir -p $DOCKER_DIR/node$i/data
mkdir -p /data/node$i/log mkdir -p $DOCKER_DIR/node$i/log
mkdir -p /data/node$i/cfg mkdir -p $DOCKER_DIR/node$i/cfg
mkdir -p /data/node$i/core mkdir -p $DOCKER_DIR/node$i/core
done done
} }
function cleanEnv { function cleanEnv {
echo "Clean up docker environment"
for i in {1..5} for i in {1..5}
do do
echo /data/node$i/data/* rm -rf $DOCKER_DIR/node$i/data/*
rm -rf /data/node$i/data/* rm -rf $DOCKER_DIR/node$i/log/*
echo /data/node$i/log/*
rm -rf /data/node$i/log/*
done done
} }
...@@ -98,19 +101,19 @@ function clusterUp { ...@@ -98,19 +101,19 @@ function clusterUp {
if [ $NUM_OF_NODES -eq 2 ]; then if [ $NUM_OF_NODES -eq 2 ]; then
echo "create 2 dnodes" echo "create 2 dnodes"
PACKAGE=TDengine-server-$VERSION-Linux-x64.tar.gz DIR=TDengine-server-$VERSION DIR2=TDengine-arbitrator-$VERSION VERSION=$VERSION docker-compose up -d PACKAGE=TDengine-server-$VERSION-Linux-x64.tar.gz TARBITRATORPKG=TDengine-arbitrator-$VERSION-Linux-x64.tar.gz DIR=TDengine-server-$VERSION DIR2=TDengine-arbitrator-$VERSION VERSION=$VERSION docker-compose up -d
fi fi
if [ $NUM_OF_NODES -eq 3 ]; then if [ $NUM_OF_NODES -eq 3 ]; then
PACKAGE=TDengine-server-$VERSION-Linux-x64.tar.gz DIR=TDengine-server-$VERSION DIR2=TDengine-arbitrator-$VERSION VERSION=$VERSION docker-compose -f docker-compose.yml -f node3.yml up -d PACKAGE=TDengine-server-$VERSION-Linux-x64.tar.gz TARBITRATORPKG=TDengine-arbitrator-$VERSION-Linux-x64.tar.gz DIR=TDengine-server-$VERSION DIR2=TDengine-arbitrator-$VERSION VERSION=$VERSION docker-compose -f docker-compose.yml -f node3.yml up -d
fi fi
if [ $NUM_OF_NODES -eq 4 ]; then if [ $NUM_OF_NODES -eq 4 ]; then
PACKAGE=TDengine-server-$VERSION-Linux-x64.tar.gz DIR=TDengine-server-$VERSION DIR2=TDengine-arbitrator-$VERSION VERSION=$VERSION docker-compose -f docker-compose.yml -f node3.yml -f node4.yml up -d PACKAGE=TDengine-server-$VERSION-Linux-x64.tar.gz TARBITRATORPKG=TDengine-arbitrator-$VERSION-Linux-x64.tar.gz DIR=TDengine-server-$VERSION DIR2=TDengine-arbitrator-$VERSION VERSION=$VERSION docker-compose -f docker-compose.yml -f node3.yml -f node4.yml up -d
fi fi
if [ $NUM_OF_NODES -eq 5 ]; then if [ $NUM_OF_NODES -eq 5 ]; then
PACKAGE=TDengine-server-$VERSION-Linux-x64.tar.gz DIR=TDengine-server-$VERSION DIR2=TDengine-arbitrator-$VERSION VERSION=$VERSION docker-compose -f docker-compose.yml -f node3.yml -f node4.yml -f node5.yml up -d PACKAGE=TDengine-server-$VERSION-Linux-x64.tar.gz TARBITRATORPKG=TDengine-arbitrator-$VERSION-Linux-x64.tar.gz DIR=TDengine-server-$VERSION DIR2=TDengine-arbitrator-$VERSION VERSION=$VERSION docker-compose -f docker-compose.yml -f node3.yml -f node4.yml -f node5.yml up -d
fi fi
echo "docker compose finish" echo "docker compose finish"
......
#!/bin/bash
echo "Executing cleanClusterEnv.sh"
CURR_DIR=`pwd`
if [ $# != 2 ]; then
echo "argument list need input : "
echo " -d docker dir"
exit 1
fi
DOCKER_DIR=
while getopts "d:" arg
do
case $arg in
d)
DOCKER_DIR=$OPTARG
;;
?)
echo "unkonwn argument"
;;
esac
done
function removeDockerContainers {
cd $DOCKER_DIR
docker-compose down --remove-orphans
}
function cleanEnv {
echo "Clean up docker environment"
for i in {1..5}
do
rm -rf $DOCKER_DIR/node$i/data/*
rm -rf $DOCKER_DIR/node$i/log/*
done
}
removeDockerContainers
cleanEnv
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册