测试用的54

"""
-*- 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()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值