"""
-*- coding: utf-8 -*-
@Author: zhangyuling
@file: testname.py
@Time: 2021/12/8 上午10:33
"""
import os, sys
import configparser
sys.path.append(os.getcwd())
import paramiko
import api.conn as ac
import lib.upscale_and_downscale as uad
import api.process as ap
from api.conn import GdbConn
from api.logger import logger
from time import sleep
import multiprocessing
cfgpath = os.path.abspath("./conf/config.ini")
conf = configparser.ConfigParser()
conf.read(cfgpath)
hostname = conf.get('hosts', 'homehost')
sqlnode = conf.get('hosts', 'cluster_sqlnode1')
from api.logger import logger
prepare = ("cd /pnvme/zhangyl/sysbench-tpcc && ./tpcc.lua --mysql-user=greatdb "
"--mysql-db=benchmark "
"--mysql-password=Aa111111! "
"--mysql_port=19000 "
"--mysql-host={0} "
"--use_fk=0 "
"--mysql_storage_engine=greatdb "
"--mysql_table_partitions=4 "
"--time=60 --threads=32 "
"--report-interval=1 --tables=1 "
"--scale=1 --db-driver=mysql "
"--mysql-ignore-errors=all prepare").format(sqlnode)
run = ("cd /pnvme/zhangyl/sysbench-tpcc && ./tpcc.lua --mysql-user=greatdb "
"--mysql-db=benchmark "
"--mysql-password=Aa111111! "
"--mysql_port=19000 "
"--mysql-host={0} "
"--use_fk=0 "
"--mysql_storage_engine=greatdb "
"--mysql_table_partitions=4 "
"--time=60 --threads=32 "
"--report-interval=1 --tables=1 "
"--scale=1 --db-driver=mysql "
"--mysql-ignore-errors=all run").format(sqlnode)
cleanup = ("cd /pnvme/zhangyl/sysbench-tpcc && ./tpcc.lua --mysql-user=greatdb "
"--mysql-db=benchmark "
"--mysql-password=Aa111111! "
"--mysql_port=19000 "
"--mysql-host={0} "
"--use_fk=0 "
"--mysql_storage_engine=greatdb "
"--mysql_table_partitions=4 "
"--time=60 --threads=32 "
"--report-interval=1 --tables=1 "
"--scale=1 --db-driver=mysql "
"--mysql-ignore-errors=all cleanup").format(sqlnode)
check = ("cd /pnvme/zhangyl/sysbench-tpcc && ./tpcc.lua --mysql-user=greatdb "
"--mysql-db=benchmark "
"--mysql-password=Aa111111! "
"--mysql_port=19000 "
"--mysql-host={0} "
"--use_fk=0 "
"--mysql_storage_engine=greatdb "
"--mysql_table_partitions=4 "
"--time=60 --threads=32 "
"--report-interval=1 --tables=1 "
"--scale=1 --db-driver=mysql "
"--mysql-ignore-errors=all check").format(sqlnode)
def operation(operation):
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(hostname, port=22, username='root', password='abc123')
if operation == prepare:
stdin, stdout, stderr = client.exec_command(prepare)
logger.info(f"{stdout.read().decode('utf-8')}")
elif operation == run:
stdin, stdout, stderr = client.exec_command(run)
logger.info(f"{stdout.read().decode('utf-8')}")
elif operation == check:
stdin, stdout, stderr = client.exec_command(check)
logger.info(f"{stdout.read().decode('utf-8')}")
elif operation == cleanup:
stdin, stdout, stderr = client.exec_command(cleanup)
logger.info(f"{stdout.read().decode('utf-8')}")
else:
logger.info("please check your command!")
client.close()
startrun = multiprocessing.Process(target=operation, args=(run,))
def greatdb_safe_restart_instance_kill_greatdbd():
# greatdb_safe can restart the greatdb
logger.info("create the database")
db = GdbConn(host="cluster_sqlnode1").conn().connection()
cursor = db.cursor()
sql = ("drop database if exists benchmark;create database benchmark;")
sqllist = sql.split(';')
for i in sqllist[0:-1]:
cursor.execute(i)
logger.info("finished and start prepare")
operation(prepare)
logger.info("finished and start run 60s")
startrun.start()
sleep(5)
ap.KillProcess(count=1,
nodeName="cluster_sqlnode1",
processName="greatsqld",
excludeProcess="greatsqld_safe",
sshPass="abc123",
sshUser="root",
timeout=5).kill()
sleep(60)
logger.info("start check whether pass")
operation(check)
logger.info("start check whether cleanup")
operation(cleanup)
startrun.join()
greatdb_safe_restart_instance_kill_greatdbd()
测试用的54
最新推荐文章于 2024-07-23 13:22:23 发布