def stop(self,compute_obj): """ 停止云主机的unixbench测试 :param compute_obj: :return: """ if not compute_obj.float_ip: self._loggers.stabilityUnixbenchLogger.error('云主机'+compute_obj.name+'的浮动ip为空,无法停止unixbench测试') return compute_float_ip = compute_obj.float_ip.encode('utf-8') compute_name = compute_obj.name.encode('utf-8') self._loggers.stabilityUnixbenchLogger.info('开始检测云主机' + compute_name + '的浮动ip:' + compute_float_ip + '是否可连通') is_online = CheckTool.is_compute_online(compute_float_ip) if not is_online: self._loggers.stabilityUnixbenchLogger.error('检测到云主机' + compute_name + '的浮动ip:' + compute_float_ip + '无法连通') return # 检测云主机22端口是否可用 is_port_OK = CheckTool.is_remoteService_OK(compute_float_ip, 22) if not is_port_OK: self._loggers.stabilityUnixbenchLogger.error('检测到云主机' + compute_name + '浮动ip:' + compute_float_ip + '的22端口不可用!') return # 获得ssh连接对象 sshclient = SSHClient(compute_float_ip) self._loggers.stabilityUnixbenchLogger.info('开始停止unixbench测试,云主机' + compute_name) stop_command = "cd /root/soft/unixbench/tmp;./kill_run" stdin, stdout, stderr, exit_code = sshclient.ssh_exec_command(command=stop_command, timeout=20) if exit_code: self._loggers.stabilityUnixbenchLogger.error('停止云主机' + compute_name + 'unixbench测试失败' + '\r\n' + stderr.read()) # 关闭ssh sshclient.closeSSHAndSFTP()
def reStart(self,compute_obj): """ 对云主机进行unixbench测试 :param compute_obj: :return: """ if not compute_obj.float_ip: self._loggers.stabilityUnixbenchLogger.error('云主机'+compute_obj.name+'的浮动ip为空,无法重启unixbench测试') return compute_float_ip=compute_obj.float_ip.encode('utf-8') compute_name=compute_obj.name.encode('utf-8') self._loggers.stabilityUnixbenchLogger.info('开始检测云主机'+compute_name+'浮动ip:'+compute_float_ip+'是否可连通') is_online=CheckTool.is_compute_online(compute_float_ip) if not is_online: self._loggers.stabilityUnixbenchLogger.error('检测到云主机' + compute_name + '浮动ip:' + compute_float_ip + '无法连通') return # 检测云主机22端口是否可用 is_port_OK = CheckTool.is_remoteService_OK(compute_float_ip, 22) if not is_port_OK: self._loggers.stabilityUnixbenchLogger.error('检测到云主机' + compute_name + '浮动ip:' + compute_float_ip + '的22端口不可用!') return #获得ssh连接对象 sshclient=SSHClient(compute_float_ip) self._loggers.stabilityUnixbenchLogger.info('重启unixbench测试,云主机' + compute_name) test_command = 'cd /root/soft/unixbench;nohup ./Run -c ' + self._readConfig.executeTest.stability_test_unixbench_cpu + ' -i ' + self._readConfig.executeTest.stability_test_unixbench_times + ' >nohup.out 2>&1 &' stdin, stdout, stderr, exit_code=sshclient.ssh_exec_command(command=test_command, timeout=20) if exit_code: self._loggers.stabilityUnixbenchLogger.error('unixbench测试云主机' + compute_name + '重启失败' + '\r\n' + stderr.read()) # 关闭ssh sshclient.closeSSHAndSFTP()
def stop(self, compute_client): """ 停止两台云主机进行sysbench测试 :param compute_client: :return: """ if not compute_client.float_ip: self._loggers.stabilitySysbenchLogger.error( '云主机' + compute_client.name + '的浮动ip为空,无法停止sysbench测试') return compute_client_float_ip = compute_client.float_ip.encode('utf-8') compute_client_name = compute_client.name.encode('utf-8') #trove_server_name=trove_server.name.encode('utf-8') self._loggers.stabilitySysbenchLogger.info('开始检测数据库实例' + compute_client_name + '浮动ip:' + compute_client_float_ip + '是否可连通') is_client_online = CheckTool.is_compute_online(compute_client_float_ip) if not is_client_online: self._loggers.stabilitySysbenchLogger.error( '检测到云主机' + compute_client_name + '浮动ip:' + compute_client_float_ip + '无法连通') return # 检测云主机22端口是否可用 is_port_OK = CheckTool.is_remoteService_OK(compute_client_float_ip, 22) if not is_port_OK: self._loggers.stabilitySysbenchLogger.error( '检测到云主机' + compute_client_name + '浮动ip:' + compute_client_float_ip + '的22端口不可用!') return sysbench_client_sshclient = SSHClient(compute_client_float_ip) #关闭防火墙 self._loggers.stabilitySysbenchLogger.info('关闭云主机' + compute_client_name + '的防火墙') sysbench_client_sshclient.ssh_exec_command('service iptables stop', 30) #关闭客户端程序 self._loggers.stabilitySysbenchLogger.info('停止sysbench测试') stdin, stdout, stderr, exit_code = sysbench_client_sshclient.ssh_exec_command( command= "kill -9 `ps -ef |grep sysbench|grep -v grep| awk '{print $2}'`", timeout=10) if exit_code: self._loggers.stabilitySysbenchLogger.error('关闭sysbench客户端进程失败') # 关闭ssh sysbench_client_sshclient.closeSSHAndSFTP()
def stop(self, compute_obj): """ 停止对象存储测试 :param compute_obj: :return: """ if not compute_obj.float_ip: self._loggers.stabilityObjstoreLogger.error('云主机' + compute_obj.name + '的浮动ip为空,无法重启对象存储测试') return compute_float_ip = compute_obj.float_ip.encode('utf-8') compute_name = compute_obj.name.encode('utf-8') self._loggers.stabilityObjstoreLogger.info('开始检测云主机' + compute_name + '浮动ip:' + compute_float_ip + '是否可连通') is_online = CheckTool.is_compute_online(compute_float_ip) if not is_online: self._loggers.stabilityObjstoreLogger.error('检测到云主机' + compute_name + '浮动ip:' + compute_float_ip + '无法连通') return # 检测云主机22端口是否可用 is_port_OK = CheckTool.is_remoteService_OK(compute_float_ip, 22) if not is_port_OK: self._loggers.stabilityObjstoreLogger.error('检测到云主机' + compute_name + '浮动ip:' + compute_float_ip + '的22端口不可用!') return # 获得ssh连接对象 sshclient = SSHClient(compute_float_ip) self._loggers.stabilityObjstoreLogger.info('开始停止对象存储测试,云主机' + compute_name) stop_command = "kill -9 `ps -ef |grep jmeter|grep -v grep|awk '{print $2}'`" stdin, stdout, stderr, exit_code = sshclient.ssh_exec_command( command=stop_command, timeout=20) if exit_code: self._loggers.stabilityObjstoreLogger.error('停止云主机' + compute_name + '对象存储测试失败' + '\r\n' + stderr.read()) # 关闭ssh sshclient.closeSSHAndSFTP()
def reStart(self, jmeter_compute_obj): """ 停止均衡负载器loadbalancer加压 :param jmeter_compute_obj: :return: """ if not jmeter_compute_obj.float_ip: self._loggers.stabilityLoadbalancerLogger.error( '加压云主机' + jmeter_compute_obj.name + '的浮动ip为空,无法重启loadbalancer测试') return jmeter_compute_float_ip = jmeter_compute_obj.float_ip.encode('utf-8') jmeter_compute_name = jmeter_compute_obj.name.encode('utf-8') self._loggers.stabilityLoadbalancerLogger.info( '开始检测对均衡负载器加压云主机' + jmeter_compute_name + '浮动ip:' + jmeter_compute_float_ip + '是否可连通') is_jmeter_online = CheckTool.is_compute_online(jmeter_compute_float_ip) if not is_jmeter_online: self._loggers.stabilityLoadbalancerLogger.error( '检测到对均衡负载器加压云主机' + jmeter_compute_name + '浮动ip:' + jmeter_compute_float_ip + '无法连通') return # 检测云主机22端口是否可用 is_jmeterport_OK = CheckTool.is_remoteService_OK( jmeter_compute_float_ip, 22) if not is_jmeterport_OK: self._loggers.stabilityLoadbalancerLogger.error( '检测到对负载均衡器加压云主机' + jmeter_compute_name + '浮动ip:' + jmeter_compute_float_ip + '的22端口不可用!') return # 获得ssh连接对象 jmeter_sshclient = SSHClient(jmeter_compute_float_ip) self._loggers.stabilityLoadbalancerLogger.info('重启加压云主机' + jmeter_compute_name + '对loadbalance进行加压测试') test_command = 'source /etc/profile;cd /root/soft/jmeter/bin;nohup ./jmeter -n -t /root/soft/jmeter/projects/LB/lb_forever.jmx -l logfile.jtl >nohup.out 2>&1 &' stdin, stdout, stderr, exit_code = jmeter_sshclient.ssh_exec_command( command=test_command, timeout=20) if exit_code: self._loggers.stabilityLoadbalancerLogger.error( '对均衡负载器加压云主机' + jmeter_compute_name + '重启失败' + '\r\n' + stderr.read()) # 关闭ssh jmeter_sshclient.closeSSHAndSFTP()
def stop(self, jmeter_compute_obj): """ 停止均衡负载器loadbalancer加压 :param jmeter_compute_obj: :return: """ if not jmeter_compute_obj.float_ip: self._loggers.stabilityLoadbalancerLogger.error( '加压云主机' + jmeter_compute_obj.name + '的浮动ip为空,无法停止loadbalancer测试') return jmeter_compute_float_ip = jmeter_compute_obj.float_ip.encode('utf-8') jmeter_compute_name = jmeter_compute_obj.name.encode('utf-8') self._loggers.stabilityLoadbalancerLogger.info( '开始检测对均衡负载器加压云主机' + jmeter_compute_name + '浮动ip:' + jmeter_compute_float_ip + '是否可连通') is_jmeter_online = CheckTool.is_compute_online(jmeter_compute_float_ip) if not is_jmeter_online: self._loggers.stabilityLoadbalancerLogger.error( '检测到对均衡负载器加压云主机' + jmeter_compute_name + '浮动ip:' + jmeter_compute_float_ip + '无法连通') return # 检测云主机22端口是否可用 is_jmeterport_OK = CheckTool.is_remoteService_OK( jmeter_compute_float_ip, 22) if not is_jmeterport_OK: self._loggers.stabilityLoadbalancerLogger.error( '检测到对负载均衡器加压云主机' + jmeter_compute_name + '浮动ip:' + jmeter_compute_float_ip + '的22端口不可用!') return # 获得ssh连接对象 sshclient = SSHClient(jmeter_compute_float_ip) self._loggers.stabilityLoadbalancerLogger.info( '开始停止loadbalance加压测试,云主机' + jmeter_compute_name) stop_jmeter_command = "killall -9 java" stdin, stdout, stderr, exit_code = sshclient.ssh_exec_command( command=stop_jmeter_command, timeout=20) if exit_code: self._loggers.stabilityLoadbalancerLogger.error( '停止对均衡负载器加压云主机' + jmeter_compute_name + 'loadbalancer测试失败' + '\r\n' + stderr.read()) # 关闭ssh sshclient.closeSSHAndSFTP()
def reStart(self, compute_obj): """ 重启对象存储 :param compute_obj: :return: """ if not compute_obj.float_ip: self._loggers.stabilityObjstoreLogger.error('云主机' + compute_obj.name + '的浮动ip为空,无法重启对象存储测试') return compute_float_ip = compute_obj.float_ip.encode('utf-8') compute_name = compute_obj.name.encode('utf-8') self._loggers.stabilityObjstoreLogger.info('开始检测云主机' + compute_name + '浮动ip:' + compute_float_ip + '是否可连通') is_online = CheckTool.is_compute_online(compute_float_ip) if not is_online: self._loggers.stabilityObjstoreLogger.error('检测到云主机' + compute_name + '浮动ip:' + compute_float_ip + '无法连通') return # 检测云主机22端口是否可用 is_port_OK = CheckTool.is_remoteService_OK(compute_float_ip, 22) if not is_port_OK: self._loggers.stabilityObjstoreLogger.error('检测到云主机' + compute_name + '浮动ip:' + compute_float_ip + '的22端口不可用!') return # 获得ssh连接对象 sshclient = SSHClient(compute_float_ip) self._loggers.stabilityObjstoreLogger.info('重启对象存储测试,云主机' + compute_name) test_command = 'source /etc/profile;cd /root/soft/jmeter/bin;nohup ./jmeter -n -t ../projects/baiwucloud_s3/baiwucloud_s3.jmx -l ../projects/baiwucloud_s3/result.jtl >nohup.out 2>&1 &' stdin, stdout, stderr, exit_code = sshclient.ssh_exec_command( command=test_command, timeout=20) if exit_code: self._loggers.stabilityObjstoreLogger.error('对象存储Jmeter客户端' + compute_name + '重启失败' + '\r\n' + stderr.read())
def testUinxbench(self,compute_obj): """ 对云主机进行测试 :param compute_obj: :return: """ if not compute_obj.float_ip: self._loggers.basebenchLogger.error('云主机'+compute_obj.name+'的浮动ip为空,无法进行Unixbench测试') return compute_float_ip = compute_obj.float_ip compute_name = compute_obj.name compute_testType = compute_obj.testType self._loggers.basebenchLogger.info('开始检测云主机'+compute_name+'浮动ip:'+compute_float_ip+'是否可连通') is_online=CheckTool.is_compute_online(compute_float_ip) if not is_online: self._loggers.basebenchLogger.error('检测到云主机' + compute_name + '浮动ip:' + compute_float_ip + '无法连通') return # 检测云主机22端口是否可用 is_unixbenchport_OK = CheckTool.is_remoteService_OK(compute_float_ip, 22) if not is_unixbenchport_OK: self._loggers.basebenchLogger.error('检测到云主机' + compute_name + '浮动ip:' + compute_float_ip + '的22端口不可用!') return #获得ssh连接对象 sshclient = SSHClient(compute_float_ip) self._loggers.basebenchLogger.info('开始进行unixbench测试,云主机' + compute_name + ',测试类型' + compute_testType) test_command = 'cd /root/soft/unixbench;./Run' stdin, stdout, stderr, exit_code = sshclient.ssh_exec_command(command=test_command, timeout=3600) if exit_code: self._loggers.basebenchLogger.error('unixbench测试云主机' + compute_name + '测试失败!' + '\r\n' + stderr.read()) # 获取结果文件 stdin, stdout, stderr, exit_code = sshclient.ssh_exec_command(command='cd /root/soft/unixbench;tar -zcvf ' + compute_testType + '_result.tar.gz results/', timeout=3600) if exit_code: self._loggers.basebenchLogger.error('unixbench测试云主机' + compute_name + '压缩结果文件失败!' + '\r\n' + stderr.read()) sshclient.sftp_get('/root/soft/unixbench/' + compute_testType + '_result.tar.gz','output/unixbench/'+ compute_testType + '_result.tar.gz') # 关闭ssh sshclient.closeSSHAndSFTP()
def start(self, loadbalancer_obj): """ 对loadbalancer进行请求测试 :param loadbalancer_obj: :return: """ jmeter_compute_obj = loadbalancer_obj.load_compute if not (jmeter_compute_obj.float_ip and loadbalancer_obj.virtual_ip): self._loggers.stabilityLoadbalancerLogger.error( '加压云主机' + jmeter_compute_obj.name + '或负载均衡器' + loadbalancer_obj.name + '的浮动ip为空,无法进行loadbalancer测试') return jmeter_compute_float_ip = jmeter_compute_obj.float_ip loadbalancer_float_ip = loadbalancer_obj.virtual_ip jmeter_compute_name = jmeter_compute_obj.name loadbalancer_name = loadbalancer_obj.name loadbalancer_port = loadbalancer_obj.port loadbalancer_members = loadbalancer_obj.get_members() for loadbalancer_member in loadbalancer_members: if not loadbalancer_member.float_ip: self._loggers.stabilityLoadbalancerLogger.error( '后端服务器' + loadbalancer_member.name + '的浮动ip为空,无法进行loadbalancer测试') return loadbalancer_member_float_ip = loadbalancer_member.float_ip loadbalancer_member_name = loadbalancer_member.name self._loggers.stabilityLoadbalancerLogger.info( '开始检测后端服务器' + loadbalancer_member_name + '浮动ip:' + loadbalancer_member_float_ip + '是否可连通') is_member_online = CheckTool.is_compute_online( loadbalancer_member_float_ip) if not is_member_online: self._loggers.stabilityLoadbalancerLogger.error( '检测到后端服务器' + loadbalancer_member_name + '浮动ip:' + loadbalancer_member_float_ip + '无法连通') return # 检测云主机22端口是否可用 is_memberport_OK = CheckTool.is_remoteService_OK( loadbalancer_member_float_ip, 22) if not is_memberport_OK: self._loggers.stabilityLoadbalancerLogger.error( '检测到云主机' + loadbalancer_member_name + '浮动ip:' + loadbalancer_member_float_ip + '的22端口不可用!') return loadbalancer_member_sshclient = SSHClient( loadbalancer_member_float_ip) # 关闭防火墙 self._loggers.stabilityLoadbalancerLogger.info( '关闭云主机' + loadbalancer_member_name + '的防火墙') loadbalancer_member_sshclient.ssh_exec_command( 'service iptables stop', 30) self._loggers.stabilityLoadbalancerLogger.info('启动后端服务器的nginx') # 启动服务 stdin, stdout, stderr, exit_code = loadbalancer_member_sshclient.ssh_exec_command( command= 'cd /usr/local/nginx/sbin;nohup ./nginx > nohup.out 2>&1 &') if exit_code: self._loggers.stabilityLoadbalancerLogger.error( '在云主机' + loadbalancer_member_name + '启动后端服务器的nginx失败!') return loadbalancer_member_sshclient.closeSSHAndSFTP() self._loggers.stabilityLoadbalancerLogger.info('开始检测负载均衡器' + loadbalancer_name + '的浮动ip:' + loadbalancer_float_ip + '是否可连通') is_loadbalancer_online = CheckTool.is_compute_online( loadbalancer_float_ip) self._loggers.stabilityLoadbalancerLogger.info( '开始检测对均衡负载器加压云主机' + jmeter_compute_name + '的浮动ip:' + jmeter_compute_float_ip + '是否可连通') is_jmeter_online = CheckTool.is_compute_online(jmeter_compute_float_ip) if not (is_loadbalancer_online and is_jmeter_online): self._loggers.stabilityLoadbalancerLogger.error( '检测到负载均衡器' + loadbalancer_name + '或负载均衡器加压云主机' + jmeter_compute_name + '的浮动ip:' + loadbalancer_float_ip + '或' + jmeter_compute_float_ip + '无法连通') return # 检测云主机22端口是否可用 is_jmeterport_OK = CheckTool.is_remoteService_OK( jmeter_compute_float_ip, 22) if not is_jmeterport_OK: self._loggers.stabilityLoadbalancerLogger.error( '检测到对负载均衡器加压云主机' + jmeter_compute_name + '浮动ip:' + jmeter_compute_float_ip + '的22端口不可用!') return jmeter_sshclient = SSHClient(jmeter_compute_float_ip) self._loggers.stabilityLoadbalancerLogger.info('开始对负载均衡器' + loadbalancer_name + '进行请求') test_command = 'cd /root/soft/jmeter/projects/LB;nohup sed -i "s/ip,port/' + loadbalancer_float_ip + ',' + loadbalancer_port + '/g" lb_test.txt' + ' >nohup.out 2>&1 &' stdin, stdout, stderr, exit_code = jmeter_sshclient.ssh_exec_command( command=test_command, timeout=20) if exit_code: self._loggers.stabilityLoadbalancerLogger.error( '对均衡负载器加压云主机' + jmeter_compute_name + '修改配置文件失败' + '\r\n' + stderr.read()) test_command = 'source /etc/profile;cd /root/soft/jmeter/bin;nohup ./jmeter -n -t /root/soft/jmeter/projects/LB/lb_forever.jmx -l logfile.jtl >nohup.out 2>&1 &' stdin, stdout, stderr, exit_code = jmeter_sshclient.ssh_exec_command( command=test_command, timeout=20) if exit_code: self._loggers.stabilityLoadbalancerLogger.error( '对均衡负载器加压云主机' + jmeter_compute_name + '启动失败' + '\r\n' + stderr.read()) # 关闭ssh jmeter_sshclient.closeSSHAndSFTP()
def reStart(self, compute_obj): """ 重启fio测试 :param compute_obj: :return: """ if not compute_obj.float_ip: self._loggers.stabilityFioLogger.error('云主机' + compute_obj.name + '的浮动ip为空,无法重启fio测试') return compute_float_ip = compute_obj.float_ip.encode('utf-8') compute_name = compute_obj.name.encode('utf-8') compute_testType = compute_obj.testType.encode('utf-8') self._loggers.stabilityFioLogger.info('开始检测云主机' + compute_name + '浮动ip:' + compute_float_ip + '是否可连通') is_online = CheckTool.is_compute_online(compute_float_ip) if not is_online: self._loggers.stabilityFioLogger.error('检测到云主机' + compute_name + '浮动ip:' + compute_float_ip + '无法连通') return # 检测云主机22端口是否可用 is_port_OK = CheckTool.is_remoteService_OK(compute_float_ip, 22) if not is_port_OK: self._loggers.stabilityFioLogger.error('检测到云主机' + compute_name + '浮动ip:' + compute_float_ip + '的22端口不可用!') return # 获得ssh连接对象 sshclient = SSHClient(compute_float_ip) self._loggers.stabilityFioLogger.info('重启fio测试,云主机' + compute_name) # 删除测试文件 del_command = 'cd /root/test/;rm -rf test*' stdin, stdout, stderr, exit_code = sshclient.ssh_exec_command( command=del_command, timeout=3600) if exit_code: self._loggers.stabilityFioLogger.error('fio测试后删除云主机' + compute_name + '的测试文件' + compute_testType + '失败!' + '\r\n' + stderr.read()) # 卸载云硬盘 umount_command = 'cd /root;umount /dev/vdc' stdin, stdout, stderr, exit_code = sshclient.ssh_exec_command( command=umount_command, timeout=20) if exit_code: self._loggers.stabilityFioLogger.error('卸载云主机' + compute_name + '的云硬盘/dev/vdc失败!' + '\r\n' + stderr.read()) # 格式化云硬盘 self._loggers.stabilityFioLogger.info('格式化云主机' + compute_name + '的云硬盘/dev/vdc') stdin, stdout, stderr, exit_code = sshclient.ssh_exec_command( command='mkfs -t ext4 /dev/vdc', timeout=3600) if exit_code: self._loggers.stabilityFioLogger.error('格式化云主机' + compute_name + '的云硬盘/dev/vdc失败!' + '\r\n' + stderr.read()) return # 挂载云硬盘 self._loggers.stabilityFioLogger.info('为云主机' + compute_name + '挂载云硬盘/dev/vdc') stdin, stdout, stderr, exit_code = sshclient.ssh_exec_command( command='mount /dev/vdc /root/test', timeout=20) if exit_code: self._loggers.stabilityFioLogger.error('为云主机' + compute_name + '挂载云硬盘/dev/vdc失败!+\r\n' + stderr.read()) return # 执行测试 self._loggers.stabilityFioLogger.info('重启fio稳定性测试,云主机' + compute_name + ',测试类型' + compute_testType) test_command = 'cd /root/test/;nohup fio -filename=test' + compute_testType + ' -direct=1 -iodepth 128 -thread -rw=' + compute_testType + ' -ioengine=libaio -bs=4k -size=' + \ self._readConfig.executeTest.stability_test_fio_volume_size + 'G -numjobs=10 -runtime=' + self._readConfig.executeTest.stability_test_fio_seconds + ' -name=' + compute_testType + '-libaio -group_reporting --output /root/result/' + compute_name + '_output.html > nohup.out 2>&1 &' stdin, stdin, stderr, exit_code = sshclient.ssh_exec_command( command=test_command, timeout=20) if exit_code: self._loggers.stabilityFioLogger.error('fio测试云主机' + compute_name + '测试' + compute_testType + '失败!' + '\r\n' + stderr.read()) # 关闭ssh sshclient.closeSSHAndSFTP()
def start(self, compute_obj, project_name): """ 测试对象存储 :param compute_obj: :param project_name: :return: """ if not compute_obj.float_ip: self._loggers.stabilityObjstoreLogger.error('云主机' + compute_obj.name + '的浮动ip为空,无法重启对象存储测试') return compute_float_ip = compute_obj.float_ip compute_name = compute_obj.name self._loggers.stabilityObjstoreLogger.info('开始检测云主机' + compute_name + '浮动ip:' + compute_float_ip + '是否可连通') is_online = CheckTool.is_compute_online(compute_float_ip) if not is_online: self._loggers.stabilityObjstoreLogger.error('检测到云主机' + compute_name + '浮动ip:' + compute_float_ip + '无法连通') return # 检测云主机22端口是否可用 is_port_OK = CheckTool.is_remoteService_OK(compute_float_ip, 22) if not is_port_OK: self._loggers.stabilityObjstoreLogger.error('检测到云主机' + compute_name + '浮动ip:' + compute_float_ip + '的22端口不可用!') return # 获得ssh连接对象 sshclient = SSHClient(compute_float_ip) # 上传本地所有文件到Jmeter客户端 self._loggers.stabilityObjstoreLogger.info('===从本地上传测试文件到Jmeter客户端===') sshclient.sftp_put_dir( self._readConfig.executeTest.stability_test_objstore_files_dir, '/root/soft/jmeter/projects/baiwucloud_s3/file') self._loggers.stabilityObjstoreLogger.info('===参数化设置===') keystoneclient = KeystoneClient() objectstoreclient = ObjectStoreClient() project_id = keystoneclient.getProjectId(project_name) keys = objectstoreclient.getKeys(project_id) access_key = keys[0] secret_key = keys[1] ip = objectstoreclient.getIp() command = 'sed -i "s/accesskey,secretkey,endPoint,createBucketPercent,createObjectPercent,deleteBucketPercent,deleteObjectPercent,downloadObjectPercent/' + access_key + ',' + secret_key + ',' + ip + ',0-10,0-90,0-0,0-0,0-0/g" /root/soft/jmeter/projects/baiwucloud_s3/baiwucloud_s3.txt' command = command.encode('utf-8') stdin, stdout, stderr, exit_code = sshclient.ssh_exec_command( command=command, timeout=180) if exit_code: self._loggers.stabilityObjstoreLogger.error('设置' + compute_name + '参数化失败' + '\r\n' + stderr.read()) self._loggers.stabilityObjstoreLogger.info('开始测试对象存储') stdin, stdout, stderr, exit_code = sshclient.ssh_exec_command( command= 'source /etc/profile;cd /root/soft/jmeter/bin;nohup ./jmeter -n -t ../projects/baiwucloud_s3/baiwucloud_s3.jmx -l ../projects/baiwucloud_s3/result.jtl >nohup.out 2>&1 &', timeout=60) if exit_code: self._loggers.stabilityObjstoreLogger.error('对象存储' + compute_name + '测试失败' + '\r\n' + stderr.read()) # 关闭ssh sshclient.closeSSHAndSFTP()
def reStart(self, compute_client, trove_server): """ 对两台云主机进行sysbench测试 :param compute_client: :param trove_server: :return: """ if not compute_client.float_ip: self._loggers.stabilitySysbenchLogger.error( '云主机' + compute_client.name + '的浮动ip为空,无法进行重启sysbench测试') return compute_client_float_ip = compute_client.float_ip.encode('utf-8') # compute_server_float_ip=trove_server.float_ip # compute_client_ip=compute_client.ip trove_server_ip = trove_server.ip.encode('utf-8') compute_client_name = compute_client.name.encode('utf-8') trove_server_name = trove_server.name.encode('utf-8') compute_testType = compute_client.testType.encode('utf-8') self._loggers.stabilitySysbenchLogger.info('开始检测云主机' + compute_client_name + '浮动ip:' + compute_client_float_ip + '是否可连通') is_client_online = CheckTool.is_compute_online(compute_client_float_ip) if not is_client_online: self._loggers.stabilitySysbenchLogger.error( '检测到云主机' + compute_client_name + '浮动ip:' + compute_client_float_ip + '无法连通') return # 检测云主机22端口是否可用 is_port_OK = CheckTool.is_remoteService_OK(compute_client_float_ip, 22) if not is_port_OK: self._loggers.stabilitySysbenchLogger.error( '检测到云主机' + compute_client_name + '浮动ip:' + compute_client_float_ip + '的22端口不可用!') return sysbench_client_sshclient = SSHClient(compute_client_float_ip) # 关闭防火墙 self._loggers.stabilitySysbenchLogger.info('关闭云主机' + compute_client_name + '的防火墙') sysbench_client_sshclient.ssh_exec_command('service iptables stop', 30) self._loggers.stabilitySysbenchLogger.info('清空数据库实例' + trove_server_name + '中的数据库sbtest的数据') stdin, stdout, stderr, exit_code = sysbench_client_sshclient.ssh_exec_command( command='mysql -h' + trove_server_ip + ' -utest -p123456.. -e "drop database sbtest;CREATE DATABASE sbtest CHARACTER SET utf8 COLLATE utf8_general_ci"', timeout=100) if exit_code: self._loggers.stabilitySysbenchLogger.error('删除数据库实例' + trove_server_name + '的数据库sbtest失败!') return self._loggers.stabilitySysbenchLogger.info('重新开始测试sysbench,测试类型' + compute_testType) # 启动客户端开始测试 stdin, stdout, stderr, exit_code = sysbench_client_sshclient.ssh_exec_command( command= 'nohup sysbench /usr/local/share/sysbench/oltp_read_write.lua --db-driver=mysql --threads=100 --tables=20 --table_size=100000000 --mysql-user=test --mysql-password=123456.. --mysql-host=' + trove_server_ip + ' --mysql-port=3306 --mysql-db=sbtest prepare >nohup.out 2>&1 &', timeout=20) if exit_code: self._loggers.stabilitySysbenchLogger.error('使用sysbench测试' + trove_server_name + '失败!') return # 关闭ssh sysbench_client_sshclient.closeSSHAndSFTP()
def testIperf(self,compute_client,compute_server): """ 对两台云主机进行iperf测试 :param compute_client: :param compute_server: :return: """ if not compute_client.float_ip or not compute_server.float_ip: self._loggers.basebenchLogger.error('云主机'+compute_client.name+'的浮动ip或云主机'+compute_server.name+'的浮动ip为空,无法进行iperf测试') return compute_client_float_ip=compute_client.float_ip compute_server_float_ip=compute_server.float_ip #compute_client_ip=compute_client.ip compute_server_ip=compute_server.ip compute_client_name=compute_client.name compute_server_name=compute_server.name compute_testType=compute_client.testType self._loggers.basebenchLogger.info('开始检测云主机'+compute_client_name+'的ip:'+compute_client_float_ip+'是否可连通') is_client_online=CheckTool.is_compute_online(compute_client_float_ip) self._loggers.basebenchLogger.info('开始检测云主机' + compute_server_name + '的ip:' + compute_server_float_ip + '是否可连通') is_server_online = CheckTool.is_compute_online(compute_server_float_ip) if not (is_client_online and is_server_online): self._loggers.basebenchLogger.error('检测到云主机'+ compute_server_name + "或" + compute_client_name + '浮动ip:' + compute_server_float_ip + "或" + compute_client_float_ip + '无法连通') return # 检测iperf服务端22端口是否可用 is_iperfserviceport_OK = CheckTool.is_remoteService_OK(compute_server_float_ip, 22) if not is_iperfserviceport_OK: self._loggers.basebenchLogger.error('检测到云主机' + compute_server_name + '浮动ip:' + compute_server_float_ip + '的22端口不可用!') return # 检测iperf客户端22端口是否可用 is_iperfclientport_OK = CheckTool.is_remoteService_OK(compute_client_float_ip, 22) if not is_iperfclientport_OK: self._loggers.basebenchLogger.error('检测到云主机' + compute_client_name + '浮动ip:' + compute_client_float_ip+ '的22端口不可用!') return iperf_client_sshclient=SSHClient(compute_client_float_ip) iperf_server_sshclient=SSHClient(compute_server_float_ip) #关闭防火墙 self._loggers.basebenchLogger.info('关闭云主机'+compute_client_name+'和云主机'+compute_server_name+'的防火墙') iperf_client_sshclient.ssh_exec_command('service iptables stop',30) iperf_server_sshclient.ssh_exec_command('service iptables stop', 30) # 创建测试结果保存目录 self._loggers.basebenchLogger.info('在iperf客户端云主机' + compute_client_name + '里创建结果保存目录/root/result') stdin, stdout, stderr, exit_code = iperf_client_sshclient.ssh_exec_command(command='mkdir -p /root/result') if exit_code: self._loggers.basebenchLogger.error('在云主机' + compute_client_name + '里创建结果保存目录/root/result失败!' + '\r\n' + stderr.read()) return self._loggers.basebenchLogger.info('开始测试iperf,测试类型'+compute_testType) #启动服务端 stdin,stdout,stderr,exit_code=iperf_server_sshclient.ssh_exec_command(command='nohup iperf3 -s -p 8100 -i 1 > nohup.out 2>&1 &',timeout=10) if exit_code: self._loggers.basebenchLogger.error('在云主机'+compute_server_name+'启动iperf服务端失败!') return #检测服务端启动是否可用 is_service_OK=CheckTool.is_remoteService_OK(compute_server_float_ip,8100) if not is_service_OK: self._loggers.basebenchLogger.error('检测到云主机' + compute_server_name + '浮动ip:' + compute_server_float_ip + '的8100端口不存在!') return #启动客户端开始测试 stdin, stdout, stderr, exit_code = iperf_client_sshclient.ssh_exec_command(command='iperf3 -c '+compute_server_ip+' -p 8100 -i 1 -t 60 -P 10 >/root/result/'+compute_testType+'_result.txt',timeout=180) if exit_code: self._loggers.basebenchLogger.error('测试云主机'+compute_client_name+'和云主机'+compute_server_name+'的iperf失败!') #下载测试结果 iperf_client_sshclient.sftp_get('/root/result/'+compute_testType+'_result.txt','output/iperf/'+compute_testType+'_result.txt') #关闭服务端程序 stdin, stdout, stderr, exit_code=iperf_server_sshclient.ssh_exec_command(command="kill -9 `ps -ef |grep iperf3|grep -v grep|awk '{print $2}'`",timeout=10) if exit_code: self._loggers.basebenchLogger.error('关闭iperf服务端进程失败') # 关闭ssh iperf_client_sshclient.closeSSHAndSFTP() iperf_server_sshclient.closeSSHAndSFTP()
def testFio(self,compute_obj): """ 对云主机进行测试 :param compute_obj: :return: """ if not compute_obj.float_ip: self._loggers.basebenchLogger.error('云主机'+compute_obj.name+'的浮动ip为空,无法进行FIO测试') return compute_float_ip=compute_obj.float_ip compute_name=compute_obj.name compute_testType=compute_obj.testType self._loggers.basebenchLogger.info('开始检测云主机'+compute_name+'浮动ip:'+compute_float_ip+'是否可连通') is_online=CheckTool.is_compute_online(compute_float_ip) if not is_online: self._loggers.basebenchLogger.error('检测到云主机' + compute_name + '浮动ip:' + compute_float_ip + '无法连通') return # 检测云主机22端口是否可用 is_fioport_OK = CheckTool.is_remoteService_OK(compute_float_ip, 22) if not is_fioport_OK: self._loggers.basebenchLogger.error('检测到云主机' + compute_name + '浮动ip:' + compute_float_ip + '的22端口不可用!') return #获得ssh连接对象 self._loggers.basebenchLogger.info('开始获得云主机'+compute_float_ip+'的ssh连接') sshclient=SSHClient(compute_float_ip) self._loggers.basebenchLogger.info('格式化云主机' + compute_name + '的云硬盘/dev/vdc') stdin, stdout, stderr, exit_code = sshclient.ssh_exec_command('mkfs -t ext4 /dev/vdc', timeout=1200) if exit_code: self._loggers.basebenchLogger.error('格式化云主机' + compute_name + '的云硬盘/dev/vdc失败!' + '\r\n' + stderr.read()) return # 创建磁盘挂载目录 self._loggers.basebenchLogger.info('创建云主机云' + compute_name + '硬盘挂载目录/root/test') stdin, stdout, stderr, exit_code = sshclient.ssh_exec_command(command='mkdir -p /root/test') if exit_code: self._loggers.basebenchLogger.error('创建云主机云' + compute_name + '硬盘挂载目录/root/test失败!' + '\r\n' + stderr.read()) return # 挂载云硬盘 self._loggers.basebenchLogger.info('为云主机' + compute_name + '挂载云硬盘/dev/vdc') stdin, stdout, stderr, exit_code = sshclient.ssh_exec_command(command='mount /dev/vdc /root/test', timeout=20) if exit_code: self._loggers.basebenchLogger.error('为云主机' + compute_name + '挂载云硬盘/dev/vdc失败!+\r\n' + stderr.read()) return # 创建测试结果保存目录 self._loggers.basebenchLogger.info('在云主机' + compute_name + '里创建结果保存目录/root/result') stdin, stdout, stderr, exit_code = sshclient.ssh_exec_command(command='mkdir -p /root/result') if exit_code: self._loggers.basebenchLogger.error('在云主机' + compute_name + '里创建结果保存目录/root/result失败!' + '\r\n' + stderr.read()) return test_fio_volume_types=self._readConfig.executeTest.basebench_test_fio_volume_types.split('||') test_fio_types=self._readConfig.executeTest.basebench_test_fio_types.split('||') for test_fio_volume_type in test_fio_volume_types: for test_fio_type in test_fio_types: testType = test_fio_type + test_fio_volume_type if testType == compute_testType: self._loggers.basebenchLogger.info('开始fio测试,云主机' + compute_name + ',测试类型' + testType) test_command = 'cd /root/test/;fio -filename=test' + testType + ' -direct=1 -iodepth 128 -thread -rw=' + test_fio_type + ' -ioengine=libaio -bs=4k -size=' + self._readConfig.executeTest.basebench_test_fio_volume_size + 'G -numjobs=10 -runtime=60 -name=' + testType + '-libaio -group_reporting --output /root/result/fio_' + testType + '_output.html' stdin, stdout, stderr, exit_code=sshclient.ssh_exec_command(command=test_command, timeout=3600) if exit_code: self._loggers.basebenchLogger.error('fio测试云主机' + compute_name + '测试' + testType + '失败!' + '\r\n' + stderr.read()) # 获取结果文件 sshclient.sftp_get('/root/result/fio_' + testType + '_output.html', 'output/fio/fio_' + testType + '_output.html') #删除测试文件 del_command='cd /root/test/;rm -rf test' + testType stdin, stdout, stderr, exit_code = sshclient.ssh_exec_command(command=del_command, timeout=3600) if exit_code: self._loggers.basebenchLogger.error('fio测试后删除云主机'+compute_name+'的文件test'+testType+'失败!'+'\r\n'+stderr.read()) #关闭ssh sshclient.closeSSHAndSFTP()
def reStart(self, compute_client, compute_server): """ 对两台云主机进行iperf测试 :param compute_client: :param compute_server: :return: """ if not compute_client.float_ip or not compute_server.float_ip: self._loggers.stabilityIperfLogger.error( '云主机' + compute_client.name.encode('utf-8') + '的浮动ip或云主机' + compute_server.name.encode('utf-8') + '的浮动ip为空,无法重启iperf测试') return compute_client_float_ip = compute_client.float_ip.encode('utf-8') compute_server_float_ip = compute_server.float_ip.encode('utf-8') #compute_client_ip=compute_client.ip.encode('utf-8') compute_server_ip = compute_server.ip.encode('utf-8') compute_client_name = compute_client.name.encode('utf-8') compute_server_name = compute_server.name.encode('utf-8') compute_testType = compute_client.testType.encode('utf-8') self._loggers.stabilityIperfLogger.info('开始检测云主机' + compute_client_name + '的ip:' + compute_client_float_ip + '是否可连通') is_client_online = CheckTool.is_compute_online(compute_client_float_ip) self._loggers.stabilityIperfLogger.info('开始检测云主机' + compute_server_name + '的ip:' + compute_server_float_ip + '是否可连通') is_server_online = CheckTool.is_compute_online(compute_server_float_ip) if not (is_client_online and is_server_online): self._loggers.stabilityIperfLogger.error('检测到云主机' + compute_server_name + "或" + compute_client_name + '浮动ip:' + compute_server_float_ip + "或" + compute_client_float_ip + '无法连通') return # 检测iperf服务端22端口是否可用 is_serverport_OK = CheckTool.is_remoteService_OK( compute_server_float_ip, 22) if not is_serverport_OK: self._loggers.stabilityIperfLogger.error('检测到云主机' + compute_server_name + '浮动ip:' + compute_server_float_ip + '的22端口不可用!') return # 检测iperf客户端22端口是否可用 is_clientport_OK = CheckTool.is_remoteService_OK( compute_client_float_ip, 22) if not is_clientport_OK: self._loggers.stabilityIperfLogger.error('检测到云主机' + compute_client_name + '浮动ip:' + compute_client_float_ip + '的22端口不可用!') return iperf_client_sshclient = SSHClient(compute_client_float_ip) iperf_server_sshclient = SSHClient(compute_server_float_ip) self._loggers.stabilityIperfLogger.info('开始重启测试iperf,测试类型' + compute_testType) #启动服务端 stdin, stdout, stderr, exit_code = iperf_server_sshclient.ssh_exec_command( command='nohup iperf3 -s -p 8100 -i 1 > nohup.out 2>&1 &', timeout=20) if exit_code: self._loggers.stabilityIperfLogger.error('在云主机' + compute_server_name + '启动iperf服务端失败!') return #检测服务端启动是否可用 is_service_OK = CheckTool.is_remoteService_OK(compute_server_float_ip, 8100) if not is_service_OK: self._loggers.stabilityIperfLogger.error('检测到云主机' + compute_server_name + '浮动ip:' + compute_server_float_ip + '的8100端口不存在!') return #启动客户端开始测试 stdin, stdout, stderr, exit_code = iperf_client_sshclient.ssh_exec_command( command='nohup iperf3 -c ' + compute_server_ip + ' -p 8100 -i 1 -t ' + self._readConfig.executeTest.stability_test_iperf_seconds + ' -P 10 >nohup.out 2>&1 &', timeout=20) if exit_code: self._loggers.stabilityIperfLogger.error('测试云主机' + compute_client_name + '和云主机' + compute_server_name + '的iperf失败!') # 关闭ssh iperf_client_sshclient.closeSSHAndSFTP() iperf_server_sshclient.closeSSHAndSFTP()
def stop(self, compute_client, compute_server): """ 停止两台云主机进行iperf测试 :param compute_client: :param compute_server: :return: """ if not compute_client.float_ip or not compute_server.float_ip: self._loggers.stabilityIperfLogger.error( '云主机' + compute_client.name.encode('utf-8') + '的浮动ip或云主机' + compute_server.name.encode('utf-8') + '的浮动ip为空,无法停止iperf测试') return compute_client_float_ip = compute_client.float_ip.encode('utf-8') compute_server_float_ip = compute_server.float_ip.encode('utf-8') compute_client_name = compute_client.name.encode('utf-8') compute_server_name = compute_server.name.encode('utf-8') self._loggers.stabilityIperfLogger.info('开始检测云主机' + compute_client_name + '的ip:' + compute_client_float_ip + '是否可连通') is_client_online = CheckTool.is_compute_online(compute_client_float_ip) self._loggers.stabilityIperfLogger.info('开始检测云主机' + compute_server_name + '的ip:' + compute_server_float_ip + '是否可连通') is_server_online = CheckTool.is_compute_online(compute_server_float_ip) if not (is_client_online and is_server_online): self._loggers.stabilityIperfLogger.error('检测到云主机' + compute_server_name + "或" + compute_client_name + '浮动ip:' + compute_server_float_ip + "或" + compute_client_float_ip + '无法连通') return # 检测iperf服务端22端口是否可用 is_serverport_OK = CheckTool.is_remoteService_OK( compute_server_float_ip, 22) if not is_serverport_OK: self._loggers.stabilityIperfLogger.error('检测到云主机' + compute_server_name + '浮动ip:' + compute_server_float_ip + '的22端口不可用!') return # 检测iperf客户端22端口是否可用 is_clientport_OK = CheckTool.is_remoteService_OK( compute_client_float_ip, 22) if not is_clientport_OK: self._loggers.stabilityIperfLogger.error('检测到云主机' + compute_client_name + '浮动ip:' + compute_client_float_ip + '的22端口不可用!') return iperf_client_sshclient = SSHClient(compute_client_float_ip) iperf_server_sshclient = SSHClient(compute_server_float_ip) # 关闭防火墙 iperf_client_sshclient.ssh_exec_command('service iptables stop', 30) iperf_server_sshclient.ssh_exec_command('service iptables stop', 30) #关闭客户端程序 stdin, stdout, stderr, exit_code = iperf_client_sshclient.ssh_exec_command( command= "kill -9 `ps -ef |grep iperf3|grep -v grep|awk '{print $2}'`", timeout=10) if exit_code: self._loggers.stabilityIperfLogger.error('关闭iperf客户端进程失败') #关闭服务端程序 stdin, stdout, stderr, exit_code = iperf_server_sshclient.ssh_exec_command( command= "kill -9 `ps -ef |grep iperf3|grep -v grep|awk '{print $2}'`", timeout=10) if exit_code: self._loggers.stabilityIperfLogger.error('关闭iperf服务端进程失败') # 关闭ssh iperf_client_sshclient.closeSSHAndSFTP() iperf_server_sshclient.closeSSHAndSFTP()