def chunkserver_log_create(): try: mkdir_cmd = "mkdir -p %s + '/' + %s" %(config.curve_workspace, config.chunkserver_log_dir) shell_operator.run_exec(mkdir_cmd) except Exception: logger.error("mkdir for chunkserver dir fail.") raise
def stop_chunkserver(): try: stop_cmd = "cd %s && %s" %(config.curve_workspace, config.chunkserver_stop_script) shell_operator.run_exec(stop_cmd) except Exception: logger.error("stop chunkserver fail.") raise
def cat_chunkserver_log(chunkserver_id): chunkserver_log = config.chunkserver_log_dir + chunkserver_id cmd = "cat %s" % chunkserver_log logger.debug("%scmdcmd" % cmd) if os.path.exists(chunkserver_log): shell_operator.run_exec(cmd) else: logger.error("chunkserver log not exists!")
def deploy_all_servers(): try: cmd = "/home/nbs/.curveadm/bin/curveadm cluster checkout citest" ret = shell_operator.run_exec(cmd) assert ret == 0 ,"checkout fail" cmd = "/home/nbs/.curveadm/bin/curveadm deploy" ret = shell_operator.run_exec(cmd) assert ret == 0 ,"deploy mds\etcd\metaserver fail" except Exception: logger.error("deploy curvefs fail.") raise
def use_ansible_deploy(): try: cmd = "cp robot/ansible_deploy.sh . && bash ansible_deploy.sh" ret = shell_operator.run_exec(cmd) assert ret == 0 ,"ansible deploy fail" host = config.client_list[0] cmd = "scp -i %s -o StrictHostKeyChecking=no -P 1046 %s:/etc/curve/client.conf ."%\ (config.pravie_key_path,host) ret = shell_operator.run_exec(cmd) assert ret == 0 ,"cp client.conf fail" except Exception: logger.error("deploy curve fail.") raise
def destroy_curvefs(): try: test_client = config.fs_test_client[0] ssh = shell_operator.create_ssh_connect(test_client, 1046, config.abnormal_user) for mountpoint in config.fs_mount_dir: cmd = "sudo /home/nbs/.curveadm/bin/curveadm umount %s%s"%(config.fs_mount_path,mountpoint) shell_operator.ssh_exec(ssh, cmd) cmd = "/home/nbs/.curveadm/bin/curveadm stop" ret = shell_operator.run_exec(cmd) cmd = "echo 'y' | /home/nbs/.curveadm/bin/curveadm clean" ret = shell_operator.run_exec(cmd) except Exception: logger.error("destroy curvefs fail.") raise
def test_out_metaserver_copyset(): test_client = config.fs_test_client[0] ssh = shell_operator.create_ssh_connect(test_client, 1046, config.abnormal_user) ori_cmd = "/home/nbs/.curveadm/bin/curveadm status --role=metaserver |grep metaserver| awk '{print $1}'" rs = shell_operator.run_exec2(ori_cmd) logger.info("rs is %s" % rs) rs = rs.split('\n') meta_docker = random.choice(rs) ori_cmd = "/home/nbs/.curveadm/bin/curveadm stop --id=%s" % meta_docker logger.info("|------begin test out one metaserver,docker %s------|" % (meta_docker)) try: rs = shell_operator.run_exec(ori_cmd) assert rs == 0, "stop metaserver fail" time.sleep(120) # begin_num = get_metaserver_copyset_num(chunkserver_host,cs_list[0]) starttime = time.time() while time.time() - starttime < 1200: status = check_fs_copyset_status() if status == True: break time.sleep(60) logger.info("copyset is unhealthy") assert status == True, "cluster metaserver %s not recover finish in %d" % ( meta_docker, 120) except Exception as e: # raise AssertionError() logger.error("error is %s" % e) test_start_process("metaserver") raise
def test_start_process(process_name): try: cmd = "/home/nbs/.curveadm/bin/curveadm start --role=%s" % process_name ret = shell_operator.run_exec(cmd) assert ret == 0, "start %s fail" % process_name except Exception as e: raise
def change_cfg(): try: cmd = "bash %s/change_cfg.sh"%config.fs_cfg_path ret = shell_operator.run_exec(cmd) assert ret == 0 ,"change fs cfg fail" except Exception: logger.error("change fs cfg fail.") raise
def destroy_curvefs(): try: test_client = config.fs_test_client[0] ssh = shell_operator.create_ssh_connect(test_client, 1046, config.abnormal_user) cmd = "/home/nbs/.curveadm/bin/curveadm cluster checkout citest" ret = shell_operator.run_exec(cmd) assert ret == 0 ,"checkout fail" for mountpoint in config.fs_mount_dir: cmd = "sudo /home/nbs/.curveadm/bin/curveadm umount %s%s"%(config.fs_mount_path,mountpoint) shell_operator.ssh_exec(ssh, cmd) cmd = "echo 'yes' | /home/nbs/.curveadm/bin/curveadm stop" ret = shell_operator.run_exec(cmd) cmd = "echo 'yes' | /home/nbs/.curveadm/bin/curveadm clean --only='data,container'" ret = shell_operator.run_exec(cmd) except Exception: logger.error("destroy curvefs fail.") raise
def create_physicalpool(cluster_map, mds_addr, op): #need modify cmd = config.curvefs_tool + ' -cluster_map=%s' % cluster_map + ' -mds_addr=%s' % mds_addr + \ ' -op=%s' % op ret_code = shell_operator.run_exec(cmd) if ret_code != 0: logger.error("create physicalpool failed. ret_code is %d" % ret_code) raise AssertionError() else: return ret_code
def destroy_test_env(): try: cmd = "cp robot/init_env.sh . && bash init_env.sh" ret = shell_operator.run_exec(cmd) assert ret == 0 ,"init env fail" host = config.client_list[0] except Exception: logger.error("init env fail.") raise
def kill_process(process_name): grep_cmd = "ps -ef | grep %s | grep -v grep | awk '{print $2}' " % process_name pids = shell_operator.run_exec2(grep_cmd) logger.info("pid=%s" % pids) if pids: kill_cmd = "ps -ef | grep %s | grep -v grep | awk '{print $2}' | sudo xargs kill -9" % process_name ret_code = shell_operator.run_exec(kill_cmd) if ret_code == 0: return 0 else: logger.error("kill process fail %s" % process_name) else: logger.debug("process %s not start." % process_name)
def run_libcurve_test(fake_mds, fake_chunkserver): cmd = config.libcurve_workflow + ' -fake_mds=%s' % fake_mds + ' -fake_chunkserver=%s' % fake_chunkserver ret_code = shell_operator.run_exec(cmd) print ret_code, cmd assert ret_code == 0
def clean_etcd_data(): shell_operator.run_exec("rm -rf default.etcd")
def recycle_chunk(): cmd = "ansible-playbook -i curve/curve-ansible/server.ini curve/curve-ansible/clean_curve.yml --tags chunkserver" ret = shell_operator.run_exec(cmd) assert ret == 0 ,"ansible clean chunk fail"